KVM: x86: avoid memslot check in NX hugepage recovery if it cannot succeed
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Nov 2022 17:25:02 +0000 (12:25 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 18 Nov 2022 16:30:12 +0000 (11:30 -0500)
commit6c7b2202e4d11572ab23a89aeec49005b94bb966
treeb47d8b0b67e8e9db088088efcfd969a48878832c
parent771a579c6e74f305eff97752d91e9b05c4e46323
KVM: x86: avoid memslot check in NX hugepage recovery if it cannot succeed

Since gfn_to_memslot() is relatively expensive, it helps to
skip it if it the memslot cannot possibly have dirty logging
enabled.  In order to do this, add to struct kvm a counter
of the number of log-page memslots.  While the correct value
can only be read with slots_lock taken, the NX recovery thread
is content with using an approximate value.  Therefore, the
counter is an atomic_t.

Based on https://lore.kernel.org/kvm/20221027200316.2221027-2-dmatlack@google.com/
by David Matlack.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c
include/linux/kvm_host.h
virt/kvm/kvm_main.c