Re: [PATCH v2 2/2] x86/virt/tdx: Drop tdh_phymem_page_wbinvd_*()
From: Binbin Wu
Date: Tue Oct 20 2026 - 04:59:36 EST
On 10/16/2026 3:17 AM, Rick Edgecombe wrote:
> In the early days of TDX it was expected that pages being reclaimed from
> the TDX module would need any cacheline from their private KeyID alias
> flushed. The TDX docs describe doing this in a couple narrow cases, for
> example reclaiming the TDR memory or guest private memory.
>
> Similar to how the CLFLUSH_BEFORE_ALLOC features0 bit was never actually
> set in any TDX module, the flush of the private KeyID cachelines turned
> out to not be needed by the final TDX HW either. However, the TDX docs
> were never updated to reflect that.
>
> CLFLUSH_BEFORE_ALLOC handles flushing when giving memory to the TDX
> module, where the alias that needs flushing is the default, normal KeyID
> 0. This was done with a clflush of the kernel's KeyID 0 mapping of the
> memory. For the reclaim path, instead it is the TDX KeyID aliases that
> need to be flushed. Since virtual mappings for these aliases are
> restricted to the TDX module, the module is the only thing that can map
> the page to do the clflush. The TDH.PHYMEM.PAGE.WBINVD SEAMCALL leaf was
> created to facilitate this.
>
> The docs are being updated to clarify that calling TDH.PHYMEM.PAGE.WBINVD
> is not needed. So drop the kernel code that calls this SEAMCALL and the
> helpers that facilitate it. With the removal of
> tdh_phymem_page_wbinvd_tdr(), tdx_global_keyid no longer needs to be kept
> around as a global variable. It just needs to be selected and provided to
> the TDX module during initial setup.
>
> However, don't churn the code to remove the global variable because
> it fits neatly with the other KeyID partitioning global data. It is also
> foreseeable that this would be used in the future for other SEAMCALLs that
> require passing the global KeyID.
>
> KVM previously needed to call different types of tdh_phymem_page_wbinvd_*()
> helpers for different types of reclaim. So it had a stack of helpers and
> some open coded logic to use them in the rarer TDR reclaim case. Now that
> the wbinvd is gone, the steps for each operation are logically equivalent.
> So collapse the helpers and just call tdx_reclaim_control_page() from the
> TDR reclaim path.
>
> This unification brings TDR reclaim in line with the behavior of the other
> reclaim paths, by handling TDH.PHYMEM.PAGE.RECLAIM failure by leaking the
> page and setting the TDR page pointer to NULL. This results in reclaim not
> being tried a second time, which is reasonable because the first reclaim
> failing suggests a problem with the TDX module.
>
> AI was used to review the change.
>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>