Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3334169rwb; Mon, 16 Jan 2023 06:47:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXv0sTHv+/audAkgQ/2xIy9AY2pjwvnzRA8Jg9YG2/26J7R/Ka2cOAvsGdhbASs0011oKYw1 X-Received: by 2002:a17:90b:3d8b:b0:227:f86:4ac0 with SMTP id pq11-20020a17090b3d8b00b002270f864ac0mr30600273pjb.21.1673880444167; Mon, 16 Jan 2023 06:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673880444; cv=none; d=google.com; s=arc-20160816; b=ImU7BDGezXey1ia8dzKCetWRYVl2Cs8I9kYznflZO//n/ajdXpnFcL8JP+N9Tix19m 5UVtLzPJ2nMuQLIP5vrR+JeKX3KR0ZZiaO/1KKMI5duRUsBWgxArKdKkpNgOj73/hdtA GPBuXuB5jzLwdV5bMw61LwmKSQ2s2hin78GU0Wc6iTMldPBbFsDuQjEVsedDeWRtugD1 L9eNf9HY/FqsS4tHNmoLAw0t3eP9/uS0ePWh9ziksFNpGP4HciwEs+L/7MfbiBqskKw8 qo7gWCJKaAgYYJKZ93giTyxWIXs20pN+inbHsXgtcIKQtlM1CkNUbzuex27qBBKipO0x ovOA== 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=9s8Oq+snk5E2j5zXCKZbvrfIicmMz3lBjArUyISMClE=; b=Kv3SVMd1HF5z8zZ75H0R5cNwUfD8oC8NmWMZxHJBDI/gmV/mvii2vj08j02UGK0Yhr mq2KKhzYSmceKm+5IbPcLCGB2JhdzuwMTp3F0wkbCXqKQgHp10k4yIBHCXwdwLWTUWQP I8NWMzdaiyfx+wIBksfaY41Sa00/EAPnMX4hhzGupcoOkX91UrIt1Y91cS1ybhIU2Ony jWHVn3ADnX4Ea8FVJF1UkG4eQrDlny3wIpQnPtnhmYeRRS0iufEQQ63y0XkCVS5VQ0V5 hiV54cgE7HU0ifj6eAmK9K6zNRjmSoz1dhMCZA10T/mG+M5efVp9F98Qvbd6WorbH+Vn oHzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rb49y6Id; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo16-20020a17090b1c9000b00219b5765ff9si34250294pjb.105.2023.01.16.06.47.17; Mon, 16 Jan 2023 06:47:24 -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=rb49y6Id; 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 S231423AbjAPNwR (ORCPT + 50 others); Mon, 16 Jan 2023 08:52:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbjAPNup (ORCPT ); Mon, 16 Jan 2023 08:50:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B9021A11; Mon, 16 Jan 2023 05:50:43 -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 99F8BB80F63; Mon, 16 Jan 2023 13:50:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2182C433AC; Mon, 16 Jan 2023 13:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673877040; bh=2HmrqiLpP1fOhlVzV0RQxKQijAGZZDfEPgi6MiK1HtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rb49y6Id656NJswA3g3hDHkdteg7bL4SCzIxmjys0Ojd5lL4Iib9e89bCTIBEZEu1 VQP3QBxa1T13af8bvR6y6KSWJjjM4MlH/cPuK+wDmMvZQbr7A95livMwIn3cJ7Ecl+ 6iFRTf7k9Ed9zeGGUhErfscwq9yd9SeCMniw3xTv/69Tg3s6Nx8o833O7x7zKfwFJR q7x8V4WHSUtJPNqm2frdkyhln3VQ4VbOms0zTzUTpp2Ektmml0X6lfjEANQyolFGNn 8NiMbEx9k+ef51pofcWr8FMZAW0+KiPpdtgNqEgVacX8CU2/ps0r3+rIWIh817+Hth 1tCiSeIBlzXYw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pHPt6-0003v4-5a; Mon, 16 Jan 2023 14:51:00 +0100 From: Johan Hovold To: Marc Zyngier , Thomas Gleixner Cc: 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 , Hsin-Yi Wang , Mark-PK Tsai Subject: [PATCH v4 08/19] irqdomain: Refactor __irq_domain_alloc_irqs() Date: Mon, 16 Jan 2023 14:50:33 +0100 Message-Id: <20230116135044.14998-9-johan+linaro@kernel.org> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230116135044.14998-1-johan+linaro@kernel.org> References: <20230116135044.14998-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. Tested-by: Hsin-Yi Wang Tested-by: Mark-PK Tsai 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 */ -- 2.38.2