From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2FB9FF60D0 for ; Tue, 31 Mar 2026 06:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=az4WgduGThZvY6Um24xQWuxzlC406KXWRiasoJJPX+I=; b=uAHA+bG59j9pAftZJS1I2EybYB ZlL1aTD6ji8qXXoF2cAtgDMO8VF3X1QG6aEiCV3GksGLlKzp9J3gS2/q0/ZSdm0sW7wtY9phqwbtE /bzlQb76mioriYFHDDlNRdN9OwvARFnwkFz4EbXw8BEG2edwukI1LJWYuLQEfE20mDikCW9z1h1a9 mc0DjhCSK0ISd73BddpdduAXHFc2ilB5/iO7xFPI8C8fFg44wMYtNaUUHXHqOZrWcExFGZ8oyKRYs KQDyp8Y9hXovXzT4Jg2XW0gDoaeeNOnQJqUp8FYi1CUdudgU0vqXLkwlTWEea6Y/Ojx/ST+VcVnnY 5FrcZozg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7SYB-0000000CMMF-0UeM; Tue, 31 Mar 2026 06:26:07 +0000 Received: from mail-ukwestazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c206::3] helo=CWXP265CU009.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7Kpc-0000000Bx5e-1xZa for linux-nvme@lists.infradead.org; Mon, 30 Mar 2026 22:11:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XxSVMCfG10EYuZlDgk4i5BFczGMFOC9gAxpoer9B064TdZxAs/QK+J/7UrE+Pxne/zm4z0p4lvJ2MFTh4KFF60eWMSY6V0L4x67oSKh+5ILpetsGTT6w+Zkp5RxCdwWijBLelEIjS8GSwVW/wvGOF7vsmS8MBr/nbYrBwAqCSZtdSmssWRtLgyFHlMHTk+QRp/i3bRg5fbRqTytHy4a4PpqBMfBBtOYjqmTHDEMzbZ1/e6vgMBvHP7RTFkNabn2+6PD4YPCGF7/kGzrmQvmqag+Ogx61uamv62jom37fOTOEz6vrt7o3LW0yILfNXvYHAYec1yHoBWWXBnG3PA1hlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=az4WgduGThZvY6Um24xQWuxzlC406KXWRiasoJJPX+I=; b=PFsPP89iuIeV4ciuhs8Ts5hC7C+z7q33bF7rqdj/+FyqQ4kxw9bpIu7p/bU5UWEd54RhlNT+dUhU16ojE84TCLMS0RwKEnIMPZr1R/Z9INROG8RjPXD7J5bk0OouqcHFQRoArwu7ziXR83MIzMVR8+iEWxkujyhdbAMOHIxSnMOJMv9WJ/txq7ox/GGxmy7IDNu4yaX/gBZKShDipzpvEOgaR8P3RSLyqiyRR5AtstnXxsVgp8va67fCB7SHq8Vs3i1G9qOGipMZ6c6yGV7Q0DjJNSfiGnjqAAh49S4IIBryrlE9sbLHxukbNCVNTPv0zO1PLhcH+IvfW3J3kaK/kQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=atomlin.com; dmarc=pass action=none header.from=atomlin.com; dkim=pass header.d=atomlin.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=atomlin.com; Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) by CWLP123MB3841.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:a9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.28; Mon, 30 Mar 2026 22:11:34 +0000 Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf]) by CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf%2]) with mapi id 15.20.9745.022; Mon, 30 Mar 2026 22:11:34 +0000 From: Aaron Tomlin To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, mst@redhat.com Cc: atomlin@atomlin.com, aacraid@microsemi.com, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, liyihang9@h-partners.com, kashyap.desai@broadcom.com, sumit.saxena@broadcom.com, shivasharan.srikanteshwara@broadcom.com, chandrakanth.patil@broadcom.com, sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com, suganath-prabu.subramani@broadcom.com, ranjan.kumar@broadcom.com, jinpu.wang@cloud.ionos.com, tglx@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, akpm@linux-foundation.org, maz@kernel.org, ruanjinjie@huawei.com, bigeasy@linutronix.de, yphbchou0911@gmail.com, wagi@kernel.org, frederic@kernel.org, longman@redhat.com, chenridong@huawei.com, hare@suse.de, kch@nvidia.com, ming.lei@redhat.com, steve@abita.co, sean@ashe.io, chjohnst@gmail.com, neelx@suse.com, mproche@gmail.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, megaraidlinux.pdl@broadcom.com, mpi3mr-linuxdrv.pdl@broadcom.com, MPT-FusionLinux.pdl@broadcom.com Subject: [PATCH v9 12/13] genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs Date: Mon, 30 Mar 2026 18:10:46 -0400 Message-ID: <20260330221047.630206-13-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260330221047.630206-1-atomlin@atomlin.com> References: <20260330221047.630206-1-atomlin@atomlin.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BN9PR03CA0877.namprd03.prod.outlook.com (2603:10b6:408:13c::12) To CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP123MB3523:EE_|CWLP123MB3841:EE_ X-MS-Office365-Filtering-Correlation-Id: fdbd9b2a-1f11-47dd-63dd-08de8ea94de9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: vap5EtSxdaDbd2QUZiGMqquDA3zdRQ7TQEZZZ1F1VoK6mgfGlrwzo3k6cPu2fmAM0u9PeSZQbe0eCORyKBe8Pyu0bhbI3waRipV59+TAcwFf4Po+3tAfgAMlVs69MFckddRp24kz3U2wg7wTpNK725AZpxYN3wTuiULTFE8nzNpSO/UEXRceouDlp97BVrDJVNIZaZSFgtc5p4833a9BqgWikz2N2r/o9nMa9+uyel4mP4ZHBfoCOIARUmJgZogkPb3w3RSbjrzWXQR370+RBg9rxW/kF5QvfM5eIak4DcpfCfQfatfgTlP/13r+KMv/i041Ke2RuXeQ/2lX34n69VwAubHChgWQT3295aiduswpCuVrtZgFCaf7xMMDV7qOBEI5EPU4lcizbA55IIqog7BkVp/YGcvMh0t/P4Y0+1cu7+vID09dxfLr/KTsyrQT0CddU1tsNOY5/5GAGk1AN6eqM0wWWKeL/C/1pAPX4SmkMk5+Tqb4H0/+sfXuGCYGBtyLEqrgoF1za2rEZq2kLEblghl/O9I9nS7pbkZJQCOy3NqQaFfYmpmnevtPZajkk90OhGt9giu0W7jnhrewaU9vdPRCt/f3G9XcbYq2HwuNfsOgnYhB/3YOC4FP8MYxUzcM3hVs/biSLeScQT3GjadkOpuyVBYtF7L7ytIg2aWn6+6bSrrY+Vhy20ftBPpTgWcAvgtYHEzRW2z176/6Peh26OrInXQST9dS/9ZLONk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?aonJGPgcORwr6+DsdPYV8B8MJphkSN6LCUBH/RwzCaDDSGOdWUm9jBFU7V9s?= =?us-ascii?Q?OeMjal2swdU6x2nV3znFWcYNpylB74keobZhcmdz86fUf/s8LKSW+MLpZOoZ?= =?us-ascii?Q?AGLS7+oCHlMNHbV6FiNTrJPJSoXageIOTRLUdnyOGez9X9YYHAM5GlRg4PDY?= =?us-ascii?Q?47Riv+NWejJLBO4l7RwL6+MpyCZUhQ/5P3zr+NPZwNRyuSTXo19uuKW5f0PF?= =?us-ascii?Q?8iUAvOMRzRzrAT60JgNyKtMWPHhHqF2iTMfqrZm6WCqT2HNfyOSQxRrFzgmz?= =?us-ascii?Q?PEQEORhy1cfUPyHx4v97DBcxw39veR6os4lKbTLk1EMRLSdFskTajO1jK9+0?= =?us-ascii?Q?l61ZJBt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xHBQI96wNVHC8+1uZ7eb?= =?us-ascii?Q?jTCbHnBgYAx28RpGgXlKtSTTpBPpe9ibDDk5nRtFwKCVfvP9QDVWTAWk9j5U?= =?us-ascii?Q?7I8yiyZbSF47tNQ1xikuk388O6aNGXY7TNsYw+yQ+kA8Z0Rx1Ae/tZufFBWM?= =?us-ascii?Q?sGJr+h1NMYkQ1LTv5p0BT8OFpNbcxIqixu1Dkew1KJtF0cB119aaPXFNa51l?= =?us-ascii?Q?DLX9Tl0isoWL2YZdFR0Bd+da8ILhazEqYnKw34BdUbdSwU3Yt5YYOJyfbg1g?= =?us-ascii?Q?a1dg4hYxl81XbFAvhVFu7N4iF19VtGx3l39NIvnwviM1de74NJwHFKJBIcij?= =?us-ascii?Q?of2mkb/S/pu8qDVdUINFux0poj+9v1sXZtcuIfUh7MhNnGiEK7I6ixhfhWQc?= =?us-ascii?Q?AAj00JPgsS1d7SxW7WvXrbr0c0tpS9CQ83xo0iTvGXLx+oioeAc9xluz4UWp?= =?us-ascii?Q?ELA/da2CfIkVALoAR90eqsdDDRDVFpb/gj/v5W4OlJg6pLxFa+WQGfHWMuVw?= =?us-ascii?Q?5YHtYZe9hw=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: fdbd9b2a-1f11-47dd-63dd-08de8ea94de9 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2026 22:11:34.2117 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e6a32402-7d7b-4830-9a2b-76945bbbcb57 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Xqt6tdqpedFRwgmnzXRGCJgNAgtxV0/7P/of9kFqgpwxxHquR1iOgoU/aaI43/NozIsRcgHo0EOdqchJ6EwDcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB3841 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260330_151136_529958_49FF3E8C X-CRM114-Status: GOOD ( 14.64 ) X-Mailman-Approved-At: Mon, 30 Mar 2026 23:26:01 -0700 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org 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=io_queue"), 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. Introduce irq_spread_hk_filter() to intersect the natively calculated affinity mask with the HK_TYPE_IO_QUEUE mask, thereby keeping managed interrupts off isolated CPUs. To ensure strict isolation whilst guaranteeing a valid routing destination: 1. Fallback mechanism: Should the initial spreading logic assign a vector exclusively to isolated CPUs (resulting in an empty intersection), the filter safely falls back to the system's online housekeeping CPUs. 2. Hotplug safety: The fallback utilises data_race(cpu_online_mask) instead of allocating a local cpumask snapshot. This circumvents CONFIG_CPUMASK_OFFSTACK stack bloat hazards on high-core-count systems. Furthermore, it prevents deadlocks with concurrent CPU hotplug operations (e.g., during storage driver error recovery) by eliminating the need to hold the CPU hotplug read lock. 3. Fast-path optimisation: The filtering logic is conditionally executed only if housekeeping is enabled, thereby ensuring zero overhead for standard configurations. Signed-off-by: Aaron Tomlin --- kernel/irq/affinity.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index 076a5ef1e306..dd9e7f5fbdec 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -8,6 +8,24 @@ #include #include #include +#include + +/** + * irq_spread_hk_filter - Restrict an interrupt affinity mask to housekeeping CPUs + * @mask: The interrupt affinity mask to filter (in/out) + * @hk_mask: The system's housekeeping CPU mask + * + * Intersects @mask with @hk_mask to keep interrupts off isolated CPUs. + * If this intersection is empty (meaning all targeted CPUs were isolated), + * it falls back to the online housekeeping CPUs to guarantee a valid + * routing destination. + */ +static void irq_spread_hk_filter(struct cpumask *mask, + const struct cpumask *hk_mask) +{ + if (!cpumask_and(mask, mask, hk_mask)) + cpumask_and(mask, hk_mask, data_race(cpu_online_mask)); +} static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs) { @@ -27,6 +45,8 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd) { unsigned int affvecs, curvec, usedvecs, i; struct irq_affinity_desc *masks = NULL; + const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE); + bool hk_enabled = housekeeping_enabled(HK_TYPE_IO_QUEUE); /* * Determine the number of vectors which need interrupt affinities @@ -83,8 +103,12 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd) return NULL; } - for (int j = 0; j < nr_masks; j++) + for (int j = 0; j < nr_masks; j++) { cpumask_copy(&masks[curvec + j].mask, &result[j]); + if (hk_enabled) + irq_spread_hk_filter(&masks[curvec + j].mask, + hk_mask); + } kfree(result); curvec += nr_masks; -- 2.51.0