Re: [PATCH v5 3/6] x86/virt/tdx: Add extra memory to TDX module for the extensions

From: Alexey Kardashevskiy

Date: Mon Nov 16 2026 - 22:07:09 EST


On 11/11/26 14:48, Xu Yilun wrote:
TDX module extensions need memory for their execution environment to
serve SEAMCALL leafs. The TDX architecture implements the extensions
in such a way that they use the memory outside of SEAM range, so the
kernel should add the memory upfront at initialization time.

Introduce a new memory adding process backed by a new SEAMCALL leaf
TDH.EXT.MEM.ADD. The kernel queries TDX module how much memory needed,
allocates it, adds it to the module, and never gets it back. Note that
the process requires Dynamic PAMT backing. A subsequent patch adds the
support. This doesn't break bisectability cause the extensions can't be
enabled yet without a feature that uses them.

The TDX module accepts the memory in the form of an HPA array. This
array is passed via a single 64-bit SEAMCALL leaf parameter, which
encodes two values: the PFN of the container page holding the array, and
the number of entries in the array. Create a helper to encode this
format and name it after the TDX module term: HPA_LIST_INFO.

TDX module extensions consume tens of megabytes memory that will never
be returned to the host. Use contiguous page allocation to isolate these
large blocks entirely. This is a simple way to avoid permanent memory
fragmentation: requiring the full size to be contiguous is more
expensive than needed but should be good during the boot time. Print the
allocation amount on TDX module extensions initialization for
visibility.

The TDX module provides a metadata field "required_pages" to indicate
the required memory size. This metadata is meaningful only after the
add-on feature configuration. Don't read and cache the metadata in
tdx_sysinfo. Instead read it right before allocating memory for the
extensions, when it is guaranteed to be valid.

The original changelog was written by hand. AI was used to help correct
grammatical errors and polish individual sentences for better
readability.

Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
Reviewed-by: Tony Lindgren <tony.lindgren@xxxxxxxxxxxxxxx>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
---
An alternative solution is to use a loop that gives memory on a memory
error code - TDX_EXT_MEMORY_POOL_REQUIRED, add one page per iteration
until TDH.EXT.INIT succeeds. Something like:

do {
ret = tdh_sys_init();
if (ret == TDX_EXT_MEMORY_POOL_REQUIRED)
tdh_ext_mem_add(); //single page
} while (ret == TDX_EXT_MEMORY_POOL_REQUIRED);

This approach is slightly simpler as we don't have to query the module
for the total memory, no memory pre-allocation or segmentation math.
But allocating a single 4K page per iteration may cause permanent memory
fragmentation.

Why not allocating new memory in 2MB chunks, reducing fragmentation? Thanks,


--
Alexey