[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230116040405.260935-4-gshan@redhat.com>
Date: Mon, 16 Jan 2023 12:04:04 +0800
From: Gavin Shan <gshan@...hat.com>
To: kvmarm@...ts.linux.dev
Cc: kvmarm@...ts.cs.columbia.edu, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, pbonzini@...hat.com, maz@...nel.org,
corbet@....net, james.morse@....com, suzuki.poulose@....com,
oliver.upton@...ux.dev, yuzenghui@...wei.com,
catalin.marinas@....com, will@...nel.org, ricarkol@...gle.com,
eric.auger@...hat.com, yuzhe@...china.com, renzhengeek@...il.com,
ardb@...nel.org, peterx@...hat.com, seanjc@...gle.com,
shan.gavin@...il.com
Subject: [PATCH 3/4] KVM: Refactor mark_page_dirty_in_slot()
Refactor mark_page_dirty_in_slot() to bail early if the memory slot
isn't existing or dirty page tracking is disabled on it. It's the
preparatory work for the forth coming fixes.
No functional change intended.
Signed-off-by: Gavin Shan <gshan@...hat.com>
---
virt/kvm/kvm_main.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9c60384b5ae0..90f538433916 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3317,6 +3317,8 @@ void mark_page_dirty_in_slot(struct kvm *kvm,
gfn_t gfn)
{
struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
+ unsigned long rel_gfn;
+ u32 slot;
#ifdef CONFIG_HAVE_KVM_DIRTY_RING
if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm))
@@ -3325,15 +3327,16 @@ void mark_page_dirty_in_slot(struct kvm *kvm,
WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm));
#endif
- if (memslot && kvm_slot_dirty_track_enabled(memslot)) {
- unsigned long rel_gfn = gfn - memslot->base_gfn;
- u32 slot = (memslot->as_id << 16) | memslot->id;
+ if (!memslot || !kvm_slot_dirty_track_enabled(memslot))
+ return;
- if (kvm->dirty_ring_size && vcpu)
- kvm_dirty_ring_push(vcpu, slot, rel_gfn);
- else if (memslot->dirty_bitmap)
- set_bit_le(rel_gfn, memslot->dirty_bitmap);
- }
+ rel_gfn = gfn - memslot->base_gfn;
+ slot = (memslot->as_id << 16) | memslot->id;
+
+ if (kvm->dirty_ring_size && vcpu)
+ kvm_dirty_ring_push(vcpu, slot, rel_gfn);
+ else if (memslot->dirty_bitmap)
+ set_bit_le(rel_gfn, memslot->dirty_bitmap);
}
EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot);
--
2.23.0
Powered by blists - more mailing lists