Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp1123110pxr; Mon, 11 Apr 2022 15:59:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLkmBDdF0UGsOQVOrN25N8aFmoOZDaQ08WYPRPQUucz4oEyXjA5UzGKUQdNnQPyN3DWDZf X-Received: by 2002:a17:907:1ca4:b0:6da:86a4:1ec7 with SMTP id nb36-20020a1709071ca400b006da86a41ec7mr32178188ejc.556.1649717941484; Mon, 11 Apr 2022 15:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649717941; cv=none; d=google.com; s=arc-20160816; b=DjY3nj2x7ReobqVedLaywnsJ8by53JT461vzOKjXxMvEo+yuTaxoNwPxpr2s7H4hhv pjHl/rCUxFuilTZR3t/gp0c460wlzexx66IWBlIehimdodb2m99074g82f1T2sZ0eXxM r/xpOp3RvTeqDKemCAwGfxnd/KatIxuqwn25Kobmvf3nu56pkWWI0SFDYjAuOLi8JE9D qiIttyJvmiaRpZLU2cG7VIMTpYps3cKhc5hZvE24aTHsf9ZnSj9CM5g1Wqn7RCqUwupU OBQBZUeTITkVtmzfN36VqckjxNwdlPlFkKaJMoQncVEXwlxEfGteDtT9fscyyR5pa1/5 5ajw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=mGHXjJncvoi9F9WOlrUAjS83FPKbyxCHc9YHBC9NpS0=; b=agYS0lQdw624i4ONmPSAoHmpxlZXcUqpTS1RP9pWOH+z9kCsH5OoWrIWfC9eDuYdlV 1ROXP5C5hl7YsPx2/1swJP5gUuU7j4+7FxiYcAIPKX7XEvM46AJ88ZKYZ8TNxLPr0QeE kkuuVmDktpISlKLAjqXX9c/seZtGUh++laHR5IjtVlIulAoxUoCs8Sk2xjuRvCxKihI/ Jk43vjdUbYTLc4P2d4j9zFrzU7o+Wc64ms0P4z03jdDDLt81Fdpv+Kz1ErLFp7mQsi3V YMPBT+Lz9KI8a9OGS6qk4r6rF4L8bGHK9GQBQHap2b2HzC4n/yvWaigytQvT9XlhoBaO H/Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WoVTjda+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a1709063ec400b006e00ed811f2si7179355ejj.383.2022.04.11.15.58.37; Mon, 11 Apr 2022 15:59:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WoVTjda+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241128AbiDJTPP (ORCPT + 99 others); Sun, 10 Apr 2022 15:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232947AbiDJTPO (ORCPT ); Sun, 10 Apr 2022 15:15:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92F7D60CFE; Sun, 10 Apr 2022 12:13:02 -0700 (PDT) Date: Sun, 10 Apr 2022 19:12:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649617981; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mGHXjJncvoi9F9WOlrUAjS83FPKbyxCHc9YHBC9NpS0=; b=WoVTjda+vR274+GnZ+rHqXYcdL67sfGLkHmRu5b4qs5LiZDDPomkjnfstQ0N4QgunDy+e0 grBCyDFzA/HbXz0HHUYmACCLKcVjXeSG2jX9K+AUIztsU5m57mn87oEFT1gmh1Nr6mCljk pK2pyYw51c+m/SzfJW9GjEC4JId+fTWeWRUs925/upwyj1WcCSS84xEBSQ0Z5fZj8RNyiE LBp4OIA/7CfdwOkqbqeyEPcttzvLSCApJqhXkYUH2tGQcXB253e28ZTtCqUKHxUOF1llxY 3ICg7BaW4JzQC4xbXvbBWai9ztMDv6L8t603s/BHQw0YiWDsvUleBLLaqpUYNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649617981; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mGHXjJncvoi9F9WOlrUAjS83FPKbyxCHc9YHBC9NpS0=; b=3QNV/QDIjFMDkTE9JGe14Z8lpG2dRmAVsZ4VLBX0BBwwodOHx4D/BsxEbxUyPbf7mdzjod uX3ppsxRagf7WzBg== From: "tip-bot2 for Marc Zyngier" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq: Always limit the affinity to online CPUs Cc: Marc Zyngier , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405185040.206297-3-maz@kernel.org> References: <20220405185040.206297-3-maz@kernel.org> MIME-Version: 1.0 Message-ID: <164961797999.4207.6664692900996135522.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/core branch of tip: Commit-ID: 33de0aa4bae982ed6f7c777f86b5af3e627ac937 Gitweb: https://git.kernel.org/tip/33de0aa4bae982ed6f7c777f86b5af3e627ac937 Author: Marc Zyngier AuthorDate: Tue, 05 Apr 2022 19:50:39 +01:00 Committer: Thomas Gleixner CommitterDate: Sun, 10 Apr 2022 21:06:30 +02:00 genirq: Always limit the affinity to online CPUs When booting with maxcpus= (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 Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20220405185040.206297-3-maz@kernel.org --- 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 c03f71d..f71ecc1 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 = irq_data_to_desc(data); struct irq_chip *chip = irq_data_get_irq_chip(data); + const struct cpumask *prog_mask; int ret; + static DEFINE_RAW_SPINLOCK(tmp_mask_lock); + static struct cpumask tmp_mask; + if (!chip || !chip->irq_set_affinity) return -EINVAL; + 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; hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); - raw_spin_lock(&tmp_mask_lock); cpumask_and(&tmp_mask, mask, hk_mask); if (!cpumask_intersects(&tmp_mask, cpu_online_mask)) prog_mask = mask; else prog_mask = &tmp_mask; - ret = chip->irq_set_affinity(data, prog_mask, force); - raw_spin_unlock(&tmp_mask_lock); } else { - ret = chip->irq_set_affinity(data, mask, force); + prog_mask = 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 = chip->irq_set_affinity(data, &tmp_mask, force); + else + ret = -EINVAL; + + raw_spin_unlock(&tmp_mask_lock); + switch (ret) { case IRQ_SET_MASK_OK: case IRQ_SET_MASK_OK_DONE: