From: Chao Gao <chao.gao@intel.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "Hansen, Dave" <dave.hansen@intel.com>,
"Van De Ven, Arjan" <arjan.van.de.ven@intel.com>,
"Xu, Yilun" <yilun.xu@intel.com>, "bp@alien8.de" <bp@alien8.de>,
"binbin.wu@linux.intel.com" <binbin.wu@linux.intel.com>,
"kas@kernel.org" <kas@kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
"hpa@zytor.com" <hpa@zytor.com>,
"tglx@kernel.org" <tglx@kernel.org>
Subject: Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries
Date: Tue, 24 Nov 2026 14:22:28 +0800 [thread overview]
Message-ID: <awUtJKFl0UMMHVQi@intel.com> (raw)
In-Reply-To: <41dc795ec6611a1998e94d8b422172d1cb588df4.camel@intel.com>
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);
}
/*
next prev parent reply other threads:[~2026-11-24 6:42 UTC|newest]
Thread overview: 9+ 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 ` [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 [this message]
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=awUtJKFl0UMMHVQi@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@intel.com \
--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