From nobody Mon Jun 22 15:38:36 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 715BEC433F5 for ; Mon, 21 Mar 2022 19:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352773AbiCUTin (ORCPT ); Mon, 21 Mar 2022 15:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237280AbiCUTif (ORCPT ); Mon, 21 Mar 2022 15:38:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFBA45F8FD for ; Mon, 21 Mar 2022 12:37:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7BB45B819C1 for ; Mon, 21 Mar 2022 19:37:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFC19C340F0; Mon, 21 Mar 2022 19:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647891427; bh=9v4RqTFBMhIkEMkcdqjBprzzsU8Kal+EmgXjHs9Hfvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWijfcPrBCtWz/eUo1xQ7mM+aDLRzUz/CywDMooDoGyfjquZnvUcs6qkqTH7BMYBr mWg7FhqodPCPJssDrcY+D+qiS+zeHYZd+onORcGLS/Fpw0VMxa9YV4iHQI7SZ3LEm7 fiSX+Ajs3ewReMRV1Du/RLMkc53cej1ehLW6WZIDX6UlP3rmc5pT1LgVssUPvQ9OUZ ab+meUhtXutFUNqZQiqBjia3Wx3IuPi3I4u5sNFRnNC1tQs0t4jzT2RYb4A1F/RLMH GNEtsFkW5jQwXNygSh3EFGPhIzp5PPz2tZe1M0pLyiugJILoAR/M0QbuVUl72pxWbT azllA4QFpWUnQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nWNpw-00G5T9-ID; Mon, 21 Mar 2022 19:37:04 +0000 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v2 1/3] genirq/msi: Shutdown managed interrupts with unsatifiable affinities Date: Mon, 21 Mar 2022 19:36:06 +0000 Message-Id: <20220321193608.975495-2-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220321193608.975495-1-maz@kernel.org> References: <20220321193608.975495-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, john.garry@huawei.com, wangxiongfeng2@huawei.com, ddecotig@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When booting with maxcpus=3D, interrupt controllers such as the GICv3 ITS may not be able to satisfy the affinity of some managed interrupts, as some of the HW resources are simply not available. The same thing happens when loading a driver using managed interrupts while CPUs are offline. In order to deal with this, do not try to activate such interrupt if there is no online CPU capable of handling it. Instead, place it in shutdown state. Once a capable CPU shows up, it will be activated. Reported-by: John Garry Tested-by: John Garry Reported-by: David Decotigny Signed-off-by: Marc Zyngier --- kernel/irq/msi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 2bdfce5edafd..a9ee535293eb 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -818,6 +818,21 @@ static int msi_init_virq(struct irq_domain *domain, in= t virq, unsigned int vflag irqd_clr_can_reserve(irqd); if (vflags & VIRQ_NOMASK_QUIRK) irqd_set_msi_nomask_quirk(irqd); + + /* + * If the interrupt is managed but no CPU is available to + * service it, shut it down until better times. Note that + * we only do this on the !RESERVE path as x86 (the only + * architecture using this flag) deals with this in a + * different way by using a catch-all vector. + */ + if ((vflags & VIRQ_ACTIVATE) && + irqd_affinity_is_managed(irqd) && + !cpumask_intersects(irq_data_get_affinity_mask(irqd), + cpu_online_mask)) { + irqd_set_managed_shutdown(irqd); + return 0; + } } =20 if (!(vflags & VIRQ_ACTIVATE)) --=20 2.34.1 From nobody Mon Jun 22 15:38:36 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C162EC433EF for ; Mon, 21 Mar 2022 19:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352809AbiCUTip (ORCPT ); Mon, 21 Mar 2022 15:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352776AbiCUTig (ORCPT ); Mon, 21 Mar 2022 15:38:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91845F8FC for ; Mon, 21 Mar 2022 12:37:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5AEEEB819C7 for ; Mon, 21 Mar 2022 19:37:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3222C340F2; Mon, 21 Mar 2022 19:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647891427; bh=1ZwAePmWdIAmK6iGwl3RMQhIQ7Z0QG8CpgBItccv0tM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/ukm3JmCXrqOs1wjURUAMD3n6CrXsvCXPmRnhMur5TWPGk4odgr+w8PCI3HFo5IX dAvg+IlScuQVBHImfwFVPq3TuIrHfYl5P1lEifay0FUOr2YfxWh4xI0PatvtKEQPKu SgWjSXXDQvabcn+MlytRExeoXwlqtPkcGtC4HuZ1X+clUTnBq/CBjVNoEpqQ6rRJJ4 oKquwyx4YOgqOjxAbIzRkVJ5cm3/ankcrO7xMVNRt4KTZr3RkRhDUiQpZvuiEpcGbn akMH/c8Xlp2BC63Pyye9WMeOOkJIiPuh0fQBgTGNuvDaUyZ88es1znH0oa0NRXP9yb yKRuNAYaxgWSw== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nWNpw-00G5T9-Qt; Mon, 21 Mar 2022 19:37:04 +0000 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v2 2/3] genirq: Always limit the affinity to online CPUs Date: Mon, 21 Mar 2022 19:36:07 +0000 Message-Id: <20220321193608.975495-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220321193608.975495-1-maz@kernel.org> References: <20220321193608.975495-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, john.garry@huawei.com, wangxiongfeng2@huawei.com, ddecotig@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When booting with maxcpus=3D (or even loading a driver while most CPUs are offline), it is pretty easy to observe managed affinities containing a mix of online and offline CPUs being passed to the irqchip driver. This means that the irqchip cannot trust the affinity passed down from the core code, which is a bit annoying and requires (at least in theory) all drivers to implement some sort of affinity narrowing. In order to address this, always limit the cpumask to the set of online CPUs. Signed-off-by: Marc Zyngier --- kernel/irq/manage.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index f23ffd30385b..351024253ce8 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -222,11 +222,16 @@ int irq_do_set_affinity(struct irq_data *data, const = struct cpumask *mask, { struct irq_desc *desc =3D irq_data_to_desc(data); struct irq_chip *chip =3D irq_data_get_irq_chip(data); + const struct cpumask *prog_mask; int ret; =20 + static DEFINE_RAW_SPINLOCK(tmp_mask_lock); + static struct cpumask tmp_mask; + if (!chip || !chip->irq_set_affinity) return -EINVAL; =20 + raw_spin_lock(&tmp_mask_lock); /* * If this is a managed interrupt and housekeeping is enabled on * it check whether the requested affinity mask intersects with @@ -248,24 +253,28 @@ int irq_do_set_affinity(struct irq_data *data, const = struct cpumask *mask, */ if (irqd_affinity_is_managed(data) && housekeeping_enabled(HK_FLAG_MANAGED_IRQ)) { - const struct cpumask *hk_mask, *prog_mask; - - static DEFINE_RAW_SPINLOCK(tmp_mask_lock); - static struct cpumask tmp_mask; + const struct cpumask *hk_mask; =20 hk_mask =3D housekeeping_cpumask(HK_FLAG_MANAGED_IRQ); =20 - raw_spin_lock(&tmp_mask_lock); cpumask_and(&tmp_mask, mask, hk_mask); if (!cpumask_intersects(&tmp_mask, cpu_online_mask)) prog_mask =3D mask; else prog_mask =3D &tmp_mask; - ret =3D chip->irq_set_affinity(data, prog_mask, force); - raw_spin_unlock(&tmp_mask_lock); } else { - ret =3D chip->irq_set_affinity(data, mask, force); + prog_mask =3D mask; } + + /* Make sure we only provide online CPUs to the irqchip */ + cpumask_and(&tmp_mask, prog_mask, cpu_online_mask); + if (!cpumask_empty(&tmp_mask)) + ret =3D chip->irq_set_affinity(data, &tmp_mask, force); + else + ret =3D -EINVAL; + + raw_spin_unlock(&tmp_mask_lock); + switch (ret) { case IRQ_SET_MASK_OK: case IRQ_SET_MASK_OK_DONE: --=20 2.34.1 From nobody Mon Jun 22 15:38:36 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBA56C433F5 for ; Mon, 21 Mar 2022 19:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352770AbiCUTif (ORCPT ); Mon, 21 Mar 2022 15:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237280AbiCUTie (ORCPT ); Mon, 21 Mar 2022 15:38:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1210F5F4D4 for ; Mon, 21 Mar 2022 12:37:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9F6F860DEA for ; Mon, 21 Mar 2022 19:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BE7FC340F4; Mon, 21 Mar 2022 19:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647891427; bh=SEYzK4vSPeMJtzy43JQGZXAJd12jPg80CMxvL3TbA+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r846iCeB6K3PL1kLU1vH2gs6a0PdIpzad36VDkx9u7cQEhYoP7Jz2uHj6EmCP3PDh FZRxAvWV9kSDFGrSVbX/XXZOc88F1CnddJpESghMwKrB4CvElhttUUG6qwqUU33+Cf hS2u1Y+BXRPXWkuVCXJOP3MsKPSpAU9T+2WTdTXolpP2QOBAVyuraAU0pgNTWl8B1a ahFuDiaEXVIKAQwwAWwEKiE2B/0ZlDRSFeVR3wBpOnoVVmig0lAsPajF+JKSAQy00v VanAANIldemXRhCskV3UrPkOxEGR+8GDw2mTDEHv9rpH0je46UmBtvtF8ZrGSaYdvN +BMezvI1JakXg== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nWNpx-00G5T9-0T; Mon, 21 Mar 2022 19:37:05 +0000 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v2 3/3] irqchip/gic-v3: Always trust the managed affinity provided by the core code Date: Mon, 21 Mar 2022 19:36:08 +0000 Message-Id: <20220321193608.975495-4-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220321193608.975495-1-maz@kernel.org> References: <20220321193608.975495-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, john.garry@huawei.com, wangxiongfeng2@huawei.com, ddecotig@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that the core code has been fixed to always give us an affinity that only includes online CPUs, directly use this affinity when computing a target CPU. Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-= its.c index cd772973114a..2656efd5d2b6 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1624,7 +1624,7 @@ static int its_select_cpu(struct irq_data *d, =20 cpu =3D cpumask_pick_least_loaded(d, tmpmask); } else { - cpumask_and(tmpmask, irq_data_get_affinity_mask(d), cpu_online_mask); + cpumask_copy(tmpmask, aff_mask); =20 /* If we cannot cross sockets, limit the search to that node */ if ((its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) && --=20 2.34.1