Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v4 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs
@ 2026-12-04 10:59 Chao Gao
  2026-12-04 10:59 ` [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao
  2026-12-04 10:59 ` [PATCH v4 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao
  0 siblings, 2 replies; 4+ messages in thread
From: Chao Gao @ 2026-12-04 10:59 UTC (permalink / raw)
  To: x86, linux-coco, kvm, linux-kernel
  Cc: yilun.xu, arjan.van.de.ven, binbin.wu, Chao Gao, Kiryl Shutsemau,
	Rick Edgecombe, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin

This series lets TDX module updates handle large TDX modules and
sigstructs.

Dave, feel free to ignore this series for now. TDX developers, please
take a look. I would like to collect Reviewed-by tags on this version.

== Changes ==
Changes since v3:

The biggest change is that 'struct seamldr_params' now matches the new
ABI layout. In v3 it was one large array of module page addresses, and
the pointers that chain the pages were written into that array wherever
an entry fell at the end of a page. That kept the diff small, but the
code did not show the layout. Now the structure spells it out: 495
addresses and a pointer in the first page, then pages of 511 addresses
and a pointer each.

- Make 'struct seamldr_params' follow the ABI layout [Dave/Rick]
- Populate module page addresses in a new helper and leave
  populate_pa_list() untouched.
- Add a diagram of the old and new layouts to patch 1. [Dave]
- Describe the ABI changes in more detail in both changelogs.
- Explain the design decisions in patch 1 and the reasons for them.

v3: https://lore.kernel.org/all/20261119074925.3933804-1-chao.gao@intel.com/
v2: https://lore.kernel.org/all/20261106132159.1551365-1-chao.gao@intel.com/
v1: https://lore.kernel.org/kvm/20261030085304.3886520-1-chao.gao@intel.com/

===

This series is a follow-up to the TDX module update series. As thanks
for merging that series, we agreed to take on the TDX metadata cleanup [1].
With the cleanup converging, we are starting on this work and expect it
to be merged after the cleanup.

Today a TDX module binary can be at most 496 pages and its sigstruct at
most one page. Both limits come from the P-SEAMLDR ABI.

TDX modules are outgrowing them. A post-quantum signature algorithm
pushes the sigstruct past 4KB, and new module features push the binary
past 496 pages. The P-SEAMLDR ABI was extended for both.

The kernel rejects any image over these limits. TDX modules for Diamond
Rapids exceed them, so without this series, TDX module updates fail on
Diamond Rapids. This series is all that is needed to make them work.

The image format that userspace uploads ('struct tdx_image') is generic
enough and needs no change.

== AI Usage ==

AI was used under supervision to review code and refine commit messages.

== Testing ==

Tested on a Diamond Rapids system. Updates with a module larger than 2MB
and an 8KB sigstruct work, which exercises both the chained page list
and version 1 of 'struct seamldr_params'. TDs keep running across
updates.

== P-SEAMLDR ABI changes ==

The public P-SEAMLDR specification will be updated to document these
ABI extensions. Until then, here are the changes to
'struct seamldr_params' that this series relies on:

- VERSION (offset 0) may now be 1. Version 1 support is enumerated by
bit 8 of SEAMLDR_FEATURES0.

- SIGSTRUCT_PA_1..3 (offsets 16, 24 and 32) are new. In version 1, they
hold the addresses of the second to fourth sigstruct pages, or 0 if
the sigstruct does not reach that page. In version 0, they must be 0.

- RESERVED shrinks from 104 to 80 bytes and now starts at offset 40.

- MOD_PAGES_PA_LIST (offset 128) can be chained. For a module over 495
pages, its last entry points to a 4KB page holding up to 511 more
addresses. Each such page uses its last entry to point to the next
page, until all module pages are listed. Chaining support is enumerated
by bit 11 of SEAMLDR_FEATURES0.

[1]: https://lore.kernel.org/kvm/20261012094754.27702-1-chao.gao@intel.com/


Chao Gao (2):
  x86/virt/seamldr: Support large TDX module binaries
  x86/virt/seamldr: Support multiple sigstruct pages

 arch/x86/virt/vmx/tdx/seamldr.c | 78 ++++++++++++++++++++++++++++++---
 1 file changed, 72 insertions(+), 6 deletions(-)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries
  2026-12-04 10:59 [PATCH v4 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao
@ 2026-12-04 10:59 ` Chao Gao
  2026-12-04 11:11   ` sashiko-bot
  2026-12-04 10:59 ` [PATCH v4 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao
  1 sibling, 1 reply; 4+ messages in thread
From: Chao Gao @ 2026-12-04 10:59 UTC (permalink / raw)
  To: linux-kernel, linux-coco, kvm
  Cc: yilun.xu, arjan.van.de.ven, binbin.wu, Chao Gao, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Kiryl Shutsemau, Rick Edgecombe

The kernel hands a TDX module to P-SEAMLDR through a 4KB ABI structure,
mirrored in 'struct seamldr_params'. The structure holds a list of the
physical addresses of all module pages. The list has to fit in the 4KB
structure, which limits modules to just under 2MB.

Upcoming TDX modules will be over that limit. So the P-SEAMLDR ABI was
extended to support them. The last entry of the list is now a pointer
to another 4KB page, which holds more entries and ends with a pointer
to the next page. Pages are added this way until every module page is
listed:

    Old layout:                   New layout:

    +-------- 4KB ---------+      +-------- 4KB ---------+
    | other fields         |      | other fields         |
    | 496 module page PAs  |      | 495 module page PAs  |
    +----------------------+      | pointer to next page |--+
                                  +----------------------+  |
                                                            |
                                  +-------- 4KB ---------+<-+
                                  | 511 module page PAs  |
                                  | pointer to next page |--> ...
                                  +----------------------+

P-SEAMLDR enumerates its support for the new layout with a feature
bit. A P-SEAMLDR with that support always expects the new layout.

Redefine 'struct seamldr_params' as a 16-page structure. Its first page
mirrors the first page of the new layout. The other pages mirror the
pages chained to it. Fill the structure in accordingly and raise the
maximum number of module pages.

To keep the implementation simple:

- Always use the new layout. Do not support the old one.

  The new layout and the old layout are identical for modules of fewer
  than 496 pages, so every existing module works as before. A module
  of more than 496 pages was never accepted by an old P-SEAMLDR. Only
  a module of exactly 496 pages breaks, and only on an old P-SEAMLDR,
  which treats the last entry as a module page address. No such module
  has been released. Checking the feature bit to choose a layout for
  that one size is not worth the extra code.

- Represent all the pages of the new layout in one structure.

  The pages are then allocated together rather than one by one, which
  simplifies the allocation and free paths.

- Cap the module size at a reasonable limit.

  Supporting any module size that the ABI allows adds complexity. It
  means sizing the structure for each module after its image is
  validated. The size also must not exceed what kmalloc() supports, or
  another allocator would be needed.

  Fix the structure at 16 pages to avoid that. 16 pages is an
  arbitrary choice. It fits modules of up to about 32MB. That limit
  will not be reached in the foreseeable future, as upcoming modules
  are a little over 2MB. Small modules leave up to 15 pages unused
  until the structure is freed at the end of the update.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v4:
 - Add a diagram of the old and new layouts [Dave]
 - Make 'struct seamldr_params' follow the ABI layout, with explicit
   next_pa fields [Dave/Rick]
 - Explain how the new layout is enumerated and enforced by P-SEAMLDR
 - Explain the design decisions and the reasons for them

v3:
 - Explain the math of the max module page count [Rick/Yilun]
 - Call out the 496-page behavior change [Binbin]
 - Drop the exact numbers (496/495) from the ABI description [Yilun]
 - Drop the boilerplate AI usage note [Dave]
 - Note that sigstruct_pages_pa_list[] is never chained [Yilun]
 - Comment the PAGE_ALIGNED() check in populate_pa_list() [Rick]

v2:
 - Make 'struct seamldr_params' a fixed 16 pages instead of sizing it
   to each module, capping modules at about 32MB. [Rick]
 - Drop the patch that moved the allocation after image validation. [Rick]
---
 arch/x86/virt/vmx/tdx/seamldr.c | 67 +++++++++++++++++++++++++++++++--
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
index b1137ca6150d..5678309624ab 100644
--- a/arch/x86/virt/vmx/tdx/seamldr.c
+++ b/arch/x86/virt/vmx/tdx/seamldr.c
@@ -24,7 +24,23 @@
 #define P_SEAMLDR_INFO			0x8000000000000000
 #define P_SEAMLDR_INSTALL		0x8000000000000001
 
-#define SEAMLDR_MAX_NR_MODULE_PAGES	496
+/*
+ * The number of pages in 'struct seamldr_params'. The value is arbitrary
+ * and can be increased to fit larger modules.
+ */
+#define SEAMLDR_PARAMS_NR_PAGES		16
+
+#define SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE	495
+#define SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE	(PAGE_SIZE / sizeof(u64) - 1)
+
+/*
+ * The number of module page addresses that 'struct seamldr_params' can
+ * hold. Its first page holds fewer addresses than each of the chained
+ * pages.
+ */
+#define SEAMLDR_MAX_NR_MODULE_PAGES \
+	(SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE + \
+	 (SEAMLDR_PARAMS_NR_PAGES - 1) * SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE)
 #define SEAMLDR_MAX_NR_SIG_PAGES	1
 
 /*
@@ -48,10 +64,15 @@ struct seamldr_params {
 	u64	sigstruct_pages_pa_list[SEAMLDR_MAX_NR_SIG_PAGES];
 	u8	reserved[104];
 	u64	module_nr_pages;
-	u64	module_pages_pa_list[SEAMLDR_MAX_NR_MODULE_PAGES];
+	u64	module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE];
+	u64	next_pa; /* Points to chained_pages[0]. */
+	struct {
+		u64	module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE];
+		u64	next_pa; /* Points to the next chained page. */
+	} chained_pages[SEAMLDR_PARAMS_NR_PAGES - 1];
 } __packed;
 
-static_assert(sizeof(struct seamldr_params) == 4096);
+static_assert(sizeof(struct seamldr_params) == SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE);
 
 /*
  * Serialize P-SEAMLDR calls since the hardware only allows a single CPU to
@@ -143,6 +164,44 @@ static void populate_pa_list(u64 *pa_list, const u8 *vmalloc_addr, u32 vmalloc_l
 	}
 }
 
+/*
+ * Write the physical addresses of all module pages to @params. The
+ * addresses are spread across the pages of @params, and the first
+ * page holds a different number of addresses than the chained pages.
+ * Link a chained page when it is first used.
+ */
+static void populate_module_pa_list(struct seamldr_params *params,
+				    const u8 *mod, u32 mod_nr_pages)
+{
+	u64 *next_pa = &params->next_pa;
+	u32 nr;
+	int i;
+
+	/* Fill in the first page. */
+	nr = min(mod_nr_pages, SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE);
+	populate_pa_list(params->module_pages_pa_list, mod, nr);
+	mod		+= nr * PAGE_SIZE;
+	mod_nr_pages	-= nr;
+
+	/* Fill in the chained pages. */
+	for (i = 0; i < ARRAY_SIZE(params->chained_pages); i++) {
+		u64 *list = params->chained_pages[i].module_pages_pa_list;
+
+		nr = min(mod_nr_pages, SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE);
+		/* All module pages have been processed. */
+		if (nr == 0)
+			break;
+
+		/* Point the previous page to this one. */
+		*next_pa = __pa(&params->chained_pages[i]);
+		next_pa  = &params->chained_pages[i].next_pa;
+
+		populate_pa_list(list, mod, nr);
+		mod		+= nr * PAGE_SIZE;
+		mod_nr_pages	-= nr;
+	}
+}
+
 static void populate_seamldr_params(struct seamldr_params *params,
 				    const u8 *sig, u32 sig_nr_pages,
 				    const u8 *mod, u32 mod_nr_pages)
@@ -152,7 +211,7 @@ static void populate_seamldr_params(struct seamldr_params *params,
 	params->module_nr_pages	= mod_nr_pages;
 
 	populate_pa_list(params->sigstruct_pages_pa_list, sig, sig_nr_pages);
-	populate_pa_list(params->module_pages_pa_list,	  mod, mod_nr_pages);
+	populate_module_pa_list(params, mod, mod_nr_pages);
 }
 
 /*
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] x86/virt/seamldr: Support multiple sigstruct pages
  2026-12-04 10:59 [PATCH v4 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao
  2026-12-04 10:59 ` [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao
@ 2026-12-04 10:59 ` Chao Gao
  1 sibling, 0 replies; 4+ messages in thread
From: Chao Gao @ 2026-12-04 10:59 UTC (permalink / raw)
  To: linux-kernel, linux-coco, kvm
  Cc: yilun.xu, arjan.van.de.ven, binbin.wu, Chao Gao, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Kiryl Shutsemau, Rick Edgecombe

TDX module sigstructs are limited to 4KB. Each update image carries a
sigstruct, which is handed to P-SEAMLDR in 'struct seamldr_params'
along with the module binary. The structure has room for the physical
address of only one sigstruct page.

TDX modules are moving to a post-quantum signature algorithm. Its
signatures are far larger than the ones in use today, so the sigstruct
no longer fits in 4KB.

The P-SEAMLDR ABI was extended to take up to four sigstruct pages. The
physical addresses of the three added pages follow the existing one, in
space that was reserved. Setting the 'version' field of the structure
to 1 tells P-SEAMLDR that the added addresses are in use.

Grow sigstruct_pages_pa_list[] to four entries to match. In anticipation
of this change, the list is already filled in a loop, so filling the
new entries needs no new code.

Use version 1 only when the sigstruct spans more than one page. Old
P-SEAMLDRs reject version 1, so this keeps today's modules working on
them.

P-SEAMLDR enumerates its support for version 1 with a feature bit. Do
not query it. Userspace selects the update image and is responsible
for ensuring the module is compatible with P-SEAMLDR.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v4:
 - Describe where the added sigstruct page addresses go in the
   structure and what version 1 tells P-SEAMLDR
 - Mention that P-SEAMLDR enumerates version 1 with a feature bit

v3:
 - Explain why sigstruct filling code is a loop already [Rick]
 - Drop the boilerplate AI usage note [Dave]

v2:
 - drop macros for versions to keep the diff minimal
 - explain why the sigstruct filling code needs no change
---
 arch/x86/virt/vmx/tdx/seamldr.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
index 5678309624ab..497d83cc3432 100644
--- a/arch/x86/virt/vmx/tdx/seamldr.c
+++ b/arch/x86/virt/vmx/tdx/seamldr.c
@@ -41,7 +41,7 @@
 #define SEAMLDR_MAX_NR_MODULE_PAGES \
 	(SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE + \
 	 (SEAMLDR_PARAMS_NR_PAGES - 1) * SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE)
-#define SEAMLDR_MAX_NR_SIG_PAGES	1
+#define SEAMLDR_MAX_NR_SIG_PAGES	4
 
 /*
  * The seamldr_params "scenario" field specifies the operation mode:
@@ -62,7 +62,7 @@ struct seamldr_params {
 	u32	version;
 	u32	scenario;
 	u64	sigstruct_pages_pa_list[SEAMLDR_MAX_NR_SIG_PAGES];
-	u8	reserved[104];
+	u8	reserved[80];
 	u64	module_nr_pages;
 	u64	module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE];
 	u64	next_pa; /* Points to chained_pages[0]. */
@@ -207,6 +207,13 @@ static void populate_seamldr_params(struct seamldr_params *params,
 				    const u8 *mod, u32 mod_nr_pages)
 {
 	params->version		= 0;
+	/*
+	 * Use version 1 only for multi-page sigstructs, to stay
+	 * compatible with old P-SEAMLDRs that lack version 1 support.
+	 */
+	if (sig_nr_pages > 1)
+		params->version	= 1;
+
 	params->scenario	= SEAMLDR_SCENARIO_UPDATE;
 	params->module_nr_pages	= mod_nr_pages;
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries
  2026-12-04 10:59 ` [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao
@ 2026-12-04 11:11   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 11:11 UTC (permalink / raw)
  To: Chao Gao, kvm

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] x86/virt/seamldr: costly order-4 kzalloc_obj() in
  seamldr_install_module()
--

commit 3d3e8627ca619b4725aef21c808f3c7dcc4e909c
Author: Chao Gao <chao.gao@intel.com>

x86/virt/seamldr: Support large TDX module binaries

This commit extends struct seamldr_params to 16 pages using P-SEAMLDR's
chained page-list layout so the kernel can load TDX modules larger than
2MB.

> diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c
> index b1137ca6150d4..5678309624ab9 100644
> --- a/arch/x86/virt/vmx/tdx/seamldr.c
> +++ b/arch/x86/virt/vmx/tdx/seamldr.c
> @@ -24,7 +24,23 @@
>  #define P_SEAMLDR_INFO			0x8000000000000000
>  #define P_SEAMLDR_INSTALL		0x8000000000000001
>  
> -#define SEAMLDR_MAX_NR_MODULE_PAGES	496
> +/*
> + * The number of pages in 'struct seamldr_params'. The value is arbitrary
> + * and can be increased to fit larger modules.
> + */
> +#define SEAMLDR_PARAMS_NR_PAGES		16

[Severity: Medium]
Can setting SEAMLDR_PARAMS_NR_PAGES to 16 cause kzalloc_obj(*params) in
seamldr_install_module() to fail under memory fragmentation?

Growing struct seamldr_params from 4KB to 64KB turns every runtime module
update into an order-4 GFP_KERNEL allocation, above PAGE_ALLOC_COSTLY_ORDER
(order 3).  On a long-running TDX host fragmented by unmovable guest TD
private memory, this triggers direct compaction and fails with -ENOMEM.

tdx_fw_write() maps -ENOMEM to FW_UPLOAD_ERR_FW_INVALID, blocking live TDX
module updates even for small modules that previously needed one page.
Since P-SEAMLDR chains 4KB pages by physical address, using kvzalloc_obj()
with slow_virt_to_phys() instead of __pa() would avoid order-4 allocations.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204105951.1811487-1-chao.gao@intel.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04 11:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 10:59 [PATCH v4 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao
2026-12-04 10:59 ` [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao
2026-12-04 11:11   ` sashiko-bot
2026-12-04 10:59 ` [PATCH v4 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox