From patchwork Mon Feb 13 19:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 56516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2537555wrn; Mon, 13 Feb 2023 11:43:35 -0800 (PST) X-Google-Smtp-Source: AK7set9U0e8+IkvrYeIVIDq0seR7jLw/I89E79mcyOrSq8oXrYcW9L+2O7SD5srOXxSeZpVfMkrJ X-Received: by 2002:a50:d547:0:b0:4ab:15d9:2dae with SMTP id f7-20020a50d547000000b004ab15d92daemr20641650edj.14.1676317415544; Mon, 13 Feb 2023 11:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676317415; cv=none; d=google.com; s=arc-20160816; b=P8bZ/i6KkZOxISBiv2EYZSZHvLSasLXXPURPxmTRl1vzBR8c+63kprybfL3FaJeC1Q Hxjf0NImOlB7EEhip+9bcxH4lkEyBrUsRTTDqsDQ80NhXaBrt4lBpI9LJlGzIa25hYha 4Xujpj5g4hTlP2SvD+zFRBQdI2SsaZ8hnmqyR5YNN5/a3sQoU1As3UxEPg14EWhzluHX 5O/fxQeN27bJ9CR2+WelzFK89Av8rhPug6urSWtXCimkaAMwD502z4+nTTrW2rQcIed6 r0xjs4nsGjohSpUFV9MXs+FUjrBp8v38aQPNQMQmqtki8axsT9xSjO2FxTdT+kcsDWko J0vA== 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=IZETnV9ykyuX3gKf2sQ098jj0lnFkkoCAQ8cb9bt5mA=; b=rQauToYLOiU/jWCClXULHlxjpXgXMVBn9v47wYgLNJ8gvskkDAB/kDI5YJvNbXH+iQ CAjt+CzSj57nRwcNkaqshKsQ2J4WrXb5FeXxOxibNjGIFnGjz1zINeWFbOmlI1pSKMki 1DciTqVkqe3S4np81tA9UfqPTBF4rmZmiuZfZe4NUFkJDAFMqLH+bKrnK9WA/NJC7SuM KnNG8pNNYBAx0YxeVAnnneqLWTvjp+WJSevIEVjT5OXyqOvAzNhn+IzWi+2IA3JFuu6u FYqfNGABtfCd/jDRA4ZwP6M71GQrOhnpbZ01SRB0cHNslFJ05Iv7oviZha/13smoBIc+ wC0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CMiEJddW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=xw2jbA8o; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020aa7c3cf000000b004aaa6348a0esi14692907edr.247.2023.02.13.11.43.12; Mon, 13 Feb 2023 11:43:35 -0800 (PST) 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=CMiEJddW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=xw2jbA8o; 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 S231234AbjBMTlU (ORCPT + 99 others); Mon, 13 Feb 2023 14:41:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231356AbjBMTlE (ORCPT ); Mon, 13 Feb 2023 14:41:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE76221964; Mon, 13 Feb 2023 11:40:47 -0800 (PST) Date: Mon, 13 Feb 2023 19:40:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1676317246; 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=IZETnV9ykyuX3gKf2sQ098jj0lnFkkoCAQ8cb9bt5mA=; b=CMiEJddW5ZiNY/G6B05EA8iMzBen+7I3dwe9OUkyyZuXwh77cLCetYT92Wav5YvGuYeQvq ZpoHpW2wdOSICdXEh6x9Dsz2h55hatneN/gCqxVY8QyjoaAzNN8gl82pBamYTMO+V6F822 0GD2Ynxi2W5tY6gqIWB42kHQJaI9we9Jf1/s2vRwc1guddU1P5GXwbCQpN8VyoCpJ8WGV+ mCkpYq5u+gt4CIMEgSBqb+WOstRS0s0HdbBiAuFC//lVF/ofJfw/Fd2MnD9jGdA0HqKSxk xiiLD7W+xx7qy7G+e3ovYfAotsakDAWSfiNCnyxyELkiOWmF/iIicocidcSxUg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1676317246; 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=IZETnV9ykyuX3gKf2sQ098jj0lnFkkoCAQ8cb9bt5mA=; b=xw2jbA8ogvE9+/0xgXzhXyUKyA4DRiXZ6uy4qpdYYRBmgNIpleVAM81vFN9ld0XfxIkaA1 SZdBW7SkxvqrjVDA== From: "irqchip-bot for Johan Hovold" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [irqchip: irq/irqchip-next] irqdomain: Refactor __irq_domain_alloc_irqs() Cc: stable@vger.kernel.org, #@tip-bot2.tec.linutronix.de, 4.8@tip-bot2.tec.linutronix.de, "Hsin-Yi Wang" , "Mark-PK Tsai" , Johan Hovold , Marc Zyngier , tglx@linutronix.de In-Reply-To: <20230213104302.17307-6-johan+linaro@kernel.org> References: <20230213104302.17307-6-johan+linaro@kernel.org> MIME-Version: 1.0 Message-ID: <167631724623.4906.9249607211486146477.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757712281720377237?= X-GMAIL-MSGID: =?utf-8?q?1757746210272454781?= The following commit has been merged into the irq/irqchip-next branch of irqchip: Commit-ID: d55f7f4c58c07beb5050a834bf57ae2ede599c7e Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/d55f7f4c58c07beb5050a834bf57ae2ede599c7e Author: Johan Hovold AuthorDate: Mon, 13 Feb 2023 11:42:47 +01:00 Committer: Marc Zyngier CommitterDate: Mon, 13 Feb 2023 19:31:24 irqdomain: Refactor __irq_domain_alloc_irqs() Refactor __irq_domain_alloc_irqs() so that it can be called internally while holding the irq_domain_mutex. This will be used to fix a shared-interrupt mapping race, hence the Fixes tag. Fixes: b62b2cf5759b ("irqdomain: Fix handling of type settings for existing mappings") Cc: stable@vger.kernel.org # 4.8 Tested-by: Hsin-Yi Wang Tested-by: Mark-PK Tsai Signed-off-by: Johan Hovold Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20230213104302.17307-6-johan+linaro@kernel.org --- kernel/irq/irqdomain.c | 88 ++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 9f95047..78fb480 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1441,40 +1441,12 @@ int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain, return domain->ops->alloc(domain, irq_base, nr_irqs, arg); } -/** - * __irq_domain_alloc_irqs - Allocate IRQs from domain - * @domain: domain to allocate from - * @irq_base: allocate specified IRQ number if irq_base >= 0 - * @nr_irqs: number of IRQs to allocate - * @node: NUMA node id for memory allocation - * @arg: domain specific argument - * @realloc: IRQ descriptors have already been allocated if true - * @affinity: Optional irq affinity mask for multiqueue devices - * - * Allocate IRQ numbers and initialized all data structures to support - * hierarchy IRQ domains. - * Parameter @realloc is mainly to support legacy IRQs. - * Returns error code or allocated IRQ number - * - * The whole process to setup an IRQ has been split into two steps. - * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ - * descriptor and required hardware resources. The second step, - * irq_domain_activate_irq(), is to program the hardware with preallocated - * resources. In this way, it's easier to rollback when failing to - * allocate resources. - */ -int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, - unsigned int nr_irqs, int node, void *arg, - bool realloc, const struct irq_affinity_desc *affinity) +static int irq_domain_alloc_irqs_locked(struct irq_domain *domain, int irq_base, + unsigned int nr_irqs, int node, void *arg, + bool realloc, const struct irq_affinity_desc *affinity) { int i, ret, virq; - if (domain == NULL) { - domain = irq_default_domain; - if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) - return -EINVAL; - } - if (realloc && irq_base >= 0) { virq = irq_base; } else { @@ -1493,24 +1465,18 @@ int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, goto out_free_desc; } - mutex_lock(&irq_domain_mutex); ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg); - if (ret < 0) { - mutex_unlock(&irq_domain_mutex); + if (ret < 0) goto out_free_irq_data; - } for (i = 0; i < nr_irqs; i++) { ret = irq_domain_trim_hierarchy(virq + i); - if (ret) { - mutex_unlock(&irq_domain_mutex); + if (ret) goto out_free_irq_data; - } } - + for (i = 0; i < nr_irqs; i++) irq_domain_insert_irq(virq + i); - mutex_unlock(&irq_domain_mutex); return virq; @@ -1520,6 +1486,48 @@ out_free_desc: irq_free_descs(virq, nr_irqs); return ret; } + +/** + * __irq_domain_alloc_irqs - Allocate IRQs from domain + * @domain: domain to allocate from + * @irq_base: allocate specified IRQ number if irq_base >= 0 + * @nr_irqs: number of IRQs to allocate + * @node: NUMA node id for memory allocation + * @arg: domain specific argument + * @realloc: IRQ descriptors have already been allocated if true + * @affinity: Optional irq affinity mask for multiqueue devices + * + * Allocate IRQ numbers and initialized all data structures to support + * hierarchy IRQ domains. + * Parameter @realloc is mainly to support legacy IRQs. + * Returns error code or allocated IRQ number + * + * The whole process to setup an IRQ has been split into two steps. + * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ + * descriptor and required hardware resources. The second step, + * irq_domain_activate_irq(), is to program the hardware with preallocated + * resources. In this way, it's easier to rollback when failing to + * allocate resources. + */ +int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, + unsigned int nr_irqs, int node, void *arg, + bool realloc, const struct irq_affinity_desc *affinity) +{ + int ret; + + if (domain == NULL) { + domain = irq_default_domain; + if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) + return -EINVAL; + } + + mutex_lock(&irq_domain_mutex); + ret = irq_domain_alloc_irqs_locked(domain, irq_base, nr_irqs, node, arg, + realloc, affinity); + mutex_unlock(&irq_domain_mutex); + + return ret; +} EXPORT_SYMBOL_GPL(__irq_domain_alloc_irqs); /* The irq_data was moved, fix the revmap to refer to the new location */