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 0/4] KVM: Don't let dirty ring resets pass dirty_index
Date: Tue, 17 Nov 2026 21:29:09 +0000	[thread overview]
Message-ID: <20261117212913.3634487-1-jthoughton@google.com> (raw)

Fix a userspace-triggerable WARN in kvm_dirty_ring_push() reported by
syzbot [1], and tidy up the memory ordering and annotations around the
dirty ring indices while in the area.

Patch 1 is the fix. The dirty ring is mapped writable into userspace, so
userspace can set KVM_DIRTY_GFN_F_RESET on entries that KVM never pushed.
KVM_RESET_DIRTY_RINGS then advances reset_index past dirty_index, the u32
math in kvm_dirty_ring_used() underflows, and the next push hits
WARN_ON_ONCE(kvm_dirty_ring_full(ring)). Stop resetting entries once
reset_index catches up to dirty_index, and bump dirty_index before
publishing the DIRTY flag, so that a VMM that reaps the ring while the
vCPU is running never has a legitimately harvested entry skipped.

Patch 2 converts the DIRTY side of the flags handshake with userspace to
smp_store_release(), to match the acquire/release semantics already used
for the RESET side. No functional change intended.

Patch 3 is optional. It marks the remaining concurrent accesses to the
ring indices: WRITE_ONCE() for reset_index, which the vCPU reads with
READ_ONCE(), and READ_ONCE() for the reads of the other task's index in
the kvm_dirty_ring_push and kvm_dirty_ring_reset tracepoints. I'm not
aware of any KCSAN reports or miscompiles, so this mostly documents the
concurrency and ensures the compiler can't tear the accesses. Feel free
to drop it if that is appropriate.

Patch 4 adds a regression test for patch 1 to dirty_log_test. It fails
without patch 1 (KVM resets two entries it never pushed), and passes with
the series applied, including with a minimally sized ring so that the
vCPU repeatedly exits with KVM_EXIT_DIRTY_RING_FULL while the ring is
being reaped.

[1] https://lore.kernel.org/all/6afbad4d.f3cfa7c9.844a4.0002.GAE@google.com

James Houghton (4):
  KVM: Don't reset dirty ring entries that KVM hasn't pushed
  KVM: Use smp_store_release() to mark dirty ring entries as dirtied
  KVM: Annotate concurrent accesses to dirty ring indices
  KVM: selftests: Verify KVM doesn't reset unused dirty ring entries

 include/trace/events/kvm.h                   |  4 ++--
 tools/testing/selftests/kvm/dirty_log_test.c | 18 +++++++++++++++
 virt/kvm/dirty_ring.c                        | 23 +++++++++++++++-----
 3 files changed, 37 insertions(+), 8 deletions(-)


base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
-- 
2.56.1.708.g77570a6a1d-goog


             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 James Houghton [this message]
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 ` [PATCH 2/4] KVM: Use smp_store_release() to mark dirty ring entries as dirtied James Houghton
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-1-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