From: James Houghton <jthoughton@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
sashiko-bot@kernel.org
Cc: jthoughton@google.com, kvm@vger.kernel.org,
sashiko-reviews@lists.linux.dev
Subject: Re: [PATCH 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
Date: Tue, 17 Nov 2026 21:55:57 +0000 [thread overview]
Message-ID: <20261117215557.3756787-1-jthoughton@google.com> (raw)
In-Reply-To: <sashiko-outbox-219706@kernel.org>
On 17 November 2026, sashiko-bot@kernel.org wrote:
> [Severity: Low]
> Should dirty_ring_reset_unused_entries() clear flags back to 0 on
> dirty_gfns[0] and dirty_gfns[1] after kvm_vm_reset_dirty_ring() returns?
>
> When kvm_dirty_ring_used(ring) is 0, kvm_dirty_ring_reset() breaks out of
> its loop before calling kvm_dirty_gfn_set_invalid(entry), leaving both
> entries with KVM_DIRTY_GFN_F_RESET set when vcpu_worker starts. In
> kvm_dirty_ring_push(), KVM increments ring->dirty_index before overwriting
> entry->flags with KVM_DIRTY_GFN_F_DIRTY:
[...]
> If the host reaping loop runs while the vCPU is pushing its first two dirty
> ring entries (for example when reap_i is 0), kvm_dirty_ring_reset() can
> observe the stale KVM_DIRTY_GFN_F_RESET flag together with the incremented
> ring->dirty_index and reset an entry that userspace never collected:
Yeah, this is possible. Sashiko's suggestion is the right one, I think.
Sean/Paolo, if nothing else in the series needs a v2, would you mind squashing
in the below when applying? Otherwise I'll fold it into v2.
Thanks!
---
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 96a4048..b03ce06 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -381,13 +381,20 @@ static void dirty_ring_reset_unused_entries(struct kvm_vcpu *vcpu)
/*
* Mark unused entries as harvested, and verify KVM doesn't reset any
- * entries, as KVM hasn't pushed anything to the ring. KVM will
- * overwrite the flags when it pushes to the entries.
+ * 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)
prev parent reply other threads:[~2026-11-17 21:55 UTC|newest]
Thread overview: 7+ 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 ` [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
2026-11-17 21:55 ` James Houghton [this message]
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=20261117215557.3756787-1-jthoughton@google.com \
--to=jthoughton@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanjc@google.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