From nobody Fri Jun 19 08:29:33 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 7EDC9C35276 for ; Tue, 5 Apr 2022 23:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242074AbiDEXNp (ORCPT ); Tue, 5 Apr 2022 19:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573309AbiDESwp (ORCPT ); Tue, 5 Apr 2022 14:52:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60D74B1AA3 for ; Tue, 5 Apr 2022 11:50:46 -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 F042B618DE for ; Tue, 5 Apr 2022 18:50:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E675C385A0; Tue, 5 Apr 2022 18:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649184645; bh=9v4RqTFBMhIkEMkcdqjBprzzsU8Kal+EmgXjHs9Hfvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8cbUPZf+01/VPHkKaT4bjtrcbCTPE/ZabeIa9eTs4fyYuli/cUP8iQoLAWxzxkNl rHXogKRj2emil3DSJYuRhHhLeNBKsBHQHk4qhR/uuL2StPZsxFb5wWXMgk4U/DdlgR dfY99/C99VG5URZEklSy5J9kJgJBRjq0ytC2SFGM559ZyEaq+MMEmFQWOK3C3ymhsn fuiG9Y5L09kNj0ICIVf10hPLNcSIRqKp5pVxAvwvn0j3HRGolA3OgadYItGNfABf+O MOShxM/ZaPCf1y81V96V9FZTiQJApA4VJ+I72ukQVcbl4rzRBOaLsIwfIeq6oy2P8s erqd7vDKfYAfQ== 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 1nboGJ-001tpg-5z; Tue, 05 Apr 2022 19:50:43 +0100 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v3 1/3] genirq/msi: Shutdown managed interrupts with unsatifiable affinities Date: Tue, 5 Apr 2022 19:50:38 +0100 Message-Id: <20220405185040.206297-2-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220405185040.206297-1-maz@kernel.org> References: <20220405185040.206297-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 Fri Jun 19 08:29:33 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 8CDBCC433EF for ; Wed, 6 Apr 2022 00:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1835734AbiDFAdN (ORCPT ); Tue, 5 Apr 2022 20:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573315AbiDESwq (ORCPT ); Tue, 5 Apr 2022 14:52:46 -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 E9F1DB1AB7 for ; Tue, 5 Apr 2022 11:50:47 -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 9B3BBB81FA2 for ; Tue, 5 Apr 2022 18:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48244C385A3; Tue, 5 Apr 2022 18:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649184645; bh=2pq6znDDwTPrws53shxITQ/dvLLKRa5w89+EvNf5cJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=og5ypzWByBszzByi63oVJK93kiLlbax4+fz+A5CwFLVQUDtQpAAJ2uKKT66u9Sciu +3z6dMSFhYm0HB09BlPxRYx7MWFiuFnk+7da4jDGGJxPRD1ErD4mGLY72lX2bTZvxM U+3FObd+AtSdxYuCfBCJg5PhxzghPa7wo+GzgY77NJBmkXEHos/9ccvOvSsEQo2rtH QDUuN+pIHHX43x7kB9FZkLu+a8uC2Om88KyXz+PksCm1qgk2K2L4n9lxh9u9aJ5qlX or3qNDId0kejyO5uZ/Wvd/CVkHtgCMLDvMty/hs1+gNOHjQ8s4smVllfJgTjcdanw2 5N5w+2QsxHtpw== 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 1nboGJ-001tpg-Al; Tue, 05 Apr 2022 19:50:43 +0100 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v3 2/3] genirq: Always limit the affinity to online CPUs Date: Tue, 5 Apr 2022 19:50:39 +0100 Message-Id: <20220405185040.206297-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220405185040.206297-1-maz@kernel.org> References: <20220405185040.206297-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 Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski --- 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 c03f71d5ec10..f71ecc100545 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_TYPE_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_TYPE_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 Fri Jun 19 08:29:33 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 49A75C433EF for ; Tue, 5 Apr 2022 21:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233290AbiDEVkA (ORCPT ); Tue, 5 Apr 2022 17:40:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573312AbiDESwp (ORCPT ); Tue, 5 Apr 2022 14:52:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7259B1AAB for ; Tue, 5 Apr 2022 11:50:46 -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 27FB1618E1 for ; Tue, 5 Apr 2022 18:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81310C385A7; Tue, 5 Apr 2022 18:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649184645; bh=SEYzK4vSPeMJtzy43JQGZXAJd12jPg80CMxvL3TbA+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ftuf1iTnz8Nu5ZYDyk8s11y7iQSVnmZXMjBWjZkkG+vjWMk+7bJATzu15mgn0PQPN c7WdUa//KVMOS/YfTc5PpI3Fs3Of6n8MCsI/AAMODdDuo4m88I0tklSSIkFOr9pUKp zjJuNazMQLa4iMionLKyXyV3Rk6Haa8ZNHlf9GOvAuFhNT7aQ2ChjU8CoVO+zIZYLS tqEpjwrlwwaIBXdeQ8TJmdAbpj4M7J/naaKnah3PHJIwmrvmfNR0CnHb18iNEoW6bO Y17bP3EuCu908PqsT/LplVGE/crve5mY7xNBBXisSKQFOg8FiZNoK99SU5QVo8NpD6 gJxk7Z1YyKTug== 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 1nboGJ-001tpg-Fx; Tue, 05 Apr 2022 19:50:43 +0100 From: Marc Zyngier To: linux-kernel Cc: Thomas Gleixner , John Garry , Xiongfeng Wang , David Decotigny Subject: [PATCH v3 3/3] irqchip/gic-v3: Always trust the managed affinity provided by the core code Date: Tue, 5 Apr 2022 19:50:40 +0100 Message-Id: <20220405185040.206297-4-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220405185040.206297-1-maz@kernel.org> References: <20220405185040.206297-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