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

From: Xu Yilun

Date: Fri Sep 18 2026 - 06:27:12 EST


On Wed, Sep 16, 2026 at 03:40:51PM +0800, Chao Gao wrote:
> >+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.
> */

Since we will drop ext_required check, I've found a reason why no memory
is required.

/*
* Skip the memory setup if no memory is required. This may happen when
* no add-on features requiring TDX module extensions are configured
* via TDH.SYS.CONFIG.
*/

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