tdx_clear_page() and reset_tdx_pages() duplicate the TDX page clearing
logic. Keep the tdx_clear_page() prototype but call reset_tdx_pages() for
the implementation.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
arch/x86/include/asm/tdx.h | 2 ++
arch/x86/kvm/vmx/tdx.c | 19 -------------------
arch/x86/virt/vmx/tdx/tdx.c | 6 ++++++
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index 7ddef3a69866..e94eb0711bf1 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -131,6 +131,8 @@ int tdx_guest_keyid_alloc(void);
u32 tdx_get_nr_guest_keyids(void);
void tdx_guest_keyid_free(unsigned int keyid);
+void tdx_clear_page(struct page *page);
+
struct tdx_td {
/* TD root structure: */
struct page *tdr_page;
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index a08e7055d1db..098e4ee574bb 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -276,25 +276,6 @@ static inline void tdx_disassociate_vp(struct kvm_vcpu *vcpu)
vcpu->cpu = -1;
}
-static void tdx_clear_page(struct page *page)
-{
- const void *zero_page = (const void *) page_to_virt(ZERO_PAGE(0));
- void *dest = page_to_virt(page);
- unsigned long i;
-
- /*
- * The page could have been poisoned. MOVDIR64B also clears
- * the poison bit so the kernel can safely use the page again.
- */
- for (i = 0; i < PAGE_SIZE; i += 64)
- movdir64b(dest + i, zero_page);
- /*
- * MOVDIR64B store uses WC buffer. Prevent following memory reads
- * from seeing potentially poisoned cache.
- */
- __mb();
-}
-
static void tdx_no_vcpus_enter_start(struct kvm *kvm)
{
struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm);
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index c7a9a087ccaf..17a7a599facd 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -654,6 +654,12 @@ static void reset_tdx_pages(unsigned long base, unsigned long size)
mb();
}
+void tdx_clear_page(struct page *page)
+{
+ reset_tdx_pages(page_to_phys(page), PAGE_SIZE);
+}
+EXPORT_SYMBOL_GPL(tdx_clear_page);
+
static void tdmr_reset_pamt(struct tdmr_info *tdmr)
{
tdmr_do_pamt_func(tdmr, reset_tdx_pages);
--
2.48.1
On 7/3/25 04:40, Adrian Hunter wrote: > tdx_clear_page() and reset_tdx_pages() duplicate the TDX page clearing > logic. Keep the tdx_clear_page() prototype but call reset_tdx_pages() for > the implementation. Why keep the old prototype?
On 03/07/2025 17:14, Dave Hansen wrote: > On 7/3/25 04:40, Adrian Hunter wrote: >> tdx_clear_page() and reset_tdx_pages() duplicate the TDX page clearing >> logic. Keep the tdx_clear_page() prototype but call reset_tdx_pages() for >> the implementation. > > Why keep the old prototype? What prototype would you prefer?
On 7/3/25 07:39, Adrian Hunter wrote: > On 03/07/2025 17:14, Dave Hansen wrote: >> On 7/3/25 04:40, Adrian Hunter wrote: >>> tdx_clear_page() and reset_tdx_pages() duplicate the TDX page clearing >>> logic. Keep the tdx_clear_page() prototype but call reset_tdx_pages() for >>> the implementation. >> Why keep the old prototype? > What prototype would you prefer? My first reaction is that there should be _one_ function that does the erratum-related clearing. I'd rather have the KVM sites use the slightly cumbersome paddr/size arguments than have two functions. Worst, case, have two functions that have similar names to make it clear that they are doing the same thing. It is *NOT* clear that: tdx_clear_page() and reset_tdx_pages() are doing the exact same thing. I think I'd probably rename reset_tdx_pages() to tdx_reset_paddr() and then use it in KVM like this: tdx_quirk_reset_paddr(page_to_phys(page), PAGE_SIZE); The alternative would be to retain a function that keeps the 'struct page' as an argument. Something like: tdx_quirk_reset_paddr(unsigned long base, unsigned long size) and tdx_quirk_reset_page(struct page *page) But the way proposed in this patch is very much a half measure.
© 2016 - 2025 Red Hat, Inc.