From: Yan Zhao Date: Tue, 18 Mar 2025 01:32:38 +0000 (+0800) Subject: KVM: x86/tdp_mmu: WARN if PFN changes for spurious faults X-Git-Tag: v6.16-rc1~78^2~8^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=988da7820206405ef2d8afde83c2c2cd7af503a2;p=thirdparty%2Fkernel%2Flinux.git KVM: x86/tdp_mmu: WARN if PFN changes for spurious faults Add a WARN() to assert that KVM does _not_ change the PFN of a shadow-present SPTE during spurious fault handling. KVM should _never_ change the PFN of a shadow-present SPTE and TDP MMU already BUG()s on this. However, spurious faults just return early before the existing BUG() could be hit. Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao Link: https://lore.kernel.org/r/20250318013238.5732-1-yan.y.zhao@intel.com Signed-off-by: Sean Christopherson --- diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index d16e3e6e46a51..1e2db49174594 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1155,8 +1155,10 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, if (is_shadow_present_pte(iter->old_spte) && (fault->prefetch || is_access_allowed(fault, iter->old_spte)) && - is_last_spte(iter->old_spte, iter->level)) + is_last_spte(iter->old_spte, iter->level)) { + WARN_ON_ONCE(fault->pfn != spte_to_pfn(iter->old_spte)); return RET_PF_SPURIOUS; + } if (unlikely(!fault->slot)) new_spte = make_mmio_spte(vcpu, iter->gfn, ACC_ALL);