Skip to content

Commit 6d3085e

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Block all page faults during kvm_zap_gfn_range()
When zapping a GFN range, pass 0 => ALL_ONES for the to-be-invalidated range to effectively block all page faults while the zap is in-progress. The invalidation helpers take a host virtual address, whereas zapping a GFN obviously provides a guest physical address and with the wrong unit of measurement (frame vs. byte). Alternatively, KVM could walk all memslots to get the associated HVAs, but thanks to SMM, that would require multiple lookups. And practically speaking, kvm_zap_gfn_range() usage is quite rare and not a hot path, e.g. MTRR and CR0.CD are almost guaranteed to be done only on vCPU0 during boot, and APICv inhibits are similarly infrequent operations. Fixes: edb298c ("KVM: x86/mmu: bump mmu notifier count in kvm_zap_gfn_range") Reported-by: Chao Peng <chao.p.peng@linux.intel.com> Cc: stable@vger.kernel.org Cc: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20221111001841.2412598-1-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d72cf8f commit 6d3085e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6056,7 +6056,7 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
60566056

60576057
write_lock(&kvm->mmu_lock);
60586058

6059-
kvm_mmu_invalidate_begin(kvm, gfn_start, gfn_end);
6059+
kvm_mmu_invalidate_begin(kvm, 0, -1ul);
60606060

60616061
flush = kvm_rmap_zap_gfn_range(kvm, gfn_start, gfn_end);
60626062

@@ -6070,7 +6070,7 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
60706070
kvm_flush_remote_tlbs_with_address(kvm, gfn_start,
60716071
gfn_end - gfn_start);
60726072

6073-
kvm_mmu_invalidate_end(kvm, gfn_start, gfn_end);
6073+
kvm_mmu_invalidate_end(kvm, 0, -1ul);
60746074

60756075
write_unlock(&kvm->mmu_lock);
60766076
}

0 commit comments

Comments
 (0)