aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2025-05-16 14:35:40 -0700
committerSean Christopherson <seanjc@google.com>2025-06-20 13:41:04 -0700
commit614fb9d1479b1d90721ca70da8b7c55f69fe9ad2 (patch)
tree7a1835eccd50d8c0489c64218864105a71e1ab7f
parente46ad851150f1dd14b8542b6fb7a51f695a99eb1 (diff)
downloadnet-614fb9d1479b1d90721ca70da8b7c55f69fe9ad2.tar.gz
KVM: Assert that slots_lock is held when resetting per-vCPU dirty rings
Assert that slots_lock is held in kvm_dirty_ring_reset() and add a comment to explain _why_ slots needs to be held for the duration of the reset. Link: https://lore.kernel.org/all/aCSns6Q5oTkdXUEe@google.com Suggested-by: James Houghton <jthoughton@google.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/20250516213540.2546077-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r--virt/kvm/dirty_ring.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 4caa63e610d261..02bc6b00d76cbd 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -122,6 +122,14 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring,
unsigned long mask = 0;
struct kvm_dirty_gfn *entry;
+ /*
+ * Ensure concurrent calls to KVM_RESET_DIRTY_RINGS are serialized,
+ * e.g. so that KVM fully resets all entries processed by a given call
+ * before returning to userspace. Holding slots_lock also protects
+ * the various memslot accesses.
+ */
+ lockdep_assert_held(&kvm->slots_lock);
+
while (likely((*nr_entries_reset) < INT_MAX)) {
if (signal_pending(current))
return -EINTR;