[PATCH 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
From: James Houghton
Date: Tue Nov 17 2026 - 16:30:00 EST
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.
Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
tools/testing/selftests/kvm/dirty_log_test.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 8189eaac713c..96a40488eccb 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);
+}
+
static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu->run;
@@ -687,6 +702,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.708.g77570a6a1d-goog