Re: [PATCH 2/2] x86/virt/tdx: Drop tdh_phymem_page_wbinvd_*()

From: Xu Yilun

Date: Wed Sep 23 2026 - 03:14:59 EST


On Tue, Sep 22, 2026 at 01:52:15PM -0700, 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 cases, for example
> reclaiming the TDR memory:
> Flush MODIFIED cache lines: this is required to avoid corruption due to
> cache line aliasing. Note that all cache lines for all other TD pages
> must have been flushed before the TDR page was reclaimed.
>
> For a similar reasons as why the CLFLUSH_BEFORE_ALLOC features0 bit was
> never actually set in any TDX module, this flush of the private KeyID
> cachelines turned out to not be needed by the final TDX solution. However,
> the TDX docs were never updated to reflect that.
>
> Since private KeyID virtual mappings are reserved for TDX use, the TDX
> module has to do the clflush itself.

This paragraph is a little confusing to me. Here reads like the TDX
module does the clflush internally and the host doesn't have to opt-in.

> The TDH.PHYMEM.PAGE.WBINVD SEAMCALL
> leaf was created for this purpose.

But the SEAMCALL leaf shows host should opt-in.

Ah, you want to say host can't directly do clflush because of some
reason, so we need a SEAMCALL, is it?

[...]

> @@ -578,15 +577,6 @@ static void tdx_reclaim_td_control_pages(struct kvm *kvm)
> if (__tdx_reclaim_page(kvm_tdx->td.tdr_page))
> return;
>
> - /*
> - * Use a SEAMCALL to ask the TDX module to flush the cache based on the
> - * KeyID. TDX module may access TDR while operating on TD (Especially
> - * when it is reclaiming TDCS).
> - */
> - err = tdh_phymem_page_wbinvd_tdr(&kvm_tdx->td);
> - if (TDX_BUG_ON(err, TDH_PHYMEM_PAGE_WBINVD, kvm))
> - return;
> -
> tdx_quirk_reset_paddr(page_to_phys(kvm_tdx->td.tdr_page), PAGE_SIZE);
>
> __free_page(kvm_tdx->td.tdr_page);

After removing the wbinvd, we don't need open code to reclaim tdr
anymore, is it? tdx_reclaim_control_page(kvm_tdx->td.tdr_page)?

This may not be relevant to the topic, not sure if we are good to clean
up it in this series.


Another thing. There are also 2 wbinvd_on_all_cpus() on PAMT
adding/reclaiming. Remove them?