Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+8
+8
virt/kvm/dirty_ring.c
··· 122 122 unsigned long mask = 0; 123 123 struct kvm_dirty_gfn *entry; 124 124 125 + /* 126 + * Ensure concurrent calls to KVM_RESET_DIRTY_RINGS are serialized, 127 + * e.g. so that KVM fully resets all entries processed by a given call 128 + * before returning to userspace. Holding slots_lock also protects 129 + * the various memslot accesses. 130 + */ 131 + lockdep_assert_held(&kvm->slots_lock); 132 + 125 133 while (likely((*nr_entries_reset) < INT_MAX)) { 126 134 if (signal_pending(current)) 127 135 return -EINTR;