Re: [PATCH v3 1/2] x86/virt/seamldr: Support large TDX module binaries

From: Chao Gao

Date: Mon Nov 23 2026 - 08:10:37 EST


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.