* [PATCH] blk-mq: clear stale inactive flag on hctx reuse
@ 2026-10-20 12:51 Nirmoy Das
2026-10-20 14:13 ` Bart Van Assche
2026-10-20 14:40 ` Jens Axboe
0 siblings, 2 replies; 6+ messages in thread
From: Nirmoy Das @ 2026-10-20 12:51 UTC (permalink / raw)
To: axboe
Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, Nirmoy Das, stable
When the last CPU mapped to an hctx goes offline,
blk_mq_hctx_notify_offline() sets BLK_MQ_S_INACTIVE. Updating the
number of hardware queues exits every hctx and parks it on
q->unused_hctx_list. A later update can reuse a parked hctx through
blk_mq_alloc_and_init_hctx(), at any queue index, and nothing clears
the flag.
If the reused hctx is mapped to an online CPU, blk_mq_get_tag() keeps
returning BLK_MQ_NO_TAG for it. __blk_mq_alloc_requests() sleeps and
retries, expecting CPU hotplug to move the task to another CPU, so a
task that stays on that CPU never gets a tag. Onlining the original CPU
doesn't recover it either, because blk_mq_hctx_notify_online() only
clears the flag on the hctx that CPU now maps to.
Clear BLK_MQ_S_INACTIVE in blk_mq_init_hctx() so a reused hctx starts
like a freshly allocated one. A reused hctx has no cpuhp instances at
that point, so the offline callback can't set the flag again before
blk_mq_add_hw_queues_cpuhp() registers it. Clearing the flag in
blk_mq_exit_hctx() is not enough, because a parked hctx keeps its cpuhp
instances until blk_mq_remove_hw_queues_cpuhp(). Preserve the other
hctx state flags.
Reproduced with null_blk on v7.3 in a four-vCPU arm64 QEMU/KVM guest:
modprobe null_blk nr_devices=0
mkdir /sys/kernel/config/nullb/nullb0
cd /sys/kernel/config/nullb/nullb0
echo 4 > submit_queues; echo 1 > memory_backed; echo 16 > size
echo 1 > power
echo 0 > /sys/devices/system/cpu/cpu3/online
echo 2 > submit_queues
echo 4 > submit_queues
Offlining CPU3 marks hctx3 inactive. After the two updates it comes back
as hctx1 and is mapped to CPU0:
# cat /sys/block/nullb0/mq/1/cpu_list
0
# cat /sys/kernel/debug/block/nullb0/hctx1/state
INACTIVE
A 4K O_DIRECT read pinned to CPU0 hangs in D state, while the same read
on CPU1 and CPU2 completes. Onlining CPU3 again leaves hctx1 inactive
and the CPU0 read still hangs. With this change hctx1 state is empty and
the reads on CPU0, CPU1 and CPU2 complete, before and after onlining
CPU3.
Fixes: bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
---
block/blk-mq.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 025a799f35b924d..00b75eb95dd943a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4002,6 +4002,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
goto fail;
hctx->queue_num = hctx_idx;
+ clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
hctx->tags = set->tags[hctx_idx];
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] blk-mq: clear stale inactive flag on hctx reuse
2026-10-20 12:51 [PATCH] blk-mq: clear stale inactive flag on hctx reuse Nirmoy Das
@ 2026-10-20 14:13 ` Bart Van Assche
2026-10-20 14:28 ` Nirmoy Das
2026-10-20 14:39 ` Jens Axboe
2026-10-20 14:40 ` Jens Axboe
1 sibling, 2 replies; 6+ messages in thread
From: Bart Van Assche @ 2026-10-20 14:13 UTC (permalink / raw)
To: Nirmoy Das, axboe
Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, stable
On 10/20/26 5:51 AM, Nirmoy Das wrote:
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 025a799f35b924d..00b75eb95dd943a 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -4002,6 +4002,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
> goto fail;
>
> hctx->queue_num = hctx_idx;
> + clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
>
> hctx->tags = set->tags[hctx_idx];
Why clear_bit() instead of __clear_bit()?
Thanks,
Bart.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blk-mq: clear stale inactive flag on hctx reuse
2026-10-20 14:13 ` Bart Van Assche
@ 2026-10-20 14:28 ` Nirmoy Das
2026-10-20 14:39 ` Jens Axboe
1 sibling, 0 replies; 6+ messages in thread
From: Nirmoy Das @ 2026-10-20 14:28 UTC (permalink / raw)
To: Bart Van Assche, axboe
Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, stable
On 20.10.26 16:13, Bart Van Assche wrote:
> On 10/20/26 5:51 AM, Nirmoy Das wrote:
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 025a799f35b924d..00b75eb95dd943a 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -4002,6 +4002,7 @@ static int blk_mq_init_hctx(struct
>> request_queue *q,
>> goto fail;
>> hctx->queue_num = hctx_idx;
>> + clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
>> hctx->tags = set->tags[hctx_idx];
>
> Why clear_bit() instead of __clear_bit()?
No strong reason, I followed the other hctx->state
updates. __clear_bit() should work too I think. Should I resend with that ?
>
> Thanks,
>
> Bart.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blk-mq: clear stale inactive flag on hctx reuse
2026-10-20 14:13 ` Bart Van Assche
2026-10-20 14:28 ` Nirmoy Das
@ 2026-10-20 14:39 ` Jens Axboe
1 sibling, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-10-20 14:39 UTC (permalink / raw)
To: Bart Van Assche, Nirmoy Das
Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, stable
On 10/20/26 8:13 AM, Bart Van Assche wrote:
> On 10/20/26 5:51 AM, Nirmoy Das wrote:
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 025a799f35b924d..00b75eb95dd943a 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -4002,6 +4002,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
>> goto fail;
>> hctx->queue_num = hctx_idx;
>> + clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
>> hctx->tags = set->tags[hctx_idx];
>
> Why clear_bit() instead of __clear_bit()?
Since this isn't a hot path at all, going into details like
that does more harm than good. clear_bit() is totally fine
and honestly preferred.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blk-mq: clear stale inactive flag on hctx reuse
2026-10-20 12:51 [PATCH] blk-mq: clear stale inactive flag on hctx reuse Nirmoy Das
2026-10-20 14:13 ` Bart Van Assche
@ 2026-10-20 14:40 ` Jens Axboe
2026-10-20 14:43 ` Nirmoy Das
1 sibling, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2026-10-20 14:40 UTC (permalink / raw)
To: Nirmoy Das; +Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, stable
On Tue, 20 Oct 2026 05:51:29 -0700, Nirmoy Das wrote:
> When the last CPU mapped to an hctx goes offline,
> blk_mq_hctx_notify_offline() sets BLK_MQ_S_INACTIVE. Updating the
> number of hardware queues exits every hctx and parks it on
> q->unused_hctx_list. A later update can reuse a parked hctx through
> blk_mq_alloc_and_init_hctx(), at any queue index, and nothing clears
> the flag.
>
> [...]
Applied, thanks!
[1/1] blk-mq: clear stale inactive flag on hctx reuse
commit: afc1de47a7ab607ae6403c4bfda36b0bf3cd342f
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] blk-mq: clear stale inactive flag on hctx reuse
2026-10-20 14:40 ` Jens Axboe
@ 2026-10-20 14:43 ` Nirmoy Das
0 siblings, 0 replies; 6+ messages in thread
From: Nirmoy Das @ 2026-10-20 14:43 UTC (permalink / raw)
To: Jens Axboe; +Cc: ming.lei, hare, dwagner, linux-block, linux-kernel, stable
On 20.10.26 16:40, Jens Axboe wrote:
> On Tue, 20 Oct 2026 05:51:29 -0700, Nirmoy Das wrote:
>> When the last CPU mapped to an hctx goes offline,
>> blk_mq_hctx_notify_offline() sets BLK_MQ_S_INACTIVE. Updating the
>> number of hardware queues exits every hctx and parks it on
>> q->unused_hctx_list. A later update can reuse a parked hctx through
>> blk_mq_alloc_and_init_hctx(), at any queue index, and nothing clears
>> the flag.
>>
>> [...]
> Applied, thanks!
>
> [1/1] blk-mq: clear stale inactive flag on hctx reuse
> commit: afc1de47a7ab607ae6403c4bfda36b0bf3cd342f
>
> Best regards,
Thanks, Jens.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-20 14:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 12:51 [PATCH] blk-mq: clear stale inactive flag on hctx reuse Nirmoy Das
2026-10-20 14:13 ` Bart Van Assche
2026-10-20 14:28 ` Nirmoy Das
2026-10-20 14:39 ` Jens Axboe
2026-10-20 14:40 ` Jens Axboe
2026-10-20 14:43 ` Nirmoy Das
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®