All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-scsi@vger.kernel.org, virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v17 08/10] genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs
Date: Sun, 29 Nov 2026 07:48:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-239401@kernel.org> (raw)
In-Reply-To: <20261129072612.257915-3-atomlin@atomlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] genirq/affinity: padding excess vectors with full mask
  collapses queues
--

commit 7b34278d7bc0891686d6faff17c09feec98bd7c5
Author: Aaron Tomlin <atomlin@atomlin.com>

genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs

This commit restricts managed interrupt affinity masks and vector count
calculations to HK_TYPE_MANAGED_IRQ housekeeping CPUs, while clamping the
calculated vector count to at least minvec and padding excess vector slots
with the housekeeping mask.

> diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
> index 78f2418a89252..a4bbcaafbe366 100644
> --- a/kernel/irq/affinity.c
> +++ b/kernel/irq/affinity.c
[ ... ]
> @@ -70,19 +73,29 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
>  	 */
>  	for (i = 0, usedvecs = 0; i < affd->nr_sets; i++) {
>  		unsigned int nr_masks, this_vecs = affd->set_size[i];
> -		struct cpumask *result = group_cpus_evenly(this_vecs, &nr_masks);
> +		struct cpumask *result;
> +		const struct cpumask *mask;
>  
> +		if (hk_enabled)
> +			mask = hk_mask;
> +		else
> +			mask = cpu_possible_mask;
> +
> +		result = group_mask_cpus_evenly(this_vecs, mask,
> +						&nr_masks);
>  		if (!result) {
>  			kfree(masks);
>  			return NULL;
>  		}
> -
> -		for (int j = 0; j < nr_masks; j++)
> +		for (j = 0; j < nr_masks; j++)
>  			cpumask_copy(&masks[curvec + j].mask, &result[j]);
> +		for (j = nr_masks; j < this_vecs; j++)
> +			cpumask_copy(&masks[curvec + j].mask, mask);
> +
>  		kfree(result);
>  
> -		curvec += nr_masks;
> -		usedvecs += nr_masks;
> +		curvec += this_vecs;
> +		usedvecs += this_vecs;
>  	}

[Severity: High]
When this_vecs exceeds nr_masks, does copying the full mask into the
trailing vector slots collapse all CPUs onto the last hardware queue in
blk_mq_map_hw_queues()?

This happens under isolcpus=managed_irq whenever a set requests more
vectors than the number of housekeeping CPUs, such as via a driver
affd->calc_sets callback (e.g. nvme_calc_irq_sets()) or via the new
max(minvec, ...) floor in irq_calc_affinity_vectors().
group_mask_cpus_evenly() returns nr_masks equal to the housekeeping CPU
count, and the second loop assigns the full housekeeping mask to every
remaining vector j >= nr_masks.

In blk_mq_map_hw_queues(), each queue maps its affinity mask in order:

block/blk-mq-cpumap.c:blk_mq_map_hw_queues() {
    ...
	for (queue = 0; queue < qmap->nr_queues; queue++) {
		...
		for_each_cpu_and(cpu, affinity_mask, constraint) {
			qmap->mq_map[cpu] = qmap->queue_offset + queue;
			cpumask_set_cpu(cpu, mask);
		}
	}
    ...
}

Because the padded vectors cover every housekeeping CPU, the final vector
(this_vecs - 1) overwrites qmap->mq_map[cpu] for all housekeeping CPUs
(and subsequently all isolated CPUs), leaving queues 0 .. this_vecs - 2
unused.  In addition, on architectures using the generic IRQ matrix
allocator, irq_matrix_reserve_managed() reserves a vector slot on every
CPU in the mask, so each excess vector consumes a vector on all
housekeeping CPUs instead of one group.

Wrapping the excess slots across the grouped masks (&result[j % nr_masks])
would keep each excess vector scoped to a single group.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129045436.255364-1-atomlin@atomlin.com?part=8

  reply	other threads:[~2026-11-29  7:48 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  4:54 [PATCH v17 00/10] blk: honor isolcpus configuration Aaron Tomlin
2026-11-29  4:54 ` [PATCH v17 01/10] scsi: aacraid: use block layer helpers to calculate num of queues Aaron Tomlin
2026-11-29  4:54 ` [PATCH v17 02/10] lib/group_cpus: remove dead !SMP code Aaron Tomlin
2026-11-29  4:54 ` [PATCH v17 03/10] lib/group_cpus: Add group_mask_cpus_evenly() Aaron Tomlin
2026-11-29  7:33   ` sashiko-bot
2026-11-29 17:32     ` Aaron Tomlin
2026-11-29  4:54 ` [PATCH v17 04/10] sched/isolation: Prevent out-of-bounds read in isolcpus= boot parameter parser Aaron Tomlin
2026-11-29 21:45   ` Frederic Weisbecker
2026-11-30  2:36     ` Aaron Tomlin
2026-11-29  4:54 ` [PATCH v17 05/10] blk-mq: use hk cpus only when isolcpus=managed_irq is enabled Aaron Tomlin
2026-11-29  7:58   ` sashiko-bot
2026-11-29 20:45     ` Aaron Tomlin
2026-11-29  7:26 ` [PATCH v17 06/10] blk-mq: prevent offlining hk CPUs with associated online isolated CPUs Aaron Tomlin
2026-11-29  7:46   ` sashiko-bot
2026-11-30  1:11     ` Aaron Tomlin
2026-11-29  7:26 ` [PATCH v17 07/10] virtio-fs: honour isolcpus=managed_irq in queue mapping Aaron Tomlin
2026-11-29  7:26 ` [PATCH v17 08/10] genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs Aaron Tomlin
2026-11-29  7:48   ` sashiko-bot [this message]
2026-11-30  1:42     ` Aaron Tomlin
2026-11-29  7:26 ` [PATCH v17 09/10] docs: update isolcpus=managed_irq documentation Aaron Tomlin
2026-11-29  7:26 ` [PATCH v17 10/10] genirq/affinity: Confine pre and post vectors to housekeeping CPUs Aaron Tomlin
2026-11-29  7:41   ` sashiko-bot
2026-11-30  2:33     ` Aaron Tomlin
2026-11-29  7:58 ` [PATCH v17 00/10] blk: honor isolcpus configuration sashiko-bot
2026-11-29 22:15 ` Frederic Weisbecker
2026-11-30  2:52   ` Aaron Tomlin
2026-11-30  9:37     ` Frederic Weisbecker
2026-11-30  9:53 ` Marco Crivellari
2026-11-30 17:00   ` Aaron Tomlin

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=sashiko-outbox-239401@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atomlin@atomlin.com \
    --cc=eperezma@redhat.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.