From: Paolo Bonzini <pbonzini@redhat.com>
To: Hao Peng <flyingpenghao@gmail.com>
Cc: Sean Christopherson <seanjc@google.com>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Simplify backwards dirty ring batch check
Date: Thu, 17 Sep 2026 18:13:00 +0200 [thread overview]
Message-ID: <5f8b0cfa-fe84-4255-a6d5-a5d9d15056ef@redhat.com> (raw)
In-Reply-To: <CAPm50aLqEYTNNwJv6TUwpsxt9gbxjzDBvJ8sFK=4qPxYKY36xQ@mail.gmail.com>
On 9/17/26 18:09, Hao Peng wrote:
>> ... I love it, but it's unreadable. The "mask << -delta >> -delta"
>> basically means no overflow on shift left. So just write
>>
>> if (!check_shl_overflow(mask, -delta, shifted_mask)) {
>> cur_offset = next_offset;
>> mask = shifted_mask | 1;
>> }
>>
> Yes, check_shl_overflow() expresses the intent much more clearly than
> the leading-zero calculation.
>
> I will use it together with an unsigned shift calculated directly from
> cur_offset and next_offset. That also avoids evaluating -delta when
> delta is S64_MIN.
That would require a 2^(64+12) bit address space, so it cannot happen I
think?
> Something along these lines:
>
> unsigned long shifted_mask;
> u64 shift = abs_diff(next_offset, cur_offset);
>
> if (next_offset < cur_offset &&
> !check_shl_overflow(mask, shift, &shifted_mask)) {
> cur_offset = next_offset;
> mask = shifted_mask | BIT(0);
> continue;
> }
shift can be just cur_offset - next_offset here, and it can be placed in
the call to check_shl_overflow().
Paolo
next prev parent reply other threads:[~2026-09-17 16:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 11:20 [PATCH] KVM: Simplify backwards dirty ring batch check Peng Hao
2026-09-10 14:40 ` Sean Christopherson
2026-09-10 15:28 ` Paolo Bonzini
2026-09-17 16:09 ` Hao Peng
2026-09-17 16:13 ` Paolo Bonzini [this message]
2026-09-17 16:07 ` Hao Peng
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=5f8b0cfa-fe84-4255-a6d5-a5d9d15056ef@redhat.com \
--to=pbonzini@redhat.com \
--cc=flyingpenghao@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=seanjc@google.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