P-SEAMLDR returns its information e.g., version and supported features, in
response to the SEAMLDR.INFO SEAMCALL.
This information is useful for userspace. For example, the admin can decide
which TDX module versions are compatible with the P-SEAMLDR according to
the P-SEAMLDR version.
Add and export seamldr_get_info() which retrieves P-SEAMLDR information by
invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR
version and other necessary information to userspace.
Signed-off-by: Chao Gao <chao.gao@intel.com>
Tested-by: Farrah Chen <farrah.chen@intel.com>
---
arch/x86/include/asm/seamldr.h | 27 +++++++++++++++++++++++++++
arch/x86/virt/vmx/tdx/seamldr.c | 17 ++++++++++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 arch/x86/include/asm/seamldr.h
diff --git a/arch/x86/include/asm/seamldr.h b/arch/x86/include/asm/seamldr.h
new file mode 100644
index 000000000000..d1e9f6e16e8d
--- /dev/null
+++ b/arch/x86/include/asm/seamldr.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SEAMLDR_H
+#define _ASM_X86_SEAMLDR_H
+
+#include <linux/types.h>
+
+struct seamldr_info {
+ u32 version;
+ u32 attributes;
+ u32 vendor_id;
+ u32 build_date;
+ u16 build_num;
+ u16 minor_version;
+ u16 major_version;
+ u16 update_version;
+ u8 reserved0[4];
+ u32 num_remaining_updates;
+ u8 reserved1[224];
+} __packed;
+
+#ifdef CONFIG_INTEL_TDX_MODULE_UPDATE
+const struct seamldr_info *seamldr_get_info(void);
+#else
+static inline const struct seamldr_info *seamldr_get_info(void) { return NULL; }
+#endif
+
+#endif
diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
index b99d73f7bb08..6a83ae405fac 100644
--- a/arch/x86/virt/vmx/tdx/seamldr.c
+++ b/arch/x86/virt/vmx/tdx/seamldr.c
@@ -9,9 +9,16 @@
#include <linux/irqflags.h>
#include <linux/types.h>
+#include <asm/seamldr.h>
+
#include "seamcall.h"
-static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
+/* P-SEAMLDR SEAMCALL leaf function */
+#define P_SEAMLDR_INFO 0x8000000000000000
+
+static struct seamldr_info seamldr_info __aligned(256);
+
+static inline int seamldr_call(u64 fn, struct tdx_module_args *args)
{
unsigned long flags;
u64 vmcs;
@@ -54,3 +61,11 @@ static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
WARN_ONCE(1, "Failed to save/restore the current VMCS");
return -EIO;
}
+
+const struct seamldr_info *seamldr_get_info(void)
+{
+ struct tdx_module_args args = { .rcx = __pa(&seamldr_info) };
+
+ return seamldr_call(P_SEAMLDR_INFO, &args) ? NULL : &seamldr_info;
+}
+EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host");
--
2.47.3
On 1/23/26 06:55, Chao Gao wrote: > +static struct seamldr_info seamldr_info __aligned(256); I also wonder if this should be __read_mostly or even read-only after boot. Is it ever modified?
On Wed, Jan 28, 2026 at 03:57:30PM -0800, Dave Hansen wrote: >On 1/23/26 06:55, Chao Gao wrote: >> +static struct seamldr_info seamldr_info __aligned(256); > >I also wonder if this should be __read_mostly or even read-only after >boot. Is it ever modified? This should be __read_mostly. num_remaining_updates changes after successful updates.
On 1/23/26 06:55, Chao Gao wrote:
> P-SEAMLDR returns its information e.g., version and supported features, in
> response to the SEAMLDR.INFO SEAMCALL.
>
> This information is useful for userspace. For example, the admin can decide
> which TDX module versions are compatible with the P-SEAMLDR according to
> the P-SEAMLDR version.
>
> Add and export seamldr_get_info() which retrieves P-SEAMLDR information by
I don't need to know what the function name is. That's in the code.
> invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR
> version and other necessary information to userspace.
I also want to know what spec you are getting this out of.
I think it's also worth calling out that there are SEAMLDR calls for both:
SEAMLDR_INFO
and
SEAMLDR_SEAMINFO
Which is astonishingly confusing. Please have mercy on folks that are
looking through the docs for the first time and explain this.
> diff --git a/arch/x86/include/asm/seamldr.h b/arch/x86/include/asm/seamldr.h
> new file mode 100644
> index 000000000000..d1e9f6e16e8d
> --- /dev/null
> +++ b/arch/x86/include/asm/seamldr.h
> @@ -0,0 +1,27 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_X86_SEAMLDR_H
> +#define _ASM_X86_SEAMLDR_H
> +
> +#include <linux/types.h>
> +
> +struct seamldr_info {
/*
* This called the "SEAMLDR_INFO" data structure and is defined
* in "SEAM Loader (SEAMLDR) Interface Specification".
*/
> + u32 version;
> + u32 attributes;
> + u32 vendor_id;
> + u32 build_date;
> + u16 build_num;
> + u16 minor_version;
> + u16 major_version;
> + u16 update_version;
> + u8 reserved0[4];
Why not label this:
u32 acm_x2apicid: /* unused by kernel */
?
> + u32 num_remaining_updates;
> + u8 reserved1[224];
> +} __packed;
> +
> +#ifdef CONFIG_INTEL_TDX_MODULE_UPDATE
> +const struct seamldr_info *seamldr_get_info(void);
> +#else
> +static inline const struct seamldr_info *seamldr_get_info(void) { return NULL; }
> +#endif
> +
> +#endif
> diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
> index b99d73f7bb08..6a83ae405fac 100644
> --- a/arch/x86/virt/vmx/tdx/seamldr.c
> +++ b/arch/x86/virt/vmx/tdx/seamldr.c
> @@ -9,9 +9,16 @@
> #include <linux/irqflags.h>
> #include <linux/types.h>
>
> +#include <asm/seamldr.h>
> +
> #include "seamcall.h"
>
> -static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
> +/* P-SEAMLDR SEAMCALL leaf function */
> +#define P_SEAMLDR_INFO 0x8000000000000000
/*
* The SEAMLDR.INFO documentation requires
* this to be aligned to a 256-byte boundary.
*/
> +static struct seamldr_info seamldr_info __aligned(256);
> +
> +static inline int seamldr_call(u64 fn, struct tdx_module_args *args)
> {
> unsigned long flags;
> u64 vmcs;
> @@ -54,3 +61,11 @@ static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
> WARN_ONCE(1, "Failed to save/restore the current VMCS");
> return -EIO;
> }
> +
> +const struct seamldr_info *seamldr_get_info(void)
> +{
> + struct tdx_module_args args = { .rcx = __pa(&seamldr_info) };
> +
> + return seamldr_call(P_SEAMLDR_INFO, &args) ? NULL : &seamldr_info;
> +}
> +EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host");
I'd also prefer a
BUILD_BUG_ON(sizeof(struct seamldr_info) != 2048);
just as a sanity check. It doesn't cost anything and it makes sure that
as you muck around with reserved fields and padding that there's at
least one check making sure it's OK.
On Wed, Jan 28, 2026 at 03:54:38PM -0800, Dave Hansen wrote:
>On 1/23/26 06:55, Chao Gao wrote:
>> P-SEAMLDR returns its information e.g., version and supported features, in
>> response to the SEAMLDR.INFO SEAMCALL.
>>
>> This information is useful for userspace. For example, the admin can decide
>> which TDX module versions are compatible with the P-SEAMLDR according to
>> the P-SEAMLDR version.
>>
>> Add and export seamldr_get_info() which retrieves P-SEAMLDR information by
>
>I don't need to know what the function name is. That's in the code.
>
Hi Dave,
Thank you for the thorough review.
I will go through the following patches to ensure they don't have the same
issues you have pointed out.
>> invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR
>> version and other necessary information to userspace.
>
>I also want to know what spec you are getting this out of.
Will add a link in the changelog.
>
>I think it's also worth calling out that there are SEAMLDR calls for both:
>
> SEAMLDR_INFO
>and
> SEAMLDR_SEAMINFO
>
>Which is astonishingly confusing. Please have mercy on folks that are
>looking through the docs for the first time and explain this.
Sorry about this. Will do.
>
>> diff --git a/arch/x86/include/asm/seamldr.h b/arch/x86/include/asm/seamldr.h
>> new file mode 100644
>> index 000000000000..d1e9f6e16e8d
>> --- /dev/null
>> +++ b/arch/x86/include/asm/seamldr.h
>> @@ -0,0 +1,27 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +#ifndef _ASM_X86_SEAMLDR_H
>> +#define _ASM_X86_SEAMLDR_H
>> +
>> +#include <linux/types.h>
>> +
>> +struct seamldr_info {
>
>/*
> * This called the "SEAMLDR_INFO" data structure and is defined
> * in "SEAM Loader (SEAMLDR) Interface Specification".
> */
Will do.
>
>
>> + u32 version;
>> + u32 attributes;
>> + u32 vendor_id;
>> + u32 build_date;
>> + u16 build_num;
>> + u16 minor_version;
>> + u16 major_version;
>> + u16 update_version;
>> + u8 reserved0[4];
>
>Why not label this:
>
> u32 acm_x2apicid: /* unused by kernel */
>
>?
Will do. Probably because I thought the kernel would never use it.
<snip>
>> +const struct seamldr_info *seamldr_get_info(void)
>> +{
>> + struct tdx_module_args args = { .rcx = __pa(&seamldr_info) };
>> +
>> + return seamldr_call(P_SEAMLDR_INFO, &args) ? NULL : &seamldr_info;
>> +}
>> +EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host");
>
>I'd also prefer a
>
> BUILD_BUG_ON(sizeof(struct seamldr_info) != 2048);
>
>just as a sanity check. It doesn't cost anything and it makes sure that
>as you muck around with reserved fields and padding that there's at
>least one check making sure it's OK.
ok.
On 1/30/26 05:55, Chao Gao wrote: ... >>> invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR >>> version and other necessary information to userspace. >> >> I also want to know what spec you are getting this out of. > > Will add a link in the changelog. Remember, as a general rule, links go stale. Document titles and Intel document numbers stay valid for *much* longer. >>> + u32 version; >>> + u32 attributes; >>> + u32 vendor_id; >>> + u32 build_date; >>> + u16 build_num; >>> + u16 minor_version; >>> + u16 major_version; >>> + u16 update_version; >>> + u8 reserved0[4]; >> >> Why not label this: >> >> u32 acm_x2apicid: /* unused by kernel */ >> >> ? > > Will do. Probably because I thought the kernel would never use it. It just makes me think that I'm looking at different documentation for this data structure than you are. It literally costs nothing to give it a real name. Maybe 5 bytes of code or something.
> I'd also prefer a
>
> BUILD_BUG_ON(sizeof(struct seamldr_info) != 2048);
^
BUILD_BUG_ON(sizeof(struct seamldr_info) != 256); is it?
>
> just as a sanity check. It doesn't cost anything and it makes sure that
> as you muck around with reserved fields and padding that there's at
> least one check making sure it's OK.
And I recently received a comments that "never __packed for naturally
aligned structures cause it leads to bad generated code and hurts
performance", but I really want to highlight nearby it is for a
formatted binary blob, so:
struct seamldr_info {
u32 version;
u32 attributes;
u32 vendor_id;
u32 build_date;
u16 build_num;
u16 minor_version;
u16 major_version;
u16 update_version;
u8 reserved0[4];
u32 num_remaining_updates;
u8 reserved1[224];
}; //delete __packed here
static_assert(sizeof(struct seamldr_info) == 256);
Is it better?
On 1/29/26 20:01, Xu Yilun wrote:
>> I'd also prefer a
>>
>> BUILD_BUG_ON(sizeof(struct seamldr_info) != 2048);
> ^
> BUILD_BUG_ON(sizeof(struct seamldr_info) != 256); is it?
Whatever the documentation says. I might have been looking at the
seamldr_seaminfo.
>> just as a sanity check. It doesn't cost anything and it makes sure that
>> as you muck around with reserved fields and padding that there's at
>> least one check making sure it's OK.
>
> And I recently received a comments that "never __packed for naturally
> aligned structures cause it leads to bad generated code and hurts
> performance", but I really want to highlight nearby it is for a
> formatted binary blob, so:
>
> struct seamldr_info {
> u32 version;
> u32 attributes;
> u32 vendor_id;
> u32 build_date;
> u16 build_num;
> u16 minor_version;
> u16 major_version;
> u16 update_version;
> u8 reserved0[4];
> u32 num_remaining_updates;
> u8 reserved1[224];
> }; //delete __packed here
>
> static_assert(sizeof(struct seamldr_info) == 256);
>
> Is it better?
I'm pretty sure __packed is used all over the place.
I'd be shocked if access to a __packed structure generated different
code than a non-packed one for the same layout. But it wouldn't be the
first time I was shocked by a compiler.
I think you might be confusing the fact that access to unaligned data
can really stink on some architectures. The code generation for *that*
can be garbage. But not on x86 really and not for data that's already
naturally aligned.
Plus, *this* data structure is far, far from being performance sensitive
anyway. So it doubly or triply doesn't matter here.
If nothing else, __packed is a good indicator that WYSIWYG for structure
layout because it's an ABI. I honestly don't see a lot of downsides.
> If nothing else, __packed is a good indicator that WYSIWYG for structure > layout because it's an ABI. I honestly don't see a lot of downsides. OK. So on x86 I can use it without worry. Thanks.
On 1/23/2026 10:55 PM, Chao Gao wrote:
> P-SEAMLDR returns its information e.g., version and supported features, in
> response to the SEAMLDR.INFO SEAMCALL.
>
> This information is useful for userspace. For example, the admin can decide
> which TDX module versions are compatible with the P-SEAMLDR according to
> the P-SEAMLDR version.
>
> Add and export seamldr_get_info() which retrieves P-SEAMLDR information by
> invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR
> version and other necessary information to userspace.
>
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> Tested-by: Farrah Chen <farrah.chen@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
One nit below.
[...]
> diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
> index b99d73f7bb08..6a83ae405fac 100644
> --- a/arch/x86/virt/vmx/tdx/seamldr.c
> +++ b/arch/x86/virt/vmx/tdx/seamldr.c
> @@ -9,9 +9,16 @@
> #include <linux/irqflags.h>
> #include <linux/types.h>
>
> +#include <asm/seamldr.h>
> +
> #include "seamcall.h"
>
> -static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
> +/* P-SEAMLDR SEAMCALL leaf function */
> +#define P_SEAMLDR_INFO 0x8000000000000000
> +
> +static struct seamldr_info seamldr_info __aligned(256);
> +
> +static inline int seamldr_call(u64 fn, struct tdx_module_args *args)
No need to tag the local function with inline.
> {
> unsigned long flags;
> u64 vmcs;
> @@ -54,3 +61,11 @@ static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *args)
> WARN_ONCE(1, "Failed to save/restore the current VMCS");
> return -EIO;
> }
On Fri, Jan 23, 2026 at 06:55:16AM -0800, Chao Gao wrote: > P-SEAMLDR returns its information e.g., version and supported features, in > response to the SEAMLDR.INFO SEAMCALL. > > This information is useful for userspace. For example, the admin can decide > which TDX module versions are compatible with the P-SEAMLDR according to > the P-SEAMLDR version. > > Add and export seamldr_get_info() which retrieves P-SEAMLDR information by > invoking SEAMLDR.INFO SEAMCALL in preparation for exposing P-SEAMLDR > version and other necessary information to userspace. Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
© 2016 - 2026 Red Hat, Inc.