KVM: x86/mmu: Don't do TLB flush when zappings SPTEs in invalid roots
authorSean Christopherson <seanjc@google.com>
Thu, 11 Jan 2024 02:00:42 +0000 (18:00 -0800)
committerSean Christopherson <seanjc@google.com>
Fri, 23 Feb 2024 00:28:45 +0000 (16:28 -0800)
Don't force a TLB flush when zapping SPTEs in invalid roots as vCPUs
can't be actively using invalid roots (zapping SPTEs in invalid roots is
necessary only to ensure KVM doesn't mark a page accessed/dirty after it
is freed by the primary MMU).

Link: https://lore.kernel.org/r/20240111020048.844847-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/mmu/tdp_mmu.c

index 372da098d3ce7118f96043084cc69351d1ba03b0..68920877370b24d7f31a167c718f52186da29481 100644 (file)
@@ -811,7 +811,13 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
                        continue;
 
                tdp_mmu_iter_set_spte(kvm, &iter, 0);
-               flush = true;
+
+               /*
+                * Zappings SPTEs in invalid roots doesn't require a TLB flush,
+                * see kvm_tdp_mmu_zap_invalidated_roots() for details.
+                */
+               if (!root->role.invalid)
+                       flush = true;
        }
 
        rcu_read_unlock();