From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=34.202.193.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795937248; b=rEHNBQaVgW6wD2AZup+L+gKDBsuirfE7Ffkxt3MFTnNs/jCeS3qAyyKDz9orcdRouDj9 NNTJ02RY9xxed74vTpMk5OCxhp80Uz+dHKsL6C4tkLSspjnuIbiWd/0Rsl4zXolRddRb6 HYKkW64WWlMUTyX9DpVC67JNWqHT2gDXaozqhfN3RP4nZHZiTuNuasqbnRP2YsIjaeEJ5 O068OwWfzTWkE6EAInPGOpCBTVdxCwSDWhLUAGA2OxtK3LQNYPlmgMtQh0PvPosXa8p3N srqCmsVCAK7bucuImCJ/NbDbFCpcHuX8dwEqzaC3kMYU94yoREvVzKKJsl3ReCVDKJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795937248; h=DMARC-Filter:DKIM-Signature:DKIM-Signature:Feedback-ID: X-Pm-Original-To:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-MIME-Autoconverted:Content-Type; bh=jGrq9FvxvG4RjJMbBJ1NEF9D6AryzAohjeeM/79arVA=; b=H3Kzl7XPEesg+uUCm6T7m6+pqxOoIj9RLVRl9q7TXz2fYnTVfVvj+ss86w7+uNg7QzJF bQFkaZ2/f4HrQ1UbZ4mfuc6Gince/0NpCHrBqCxnzBFWvtLvt3z62B+g1SIZmqFcierd2 KyKljtAtwxSCIcCRYFWVVbZ3qFwgAoumiq0MBRYvt8VLvlWAvrVp5uuJNxl2Wvri93eOb RQ8zjNTxe3oXGD8d/YVReS8HjA+RfDwjDAu1EfH3iN82SvHdYR/hFluIbHXLxfN8BV7N1 G48T6/qor/sB88hlEGYROFglHeZa77L/KO3u4od2ioS5CgQMk1J9ILtzeFFVRHc9y9A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=atomlin.com; spf=pass smtp.mailfrom=atomlin.com; dkim=pass header.d=atomlin.com header.i=@atomlin.com header.a=rsa-sha256 header.s=purelymail3 header.b=rP58eNUF; dkim=pass header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=TuqZJHtj; arc=none smtp.remote-ip=34.202.193.197 Received: from sendmail.purelymail.com (sendmail.purelymail.com [34.202.193.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4213606A31C for ; Sun, 29 Nov 2026 07:27:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C4213606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=atomlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atomlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=atomlin.com header.i=@atomlin.com header.a=rsa-sha256 header.s=purelymail3 header.b=rP58eNUF; dkim=pass (2048-bit key, unprotected) header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=TuqZJHtj DKIM-Signature: a=rsa-sha256; b=rP58eNUFjfNtQzLvpodcUEO11hJEFRMheoiV8Kb6Q3afe+C33uq2mc1Wzj5YgyEgmhuqhv2A0kPyYVZkyIwfuG+h+DgrCI5CVk6KGxcGxrANnEQZ00cWxYnxELtXSZupYIZ/oED04Eu1ihGgS8BgUmk0FoUsTnv5tRoCOsyEEZMMGOAqyErVeuDNw/47QzkbB0qD9FIXM5cSoHPXz8dHz4ZaMgIx33TcJ389HupOQptNc6DMH0oHrBgaAVKInuMwt7Hmnu4xRhpUFkjeIiQZlKhHwMCodj3Oo48cX2Nv6CtiVHRfEvnCqSYsUGVm8kYNcb8vM7U/YmIj3R/BeLTFYA==; s=purelymail3; d=atomlin.com; v=1; bh=M7BkVUGAqybIHgBhGj5tGcsnXTBD1bvZcdkrGI0X8HU=; h=Received:From:To:Subject:Date:Message-ID; DKIM-Signature: a=rsa-sha256; b=TuqZJHtj0WlU0lfKINHtuZ2v0vk+x3YbX24292JJHlXEV98ffF26B+MC7YwHQQjnJ/Xd/CCgtVb0zw1YSkcIIPQ9fpM+2dmM8c1LQeUlWdx+zge8EG61DDr6aCJxnny6auvP56Qa7SC5iHDRY56vLjp465YEcMhnDd0hD5uUV9fZ4c3Wvi4vlOhdO6RyymOsb7gxqGW5em3PZYWYlthOGI0R2/VTXEMOLmwr2WHxprqwPQb1eWzs3M4uaC1b7T+3oKJsJJIpCuzj3EHr2f470J6rzW8qA5RcnUVyIN/kNYCUJBQ0tKgB9wi9Ocah+G+nJwNTWuSuzA0RWQCxCUANTA==; s=purelymail3; d=purelymail.com; v=1; bh=M7BkVUGAqybIHgBhGj5tGcsnXTBD1bvZcdkrGI0X8HU=; h=Feedback-ID:Received:From:To:Subject:Date:Message-ID; Feedback-ID: 1802931:67223:null:purelymail X-Pm-Original-To: linux-scsi@vger.kernel.org Authentication-Results: purelymail.com; auth=pass Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 184166521; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 29 Nov 2026 07:26:14 +0000 (UTC) From: Aaron Tomlin 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 08/10] genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs Date: Sun, 29 Nov 2026 02:26:08 -0500 Message-ID: <20261129072612.257915-3-atomlin@atomlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129045436.255364-1-atomlin@atomlin.com> References: <20261129045436.255364-1-atomlin@atomlin.com> X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail Content-Type: text/plain; charset=UTF-8 At present, the managed interrupt spreading algorithm distributes vectors across all available CPUs within a given node or system. On systems employing CPU isolation (e.g. "isolcpus=3Dmanaged_irq"), this behaviour defeats the primary purpose of isolation by routing hardware interrupts (such as NVMe completion queues) directly to isolated cores. Update irq_create_affinity_masks() to respect the housekeeping CPU mask. By passing the HK_TYPE_MANAGED_IRQ mask directly to the topological distribution function (group_mask_cpus_evenly()), we ensure that managed interrupts are kept strictly off isolated CPUs. This patch additionally addresses the architectural constraints of restricted vector distribution: 1. Vector limits and multi-set scaling Updated irq_calc_affinity_vectors() to bound the maximum number of allocated vectors to the weight of the housekeeping mask for single-set drivers. For drivers providing a calc_sets() callback, vector calculations continue to scale with the driver's requested set sizes (maxvec - resv), preventing unnecessary queue contention across distinct functional sets while irq_create_affinity_masks() guarantees that all allocated vectors remain strictly restricted to housekeeping CPUs. 2. Multi-set alignment and leak prevention When isolation constraints result in fewer available masks than requested vectors for a given set, the remaining vector slots are padded with the housekeeping mask. This replaces the historical irq_default_affinity padding, ensuring excess managed queues do not leak interrupts onto isolated CPUs. 3. Minimum vector safety net To prevent fatal -ENOSPC device probe aborts on heavily isolated systems (where the housekeeping CPU count might be lower than a device's structural minimum), the final vector calculation is safeguarded to never drop below minvec. Queues will safely share the available housekeeping CPUs instead of failing the probe. 4. Zero overhead The housekeeping mask is conditionally assigned via a direct pointer, completely avoiding temporary mask allocations (e.g. alloc_cpumask_var) and bitwise operations when CPU isolation is disabled. This guarantees zero performance or memory overhead for standard configurations. Tested-by: Ionut Nechita Signed-off-by: Aaron Tomlin --- kernel/irq/affinity.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index 78f2418a8925..a4bbcaafbe36 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 static void default_calc_sets(struct irq_affinity *affd, unsigned int affv= ecs) { @@ -25,8 +26,10 @@ static void default_calc_sets(struct irq_affinity *affd,= unsigned int affvecs) struct irq_affinity_desc * irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd) { -=09unsigned int affvecs, curvec, usedvecs, i; +=09unsigned int affvecs, curvec, usedvecs, i, j; =09struct irq_affinity_desc *masks =3D NULL; +=09const struct cpumask *hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_= IRQ); +=09bool hk_enabled =3D housekeeping_enabled(HK_TYPE_MANAGED_IRQ); =20 =09/* =09 * Determine the number of vectors which need interrupt affinities @@ -70,19 +73,29 @@ irq_create_affinity_masks(unsigned int nvecs, struct ir= q_affinity *affd) =09 */ =09for (i =3D 0, usedvecs =3D 0; i < affd->nr_sets; i++) { =09=09unsigned int nr_masks, this_vecs =3D affd->set_size[i]; -=09=09struct cpumask *result =3D group_cpus_evenly(this_vecs, &nr_masks); +=09=09struct cpumask *result; +=09=09const struct cpumask *mask; =20 +=09=09if (hk_enabled) +=09=09=09mask =3D hk_mask; +=09=09else +=09=09=09mask =3D cpu_possible_mask; + +=09=09result =3D group_mask_cpus_evenly(this_vecs, mask, +=09=09=09=09=09=09&nr_masks); =09=09if (!result) { =09=09=09kfree(masks); =09=09=09return NULL; =09=09} - -=09=09for (int j =3D 0; j < nr_masks; j++) +=09=09for (j =3D 0; j < nr_masks; j++) =09=09=09cpumask_copy(&masks[curvec + j].mask, &result[j]); +=09=09for (j =3D nr_masks; j < this_vecs; j++) +=09=09=09cpumask_copy(&masks[curvec + j].mask, mask); + =09=09kfree(result); =20 -=09=09curvec +=3D nr_masks; -=09=09usedvecs +=3D nr_masks; +=09=09curvec +=3D this_vecs; +=09=09usedvecs +=3D this_vecs; =09} =20 =09/* Fill out vectors at the end that don't need affinity */ @@ -117,8 +130,10 @@ unsigned int irq_calc_affinity_vectors(unsigned int mi= nvec, unsigned int maxvec, =20 =09if (affd->calc_sets) =09=09set_vecs =3D maxvec - resv; +=09else if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) +=09=09set_vecs =3D cpumask_weight(housekeeping_cpumask(HK_TYPE_MANAGED_IRQ= )); =09else =09=09set_vecs =3D cpumask_weight(cpu_possible_mask); =20 -=09return resv + min(set_vecs, maxvec - resv); +=09return max(minvec, resv + min(set_vecs, maxvec - resv)); } --=20 2.55.0