Skip to contentSkip to conversation

x86/virt/tdx: Formalize SEAMCALL version encoding support

PATCH Superseded Xu Yilun 5 participants 10 messages Jul 22 – Sep 15

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Xu Yilun

author
#0 lore raw

PATCH v3 1/1 x86/virt/tdx: Formalize SEAMCALL version encoding support

SEAMCALL invokes TDX module functions using a function number and parameters. To extend the functionality of existing SEAMCALLs while keeping backward compatibility, TDX adds more numbered SEAMCALLs of the same family. This is just like syscalls, except that TDX defines a specific function number encoding pattern: a base function number and a version together encode the full function number.

One concern is the compatibility with older TDX modules which don't recognize the new SEAMCALLs. The kernel should decide which SEAMCALL version to use at runtime, selecting the minimum version number for the required functionality. It can't overwrite the function number with a new value at compile time.

Another concern is the obscure usage of the 'fn' parameter for SEAMCALL wrappers. An existing caller for TDH.VP.INIT packs the version into the 'fn' to match the low-level TDX ABI RAX layout. The RAX layout interprets some bits differently, such as INTERRUPT_MODE, SEAMLDR flag, which are not a good fit for the function number definition.

Refactor the SEAMCALL wrappers to allow for version selection. Add a version field in struct tdx_module_args [1], so that most existing callers get a default "version == 0" behavior without code churn, while callers requiring extended functionalities can specify the version descriptively. Enforce the 'fn' parameter as the base function number. Encode the base function number and tdx_module_args.version in RAX before invoking the SEAMCALL instruction in assembly code.

---
The main concern in v2 is: should we make 'fn' exactly match the RAX layout of TDX module ABI?

Kiryl's point is that SEAMCALL wrappers are the representation of the ABI functions, so make the 'fn' match the RAX and struct tdx_module_args match the other CPU registers, compose base leaf number & version into 'fn'. This saves callers from digging into low-level code to understand what happens.

Dave's point is that the RAX layout is logically unfriendly, we want SEAMCALL wrappers to be the logically sound software APIs to the rest of the system. So 'fn' only contains the base leaf number, version and other RAX fields are in struct tdx_module_args.

While both options have merits, I chose the latter from a software-centric perspective. I sent v3 to invite more discussion.

Change in v3:
- Move the RAX encoding in assembly code.
- Compile-time check that fn only contain base leaf number bits
- Add the full description of SEAMCALL leaf according to TDX module SPEC
- Fix the description of struct tdx_module_args.

v2: https://lore.kernel.org/all/[email protected]/
- Drop the C wrapper __seamcall_encode_fn()
- Rewrite the first paragraph of the changelog
- Make change log concise
- Add a link to the thread where this was suggested
- Move alternative schemes description below the separator

v1: https://lore.kernel.org/all/[email protected]/

---
 arch/x86/include/asm/shared/tdx.h         | 10 +++++++---
 arch/x86/virt/vmx/tdx/seamcall_internal.h | 19 +++++++++++++++++++
 arch/x86/virt/vmx/tdx/tdx.h               |  8 --------
 arch/x86/virt/vmx/tdx/tdxcall.S           | 10 ++++++++--
 arch/x86/kernel/asm-offsets.c             |  1 +
 arch/x86/virt/vmx/tdx/tdx.c               |  5 +++--
 6 files changed, 38 insertions(+), 15 deletions(-)
arch/x86/include/asm/shared/tdx.h +7 -3
index f20e91d7ac35..67490c330d91 100644
@@ -122,9 +122,11 @@
 #include <linux/compiler_attributes.h>
 
 /*
- * Used in __tdcall*() to gather the input/output registers' values of the
- * TDCALL instruction when requesting services from the TDX module. This is a
- * software only structure and not part of the TDX module/VMM ABI
+ * Used in __tdcall*() to gather the input/output parameters of the TDCALL
+ * instruction when requesting services from the TDX module. 'version' is
+ * encoded in rax along with the Leaf number. Others are raw input/output
+ * registers' values. This is a software only structure and not part of the TDX
+ * module/VMM ABI.
  */
 struct tdx_module_args {
 	/* callee-clobbered */
@@ -143,6 +145,8 @@ struct tdx_module_args {
 	u64 rbx;
 	u64 rdi;
 	u64 rsi;
+	/* Leaf ABI version, encoded in rax */
+	u8  version;
 };
 
 /* Used to communicate with the TDX module */
arch/x86/virt/vmx/tdx/seamcall_internal.h +19 -0
index be5f446467df..c586ddad072f 100644
@@ -11,6 +11,7 @@
 #ifndef _X86_VIRT_SEAMCALL_INTERNAL_H
 #define _X86_VIRT_SEAMCALL_INTERNAL_H
 
+#include <linux/bitfield.h>
 #include <linux/printk.h>
 #include <linux/types.h>
 #include <asm/archrandom.h>
@@ -23,9 +24,27 @@ u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args);
 
 typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args);
 
+/*
+ * SEAMCALL leaf:
+ *
+ * Bit 15:0	Leaf number
+ * Bit 23:16	Leaf ABI version number
+ * Bit 24	Pending interrupts detection mode
+ * Bit 63	1 for P-SEAMLDR leaf, 0 for TDX module leaf
+ */
+#define SEAMCALL_LEAF_MASK		GENMASK_U64(15, 0)
+#define SEAMCALL_SEAMLDR_MASK		BIT_U64(63)
+
 static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,
 						  struct tdx_module_args *args)
 {
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));
+
 	lockdep_assert_preemption_disabled();
 
 	/*
arch/x86/virt/vmx/tdx/tdx.h +0 -8
index bdfd0e1e337a..63e3acfb5d0c 100644
@@ -50,14 +50,6 @@
 #define TDH_SYS_UPDATE			53
 #define TDH_SYS_DISABLE			69
 
-/*
- * SEAMCALL leaf:
- *
- * Bit 15:0	Leaf number
- * Bit 23:16	Version number
- */
-#define TDX_VERSION_SHIFT		16
-
 /* TDX page types */
 #define	PT_NDA		0x0
 #define	PT_RSVD		0x1
arch/x86/virt/vmx/tdx/tdxcall.S +8 -2
index 016a2a1ec1d6..a01542c02c36 100644
@@ -45,8 +45,14 @@
 .macro TDX_MODULE_CALL host:req ret=0 saved=0
 	FRAME_BEGIN
 
-	/* Move Leaf ID to RAX */
-	mov %rdi, %rax
+	/* Leaf ABI version -> RAX[23:16]. Zero rest of RAX. */
+	movzbl	TDX_MODULE_version(%rsi), %eax
+	shl	$16, %eax
+	/*
+	 * Combine base leaf number arg and leaf ABI version into RAX, they
+	 * don't overlap.
+	 */
+	or	%rdi, %rax
 
 	/* Move other input regs from 'struct tdx_module_args' */
 	movq	TDX_MODULE_rcx(%rsi), %rcx
arch/x86/kernel/asm-offsets.c +1 -0
index 081816888f7a..b3c00ff4d819 100644
@@ -95,6 +95,7 @@ static void __used common(void)
 	OFFSET(TDX_MODULE_rbx, tdx_module_args, rbx);
 	OFFSET(TDX_MODULE_rdi, tdx_module_args, rdi);
 	OFFSET(TDX_MODULE_rsi, tdx_module_args, rsi);
+	OFFSET(TDX_MODULE_version, tdx_module_args, version);
 
 	BLANK();
 	OFFSET(BP_scratch, boot_params, scratch);
arch/x86/virt/vmx/tdx/tdx.c +3 -2
index 42df8ea464c4..7a89e29b118c 100644
@@ -1910,10 +1910,11 @@ u64 tdh_vp_init(struct tdx_vp *vp, u64 initial_rcx, u32 x2apicid)
 		.rcx = vp->tdvpr_pa,
 		.rdx = initial_rcx,
 		.r8 = x2apicid,
+		/* apicid requires version == 1. */
+		.version = 1,
 	};
 
-	/* apicid requires version == 1. */
-	return seamcall(TDH_VP_INIT | (1ULL << TDX_VERSION_SHIFT), &args);
+	return seamcall(TDH_VP_INIT, &args);
 }
 EXPORT_SYMBOL_FOR_KVM(tdh_vp_init);
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 2 lines · Xu Yilun

While both options have merits, I chose the latter from a software-centric perspective. I sent v3 to invite more discussion.

I still don't see what postponing the encoding to assembly buys us, but it is not the hill I want to die on. The result is centralized and correct, so let's move on.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
author
#2 lore raw
Quoted 5 lines · Kiryl Shutsemau
Quoted 2 lines · Xu Yilun

While both options have merits, I chose the latter from a software-centric perspective. I sent v3 to invite more discussion.

I still don't see what postponing the encoding to assembly buys us,

Sorry, I overlooked it. I think this gives us consistent view of what 'fn' is for all seamcall-related functions.

Quoted 4 lines

but it is not the hill I want to die on. The result is centralized and correct, so let's move on.

Thanks!

Reviewed-by on v3 1/1
#3 lore raw
In reply to Xu Yilun
Quoted 27 lines · Xu Yilun

SEAMCALL invokes TDX module functions using a function number and parameters. To extend the functionality of existing SEAMCALLs while keeping backward compatibility, TDX adds more numbered SEAMCALLs of the same family. This is just like syscalls, except that TDX defines a specific function number encoding pattern: a base function number and a version together encode the full function number.

One concern is the compatibility with older TDX modules which don't recognize the new SEAMCALLs. The kernel should decide which SEAMCALL version to use at runtime, selecting the minimum version number for the required functionality. It can't overwrite the function number with a new value at compile time.

Another concern is the obscure usage of the 'fn' parameter for SEAMCALL wrappers. An existing caller for TDH.VP.INIT packs the version into the 'fn' to match the low-level TDX ABI RAX layout. The RAX layout interprets some bits differently, such as INTERRUPT_MODE, SEAMLDR flag, which are not a good fit for the function number definition.

Refactor the SEAMCALL wrappers to allow for version selection. Add a version field in struct tdx_module_args [1], so that most existing callers get a default "version == 0" behavior without code churn, while callers requiring extended functionalities can specify the version descriptively. Enforce the 'fn' parameter as the base function number. Encode the base function number and tdx_module_args.version in RAX before invoking the SEAMCALL instruction in assembly code.

Quoted 3 lines

---

#4 lore raw
In reply to Xu Yilun
Quoted 39 lines · Xu Yilun

SEAMCALL invokes TDX module functions using a function number and parameters. To extend the functionality of existing SEAMCALLs while keeping backward compatibility, TDX adds more numbered SEAMCALLs of the same family. This is just like syscalls, except that TDX defines a specific function number encoding pattern: a base function number and a version together encode the full function number.

One concern is the compatibility with older TDX modules which don't recognize the new SEAMCALLs. The kernel should decide which SEAMCALL version to use at runtime, selecting the minimum version number for the required functionality. It can't overwrite the function number with a new value at compile time.

Another concern is the obscure usage of the 'fn' parameter for SEAMCALL wrappers. An existing caller for TDH.VP.INIT packs the version into the 'fn' to match the low-level TDX ABI RAX layout. The RAX layout interprets some bits differently, such as INTERRUPT_MODE, SEAMLDR flag, which are not a good fit for the function number definition.

Refactor the SEAMCALL wrappers to allow for version selection. Add a version field in struct tdx_module_args [1], so that most existing callers get a default "version == 0" behavior without code churn, while callers requiring extended functionalities can specify the version descriptively. Enforce the 'fn' parameter as the base function number. Encode the base function number and tdx_module_args.version in RAX before invoking the SEAMCALL instruction in assembly code.

---
The main concern in v2 is: should we make 'fn' exactly match the RAX layout of TDX module ABI?

Kiryl's point is that SEAMCALL wrappers are the representation of the ABI functions, so make the 'fn' match the RAX and struct tdx_module_args match the other CPU registers, compose base leaf number & version into 'fn'. This saves callers from digging into low-level code to understand what happens.

Quoted 7 lines

Dave's point is that the RAX layout is logically unfriendly, we want SEAMCALL wrappers to be the logically sound software APIs to the rest of the system. So 'fn' only contains the base leaf number, version and other RAX fields are in struct tdx_module_args.

While both options have merits, I chose the latter from a software-centric perspective. I sent v3 to invite more discussion.

Yea, I think it's good enough. Let's keep the option to revisit it if needed, when we get to shrinking the layers of seamcall wrappers. One question below...

Quoted 79 lines

Change in v3:
- Move the RAX encoding in assembly code.
- Compile-time check that fn only contain base leaf number bits
- Add the full description of SEAMCALL leaf according to TDX module SPEC
- Fix the description of struct tdx_module_args.

v2: https://lore.kernel.org/all/[email protected]/
- Drop the C wrapper __seamcall_encode_fn()
- Rewrite the first paragraph of the changelog
- Make change log concise
- Add a link to the thread where this was suggested
- Move alternative schemes description below the separator

v1: https://lore.kernel.org/all/[email protected]/

---
 arch/x86/include/asm/shared/tdx.h         | 10 +++++++---
 arch/x86/virt/vmx/tdx/seamcall_internal.h | 19 +++++++++++++++++++
 arch/x86/virt/vmx/tdx/tdx.h               |  8 --------
 arch/x86/virt/vmx/tdx/tdxcall.S           | 10 ++++++++--
 arch/x86/kernel/asm-offsets.c             |  1 +
 arch/x86/virt/vmx/tdx/tdx.c               |  5 +++--
 6 files changed, 38 insertions(+), 15 deletions(-)
arch/x86/include/asm/shared/tdx.h +7 -3
index f20e91d7ac35..67490c330d91 100644
@@ -122,9 +122,11 @@
 #include <linux/compiler_attributes.h>
 
 /*
- * Used in __tdcall*() to gather the input/output registers' values of the
- * TDCALL instruction when requesting services from the TDX module. This is a
- * software only structure and not part of the TDX module/VMM ABI
+ * Used in __tdcall*() to gather the input/output parameters of the TDCALL
+ * instruction when requesting services from the TDX module. 'version' is
+ * encoded in rax along with the Leaf number. Others are raw input/output
+ * registers' values. This is a software only structure and not part of the TDX
+ * module/VMM ABI.
  */
 struct tdx_module_args {
 	/* callee-clobbered */
@@ -143,6 +145,8 @@ struct tdx_module_args {
 	u64 rbx;
 	u64 rdi;
 	u64 rsi;
+	/* Leaf ABI version, encoded in rax */
+	u8  version;
 };
 
 /* Used to communicate with the TDX module */
arch/x86/virt/vmx/tdx/seamcall_internal.h +12 -0
index be5f446467df..c586ddad072f 100644
@@ -11,6 +11,7 @@
 #ifndef _X86_VIRT_SEAMCALL_INTERNAL_H
 #define _X86_VIRT_SEAMCALL_INTERNAL_H
 
+#include <linux/bitfield.h>
 #include <linux/printk.h>
 #include <linux/types.h>
 #include <asm/archrandom.h>
@@ -23,9 +24,27 @@ u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args);
 
 typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args);
 
+/*
+ * SEAMCALL leaf:
+ *
+ * Bit 15:0	Leaf number
+ * Bit 23:16	Leaf ABI version number
+ * Bit 24	Pending interrupts detection mode
+ * Bit 63	1 for P-SEAMLDR leaf, 0 for TDX module leaf
+ */
+#define SEAMCALL_LEAF_MASK		GENMASK_U64(15, 0)
+#define SEAMCALL_SEAMLDR_MASK		BIT_U64(63)
+

arch/x86/virt/vmx/tdx/seamcall_internal.h u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); · line 47

Quoted 10 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +7 -0
 static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,
 						  struct tdx_module_args *args)
 {
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));
+

I guess this works because the __always_inline is enough for the compiler to trace fn to a compile time constant up the callchain. It seems somewhat compiler sensitive though. Did you convince yourself somehow that some compiler will not complain?

Quoted 73 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +0 -0
 	lockdep_assert_preemption_disabled();
 
 	/*
arch/x86/virt/vmx/tdx/tdx.h +0 -8
index bdfd0e1e337a..63e3acfb5d0c 100644
@@ -50,14 +50,6 @@
 #define TDH_SYS_UPDATE			53
 #define TDH_SYS_DISABLE			69
 
-/*
- * SEAMCALL leaf:
- *
- * Bit 15:0	Leaf number
- * Bit 23:16	Version number
- */
-#define TDX_VERSION_SHIFT		16
-
 /* TDX page types */
 #define	PT_NDA		0x0
 #define	PT_RSVD		0x1
arch/x86/virt/vmx/tdx/tdxcall.S +8 -2
index 016a2a1ec1d6..a01542c02c36 100644
@@ -45,8 +45,14 @@
 .macro TDX_MODULE_CALL host:req ret=0 saved=0
 	FRAME_BEGIN
 
-	/* Move Leaf ID to RAX */
-	mov %rdi, %rax
+	/* Leaf ABI version -> RAX[23:16]. Zero rest of RAX. */
+	movzbl	TDX_MODULE_version(%rsi), %eax
+	shl	$16, %eax
+	/*
+	 * Combine base leaf number arg and leaf ABI version into RAX, they
+	 * don't overlap.
+	 */
+	or	%rdi, %rax
 
 	/* Move other input regs from 'struct tdx_module_args' */
 	movq	TDX_MODULE_rcx(%rsi), %rcx
arch/x86/kernel/asm-offsets.c +1 -0
index 081816888f7a..b3c00ff4d819 100644
@@ -95,6 +95,7 @@ static void __used common(void)
 	OFFSET(TDX_MODULE_rbx, tdx_module_args, rbx);
 	OFFSET(TDX_MODULE_rdi, tdx_module_args, rdi);
 	OFFSET(TDX_MODULE_rsi, tdx_module_args, rsi);
+	OFFSET(TDX_MODULE_version, tdx_module_args, version);
 
 	BLANK();
 	OFFSET(BP_scratch, boot_params, scratch);
arch/x86/virt/vmx/tdx/tdx.c +3 -2
index 42df8ea464c4..7a89e29b118c 100644
@@ -1910,10 +1910,11 @@ u64 tdh_vp_init(struct tdx_vp *vp, u64 initial_rcx, u32 x2apicid)
 		.rcx = vp->tdvpr_pa,
 		.rdx = initial_rcx,
 		.r8 = x2apicid,
+		/* apicid requires version == 1. */
+		.version = 1,
 	};
 
-	/* apicid requires version == 1. */
-	return seamcall(TDH_VP_INIT | (1ULL << TDX_VERSION_SHIFT), &args);
+	return seamcall(TDH_VP_INIT, &args);
 }
 EXPORT_SYMBOL_FOR_KVM(tdh_vp_init);
 
author
#5 lore raw
Quoted 7 lines
Quoted 7 lines

static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,

arch/x86/virt/vmx/tdx/seamcall_internal.h +4 -0
 						  struct tdx_module_args *args)
 {
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
Quoted 8 lines

arch/x86/virt/vmx/tdx/seamcall_internal.h u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); · line 47

Quoted 3 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +3 -0
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));
+

I guess this works because the __always_inline is enough for the compiler to trace fn to a compile time constant up the callchain. It seems somewhat compiler sensitive though. Did you convince yourself somehow that some compiler will not complain?

I see the previous talk [1][2], that existing __seamcall*() rely on the direct call, though there is no guarantee. We accept the assumption until there is compiler issue. So I think this doesn't add more problem.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] 0b3bc018e86a ("x86/virt/tdx: Avoid indirect calls to TDX assembly function")

#6 lore raw
Quoted 7 lines · Xu Yilun
Quoted 6 lines

I guess this works because the __always_inline is enough for the compiler to trace fn to a compile time constant up the callchain. It seems somewhat compiler
sensitive though. Did you convince yourself somehow that some compiler will not
complain?

Quoted 8 lines

I see the previous talk [1][2], that existing __seamcall*() rely on the direct call, though there is no guarantee. We accept the assumption until there is compiler issue. So I think this doesn't add more problem.

[1]
https://lore.kernel.org/lkml/[email protected]/
[2] 0b3bc018e86a ("x86/virt/tdx: Avoid indirect calls to TDX assembly function")

Oh, right. It is one more layer of function it has to track it through compared to that case, but LGTM.

Reviewed-by on v3 1/1
#7 lore raw
In reply to Xu Yilun
Quoted 11 lines · Xu Yilun

...

arch/x86/virt/vmx/tdx/seamcall_internal.h +10 -0
+/*
+ * SEAMCALL leaf:
+ *
+ * Bit 15:0	Leaf number
+ * Bit 23:16	Leaf ABI version number
+ * Bit 24	Pending interrupts detection mode
+ * Bit 63	1 for P-SEAMLDR leaf, 0 for TDX module leaf
+ */
+#define SEAMCALL_LEAF_MASK		GENMASK_U64(15, 0)
+#define SEAMCALL_SEAMLDR_MASK		BIT_U64(63)

arch/x86/virt/vmx/tdx/seamcall_internal.h u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); · line 46

Quoted 10 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +7 -0
+
 static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,
 						  struct tdx_module_args *args)
 {
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));

The changelog lists the SEAMLDR flag among the RAX fields that are not a good fit for the function number definition, but 'fn' still carries it. Why does 'version' get a field in struct tdx_module_args while the SEAMLDR flag stays in 'fn'?

Otherwise, looks fine.

author
#8 lore raw
Quoted 16 lines · Kishen Maloor
Quoted 15 lines · Xu Yilun

...

arch/x86/virt/vmx/tdx/seamcall_internal.h +11 -0
+/*
+ * SEAMCALL leaf:
+ *
+ * Bit 15:0	Leaf number
+ * Bit 23:16	Leaf ABI version number
+ * Bit 24	Pending interrupts detection mode
+ * Bit 63	1 for P-SEAMLDR leaf, 0 for TDX module leaf
+ */
+#define SEAMCALL_LEAF_MASK		GENMASK_U64(15, 0)
+#define SEAMCALL_SEAMLDR_MASK		BIT_U64(63)
+
 static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,
 						  struct tdx_module_args *args)
 {
Quoted 8 lines

arch/x86/virt/vmx/tdx/seamcall_internal.h u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); · line 46

Quoted 6 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +6 -0
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));

The changelog lists the SEAMLDR flag among the RAX fields that are not a good fit for the function number definition, but 'fn' still carries it. Why does 'version'

Yeah, it makes confusion. I deleted these words in v6 [1].

Quoted 1 line

get a field in struct tdx_module_args while the SEAMLDR flag stays in 'fn'?

Because SEAMLDR flag is now defined as a part of the leaf number for SEAM loader calls, for example:

/* P-SEAMLDR SEAMCALL leaf function */
#define P_SEAMLDR_INFO 0x8000000000000000
#define P_SEAMLDR_INSTALL 0x8000000000000001

Quoted 4 lines

Otherwise, looks fine.

I assume you are also good to the v6 and added your RB, please let me know if you object.

[1]: https://lore.kernel.org/all/[email protected]/

Thanks,
Yilun

#9 lore raw
Quoted 28 lines · Xu Yilun
Quoted 16 lines · Kishen Maloor
Quoted 15 lines · Xu Yilun

...

arch/x86/virt/vmx/tdx/seamcall_internal.h +11 -0
+/*
+ * SEAMCALL leaf:
+ *
+ * Bit 15:0	Leaf number
+ * Bit 23:16	Leaf ABI version number
+ * Bit 24	Pending interrupts detection mode
+ * Bit 63	1 for P-SEAMLDR leaf, 0 for TDX module leaf
+ */
+#define SEAMCALL_LEAF_MASK		GENMASK_U64(15, 0)
+#define SEAMCALL_SEAMLDR_MASK		BIT_U64(63)
+
 static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn,
 						  struct tdx_module_args *args)
 {
Quoted 8 lines

arch/x86/virt/vmx/tdx/seamcall_internal.h u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); · line 46

Quoted 6 lines
arch/x86/virt/vmx/tdx/seamcall_internal.h +6 -0
+	/*
+	 * fn contains base leaf number for TDX module calls and P-SEAMLDR
+	 * calls. Other fields in SEAMCALL leaf like leaf ABI version number
+	 * are in struct tdx_module_args.
+	 */
+	BUILD_BUG_ON(fn & ~(SEAMCALL_LEAF_MASK | SEAMCALL_SEAMLDR_MASK));

The changelog lists the SEAMLDR flag among the RAX fields that are not a good fit for the function number definition, but 'fn' still carries it. Why does 'version'

Yeah, it makes confusion. I deleted these words in v6 [1].

Quoted 8 lines
Quoted 1 line

get a field in struct tdx_module_args while the SEAMLDR flag stays in 'fn'?

Because SEAMLDR flag is now defined as a part of the leaf number for SEAM loader calls, for example:

/* P-SEAMLDR SEAMCALL leaf function */
#define P_SEAMLDR_INFO 0x8000000000000000
#define P_SEAMLDR_INSTALL 0x8000000000000001

Okay.

Quoted 8 lines
Quoted 5 lines

Otherwise, looks fine.

I assume you are also good to the v6 and added your RB, please let me know if you object.

Yes, v6 looks better, and you may include my RB.

Thanks!