Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2827157rwb; Fri, 9 Dec 2022 06:50:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf6aPmnmUGHGgn5t4d3jQXLIsufqSYldHR2DM9aZh6mgtV7F80EsV1JTd3vtW0v+sBFkjxTm X-Received: by 2002:a62:1bd1:0:b0:575:fc29:90b9 with SMTP id b200-20020a621bd1000000b00575fc2990b9mr5965176pfb.22.1670597448589; Fri, 09 Dec 2022 06:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670597448; cv=none; d=google.com; s=arc-20160816; b=EPSnI/9fjPvg2cuMAQSGvXO2HcAJv2/g9OGk2ThByPNU/hyXOGVu4cJFRjIpG3Le26 gfnqSSMW6eC2BlBe8HQSSz0tkH6uTYvqdQq7vWUaBKXQ2N1l89f+ax29zkpI4NptgNk8 YPMF9IUncqY2rxO6ig8fJ525psjsBW09Ijd9SnktwGfcuvNZle2jpOoQW2AV2jkbRk73 jbBgvOkFuvgYGPUnGCaXNzFoQqksDN/QNJRj/7zWk22YCx9ZMZZw9fE7v9Io77e6kEuz rsBwPq0jpKx6Ygf8Gfe2PXtSVmak1SQ0Iw7+tymQD3LTn1oE1qDErKaulu60OeIyn9ih mjXw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a625302000000b0053fafd6a529si1847326pfb.24.2022.12.09.06.50.39; Fri, 09 Dec 2022 06:50:48 -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 + 75 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 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 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 */ -- 2.37.4