Re: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions

From: Chao Gao

Date: Wed Sep 16 2026 - 03:55:28 EST


>+static __init int tdx_ext_mem_setup(void)
>+{
>+ unsigned int required_pages = tdx_sysinfo.ext.memory_pool_required_pages;
>+ struct tdx_hpa_list *hpa_list;
>+ unsigned int added_pages;
>+ struct page *page;
>+ int ret;
>+
>+ /*
>+ * TDX module uses the metadata memory_pool_required_pages to indicate
>+ * how much memory is still needed. This value decreases each time
>+ * memory is added via TDH.EXT.MEM.ADD.
>+ *
>+ * On first time initialization, a value of 0 before any memory is
>+ * added is unusual. But host makes no assumptions. Skip the memory
>+ * setup and let subsequent steps catch any actual errors.
>+ */

The fact that the value decreases on each TDH.EXT.MEM.ADD is not relevant
here.

Also, calling 0 "unusual" does not help the reader. It is either a valid
value the kernel needs to handle, or an invalid one the kernel can assert
on.

How about:

/*
* The TDX module may require no memory at all. Skip the memory
* setup in that case.
*/

>+ if (!required_pages)
>+ return 0;