Skip to content

Commit 99b85fd

Browse files
committed
KVM: x86/mmu: Skip invalid roots when zapping leaf SPTEs for GFN range
When zapping a GFN in response to an APICv or MTRR change, don't zap SPTEs for invalid roots as KVM only needs to ensure the guest can't use stale mappings for the GFN. Unlike kvm_tdp_mmu_unmap_gfn_range(), which must zap "unreachable" SPTEs to ensure KVM doesn't mark a page accessed/dirty, kvm_tdp_mmu_zap_leafs() isn't used (and isn't intended to be used) to handle freeing of host memory. Link: https://lore.kernel.org/r/20240111020048.844847-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6577f1e commit 99b85fd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,16 +830,16 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
830830
}
831831

832832
/*
833-
* Zap leaf SPTEs for the range of gfns, [start, end), for all roots. Returns
834-
* true if a TLB flush is needed before releasing the MMU lock, i.e. if one or
835-
* more SPTEs were zapped since the MMU lock was last acquired.
833+
* Zap leaf SPTEs for the range of gfns, [start, end), for all *VALID** roots.
834+
* Returns true if a TLB flush is needed before releasing the MMU lock, i.e. if
835+
* one or more SPTEs were zapped since the MMU lock was last acquired.
836836
*/
837837
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush)
838838
{
839839
struct kvm_mmu_page *root;
840840

841841
lockdep_assert_held_write(&kvm->mmu_lock);
842-
for_each_tdp_mmu_root_yield_safe(kvm, root)
842+
for_each_valid_tdp_mmu_root_yield_safe(kvm, root, -1)
843843
flush = tdp_mmu_zap_leafs(kvm, root, start, end, true, flush);
844844

845845
return flush;

0 commit comments

Comments
 (0)