Re: [PATCH v2 09/15] KVM: x86/tdp_mmu: Centrally propagate to-present/atomic zap updates to external PTEs
From: Yan Zhao
Date: Tue May 19 2026 - 02:57:42 EST
On Tue, May 19, 2026 at 09:35:14AM +0800, Yan Zhao wrote:
> On Sat, May 09, 2026 at 03:56:34PM +0800, Yan Zhao wrote:
> Oops, this patch needs a small fixup (the internal sashiko found this issue):
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index bb18e9e61542..e783886296c1 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -535,34 +535,36 @@ static int __handle_changed_spte(struct kvm *kvm, struct kvm_mmu_page *sp,
> if (!was_present && !is_present) {
> /*
> * If this change does not involve a MMIO SPTE or frozen SPTE,
> * it is unexpected. Log the change, though it should not
> * impact the guest since both the former and current SPTEs
> * are nonpresent.
> */
> if (WARN_ON_ONCE(!is_mmio_spte(kvm, old_spte) &&
> !is_mmio_spte(kvm, new_spte) &&
> !is_frozen_spte(new_spte)))
> pr_err("Unexpected SPTE change! Nonpresent SPTEs\n"
> "should not be replaced with another,\n"
> "different nonpresent SPTE, unless one or both\n"
> "are MMIO SPTEs, or the new SPTE is\n"
> "a temporary frozen SPTE.\n"
> "as_id: %d gfn: %llx old_spte: %llx new_spte: %llx level: %d",
> as_id, gfn, old_spte, new_spte, level);
> +
> + trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte);
> return 0;
> }
An alternative fix:
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index bb18e9e61542..5d7c83d74ade 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -572,7 +572,6 @@ static int __handle_changed_spte(struct kvm *kvm, struct kvm_mmu_page *sp,
if (r)
return r;
}
- trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte);
if (is_leaf != was_leaf)
kvm_update_page_stats(kvm, level, is_leaf ? 1 : -1);
@@ -586,6 +585,9 @@ static void handle_changed_spte(struct kvm *kvm, struct kvm_mmu_page *sp,
{
KVM_BUG_ON(__handle_changed_spte(kvm, sp, gfn, old_spte, new_spte,
level, shared), kvm);
+ if (old_spte != new_spte)
+ trace_kvm_tdp_mmu_spte_changed(kvm_mmu_page_as_id(sp), gfn, level,
+ old_spte, new_spte);
}
static inline int __must_check __tdp_mmu_set_spte_atomic(struct kvm *kvm,
@@ -683,6 +685,10 @@ static inline int __must_check tdp_mmu_set_spte_atomic(struct kvm *kvm,
*/
KVM_BUG_ON(ret, kvm);
}
+
+ if (!ret && iter->old_spte != new_spte)
+ trace_kvm_tdp_mmu_spte_changed(kvm_mmu_page_as_id(sp), iter->gfn,
+ iter->level, iter->old_spte, new_spte);
return ret;
}