Linux block layer
 help / color / mirror / Atom feed
From: Aaron Tomlin <atomlin@atomlin.com>
To: axboe@kernel.dk, tglx@kernel.org, aacraid@microsemi.com,
	James.Bottomley@HansenPartnership.com, mkp@kernel.org,
	frederic@kernel.org, bigeasy@linutronix.de, gmaglione@redhat.com,
	vgoyal@redhat.com, stefanha@redhat.com, miklos@szeredi.hu
Cc: atomlin@atomlin.com, dwagner@suse.de, eperezma@redhat.com,
	tom.leiming@gmail.com, ionut.nechita@windriver.com,
	corbet@lwn.net, vincent.guittot@linaro.org, mingo@redhat.com,
	peterz@infradead.org, radu@rendec.net, akpm@linux-foundation.org,
	steve@abita.co, sean@ashe.io, chjohnst@gmail.com, neelx@suse.com,
	mproche@gmail.com, nick.lange@gmail.com,
	marco.crivellari@suse.com, rishil1999@outlook.com,
	linux-doc@vger.kernel.org, linux-block@vger.kernel.org,
	linux-scsi@vger.kernel.org, virtualization@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, fuse-devel@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH v17 10/10] genirq/affinity: Confine pre and post vectors to housekeeping CPUs
Date: Sun, 29 Nov 2026 02:26:10 -0500	[thread overview]
Message-ID: <20261129072612.257915-5-atomlin@atomlin.com> (raw)
In-Reply-To: <20261129045436.255364-1-atomlin@atomlin.com>

From: Ionut Nechita <ionut.nechita@windriver.com>

The managed IRQ affinity spreading for isolcpus=managed_irq restricts the
affinity of managed interrupt vectors to housekeeping CPUs. However, the
reserved vectors that do not participate in managed affinity spreading,
namely affd->pre_vectors (such as the NVMe admin completion queue) and
trailing affd->post_vectors, are still initialised unconditionally from
irq_default_affinity, which by default spans all CPUs including isolated
ones.

Although these reserved vectors are not marked managed, on a freshly
probed device an admin queue interrupt can still be delivered to an
isolated CPU before user space has a chance to re-steer it. On PREEMPT_RT
this stray threaded interrupt wakeup on an isolated core directly
perturbs latency-critical workloads.

When HK_TYPE_MANAGED_IRQ is enabled, confine these reserved pre/post
vectors to the intersection of irq_default_affinity and the housekeeping
mask (falling back to the housekeeping mask if that intersection contains
no online CPUs). This keeps unmanaged device queues off isolated CPUs
from the moment of allocation while still honouring irqaffinity= when
configured, and leaves behaviour unchanged when managed_irq isolation is
disabled. Update the managed_irq documentation to reflect this behaviour.

Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
Co-developed-by: Aaron Tomlin <atomlin@atomlin.com>
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
 .../admin-guide/kernel-parameters.txt         |  3 +-
 Documentation/core-api/irq/managed_irq.rst    |  9 ++++--
 kernel/irq/affinity.c                         | 28 +++++++++++++++++--
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index c5bf9db3d8aa..6c99620a43ea 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2827,7 +2827,8 @@ Kernel parameters
 			  In the block layer (blk-mq), device queue allocation
 			  and CPU-to-queue mappings are restricted to
 			  housekeeping CPUs. For devices using managed
-			  interrupts, hardware completion interrupts are routed
+			  interrupts, hardware completion interrupts and any
+			  associated reserved pre/post vectors are routed
 			  exclusively to housekeeping cores, shielding isolated
 			  CPUs from I/O interruptions even if they initiated the
 			  request.
diff --git a/Documentation/core-api/irq/managed_irq.rst b/Documentation/core-api/irq/managed_irq.rst
index 850f4a7f9762..4ad5b273f245 100644
--- a/Documentation/core-api/irq/managed_irq.rst
+++ b/Documentation/core-api/irq/managed_irq.rst
@@ -56,7 +56,9 @@ queue allocation and managed interrupt affinity strictly to housekeeping CPUs
 (the CPUs outside the specified isolated mask).
 
 Isolated CPUs are excluded when computing the managed interrupt affinity masks
-and vector limits. In the block layer (blk-mq), isolated CPUs share hardware
+and vector limits, and any unmanaged pre/post reserved vectors allocated
+alongside them are confined to housekeeping CPUs (intersected with irqaffinity=
+when configured). In the block layer (blk-mq), isolated CPUs share hardware
 queues owned by housekeeping CPUs so that completion interrupts never target
 isolated cores, and offlining the last housekeeping CPU serving an active
 isolated CPU is rejected.
@@ -94,8 +96,9 @@ The following examples assume a system with 8 CPUs.
   and the kernel command line includes:
   "irqaffinity=0,1 isolcpus=domain,2-7 isolcpus=managed_irq,1-3,5-7".
   The MSI-X device exposes 5 interrupts: 3 management interrupts and 2 queue
-  interrupts. The management interrupts follow the irqaffinity= setting. The
-  queue interrupts are spread strictly across the housekeeping CPUs (0 and 4)::
+  interrupts. The management interrupts are confined to the intersection of
+  irqaffinity= and the housekeeping mask (CPU0). The queue interrupts are
+  spread strictly across the housekeeping CPUs (0 and 4)::
 
     /proc/irq/47/effective_affinity_list:0
     /proc/irq/47/smp_affinity_list:0
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index a4bbcaafbe36..e1d64657a3c3 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -16,6 +16,30 @@ static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 	affd->set_size[0] = affvecs;
 }
 
+/**
+ * irq_set_reserved_mask - Populate affinity mask for reserved pre/post vectors
+ * @dst:	Destination cpumask to populate
+ * @hk_mask:	Housekeeping cpumask for HK_TYPE_MANAGED_IRQ
+ * @hk_enabled:	True when HK_TYPE_MANAGED_IRQ isolation is active
+ *
+ * Confine unmanaged pre/post vectors (e.g. the NVMe admin queue) to
+ * housekeeping CPUs while still honouring irq_default_affinity when the
+ * intersection contains at least one online CPU.
+ */
+static void irq_set_reserved_mask(struct cpumask *dst,
+				  const struct cpumask *hk_mask,
+				  bool hk_enabled)
+{
+	if (!hk_enabled) {
+		cpumask_copy(dst, irq_default_affinity);
+		return;
+	}
+
+	if (!cpumask_and(dst, irq_default_affinity, hk_mask) ||
+	    !cpumask_intersects(dst, cpu_online_mask))
+		cpumask_copy(dst, hk_mask);
+}
+
 /**
  * irq_create_affinity_masks - Create affinity masks for multiqueue spreading
  * @nvecs:	The total number of vectors
@@ -65,7 +89,7 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 
 	/* Fill out vectors at the beginning that don't need affinity */
 	for (curvec = 0; curvec < affd->pre_vectors; curvec++)
-		cpumask_copy(&masks[curvec].mask, irq_default_affinity);
+		irq_set_reserved_mask(&masks[curvec].mask, hk_mask, hk_enabled);
 
 	/*
 	 * Spread on present CPUs starting from affd->pre_vectors. If we
@@ -104,7 +128,7 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 	else
 		curvec = affd->pre_vectors + usedvecs;
 	for (; curvec < nvecs; curvec++)
-		cpumask_copy(&masks[curvec].mask, irq_default_affinity);
+		irq_set_reserved_mask(&masks[curvec].mask, hk_mask, hk_enabled);
 
 	/* Mark the managed interrupts */
 	for (i = affd->pre_vectors; i < nvecs - affd->post_vectors; i++)
-- 
2.55.0


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

Thread overview: 11+ 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  4:54 ` [PATCH v17 04/10] sched/isolation: Prevent out-of-bounds read in isolcpus= boot parameter parser 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:26 ` [PATCH v17 06/10] blk-mq: prevent offlining hk CPUs with associated online isolated CPUs 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:26 ` [PATCH v17 09/10] docs: update isolcpus=managed_irq documentation Aaron Tomlin
2026-11-29  7:26 ` Aaron Tomlin [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=20261129072612.257915-5-atomlin@atomlin.com \
    --to=atomlin@atomlin.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=aacraid@microsemi.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bigeasy@linutronix.de \
    --cc=chjohnst@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dwagner@suse.de \
    --cc=eperezma@redhat.com \
    --cc=frederic@kernel.org \
    --cc=fuse-devel@lists.linux.dev \
    --cc=gmaglione@redhat.com \
    --cc=ionut.nechita@windriver.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=miklos@szeredi.hu \
    --cc=mingo@redhat.com \
    --cc=mkp@kernel.org \
    --cc=mproche@gmail.com \
    --cc=neelx@suse.com \
    --cc=nick.lange@gmail.com \
    --cc=peterz@infradead.org \
    --cc=radu@rendec.net \
    --cc=rishil1999@outlook.com \
    --cc=sean@ashe.io \
    --cc=stefanha@redhat.com \
    --cc=steve@abita.co \
    --cc=tglx@kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=vgoyal@redhat.com \
    --cc=vincent.guittot@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox