>From b68a2e6095d76574322ce7cf6e63406436fef36d Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Thu, 9 Jul 2020 21:25:11 -0700 Subject: [PATCH] KVM: x86/mmu: Zap only relevant last/leaf sptes when removing a memslot Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 3dd0af7e75151..9f468337f832c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5810,7 +5810,18 @@ static void kvm_mmu_invalidate_zap_pages_in_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, struct kvm_page_track_notifier_node *node) { - kvm_mmu_zap_all_fast(kvm); + bool flush; + + /* + * Zapping non-leaf SPTEs, a.k.a. not-last SPTEs, isn't required, worst + * case scenario we'll have unused shadow pages lying around until they + * are recycled due to age or when the VM is destroyed. + */ + spin_lock(&kvm->mmu_lock); + flush = slot_handle_all_level(kvm, slot, kvm_zap_rmapp, true); + if (flush) + kvm_flush_remote_tlbs(kvm); + spin_unlock(&kvm->mmu_lock); } void kvm_mmu_init_vm(struct kvm *kvm) -- 2.26.0