From: sashiko-bot@kernel.org
To: "James Houghton" <jthoughton@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
Date: Tue, 17 Nov 2026 21:37:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-219706@kernel.org> (raw)
In-Reply-To: <20261117212913.3634487-5-jthoughton@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: selftests: clear RESET flags in
dirty_ring_reset_unused_entries()
--
commit 494a32b29217257f8a046ec9364c749fef56211c
Author: James Houghton <jthoughton@google.com>
KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
This commit adds a helper to dirty_log_test that marks the first two unused
dirty ring entries as harvested before running the vCPU and asserts that
KVM_RESET_DIRTY_RINGS resets zero entries.
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> index 8189eaac713cd..96a40488eccb0 100644
> --- a/tools/testing/selftests/kvm/dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -375,6 +375,21 @@ 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. KVM will
> + * overwrite the flags when it pushes to the entries.
> + */
> + 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);
> +}
[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:
virt/kvm/dirty_ring.c:kvm_dirty_ring_push() {
...
WRITE_ONCE(ring->dirty_index, ring->dirty_index + 1);
kvm_dirty_gfn_set_dirtied(entry);
...
}
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:
host vcpu_worker
---- -----------
dirty_ring_collect_dirty_pages()
dirty_ring_collect_one()
/* flags == KVM_DIRTY_GFN_F_RESET,
stops with count == 0 */
kvm_dirty_ring_push()
ring->dirty_index++
kvm_vm_reset_dirty_ring()
kvm_dirty_ring_reset()
kvm_dirty_gfn_harvested(entry)
kvm_dirty_ring_used(ring) > 0
ring->reset_index++
cleared++
kvm_dirty_gfn_set_dirtied(entry)
TEST_ASSERT(cleared == count) <-- fails (1 != 0)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117212913.3634487-1-jthoughton@google.com?part=4
next prev parent reply other threads:[~2026-11-17 21:37 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 [this message]
2026-11-17 21:55 ` 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=sashiko-outbox-219706@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jthoughton@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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