From acafcf32c83ec16631463eeed9e87e44177c2e49 Mon Sep 17 00:00:00 2001 From: Ackerley Tng Date: Wed, 26 Aug 2026 09:01:48 +0000 Subject: [PATCH] KVM: SEV: Check for invalidation before warning on unassigned RMP entry When handling an RMP fault, KVM looks up the RMP entry for the backing PFN to determine if a 2MB page needs to be split via PSMASH. If the RMP entry is not assigned (or lookup fails), KVM logs a rate-limited warning under the assumption that private memory should always have an assigned RMP entry. However, a concurrent invalidation (such as guest_memfd hole punching) can race with RMP fault handling and transition the page to shared, unassigning the RMP entry after KVM fetched the PFN. In such cases, not finding an assigned RMP entry is benign. Check mmu_invalidate_retry_gfn() under mmu_lock before warning about a missing or unassigned RMP entry, and suppress the spurious warning if an invalidation occurred for the faulting GFN. Fixes: c63cf135cc99 ("KVM: SEV: Add support to handle RMP nested page faults") Signed-off-by: Ackerley Tng Link: https://patch.msgid.link/20260826-gmem-no-return-page-v4-3-3bb9c1ddb4e3@google.com Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 0d027cff734c..f9dce8acac8e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -5060,8 +5060,12 @@ void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code) ret = snp_lookup_rmpentry(pfn, &assigned, &rmp_level); if (ret || !assigned) { - pr_warn_ratelimited("SEV: Unexpected RMP fault, no assigned RMP entry found for GPA 0x%llx PFN 0x%llx error %d\n", - gpa, pfn, ret); + guard(read_lock)(&kvm->mmu_lock); + + if (!mmu_invalidate_retry_gfn(kvm, mmu_seq, gfn)) + pr_warn_ratelimited("SEV: Unexpected RMP fault, no assigned RMP entry found for GPA 0x%llx PFN 0x%llx error %d\n", + gpa, pfn, ret); + return; }