mirror of https://lore.kernel.org/lkml/
 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 v2 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
Date: Thu,  3 Dec 2026 21:20:53 +0000	[thread overview]
Message-ID: <20261203212054.2957430-5-jthoughton@google.com> (raw)
In-Reply-To: <20261203212054.2957430-1-jthoughton@google.com>

Before running the vCPU in the dirty ring test, mark the first two
(unused) entries of the ring as harvested and verify that
KVM_RESET_DIRTY_RINGS doesn't reset any entries, i.e. that KVM doesn't
advance reset_index beyond dirty_index. Clear the flags afterwards, so
that the bogus RESET flags can't race with KVM pushing to the entries.

Signed-off-by: James Houghton <jthoughton@google.com>
---
 tools/testing/selftests/kvm/dirty_log_test.c | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 8189eaac713c..b03ce06ce100 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -375,6 +375,28 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
 		    "with collected (%u)", cleared, count);
 }
 
+static void dirty_ring_reset_unused_entries(struct kvm_vcpu *vcpu)
+{
+	struct kvm_dirty_gfn *dirty_gfns = vcpu_map_dirty_ring(vcpu);
+
+	/*
+	 * Mark unused entries as harvested, and verify KVM doesn't reset any
+	 * entries, as KVM hasn't pushed anything to the ring.
+	 */
+	dirty_gfn_set_collected(&dirty_gfns[0]);
+	dirty_gfn_set_collected(&dirty_gfns[1]);
+
+	TEST_ASSERT_EQ(kvm_vm_reset_dirty_ring(vcpu->vm), 0);
+
+	/*
+	 * Clear the bogus RESET flags, otherwise a reset that runs while KVM
+	 * is pushing to the entries could reset them before userspace has
+	 * collected them.
+	 */
+	dirty_gfns[0].flags = 0;
+	dirty_gfns[1].flags = 0;
+}
+
 static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu)
 {
 	struct kvm_run *run = vcpu->run;
@@ -687,6 +709,9 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	TEST_ASSERT_EQ(vcpu_stop, false);
 
+	if (host_log_mode == LOG_MODE_DIRTY_RING)
+		dirty_ring_reset_unused_entries(vcpu);
+
 	kvm_pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu);
 
 	for (iteration = 1; iteration <= p->iterations; iteration++) {
-- 
2.56.1.915.g69d5ec7298-goog


  parent reply	other threads:[~2026-12-03 21:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:20 [PATCH v2 0/4] KVM: Don't let dirty ring resets pass dirty_index James Houghton
2026-12-03 21:20 ` [PATCH v2 1/4] KVM: Don't reset dirty ring entries that KVM hasn't pushed James Houghton
2026-12-03 21:20 ` [PATCH v2 2/4] KVM: Use smp_store_release() to mark dirty ring entries as dirtied James Houghton
2026-12-03 21:20 ` [PATCH v2 3/4] KVM: Annotate concurrent accesses to dirty ring indices James Houghton
2026-12-03 21:20 ` James Houghton [this message]
2026-12-03 21:36 ` [PATCH v2 0/4] KVM: Don't let dirty ring resets pass dirty_index Sean Christopherson
2026-12-03 21:47   ` James Houghton

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=20261203212054.2957430-5-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

all inboxes | Powered by JetHome®