Linux block layer
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: Zizhi Wo <wozizhi@huaweicloud.com>,
	axboe@kernel.dk, dlemoal@kernel.org, kch@nvidia.com,
	johannes.thumshirn@wdc.com, kbusch@kernel.org,
	bvanassche@acm.org, linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, yangerkun@huawei.com,
	chengzhihao1@huawei.com, wozizhi@huawei.com
Subject: Re: [PATCH V4 7/9] null_blk: reject per-device queue resize for shared tag set
Date: Fri, 10 Jul 2026 18:04:35 +0530	[thread overview]
Message-ID: <4dbcbb4a-852e-4ae8-b909-79d1aeeb0799@linux.ibm.com> (raw)
In-Reply-To: <20260709100452.3520482-8-wozizhi@huaweicloud.com>

On 7/9/26 3:34 PM, Zizhi Wo wrote:
> From: Zizhi Wo <wozizhi@huawei.com>
> 
> When shared_tags is enabled, null_setup_tagset() makes the device use the
> global tag_set, whose driver_data stays NULL. null_map_queues() therefore
> falls back to the module-wide g_submit_queues/g_poll_queues instead of any
> per-device value.
> 
> Resizing submit_queues or poll_queues via configfs on such a device calls
> blk_mq_update_nr_hw_queues() on the shared set, shrinking
> set->nr_hw_queues.  __blk_mq_realloc_hw_ctxs() only grows the
> q->queue_hw_ctx[] allocation, so on shrink it merely exits and NULLs the
> now-excess hctx slots. null_map_queues(), however, keeps mapping CPUs with
> the unchanged g_submit_queues/g_poll_queues, so mq_map[] ends up pointing
> at those NULLed hctx slots. blk_mq_map_swqueue() then dereferences the NULL
> hctx (hctx->cpumask), crashing the kernel:
> 
> [  460.218374] KASAN: null-ptr-deref in range [0x0000000000000098-0x000000000000009f]
> [  460.219003] CPU: 24 UID: 0 PID: 1492 Comm: sh Not tainted 7.2.0-rc2+ #67 PREEMPT(full)
> [  460.219792] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-4.fc41 04/01/2014
> [  460.220452] RIP: 0010:blk_mq_map_swqueue+0x4db/0x1430
> ......
> [  460.228977] Call Trace:
> [  460.229175]  <TASK>
> [  460.229354]  blk_mq_update_nr_hw_queues+0xd49/0x11c0
> [  460.229779]  ? __pfx_blk_mq_update_nr_hw_queues+0x10/0x10
> [  460.230200]  nullb_update_nr_hw_queues+0x1a9/0x370 [null_blk]
> [  460.230694]  nullb_device_submit_queues_store+0xd9/0x170 [null_blk]
> [  460.231190]  ? __pfx_nullb_device_submit_queues_store+0x10/0x10 [null_blk]
> [  460.231776]  ? configfs_write_iter+0x35c/0x4e0
> [  460.232122]  configfs_write_iter+0x286/0x4e0
> [  460.232460]  vfs_write+0x52d/0xd00
> [  460.232779]  ? __x64_sys_openat+0x108/0x1d0
> [  460.233106]  ? __pfx_vfs_write+0x10/0x10
> [  460.233413]  ? fdget_pos+0x1cf/0x4c0
> [  460.233745]  ? fput_close+0x133/0x190
> [  460.234038]  ? __pfx_expand_files+0x10/0x10
> [  460.234368]  ksys_write+0xfc/0x1d0
> 
> Reproducer:
> modprobe null_blk shared_tags=1 submit_queues=64 poll_queues=1
> mkdir /sys/kernel/config/nullb/dev
> echo 1 > /sys/kernel/config/nullb/dev/power
> echo 1 > /sys/kernel/config/nullb/dev/submit_queues
> 
> A per-device resize of a shared tag set is meaningless anyway, so reject it
> with -EINVAL in nullb_update_nr_hw_queues() when the device is bound to the
> global tag_set.
> 
> Fixes: 45919fbfe1c4 ("null_blk: Enable modifying 'submit_queues' after an instance has been configured")
> Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
> ---
>   drivers/block/null_blk/main.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 6d30591abb28..340ecc0a331e 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -380,10 +380,19 @@ static int nullb_update_nr_hw_queues(struct nullb_device *dev,
>   	int ret, nr_hw_queues;
>   
>   	if (!dev->nullb)
>   		return 0;
>   
> +	/*
> +	 * A shared tag_set is mapped via the module-wide queue counts, so a
> +	 * per-device resize is meaningless. On shrink it would also leave
> +	 * mq_map[] pointing at NULLed hctx slots, causing a NULL deref in
> +	 * blk_mq_map_swqueue(). Reject it.
> +	 */
> +	if (dev->nullb->tag_set == &tag_set)
> +		return -EINVAL;
> +

Wouldn't it be simpler to check dev->shared_tags here instead? Since the restriction
is specifically for devices configured with shared tags, that seems a bit easier to
reason about than checking whether dev->nullb->tag_set points to the global tag_set.
Something like this:

if (dev->shared_tags)
         return -EINVAL;
Thanks,
--Nilay



  reply	other threads:[~2026-07-10 12:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 10:04 [PATCH V4 0/9] null_blk: fix init/exit races and memleaks Zizhi Wo
2026-07-09 10:04 ` [PATCH V4 1/9] null_blk: use DEFINE_MUTEX for the file-scope mutex Zizhi Wo
2026-07-10 12:35   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 2/9] null_blk: register configfs subsystem after creating default devices Zizhi Wo
2026-07-10 12:36   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 3/9] null_blk: move unregister_blkdev() after destroying dev in null_exit() Zizhi Wo
2026-07-10 12:36   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 4/9] null_blk: free global tag_set on init error path Zizhi Wo
2026-07-10 12:37   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 5/9] null_blk: free zones array on device power-off Zizhi Wo
2026-07-09 10:04 ` [PATCH V4 6/9] null_blk: clean up null_del_dev() to use cached dev pointer Zizhi Wo
2026-07-10 13:03   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 7/9] null_blk: reject per-device queue resize for shared tag set Zizhi Wo
2026-07-10 12:34   ` Nilay Shroff [this message]
2026-07-09 10:04 ` [PATCH V4 8/9] null_blk: serialize configfs attribute stores with device setup Zizhi Wo
2026-07-10 12:30   ` Nilay Shroff
2026-07-09 10:04 ` [PATCH V4 9/9] null_blk: serialize configfs attribute shows with the file-scope lock Zizhi Wo
2026-07-10 12:31   ` Nilay Shroff

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=4dbcbb4a-852e-4ae8-b909-79d1aeeb0799@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=chengzhihao1@huawei.com \
    --cc=dlemoal@kernel.org \
    --cc=johannes.thumshirn@wdc.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wozizhi@huawei.com \
    --cc=wozizhi@huaweicloud.com \
    --cc=yangerkun@huawei.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