From: Chao Gao <chao.gao@intel.com>
To: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev,
kvm@vger.kernel.org
Cc: yilun.xu@intel.com, arjan.van.de.ven@intel.com,
binbin.wu@linux.intel.com, Chao Gao <chao.gao@intel.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>
Subject: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries
Date: Wed, 18 Nov 2026 23:49:21 -0800 [thread overview]
Message-ID: <20261119074925.3933804-2-chao.gao@intel.com> (raw)
In-Reply-To: <20261119074925.3933804-1-chao.gao@intel.com>
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
next prev parent reply other threads:[~2026-11-19 7:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-19 18:10 ` [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries Dave Hansen
2026-11-19 7:49 ` [PATCH v3 2/2] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119074925.3933804-2-chao.gao@intel.com \
--to=chao.gao@intel.com \
--cc=arjan.van.de.ven@intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=yilun.xu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox