Re: [RFC PATCH v2 05/23] x86/tdx: Enhance tdh_phymem_page_reclaim() to support huge pages

From: Binbin Wu
Date: Sun Nov 16 2025 - 21:10:01 EST




On 8/7/2025 5:42 PM, Yan Zhao wrote:
[...]
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 64219c659844..9ed585bde062 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -1966,19 +1966,27 @@ EXPORT_SYMBOL_GPL(tdh_vp_init);
* So despite the names, they must be interpted specially as described by the spec. Return
* them only for error reporting purposes.
*/
-u64 tdh_phymem_page_reclaim(struct page *page, u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size)
+u64 tdh_phymem_page_reclaim(struct folio *folio, unsigned long start_idx, unsigned long npages,
+ u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size)
{
+ struct page *start = folio_page(folio, start_idx);
struct tdx_module_args args = {
- .rcx = page_to_phys(page),
+ .rcx = page_to_phys(start),
};
u64 ret;
+ if (start_idx + npages > folio_nr_pages(folio))
+ return TDX_OPERAND_INVALID;
+
ret = seamcall_ret(TDH_PHYMEM_PAGE_RECLAIM, &args);
*tdx_pt = args.rcx;
*tdx_owner = args.rdx;
*tdx_size = args.r8;
+ if (npages != (1 << (*tdx_size) * PTE_SHIFT))
+ return TDX_SW_ERROR;

Nit:

The size check here is to  make sure the reclamation on the correct level,
however, tdx_size may not be updated if some other error occurs first.
Do you think it's better to check 'ret' first before returning TDX_SW_ERROR?
Otherwise, the error code provided by the TDX module, which may be helpful for
debugging,  will be buried under TDX_SW_ERROR.


+
return ret;
}
EXPORT_SYMBOL_GPL(tdh_phymem_page_reclaim);