From: "David Hildenbrand (Arm)" <david@kernel.org>
To: lirongqing <lirongqing@baidu.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virtio_mem: fix hardcoded 'vm' variable in bbm iteration macros
Date: Mon, 29 Jun 2026 08:18:19 +0200 [thread overview]
Message-ID: <944c64d6-d6d2-4e63-907c-64ea115a3888@kernel.org> (raw)
In-Reply-To: <20260629033738.2617-1-lirongqing@baidu.com>
On 6/29/26 05:37, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> virtio_mem_bbm_for_each_bb() and virtio_mem_bbm_for_each_bb_rev()
> accept a '_vm' parameter to allow callers to pass any variable name
> referring to the virtio_mem instance. However, the 'for' loop
> initializer and part of the loop condition use the bare name 'vm'
> instead of the macro parameter '_vm':
Right.
>
> All current call sites happen to pass a variable named 'vm', so the
> bug is latent and does not cause a regression today.
Unlikely to happen, because no code that iterates memory blocks deals with two
virtio-mem devices at the same time.
> Nevertheless,
> the macros are formally broken: any future caller using a different
> variable name would silently capture the outer 'vm' from the
> enclosing scope, leading to incorrect iteration bounds.
Again, unlikely, but we should clean this up.
>
> Fix by replacing all bare 'vm->' references inside the macros with
> the '_vm' parameter, and wrap in parentheses following kernel macro
> hygiene conventions.
>
> Fixes: 4ba50cd3355d ("virtio-mem: Big Block Mode (BBM) memory hotplug")
There is no user-visible bug, so drop the Fixes: tag.
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/virtio/virtio_mem.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
> index 11c4415..82a285c 100644
> --- a/drivers/virtio/virtio_mem.c
> +++ b/drivers/virtio/virtio_mem.c
> @@ -423,14 +423,14 @@ static int virtio_mem_bbm_bb_states_prepare_next_bb(struct virtio_mem *vm)
> }
>
> #define virtio_mem_bbm_for_each_bb(_vm, _bb_id, _state) \
> - for (_bb_id = vm->bbm.first_bb_id; \
> - _bb_id < vm->bbm.next_bb_id && _vm->bbm.bb_count[_state]; \
> + for (_bb_id = (_vm)->bbm.first_bb_id; \
> + _bb_id < (_vm)->bbm.next_bb_id && (_vm)->bbm.bb_count[_state]; \
> _bb_id++) \
> if (virtio_mem_bbm_get_bb_state(_vm, _bb_id) == _state)
>
> #define virtio_mem_bbm_for_each_bb_rev(_vm, _bb_id, _state) \
> - for (_bb_id = vm->bbm.next_bb_id - 1; \
> - _bb_id >= vm->bbm.first_bb_id && _vm->bbm.bb_count[_state]; \
> + for (_bb_id = (_vm)->bbm.next_bb_id - 1; \
> + _bb_id >= (_vm)->bbm.first_bb_id && (_vm)->bbm.bb_count[_state]; \
> _bb_id--) \
> if (virtio_mem_bbm_get_bb_state(_vm, _bb_id) == _state)
>
Without the Fixes: tag
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks!
--
Cheers,
David
prev parent reply other threads:[~2026-06-29 6:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 3:37 [PATCH] virtio_mem: fix hardcoded 'vm' variable in bbm iteration macros lirongqing
2026-06-29 6:18 ` 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=944c64d6-d6d2-4e63-907c-64ea115a3888@kernel.org \
--to=david@kernel.org \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lirongqing@baidu.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