From: Sean Christopherson <seanjc@google.com>
To: Bibo Mao <maobibo@loongson.cn>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset
Date: Thu, 13 Jun 2024 09:43:38 -0700 [thread overview]
Message-ID: <Zmsg8ciwSp1a_864@google.com> (raw)
In-Reply-To: <20240613122803.1031511-1-maobibo@loongson.cn>
On Thu, Jun 13, 2024, Bibo Mao wrote:
> Function kvm_reset_dirty_gfn may be called with parameters cur_slot /
> cur_offset / mask are all zero, it does not represent real dirty page.
> It is not necessary to clear dirty page in this condition. Also return
> value of macro __fls() is undefined if mask is zero which is called in
> funciton kvm_reset_dirty_gfn(). Here just discard it.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> virt/kvm/dirty_ring.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
> index 86d267db87bb..05f4c1c40cc7 100644
> --- a/virt/kvm/dirty_ring.c
> +++ b/virt/kvm/dirty_ring.c
> @@ -147,14 +147,16 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring)
> continue;
> }
> }
> - kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> + if (mask)
> + kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> cur_slot = next_slot;
> cur_offset = next_offset;
> mask = 1;
> first_round = false;
> }
>
> - kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> + if (mask)
> + kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
Given that mask must be checked before __fls(), just do:
diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 86d267db87bb..7bc74969a819 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -55,6 +55,9 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask)
struct kvm_memory_slot *memslot;
int as_id, id;
+ if (!mask)
+ return;
+
as_id = slot >> 16;
id = (u16)slot;
next prev parent reply other threads:[~2024-06-13 16:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 12:28 [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset Bibo Mao
2024-06-13 16:43 ` Sean Christopherson [this message]
2024-06-14 2:58 ` maobibo
2024-06-20 21:20 ` Paolo Bonzini
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=Zmsg8ciwSp1a_864@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maobibo@loongson.cn \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.