From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Luan Haickel Araujo <luanharaujo@gmail.com>,
mst@redhat.com, jasowang@redhat.com
Cc: xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virtio_mem: add bitmap_test_range_all_set/zero helpers
Date: Wed, 8 Apr 2026 15:49:51 +0200 [thread overview]
Message-ID: <994cccff-ba44-41e1-b8ae-e2750455dbe0@kernel.org> (raw)
In-Reply-To: <20260405213210.108533-1-luanharaujo@gmail.com>
On 4/5/26 23:32, Luan Haickel Araujo wrote:
> Encapsulate find_next_bit and find_next_zero_bit calls into helpers
> to verify if a range of subblocks is entirely plugged or unplugged.
>
> This improves readability as requested by the TODO comments in the
> source code.
>
> Validation confirms the change is binary-neutral on ARM64, with the
> generated instructions remaining identical.
>
> Suggested-by: David Hildenbrand <david@redhat.com>
>
> Signed-off-by: Luan Haickel Araujo <luanharaujo@gmail.com>
> ---
> Hi David,
>
Hi!
> This is my first patch contribution to the Linux kernel, following up on
> your TODO notes in virtio_mem.c.
>
> As part of my learning process (LFX 103), I verified the change in a
> QEMU (KVM) environment with test_bitmap. I also compared the generated
> assembly on ARM64 and it remains identical, confirming the helpers are
> binary-neutral as expected.
>
> I noticed these helpers could also be useful in include/linux/bitmap.h in
> the future. If you think it makes sense to move them there, I'd be happy
> to work on that in a next step.
Right, the TODO really indicated that core code should provide such
helpers, not virtio-mem itself. There is no real benefit in having these
local helpers.
>
> Looking forward to your feedback.
>
> Luan.
> drivers/virtio/virtio_mem.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
> index 48051e9e98ab..e94e30af3a5d 100644
> --- a/drivers/virtio/virtio_mem.c
> +++ b/drivers/virtio/virtio_mem.c
> @@ -538,6 +538,22 @@ static void virtio_mem_sbm_set_sb_unplugged(struct virtio_mem *vm,
> __bitmap_clear(vm->sbm.sb_states, bit, count);
> }
>
> +static inline bool bitmap_test_range_all_set(const unsigned long *map,
> + unsigned int start, unsigned int nbits)
> +{
> + unsigned int next_zero_bit = find_next_zero_bit(map, start + nbits, start);
> +
> + return next_zero_bit >= start + nbits;
> +}
> +
> +static inline bool bitmap_test_range_all_zero(const unsigned long *map,
> + unsigned int start, unsigned int nbits)
> +{
> + unsigned int next_set_bit = find_next_bit(map, start + nbits, start);
> +
> + return next_set_bit >= start + nbits;
> +}
If you look closely, fs/btrfs/misc.h provides these functions. So they
should probably be factored out into common code.
Then, virtio-mem could just naturally reuse them.
But, I wonder whether we want to call them
bitmap_test_set()
bitmap_test_clear()
Given that they have the exact same interface as
bitmap_set/bitmap_clear, consuming a range.
--
Cheers,
David
prev parent reply other threads:[~2026-04-08 13:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-05 21:32 [PATCH] virtio_mem: add bitmap_test_range_all_set/zero helpers Luan Haickel Araujo
2026-04-08 13:49 ` David Hildenbrand (Arm) [this message]
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=994cccff-ba44-41e1-b8ae-e2750455dbe0@kernel.org \
--to=david@kernel.org \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luanharaujo@gmail.com \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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