From patchwork Fri Dec 9 14:01:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 31761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp795037wrr; Fri, 9 Dec 2022 06:07:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UL4kW2tpLOGo/3XBpJFEtOC5D8yjs6C2rK540YvgSt3NoIGznLezbvuuWPglkG9i/9YeF X-Received: by 2002:a17:902:7081:b0:189:907b:7cc1 with SMTP id z1-20020a170902708100b00189907b7cc1mr5712362plk.51.1670594849281; Fri, 09 Dec 2022 06:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670594849; cv=none; d=google.com; s=arc-20160816; b=GKHcwgRuQYZjOaL26FzD/pc49B+n10s/8hQUDrFxPnmoprCN/T6a7o6CasmNd0+d8z kkEJa/vu7imx+E2EwDhnlZb0YlRn7WoG6V1qMnxXlce1uMVVpRBwG8yCpxQErp6WSRfQ YXZcrU9DlEIN8p93Up0Tac87DDnEcrDRFoDFk+V7pfPLWKkdLCL2GYdrw3ZeGgwqWGbE Z0Y7NKEadSj2b0xeuPrtZsYp8/NzcsdNwS+C9sFCof4SlwngiFYQyaoNkm0Suc776TCU QWgtcp7MBocUW0MMzxBM91EXJcRdbQlWDs4YtEbPSU7mUXZyu5xmU63TPkK3xi3CVR5V /wtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mMoakzuisq8sfWECDfM55I1jMZJ3dswF/ljH/Dw99T0=; b=SAdPGqgfTgHBnOH97RgU72rnB8UY0fZUp+7Yw2DPCWNaMD45tFzQNXhzUVW2HHwLfS WWHrSikGkV9KyQJdK0VhSpFpu2mWcb7w2D2BiqagjgcvpZgvZ6gvJKUK/Xf+XU6zyTvh EZSCBRWUcXD2gwxIayYGHp5c4kY7t6+HF2TSZmI2q2U7ovfj+L25oorlT2olQ4gKG/Bx HwgKOFxmZmtkor9a95vmbu7J68XODDcKRaz/nOHVgGXoAfiehoSkrBmCaapT/g59MY7g BZDxKiGo+zawq/cZienJ3DtErdIVSFVpIdae6LuLHAZW62sDSVy2sI3kTKeU1ZuY9hsb e9Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RPRB6Xwy; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n1-20020a170902f60100b001897390a9fdsi1675373plg.541.2022.12.09.06.07.12; Fri, 09 Dec 2022 06:07:29 -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=@kernel.org header.s=k20201202 header.b=RPRB6Xwy; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbiLIOF6 (ORCPT + 99 others); Fri, 9 Dec 2022 09:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbiLIOFU (ORCPT ); Fri, 9 Dec 2022 09:05:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B937F7869B; Fri, 9 Dec 2022 06:05:16 -0800 (PST) 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 662F7B82884; Fri, 9 Dec 2022 14:05:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4141C43324; Fri, 9 Dec 2022 14:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670594713; bh=lHmq3B91dsrvn0iV4+ZnPYLRzHPArBilZTdSdeuIYww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPRB6XwyWPCrk8NYr8tPhVSW4ycG+ZuiOob0VpN0c7XhIQ5ezg/uf497ovusn8T38 gCL9SrqF35c9X5WSUqMkzpnypDWlvXnstszZCDWodj9WLgXEqgkRwrGtbqEvjx9rB/ NPtqIpWK5fY1+nttim5qJ9D36XtdRTLkAsmZu9B9Fr2uzy4z5ShflHqXiot00NEbZM DGzGpAIdbhiEmallyO/2LITF3ae37tn7GzEsHqST9jEQRE9WZA8jbgJbLQPN/vu8mP /Vxjhw9zF+a9cNzrVvQ+Sig3IbpzH3Oaro5Fh7rRetaThsVwkG0hut7jf4apQQzq5s /cSsAS9RnmVyQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p3e0I-0000Rj-R9; Fri, 09 Dec 2022 15:05:30 +0100 From: Johan Hovold To: Marc Zyngier Cc: Thomas Gleixner , x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v3 08/19] irqdomain: Refactor __irq_domain_alloc_irqs() Date: Fri, 9 Dec 2022 15:01:39 +0100 Message-Id: <20221209140150.1453-9-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221209140150.1453-1-johan+linaro@kernel.org> References: <20221209140150.1453-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1751745664163417878?= X-GMAIL-MSGID: =?utf-8?q?1751745664163417878?= Refactor __irq_domain_alloc_irqs() so that it can can be called internally while holding the irq_domain_mutex. This will be used to fix a shared-interrupt mapping race. Signed-off-by: Johan Hovold --- 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 894bc6ee6348..d6139b0218d4 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1430,40 +1430,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(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 { @@ -1482,24 +1454,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; @@ -1509,6 +1475,48 @@ int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, 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(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 */