KVM: pfncache: check the need for invalidation under read lock first
authorPaul Durrant <pdurrant@amazon.com>
Thu, 15 Feb 2024 15:29:14 +0000 (15:29 +0000)
committerSean Christopherson <seanjc@google.com>
Thu, 22 Feb 2024 15:01:20 +0000 (07:01 -0800)
commit9fa336e343b2c7f6bad6fd5fa2e1cf55e80d3ed1
treefedea5f91c18f801ec7297d42f2d60e8e0ce92ce
parent615451d8cb3f82265e0ed60414b606b4fa120f5e
KVM: pfncache: check the need for invalidation under read lock first

When processing mmu_notifier invalidations for gpc caches, pre-check for
overlap with the invalidation event while holding gpc->lock for read, and
only take gpc->lock for write if the cache needs to be invalidated.  Doing
a pre-check without taking gpc->lock for write avoids unnecessarily
contending the lock for unrelated invalidations, which is very beneficial
for caches that are heavily used (but rarely subjected to mmu_notifier
invalidations).

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Link: https://lore.kernel.org/r/20240215152916.1158-20-paul@xen.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/pfncache.c