Fix a variety of flaws and false failures/passes in dirty_log_test, and drop code/behavior that adds complexity while adding little-to-no benefit. Lots of details in the changelogs, and a partial list of complaints[1] in Maxim's original thread[2]. E.g. while not a particular interesting bug, hacking KVM like so doesn't elicit a test failure. --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 401439bb21e3..bf7797ae2cdc 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -389,6 +389,8 @@ struct kvm_vcpu { */ struct kvm_memory_slot *last_used_slot; u64 last_used_slot_gen; + + bool extra_dirty; }; /* diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index de2c11dae231..9981f1cc2780 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3444,6 +3444,11 @@ void mark_page_dirty_in_slot(struct kvm *kvm, unsigned long rel_gfn = gfn - memslot->base_gfn; u32 slot = (memslot->as_id << 16) | memslot->id; + if (!vcpu->extra_dirty && + gfn_to_memslot(kvm, gfn + 1) == gfn) { + vcpu->extra_dirty = true; + mark_page_dirty_in_slot(kvm, memslot, gfn + 1); + } if (kvm->dirty_ring_size && vcpu) kvm_dirty_ring_push(vcpu, slot, rel_gfn); else if (memslot->dirty_bitmap) -- [1] https://lore.kernel.org/all/Z1vR25ylN5m_DRSy@xxxxxxxxxx [2] https://lore.kernel.org/all/20241211193706.469817-1-mlevitsk@xxxxxxxxxx Maxim Levitsky (2): KVM: selftests: Support multiple write retires in dirty_log_test KVM: selftests: Limit dirty_log_test's s390x workaround to s390x Sean Christopherson (18): KVM: selftests: Sync dirty_log_test iteration to guest *before* resuming KVM: selftests: Drop signal/kick from dirty ring testcase KVM: selftests: Drop stale srandom() initialization from dirty_log_test KVM: selftests: Precisely track number of dirty/clear pages for each iteration KVM: selftests: Read per-page value into local var when verifying dirty_log_test KVM: selftests: Continuously reap dirty ring while vCPU is running KVM: selftests: Honor "stop" request in dirty ring test KVM: selftests: Keep dirty_log_test vCPU in guest until it needs to stop KVM: selftests: Post to sem_vcpu_stop if and only if vcpu_stop is true KVM: selftests: Use continue to handle all "pass" scenarios in dirty_log_test KVM: selftests: Print (previous) last_page on dirty page value mismatch KVM: selftests: Collect *all* dirty entries in each dirty_log_test iteration KVM: sefltests: Verify value of dirty_log_test last page isn't bogus KVM: selftests: Ensure guest writes min number of pages in dirty_log_test KVM: selftests: Tighten checks around prev iter's last dirty page in ring KVM: selftests: Set per-iteration variables at the start of each iteration KVM: selftests: Fix an off-by-one in the number of dirty_log_test iterations KVM: selftests: Allow running a single iteration of dirty_log_test tools/testing/selftests/kvm/dirty_log_test.c | 515 +++++++++---------- 1 file changed, 240 insertions(+), 275 deletions(-) base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4 -- 2.47.1.613.gc27f4b7a9f-goog