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=1796079920; b=bY65m80vVsUTpJ7kpla4GN4LnciZsjMbwnhGHupAjkianD7oxHK/g4TAL0o2vTjn4dgO eyQLQvXC7yPEyzLINhspqKXx/Ld98uT7dEcFf4ZtoyztNJsMAZzrXKJV8ca/rwA5w8g1C /QWVncNKELk891K8KCpeqDcTjZ65xbOjwoZFR9srnUeh6kHpNcQg8DqknRf61e6XbPCLC qT882UGPnWWDwErKUq/wvQNk9hr40AHqBtaFP+pRT2wPgpALyfKVnRW3ftuhRyvA313Xh NifWwCcIxLMhdHevqDo4gJDBLcDwW6LcOEWTurTGDIQU0DCiAlsjYaeL5qG0RKsJWRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796079920; 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=BG2GnYZnfc6+M80EpRrsLCneoX1zIIavm7gj1W6ofrQ=; b=NaAUNrvP0ye1L5y5Oaj7/hdLOySjNomTK+JKqkOk3+kJGy9e5UlP+IbUCJktwHGjyZla uTJbWgoza/Qaao76/AnmSHfMxcRgF3Z8xeoBF1AHtODJQVuEPa8wH8FaHbh+6W0ZrIaH7 eTOtwi7Cgj2HQ+L/Q68xgR4tqPvHslrkSqYiPeW4+qKqiWtVU36EthIsfQGPJ7eo9ndIc nDOS94r+vGNc2r5q+IbQiIpmFw3GJuYFfR850Sgb8JdMHE7dRSU04IAwCcIQskn2/qMDS 1MVNBfZehB3bO9ZmUi0WY21HjC93ruvSCg0NAhFc4C4kr+TuCsx2f5qgCGAJS6Uq1MQ== 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="H/ac1HsC"; dkim=pass header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b="eQd/ZwU0"; 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 1293B606A330 for ; Mon, 30 Nov 2026 23:05:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1293B606A330 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=H/ac1HsC; dkim=pass (2048-bit key, unprotected) header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=eQd/ZwU0 DKIM-Signature: a=rsa-sha256; b=H/ac1HsC+OVqadsatbGQTMg8fxOfaF+R4dfKZDghg2fDvuv1b1/dblHG8HJfLmKw9Ka4kPs4+0+tyqz1Cc/NVYwC9Wk8Fz8kBKsQOgjBQxPbKMoJGqwk4eFQzA+0JKg5Ih8Oht1aDKOVZ/DzfZm6LbVUUvVd1n9qiLVTNvEcJMJi4C+4wjNS1MU9FbV5SS7ZtZN5usTrbhrOBhuCfH6FPIOjKm7qE2RU8cizPGDAc3Z5Lmo9586/clOLVM7g8lciaTrj9ngz5CjFfS9mC9WXkKB2p8iF6KNJ3aNEXECQ1ZgIA1EJFwm/fJvF2GYwAhZR6Oxt+kdKDxnzaZm45oXp+w==; s=purelymail3; d=atomlin.com; v=1; bh=ZpRZ1pNxD+PJm9+5A1rscWLY9l1BondQsNcSVyZZtRo=; h=Received:From:To:Subject:Date:Message-ID; DKIM-Signature: a=rsa-sha256; b=eQd/ZwU0qRZOn+0/z2/xWRFpvhFRHPrIZdFNujqSXLi7Re8bO8j/YYOMWx69hx9aMh+WbwsBgU8BhKJ4KSSTZTu6wSsh8M/yR97qUiQ55fBzm2Tx7vnMwPAZO1b1P3SVJC9JH6UsBllArEWE5n1zK/OV2bqABOpuOJVK4c06Rj7gnjUy54dCKtvADAHdTlH0bwOokM3/vWP/LVUkRWru6S5IwYlnTgNL3ADZs0NOqmDtOTvbCmCPOwQY6CpK5y9rof22yrFTeaItkDHaWCra9CAdza9Xd+0AdZq1tDwuVT/I6NQgKM5x1fxI+IUtu/LauU8Dj56ss4U/xM7o56IeTw==; s=purelymail3; d=purelymail.com; v=1; bh=ZpRZ1pNxD+PJm9+5A1rscWLY9l1BondQsNcSVyZZtRo=; h=Feedback-ID:Received:From:To:Subject:Date:Message-ID; Feedback-ID: 1802931:67223:null:purelymail X-Pm-Original-To: linux-kernel@vger.kernel.org Authentication-Results: purelymail.com; auth=pass Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 309984621; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 30 Nov 2026 23:03:44 +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 v18 7/9] genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs Date: Mon, 30 Nov 2026 18:03:38 -0500 Message-ID: <20261130230343.377682-2-atomlin@atomlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261130212830.373057-1-atomlin@atomlin.com> References: <20261130212830.373057-1-atomlin@atomlin.com> X-Mailing-List: linux-kernel@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 wrap across the generated housekeeping masks. This preserves the per-set vector offset alignment while keeping each excess vector scoped to a single housekeeping group rather than falling back to irq_default_affinity or overwriting all housekeeping queue mappings with the full mask. 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 Acked-by: Frederic Weisbecker Acked-by: Marco Crivellari Signed-off-by: Aaron Tomlin --- kernel/irq/affinity.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index 78f2418a8925..27d86b837f9d 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,28 @@ 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 (j =3D 0; j < this_vecs; j++) +=09=09=09cpumask_copy(&masks[curvec + j].mask, +=09=09=09=09 &result[j % nr_masks]); =20 -=09=09for (int j =3D 0; j < nr_masks; j++) -=09=09=09cpumask_copy(&masks[curvec + j].mask, &result[j]); =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 +129,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