From: Gavin Shan <gshan@redhat.com>
To: kvmarm@lists.linux.dev
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, pbonzini@redhat.com,
maz@kernel.org, corbet@lwn.net, james.morse@arm.com,
suzuki.poulose@arm.com, oliver.upton@linux.dev,
yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
ricarkol@google.com, eric.auger@redhat.com, yuzhe@nfschina.com,
renzhengeek@gmail.com, ardb@kernel.org, peterx@redhat.com,
seanjc@google.com, shan.gavin@gmail.com
Subject: [PATCH 3/4] KVM: Refactor mark_page_dirty_in_slot()
Date: Mon, 16 Jan 2023 12:04:04 +0800 [thread overview]
Message-ID: <20230116040405.260935-4-gshan@redhat.com> (raw)
In-Reply-To: <20230116040405.260935-1-gshan@redhat.com>
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@redhat.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
next prev parent reply other threads:[~2023-01-16 4:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-16 4:04 [PATCH 0/4] Improve dirty ring warning report Gavin Shan
2023-01-16 4:04 ` [PATCH 1/4] KVM: arm64: Allow saving vgic3 LPI pending status in no running vcpu context Gavin Shan
2023-01-17 20:51 ` Oliver Upton
2023-01-19 1:11 ` Gavin Shan
2023-01-19 15:47 ` Marc Zyngier
2023-01-19 23:04 ` Gavin Shan
2023-01-16 4:04 ` [PATCH 2/4] KVM: arm64: Allow saving vgic3 pending tables " Gavin Shan
2023-01-16 4:04 ` Gavin Shan [this message]
2023-01-16 4:04 ` [PATCH 4/4] KVM: Improve warning report in mark_page_dirty_in_slot() Gavin Shan
2023-01-17 15:42 ` Sean Christopherson
2023-01-19 1:15 ` Gavin Shan
2023-01-19 15:19 ` Sean Christopherson
2023-01-19 23:06 ` Gavin Shan
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=20230116040405.260935-4-gshan@redhat.com \
--to=gshan@redhat.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=eric.auger@redhat.com \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=renzhengeek@gmail.com \
--cc=ricarkol@google.com \
--cc=seanjc@google.com \
--cc=shan.gavin@gmail.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
--cc=yuzhe@nfschina.com \
/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
all inboxes | Powered by JetHome®