diff mbox

[00/20] KVM: selftests: Fixes and cleanups for dirty_log_test

Message ID 20241214010721.2356923-1-seanjc@google.com (mailing list archive)
State New
Headers show

Commit Message

Sean Christopherson Dec. 14, 2024, 1:07 a.m. UTC
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 mbox

Patch

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)