* [PATCH v3 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs
@ 2026-11-19 7:49 Chao Gao
2026-11-19 7:49 ` [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao
2026-11-19 7:49 ` [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao
0 siblings, 2 replies; 10+ messages in thread
From: Chao Gao @ 2026-11-19 7:49 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. I dropped the RFC tag because there are no open design
questions.
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 RFC v2:
There is no functional change. Apart from comments, the code differs
from v2 only in how the maximum module page count is derived.
- Compute the size of module_pages_pa_list[] from the size of 'struct
seamldr_params' and explain the math. [Rick/Yilun]
- Call out that a 496-page module now requires chaining support. [Binbin]
- Drop the exact entry counts (496/495) from the ABI description. [Yilun]
- Note in a comment that sigstruct_pages_pa_list[] is never chained. [Yilun]
- Comment the PAGE_ALIGNED() check in populate_pa_list(). [Rick]
- Explain why the sigstruct list is already filled in a loop. [Rick]
- Drop the AI usage note from changelogs. [Dave]
- Rework changelogs to be easier to follow.
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.
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 | 48 +++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 8 deletions(-)
base-commit: 5b8212d45d99b77c84e3ad305a295e9e65d5ef20
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-19 7:49 [PATCH v3 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao @ 2026-11-19 7:49 ` Chao Gao 2026-11-19 18:10 ` Dave Hansen 2026-11-19 7:49 ` [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao 1 sibling, 1 reply; 10+ messages in thread From: Chao Gao @ 2026-11-19 7:49 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 binaries are limited to just under 2MB. The binary is handed to P-SEAMLDR as a list of page physical addresses in 'struct seamldr_params', and the list must fit in a single 4KB page along with a few other fields. TDX modules are gaining features and are about to outgrow that limit. The P-SEAMLDR ABI was extended to let the list continue onto more 4KB pages. The last u64 of each page holds the physical address of the next page, chaining the pages together. Grow module_pages_pa_list[] so that 'struct seamldr_params' spans 16 pages, and chain the pages together in populate_pa_list(). Each page uses its last entry for chaining, so the maximum module page count is the array size minus one entry per page. The user-supplied image is checked against this count. The 16-page size is somewhat arbitrary. It fits modules of up to about 32MB, far above the roughly 2MB of current modules. It wastes 60KB for today's modules, which is fine because the memory is freed right after the update. Do not query P-SEAMLDR for chaining support. Userspace selects the update image and is responsible for ensuring the module is compatible with P-SEAMLDR. A 496-page module (the old maximum) used to fit in a single page. Now the last entry of that page is used for chaining, so the final address moves to a second page and the module requires chaining support. Do not special-case this size to make it work with a P-SEAMLDR without chaining support. No released module has exactly 496 pages, so nothing breaks. Leave it to userspace to ensure any future 496-page module is paired with a P-SEAMLDR that supports chaining, as with larger modules. Signed-off-by: Chao Gao <chao.gao@intel.com> --- Alternative (tried in v1, dropped in v2): Sizing module_pages_pa_list[] per module needs the page count from the image header. The allocation would have to either move after the header is validated, as v1 did, or use an unvalidated count. Either way it is more code churn than a fixed 16 pages. 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 | 37 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c index b1137ca6150d..6b9657a28129 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -24,7 +24,20 @@ #define P_SEAMLDR_INFO 0x8000000000000000 #define P_SEAMLDR_INSTALL 0x8000000000000001 -#define SEAMLDR_MAX_NR_MODULE_PAGES 496 +/* + * 'struct seamldr_params' spans this many pages. The number is somewhat + * arbitrary and fits modules of up to about 32MB. Increase it if modules + * outgrow that. + */ +#define SEAMLDR_PARAMS_NR_PAGES 16 + +/* + * module_pages_pa_list[] fills the rest of 'struct seamldr_params' after + * its first 128 bytes. The last entry of each page is reserved to point + * to the next page. The last entry of the final page is never used. + */ +#define SEAMLDR_NR_MODULE_PA_ENTRIES ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - 128) / sizeof(u64)) +#define SEAMLDR_MAX_NR_MODULE_PAGES (SEAMLDR_NR_MODULE_PA_ENTRIES - SEAMLDR_PARAMS_NR_PAGES) #define SEAMLDR_MAX_NR_SIG_PAGES 1 /* @@ -48,10 +61,10 @@ 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_MODULE_PA_ENTRIES]; } __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 @@ -130,16 +143,28 @@ struct tdx_image { * Given a vmalloc() allocation, write all of the backing physical * addresses to pa_list[]. Caller guarantees that the array is big * enough. + * + * If pa_list[] spans multiple pages, chain them by pointing the last + * entry of each page to the next page. Note that a pa_list[] that + * does not cross a page boundary, such as sigstruct_pages_pa_list[], + * is never chained. */ static void populate_pa_list(u64 *pa_list, const u8 *vmalloc_addr, u32 vmalloc_len_pages) { - int i; + int i, j; - for (i = 0; i < vmalloc_len_pages; i++) { + for (i = 0, j = 0; i < vmalloc_len_pages; i++) { unsigned long offset = i * PAGE_SIZE; unsigned long pfn = vmalloc_to_pfn(&vmalloc_addr[offset]); - pa_list[i] = pfn << PAGE_SHIFT; + /* Point the last entry of a page to the next page. */ + if (PAGE_ALIGNED(&pa_list[j + 1])) { + pa_list[j] = __pa(&pa_list[j + 1]); + j++; + } + + pa_list[j] = pfn << PAGE_SHIFT; + j++; } } -- 2.52.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-19 7:49 ` [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao @ 2026-11-19 18:10 ` Dave Hansen 2026-11-20 2:58 ` Chao Gao 0 siblings, 1 reply; 10+ messages in thread From: Dave Hansen @ 2026-11-19 18:10 UTC (permalink / raw) To: Chao Gao, linux-kernel, linux-coco, kvm Cc: yilun.xu, arjan.van.de.ven, binbin.wu, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau, Rick Edgecombe On 11/18/26 23:49, Chao Gao wrote: > TDX module binaries are limited to just under 2MB. The binary is handed > to P-SEAMLDR as a list of page physical addresses in > 'struct seamldr_params', and the list must fit in a single 4KB page > along with a few other fields. > > TDX modules are gaining features and are about to outgrow that limit. > > The P-SEAMLDR ABI was extended to let the list continue onto more 4KB > pages. The last u64 of each page holds the physical address of the next > page, chaining the pages together. > > Grow module_pages_pa_list[] so that 'struct seamldr_params' spans 16 > pages, and chain the pages together in populate_pa_list(). > > Each page uses its last entry for chaining, so the maximum module page > count is the array size minus one entry per page. The user-supplied > image is checked against this count. > > The 16-page size is somewhat arbitrary. It fits modules of up to about > 32MB, far above the roughly 2MB of current modules. It wastes 60KB for > today's modules, which is fine because the memory is freed right after > the update. > > Do not query P-SEAMLDR for chaining support. Userspace selects the > update image and is responsible for ensuring the module is compatible > with P-SEAMLDR. > > A 496-page module (the old maximum) used to fit in a single page. Now > the last entry of that page is used for chaining, so the final address > moves to a second page and the module requires chaining support. Do not > special-case this size to make it work with a P-SEAMLDR without > chaining support. No released module has exactly 496 pages, so nothing > breaks. Leave it to userspace to ensure any future 496-page module is > paired with a P-SEAMLDR that supports chaining, as with larger modules. This seems to be getting worse, not better. Maybe I'm being dense, but I *still* don't have a clear picture in my head of what the before and after data structures look like. > +#define SEAMLDR_NR_MODULE_PA_ENTRIES ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - 128) / sizeof(u64)) The "128" is a hard-coded struct offset. To me, that's a big anti-pattern. Use the structs themselves. I'd suggest a way to do it if I had a clear picture of the data structures in my head, which I don't at this point. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-19 18:10 ` Dave Hansen @ 2026-11-20 2:58 ` Chao Gao 2026-11-20 15:19 ` Dave Hansen 0 siblings, 1 reply; 10+ messages in thread From: Chao Gao @ 2026-11-20 2:58 UTC (permalink / raw) To: Dave Hansen Cc: linux-kernel, linux-coco, kvm, yilun.xu, arjan.van.de.ven, binbin.wu, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau, Rick Edgecombe >On 11/18/26 23:49, Chao Gao wrote: >> TDX module binaries are limited to just under 2MB. The binary is handed >> to P-SEAMLDR as a list of page physical addresses in >> 'struct seamldr_params', and the list must fit in a single 4KB page >> along with a few other fields. >> >> TDX modules are gaining features and are about to outgrow that limit. >> >> The P-SEAMLDR ABI was extended to let the list continue onto more 4KB >> pages. The last u64 of each page holds the physical address of the next >> page, chaining the pages together. >> >> Grow module_pages_pa_list[] so that 'struct seamldr_params' spans 16 >> pages, and chain the pages together in populate_pa_list(). >> >> Each page uses its last entry for chaining, so the maximum module page >> count is the array size minus one entry per page. The user-supplied >> image is checked against this count. >> >> The 16-page size is somewhat arbitrary. It fits modules of up to about >> 32MB, far above the roughly 2MB of current modules. It wastes 60KB for >> today's modules, which is fine because the memory is freed right after >> the update. >> >> Do not query P-SEAMLDR for chaining support. Userspace selects the >> update image and is responsible for ensuring the module is compatible >> with P-SEAMLDR. >> >> A 496-page module (the old maximum) used to fit in a single page. Now >> the last entry of that page is used for chaining, so the final address >> moves to a second page and the module requires chaining support. Do not >> special-case this size to make it work with a P-SEAMLDR without >> chaining support. No released module has exactly 496 pages, so nothing >> breaks. Leave it to userspace to ensure any future 496-page module is >> paired with a P-SEAMLDR that supports chaining, as with larger modules. > >This seems to be getting worse, not better. > >Maybe I'm being dense, but I *still* don't have a clear picture in my >head of what the before and after data structures look like. I tried to describe the ABI structure briefly in words, but that was not clear enough. Here are the before and after data structures. Before (one 4KB page): After (chained 4KB pages): +-------- 4KB ---------+ +-------- 4KB ---------+ | version | | version | | other fields | | other fields | | module_nr_pages | | module_nr_pages | | (128 bytes in total) | | (128 bytes in total) | |......................| |......................| | module page 0 PA | | module page 0 PA | | ... | | ... | | module page 494 PA | | module page 494 PA | | module page 495 PA | | next page PA |--+ +----------------------+ +----------------------+ | | +-------- 4KB ---------+<-+ | 511 module page PAs | | next page PA |--+ +----------------------+ | | +-------- 4KB ---------+<-+ | 511 module page PAs | | next page PA |--> ... +----------------------+ I will add this diagram to the end of the changelog, in a background section. > >> +#define SEAMLDR_NR_MODULE_PA_ENTRIES ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - 128) / sizeof(u64)) > >The "128" is a hard-coded struct offset. To me, that's a big >anti-pattern. Use the structs themselves. > >I'd suggest a way to do it if I had a clear picture of the data >structures in my head, which I don't at this point. I tried offsetof() first, but module_pages_pa_list[] cannot be sized from its own offset. The struct is still incomplete at that point, so the compiler rejects it. We can group the first 128 bytes into their own structure and size the list from it: #define SEAMLDR_NR_MODULE_PA_ENTRIES \ ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - \ sizeof(struct seamldr_params_fixed)) / sizeof(u64)) struct seamldr_params { struct_group_tagged(seamldr_params_fixed, __fixed, u32 version; u32 scenario; u64 sigstruct_pages_pa_list[SEAMLDR_MAX_NR_SIG_PAGES]; u8 reserved[104]; u64 module_nr_pages; ); u64 module_pages_pa_list[SEAMLDR_NR_MODULE_PA_ENTRIES]; } __packed; Note: struct_group_tagged() keeps the code that refers to those fields unchanged. I considered this but decided against it to keep the diff minimal. I will do this in the next version unless you have something else in mind. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-20 2:58 ` Chao Gao @ 2026-11-20 15:19 ` Dave Hansen 2026-11-23 13:10 ` Chao Gao 0 siblings, 1 reply; 10+ messages in thread From: Dave Hansen @ 2026-11-20 15:19 UTC (permalink / raw) To: Chao Gao Cc: linux-kernel, linux-coco, kvm, yilun.xu, arjan.van.de.ven, binbin.wu, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau, Rick Edgecombe On 11/19/26 18:58, Chao Gao wrote: > I tried to describe the ABI structure briefly in words, but that was not > clear enough. Here are the before and after data structures. > > Before (one 4KB page): After (chained 4KB pages): How is it that the ABI supports this? How can the module tell the difference between a chained and non-chained one? Why don't the data structures look like this disagram? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-20 15:19 ` Dave Hansen @ 2026-11-23 13:10 ` Chao Gao 2026-11-23 19:20 ` Edgecombe, Rick P 0 siblings, 1 reply; 10+ messages in thread From: Chao Gao @ 2026-11-23 13:10 UTC (permalink / raw) To: Dave Hansen Cc: linux-kernel, linux-coco, kvm, yilun.xu, arjan.van.de.ven, binbin.wu, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau, Rick Edgecombe On Fri, Nov 20, 2026 at 07:19:07AM -0800, Dave Hansen wrote: >On 11/19/26 18:58, Chao Gao wrote: >> I tried to describe the ABI structure briefly in words, but that was not >> clear enough. Here are the before and after data structures. >> >> Before (one 4KB page): After (chained 4KB pages): > >How is it that the ABI supports this? How can the module tell the >difference between a chained and non-chained one? It doesn't tell them apart. A P-SEAMLDR that supports chaining always reads the structure as a chained one, and a P-SEAMLDR that does not always reads it as a non-chained one. Chaining support is enumerated by SEAMLDR_FEATURES0[11], a new field in 'struct seamldr_info'. The only difference between the two is the last u64 of the first page. In a non-chained one it holds one more module page address, and in a chained one it holds the address of the next page. A module of up to 495 pages does not use that u64, so the two are identical. They differ only for a module with exactly 496 pages, and a larger module needs a chained one. > >Why don't the data structures look like this disagram? I started with data structures that look like the diagram. Three simplifications got from there to the current code. First, make the pages in the diagram contiguous. The diagram shows them apart, as the ABI allows, but we don't need to allocate them separately. It can be just a single large structure, and the existing allocation code is reused as is. Second, use a fixed number of pages. The ABI allows any number of them, to support a module of any size. But modules are about 2MB today, so the structure is just 16 pages, which is enough for a module of about 32MB. The number can be raised if modules outgrow it. Third, don't define the entries that point to the next page explicitly. They are always the last u64 of a page. So the code that fills in the structure can locate them as it goes. Defining those entries explicitly would match the diagram. But then those entries split the list of module page addresses into multiple lists, one per page, and the first one is shorter than the others. The code that fills them in has to keep track of which list it is in and how long that list is. That is more code. If you think any of these simplifications is not worth it, I will undo it. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-23 13:10 ` Chao Gao @ 2026-11-23 19:20 ` Edgecombe, Rick P 2026-11-24 6:22 ` Chao Gao 0 siblings, 1 reply; 10+ messages in thread From: Edgecombe, Rick P @ 2026-11-23 19:20 UTC (permalink / raw) To: Hansen, Dave, Gao, Chao Cc: Van De Ven, Arjan, Xu, Yilun, bp@alien8.de, binbin.wu@linux.intel.com, kas@kernel.org, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, mingo@redhat.com, x86@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, hpa@zytor.com, tglx@kernel.org On Mon, 2026-11-23 at 21:10 +0800, Chao Gao wrote: > > Why don't the data structures look like this disagram? > > I started with data structures that look like the diagram. Three > simplifications got from there to the current code. > > First, make the pages in the diagram contiguous. The diagram shows > them apart, as the ABI allows, but we don't need to allocate them > separately. It can be just a single large structure, and the existing > allocation code is reused as is. > > Second, use a fixed number of pages. The ABI allows any number of > them, to support a module of any size. But modules are about 2MB > today, so the structure is just 16 pages, which is enough for a module > of about 32MB. The number can be raised if modules outgrow it. > > Third, don't define the entries that point to the next page > explicitly. They are always the last u64 of a page. So the code that > fills in the structure can locate them as it goes. > > Defining those entries explicitly would match the diagram. But then > those entries split the list of module page addresses into multiple > lists, one per page, and the first one is shorter than the others. > The code that fills them in has to keep track of which list it is in > and how long that list is. That is more code. How does it look if you just have two versions of the struct and cast? Did you try it? How many more lines? We don't want to fight to save a few lines of code if we end up needing lots of explanation to justify it. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries 2026-11-23 19:20 ` Edgecombe, Rick P @ 2026-11-24 6:22 ` Chao Gao 0 siblings, 0 replies; 10+ messages in thread From: Chao Gao @ 2026-11-24 6:22 UTC (permalink / raw) To: Edgecombe, Rick P Cc: Hansen, Dave, Van De Ven, Arjan, Xu, Yilun, bp@alien8.de, binbin.wu@linux.intel.com, kas@kernel.org, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, mingo@redhat.com, x86@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, hpa@zytor.com, tglx@kernel.org On Tue, Nov 24, 2026 at 03:20:11AM +0800, Edgecombe, Rick P wrote: >On Mon, 2026-11-23 at 21:10 +0800, Chao Gao wrote: >> > Why don't the data structures look like this disagram? >> >> I started with data structures that look like the diagram. Three >> simplifications got from there to the current code. >> >> First, make the pages in the diagram contiguous. The diagram shows >> them apart, as the ABI allows, but we don't need to allocate them >> separately. It can be just a single large structure, and the existing >> allocation code is reused as is. >> >> Second, use a fixed number of pages. The ABI allows any number of >> them, to support a module of any size. But modules are about 2MB >> today, so the structure is just 16 pages, which is enough for a module >> of about 32MB. The number can be raised if modules outgrow it. >> >> Third, don't define the entries that point to the next page >> explicitly. They are always the last u64 of a page. So the code that >> fills in the structure can locate them as it goes. >> >> Defining those entries explicitly would match the diagram. But then >> those entries split the list of module page addresses into multiple >> lists, one per page, and the first one is shorter than the others. >> The code that fills them in has to keep track of which list it is in >> and how long that list is. That is more code. > >How does it look if you just have two versions of the struct and cast? Did you >try it? How many more lines? We don't want to fight to save a few lines of code >if we end up needing lots of explanation to justify it. I assume you mean keeping both definitions, the current one and one that matches the ABI layout explicitly, and casting between them. That does not look necessary to me. It would need the same amount of explanation, because the code would still treat the list as one array and special-case the last u64 of each page. I tried making the data structures match the ABI layout explicitly, with no cast (see the diff below). The patch goes from 31 added lines to 69, but the logic is simple. There is no need to special-case the last u64 of a page. So the tradeoff is about 40 more lines of code for code that is more readable, can be matched to the spec more easily, and needs less explanation. On second thought, I think the extra code is worth it. I will switch in the next version unless someone objects. diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c index b1137ca6150d..4d743a3186fc 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -24,7 +24,24 @@ #define P_SEAMLDR_INFO 0x8000000000000000 #define P_SEAMLDR_INSTALL 0x8000000000000001 -#define SEAMLDR_MAX_NR_MODULE_PAGES 496 +/* + * 'struct seamldr_params' spans this many pages. The number is somewhat + * arbitrary and fits modules of up to about 32MB. Increase it if modules + * outgrow that. + */ +#define SEAMLDR_PARAMS_NR_PAGES 16 + +/* + * The number of module page addresses that the first page and each + * following page of 'struct seamldr_params' can hold. The last u64 of + * each page points to the next page. + */ +#define SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE 495 +#define SEAMLDR_NR_PA_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(u64) - 1) + +#define SEAMLDR_MAX_NR_MODULE_PAGES \ + (SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE + \ + (SEAMLDR_PARAMS_NR_PAGES - 1) * SEAMLDR_NR_PA_ENTRIES_PER_PAGE) #define SEAMLDR_MAX_NR_SIG_PAGES 1 /* @@ -34,6 +51,14 @@ */ #define SEAMLDR_SCENARIO_UPDATE 1 +/* A page of module page addresses that follows the first page. */ +struct seamldr_pa_page { + u64 module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_PER_PAGE]; + u64 next_pa; +}; + +static_assert(sizeof(struct seamldr_pa_page) == PAGE_SIZE); + /* * This is the "SEAMLDR_PARAMS" data structure defined in the * "SEAM Loader (SEAMLDR) Interface Specification". @@ -48,10 +73,12 @@ 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; + struct seamldr_pa_page following_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 +170,44 @@ static void populate_pa_list(u64 *pa_list, const u8 *vmalloc_addr, u32 vmalloc_l } } +/* Point each page of @params to the next one. */ +static void chain_params_pages(struct seamldr_params *params) +{ + int i; + + params->next_pa = __pa(¶ms->following_pages[0]); + + for (i = 0; i < ARRAY_SIZE(params->following_pages) - 1; i++) + params->following_pages[i].next_pa = __pa(¶ms->following_pages[i + 1]); +} + +/* + * Write the addresses of all module pages to @params. Fill the first + * page, then as many of the following pages as needed. + */ +static void populate_module_pa_list(struct seamldr_params *params, + const u8 *mod, u32 mod_nr_pages) +{ + struct seamldr_pa_page *page; + u32 nr; + + chain_params_pages(params); + + 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; + + for (page = params->following_pages; mod_nr_pages; page++) { + nr = min(mod_nr_pages, SEAMLDR_NR_PA_ENTRIES_PER_PAGE); + populate_pa_list(page->module_pages_pa_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 +217,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); } /* ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages 2026-11-19 7:49 [PATCH v3 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao 2026-11-19 7:49 ` [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao @ 2026-11-19 7:49 ` Chao Gao 2026-11-19 7:53 ` sashiko-bot 1 sibling, 1 reply; 10+ messages in thread From: Chao Gao @ 2026-11-19 7:49 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 (16KB). Setting 'version' to 1 tells P-SEAMLDR to use this layout. 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. Do not query P-SEAMLDR for version 1 support. 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> --- 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 6b9657a28129..7c09c84df1aa 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -38,7 +38,7 @@ */ #define SEAMLDR_NR_MODULE_PA_ENTRIES ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - 128) / sizeof(u64)) #define SEAMLDR_MAX_NR_MODULE_PAGES (SEAMLDR_NR_MODULE_PA_ENTRIES - SEAMLDR_PARAMS_NR_PAGES) -#define SEAMLDR_MAX_NR_SIG_PAGES 1 +#define SEAMLDR_MAX_NR_SIG_PAGES 4 /* * The seamldr_params "scenario" field specifies the operation mode: @@ -59,7 +59,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_MODULE_PA_ENTRIES]; } __packed; @@ -173,6 +173,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] 10+ messages in thread
* Re: [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages 2026-11-19 7:49 ` [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao @ 2026-11-19 7:53 ` sashiko-bot 0 siblings, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-11-19 7:53 UTC (permalink / raw) To: Chao Gao, kvm Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] x86/tdx: unaligned physical memory access in seamldr_install_module() [1] -- commit 5316f95a1fa1ecb4d66f112e0d257161d81dbb1c Author: Chao Gao <chao.gao@intel.com> x86/virt/seamldr: Support multiple sigstruct pages This commit expands sigstruct_pages_pa_list[] in struct seamldr_params to four entries and sets the seamldr_params version to 1 when the sigstruct spans more than one page. > diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c > index 6b9657a28129b..7c09c84df1aa3 100644 > --- a/arch/x86/virt/vmx/tdx/seamldr.c > +++ b/arch/x86/virt/vmx/tdx/seamldr.c > @@ -38,7 +38,7 @@ > */ > #define SEAMLDR_NR_MODULE_PA_ENTRIES ((SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE - 128) / sizeof(u64)) > #define SEAMLDR_MAX_NR_MODULE_PAGES (SEAMLDR_NR_MODULE_PA_ENTRIES - SEAMLDR_PARAMS_NR_PAGES) > -#define SEAMLDR_MAX_NR_SIG_PAGES 1 > +#define SEAMLDR_MAX_NR_SIG_PAGES 4 > > /* > * The seamldr_params "scenario" field specifies the operation mode: > @@ -59,7 +59,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_MODULE_PA_ENTRIES]; > } __packed; [Severity: Critical] This problem wasn't introduced by this patch, but can allocating struct seamldr_params with kzalloc_obj() in seamldr_install_module() violate the hardware page-alignment requirement when CONFIG_SLUB_DEBUG is enabled [1]? arch/x86/virt/vmx/tdx/seamldr.c:seamldr_install_module() { ... params = kzalloc_obj(*params); if (!params) return -ENOMEM; ... } When SLUB redzoning is active, the returned object is shifted within the slab page rather than page-aligned. Passing __pa(params) to P_SEAMLDR_INSTALL in seamldr_install() (and similarly __pa(tdmr_pa_array) from kzalloc() to TDH_SYS_CONFIG in config_tdx_module()) then hands an unaligned physical address to the hardware, which truncates the address to the alignment boundary and reads SLUB metadata and redzone bytes instead of the parameters, causing initialization failure or memory corruption. [1] https://sashiko.dev/#/bug/linux-d025ea4c-abd9-44fc-9005-5b2dc7291000 -- Sashiko AI review · https://sashiko.dev/#/patchset/20261119074925.3933804-1-chao.gao@intel.com?part=2 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-24 6:42 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-19 7:49 [PATCH v3 0/2] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao 2026-11-19 7:49 ` [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries Chao Gao 2026-11-19 18:10 ` Dave Hansen 2026-11-20 2:58 ` Chao Gao 2026-11-20 15:19 ` Dave Hansen 2026-11-23 13:10 ` Chao Gao 2026-11-23 19:20 ` Edgecombe, Rick P 2026-11-24 6:22 ` Chao Gao 2026-11-19 7:49 ` [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao 2026-11-19 7:53 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox