Re: [PATCH v14 5/8] blk-mq: use hk cpus only when isolcpus=io_queue is enabled

From: Aaron Tomlin

Date: Wed May 20 2026 - 22:41:05 EST


On Wed, May 20, 2026 at 05:50:27PM -0400, Aaron Tomlin wrote:
> diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
> index 705da074ad6c..3df5c368cc08 100644
> --- a/block/blk-mq-cpumap.c
> +++ b/block/blk-mq-cpumap.c
> @@ -22,7 +22,11 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
> {
> unsigned int num;
>
> - num = cpumask_weight(mask);
> + if (housekeeping_enabled(HK_TYPE_IO_QUEUE))
> + num = cpumask_weight_and(mask, housekeeping_cpumask(HK_TYPE_IO_QUEUE));
> + else
> + num = cpumask_weight(mask);
> +
> return min_not_zero(num, max_queues);
> }

I think we could be more defensive here.

It is theoretically possible for the intersection of the provided mask and
the housekeeping mask to hit 0. We cannot allow a generic block layer
utility function to overflow to maximum queues. Therefore, if the
intersection evaluates to 0, we should enforce a safe fallback of 1:

@@ -26,7 +26,11 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
else
num = cpumask_weight(mask);

- return min_not_zero(num, max_queues);
+ /*
+ * Ensure that a count of zero does not inadvertently result in
+ * allocating the maximum number of queues.
+ */
+ return min_not_zero(num ?: 1U, max_queues);
}


--
Aaron Tomlin