From patchwork Mon Jan 16 13:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 44174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1203514wrn; Mon, 16 Jan 2023 05:56:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKj9d0+uS5k7ye90XBkCQke5ryY70CWmGe5Ih6YyfVoVlHfDli3IfsdFUxn8QKY72VGNAy X-Received: by 2002:a17:906:3687:b0:86b:914a:571 with SMTP id a7-20020a170906368700b0086b914a0571mr10481192ejc.5.1673877379686; Mon, 16 Jan 2023 05:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673877379; cv=none; d=google.com; s=arc-20160816; b=w2QkvOeYiRudCDBi2C4W1+1PZhSNRbx41sD7tG+DHTmZgGaMH1LkHlWIduMF2zotRM JrR39k96jlJQKU6876XH4KQXLPf2jfnr5wtR1kmdVyuJLqvnA/azj+bbEqWFgPF3ktF4 G7KXznHaeCcZEZn8pU2JW29B4OMrwtAYDxeAqzalzRyqJQzzGxtsvWt3A46D+J4OAz5q Ca1S9MHZEClHfW8KIiD4SwKgV09dwM6xSTSj6eaWMROXDeL5V/vD0d3k+470PYWFUYPy aXOy8JOyIuv12mZZ2mN+j6eo4IflMypgELT/ECGTTelKY89zDzhe4v5NJfafGJ9TEdLb CgOQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p34-20020a056402502200b004772b115406si6182124eda.560.2023.01.16.05.55.55; Mon, 16 Jan 2023 05:56:19 -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 + 99 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 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?1755187647383770235?= X-GMAIL-MSGID: =?utf-8?q?1755187647383770235?= 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 */