KVM: x86/mmu: Coalesce TLB flushes when zapping collapsible SPTEs
authorSean Christopherson <seanjc@google.com>
Fri, 26 Mar 2021 02:19:42 +0000 (19:19 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 17 Apr 2021 12:30:54 +0000 (08:30 -0400)
Gather pending TLB flushes across both the legacy and TDP MMUs when
zapping collapsible SPTEs to avoid multiple flushes if both the legacy
MMU (for nested guests) and TDP MMU have mappings for the memslot.

Note, this also optimizes the TDP MMU to flush only the relevant range
when running as L1 with Hyper-V enlightenments.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210326021957.1424875-4-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/mmu/tdp_mmu.h

index fbd3363eb91f3bf33143a52361f1882eec7362e5..4e09641d52ecae7578551d5f1486f8118b034d2a 100644 (file)
@@ -5629,11 +5629,13 @@ void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
 
        write_lock(&kvm->mmu_lock);
        flush = slot_handle_leaf(kvm, slot, kvm_mmu_zap_collapsible_spte, true);
+
+       if (is_tdp_mmu_enabled(kvm))
+               flush = kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot, flush);
+
        if (flush)
                kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
 
-       if (is_tdp_mmu_enabled(kvm))
-               kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot);
        write_unlock(&kvm->mmu_lock);
 }
 
index 31459c94290d4db29fc214591a7d815daea9fe48..09f4247eadfbc891747356ce86abf909ab467799 100644 (file)
@@ -1310,11 +1310,10 @@ static bool zap_collapsible_spte_range(struct kvm *kvm,
  * Clear non-leaf entries (and free associated page tables) which could
  * be replaced by large mappings, for GFNs within the slot.
  */
-void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
-                                      struct kvm_memory_slot *slot)
+bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
+                                      struct kvm_memory_slot *slot, bool flush)
 {
        struct kvm_mmu_page *root;
-       bool flush = false;
        int root_as_id;
 
        for_each_tdp_mmu_root_yield_safe(kvm, root) {
@@ -1325,8 +1324,7 @@ void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
                flush = zap_collapsible_spte_range(kvm, root, slot, flush);
        }
 
-       if (flush)
-               kvm_flush_remote_tlbs(kvm);
+       return flush;
 }
 
 /*
index 31096ece9b144a50a401c54803abff5f2cb00a0d..a76a84d2ff46dcd15d6fe114c1ad7031f7c2dcd2 100644 (file)
@@ -55,8 +55,8 @@ void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm,
                                       struct kvm_memory_slot *slot,
                                       gfn_t gfn, unsigned long mask,
                                       bool wrprot);
-void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
-                                      struct kvm_memory_slot *slot);
+bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
+                                      struct kvm_memory_slot *slot, bool flush);
 
 bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm,
                                   struct kvm_memory_slot *slot, gfn_t gfn);