Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: James Houghton <jthoughton@google.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Xu <peterx@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 syzbot+55eaa971f4924b62c9a5@syzkaller.appspotmail.com
Subject: [PATCH 2/4] KVM: Use smp_store_release() to mark dirty ring entries as dirtied
Date: Tue, 17 Nov 2026 21:29:11 +0000	[thread overview]
Message-ID: <20261117212913.3634487-3-jthoughton@google.com> (raw)
In-Reply-To: <20261117212913.3634487-1-jthoughton@google.com>

Publish dirty ring entries to userspace with smp_store_release() in
kvm_dirty_gfn_set_dirtied(), instead of an smp_wmb() in
kvm_dirty_ring_push() followed by a plain store in the helper.

Setting the DIRTY flag is the first half of a handshake with userspace:
userspace load-acquires the DIRTY flag, harvests the entry, and
store-releases the RESET flag, which KVM then load-acquires in
kvm_dirty_gfn_harvested(). Commit 8929bc965964 ("KVM: Use acquire/release
semantics when accessing dirty ring GFN state") converted KVM's side of
the RESET flag to acquire/release, but left the DIRTY side split between
a barrier in the caller and a plain store in the helper. As a result, the
helper doesn't convey that its store must be ordered, and the store isn't
marked even though userspace can access the flags concurrently.

Now that kvm_dirty_ring_reset() relies on this handshake to observe an
up-to-date dirty_index, make the ordering explicit and self-contained in
the helper, so that all three flag accessors use matching acquire/release
semantics.

No functional change intended.

Signed-off-by: James Houghton <jthoughton@google.com>
---
 virt/kvm/dirty_ring.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 8fab75dace76..d0693ef6e479 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -95,7 +95,7 @@ static inline void kvm_dirty_gfn_set_invalid(struct kvm_dirty_gfn *gfn)
 
 static inline void kvm_dirty_gfn_set_dirtied(struct kvm_dirty_gfn *gfn)
 {
-	gfn->flags = KVM_DIRTY_GFN_F_DIRTY;
+	smp_store_release(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
 }
 
 static inline bool kvm_dirty_gfn_harvested(struct kvm_dirty_gfn *gfn)
@@ -245,7 +245,6 @@ void kvm_dirty_ring_push(struct kvm_vcpu *vcpu, u32 slot, u64 offset)
 	 * the entry to userspace.
 	 */
 	WRITE_ONCE(ring->dirty_index, ring->dirty_index + 1);
-	smp_wmb();
 	kvm_dirty_gfn_set_dirtied(entry);
 	trace_kvm_dirty_ring_push(ring, slot, offset);
 
-- 
2.56.1.708.g77570a6a1d-goog


  parent reply	other threads:[~2026-11-17 21:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 21:29 [PATCH 0/4] KVM: Don't let dirty ring resets pass dirty_index James Houghton
2026-11-17 21:29 ` [PATCH 1/4] KVM: Don't reset dirty ring entries that KVM hasn't pushed James Houghton
2026-11-17 21:29 ` James Houghton [this message]
2026-11-17 21:29 ` [PATCH 3/4] KVM: Annotate concurrent accesses to dirty ring indices James Houghton
2026-11-17 21:29 ` [PATCH 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries James Houghton
2026-11-17 21:37   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117212913.3634487-3-jthoughton@google.com \
    --to=jthoughton@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=syzbot+55eaa971f4924b62c9a5@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox