OSDN Git Service

KVM: x86/mmu: Check for !leaf=>leaf, not PFN change, in TDP MMU SP removal
authorSean Christopherson <seanjc@google.com>
Sat, 26 Feb 2022 00:15:25 +0000 (00:15 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 8 Mar 2022 14:31:51 +0000 (09:31 -0500)
Look for a !leaf=>leaf conversion instead of a PFN change when checking
if a SPTE change removed a TDP MMU shadow page.  Convert the PFN check
into a WARN, as KVM should never change the PFN of a shadow page (except
when its being zapped or replaced).

From a purely theoretical perspective, it's not illegal to replace a SP
with a hugepage pointing at the same PFN.  In practice, it's impossible
as that would require mapping guest memory overtop a kernel-allocated SP.
Either way, the check is odd.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Message-Id: <20220226001546.360188-8-seanjc@google.com>
Reviewed-by: Mingwei Zhang <mizhang@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/tdp_mmu.c

index 79bc48d..53c7987 100644 (file)
@@ -491,9 +491,12 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
 
        /*
         * Recursively handle child PTs if the change removed a subtree from
-        * the paging structure.
+        * the paging structure.  Note the WARN on the PFN changing without the
+        * SPTE being converted to a hugepage (leaf) or being zapped.  Shadow
+        * pages are kernel allocations and should never be migrated.
         */
-       if (was_present && !was_leaf && (pfn_changed || !is_present))
+       if (was_present && !was_leaf &&
+           (is_leaf || !is_present || WARN_ON_ONCE(pfn_changed)))
                handle_removed_pt(kvm, spte_to_child_pt(old_spte, level), shared);
 }