KVM: x86/mmu: Skip !MMU-present SPTEs when removing SP in exclusive mode
authorSean Christopherson <seanjc@google.com>
Wed, 10 Mar 2021 00:30:29 +0000 (16:30 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 12 Mar 2021 18:18:52 +0000 (13:18 -0500)
commit8df9f1af2eced9720f71cf310275d81c1bf07a06
tree606d7db42b81d2fc5b969c08726cdc094665f47b
parentd7eb79c6290c7ae4561418544072e0a3266e7384
KVM: x86/mmu: Skip !MMU-present SPTEs when removing SP in exclusive mode

If mmu_lock is held for write, don't bother setting !PRESENT SPTEs to
REMOVED_SPTE when recursively zapping SPTEs as part of shadow page
removal.  The concurrent write protections provided by REMOVED_SPTE are
not needed, there are no backing page side effects to record, and MMIO
SPTEs can be left as is since they are protected by the memslot
generation, not by ensuring that the MMIO SPTE is unreachable (which
is racy with respect to lockless walks regardless of zapping behavior).

Skipping !PRESENT drastically reduces the number of updates needed to
tear down sparsely populated MMUs, e.g. when tearing down a 6gb VM that
didn't touch much memory, 6929/7168 (~96.6%) of SPTEs were '0' and could
be skipped.

Avoiding the write itself is likely close to a wash, but avoiding
__handle_changed_spte() is a clear-cut win as that involves saving and
restoring all non-volatile GPRs (it's a subtly big function), as well as
several conditional branches before bailing out.

Cc: Ben Gardon <bgardon@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210310003029.1250571-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/tdp_mmu.c