From patchwork Fri Dec 9 14:01:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 31767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp795404wrr; Fri, 9 Dec 2022 06:08:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7VlqsbpaBMasVOTirHZDPyDSjesEIhJVywcBFFLAKvIC0DhjrHn5I+4fb330DZNEGa9/66 X-Received: by 2002:a17:903:189:b0:18c:1bc5:bd58 with SMTP id z9-20020a170903018900b0018c1bc5bd58mr6596030plg.9.1670594883673; Fri, 09 Dec 2022 06:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670594883; cv=none; d=google.com; s=arc-20160816; b=pRkws2KvKseyx0XJhaNRnVWC4cj5YK6XG54KZHX6lSaeA41KTTO66oxtIhhi9fE+vx JG2cbuBzrqe9Bec6r4c3IQmqdTDkK7AbSW2x17GuWL+fFtuXvZ4+cYlX0/9DgTNu8HLW lDof3EMqrXRA0DBG3e7YzHDhZyhxy0YlCaQXxEm24xIiDQBgfpXqNUBmfVx9TBnSk01z YeQnVrThwmevETu7YoKMhTA8pezyzOD6F3d8SQi7ea1fm44gEZ+/dUSOEyKvBg3xGhVt 2c6teLBraZ3oqPXLefWu1frKohBFSb9hmzdUg/wvUq0FKqxCDZcLojUc/OcaVVG/LzHv VjJA== 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=JdXwRbltF2/ckQVe508m84L4WBTteZ31VKrtUR/Yb7I=; b=CxwJg645g1WUTAyPyey4uIgk5/in99Eu7qjwatWJbf3t57oc0HlHIGgyfXFxSxqedV D1qdqTuQZg5BoDFckj0apITZKSa7Egzhgcloo9JwcF7YTLlYqgw6Y6aE/RnrjADziG3C Xlyzhr3RSNj082+KH468THLJTwViRKKPOYaLM4lLUu8KIdrCDNFivR57MntyccEsH7HM WuTObcpaTdsPjplzGRkpLgwittEwkoJoBXMDKZuNEDPz0lBeAbA+VRUMMyyjPyvXcwSc icApr5HEzFiyhwNQiSy5FVhRmWgqAHyMu+F5FtWH1o9nT0t7VTosv5nnXW6UlqeM6JBe k7Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qMh5hmBZ; 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 i19-20020a170902e49300b0018c166e2304si1509747ple.299.2022.12.09.06.07.45; Fri, 09 Dec 2022 06:08:03 -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=qMh5hmBZ; 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 S230063AbiLIOFj (ORCPT + 99 others); Fri, 9 Dec 2022 09:05:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbiLIOFS (ORCPT ); Fri, 9 Dec 2022 09:05:18 -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 497B97868B; 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 E5910B82879; Fri, 9 Dec 2022 14:05:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78F51C433A7; 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=niOEf+y/CPs0Wgq9no1nSEQwpCfRmMUIj1MEHaqp6o0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMh5hmBZHRacWKxQ3PhjUYbyvKsBDG6k/6Ha4xNVKmoF0sgZWrXE30p010cv9xPbX U7mmlRkKAIpZMC/0ZhNFREAmOwYAuOedHoVxcEpAcqnQ6jvlqQVp/QXeBohqLpsu7L AGYEeDPju+UkCyuAeZGdkWg8VPRbtbrN7P4V24oCGQ2PjPBJGD0o/AqlI+izZeNe3z njngGonkfbj8pebR4ZOOqF4knVeISyx6YUQMUZvjxiKcxdtAw4W3HT8i9X637hlbDW Vg8I5CGt/E3fGd2kQOllmkhzVuWUVJJj9al7te1/JqBBgfG/Zai7rPTtPybMIUv7U0 29QVlwJLrQBBQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p3e0I-0000RV-F7; 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 04/19] irqdomain: Fix association race Date: Fri, 9 Dec 2022 15:01:35 +0100 Message-Id: <20221209140150.1453-5-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?1751745700699788970?= X-GMAIL-MSGID: =?utf-8?q?1751745700699788970?= The sanity check for an already mapped virq was done outside of the irq_domain_mutex-protected section which meant that an (unlikely) racing association may not be detected. Fix this by factoring out the association implementation, which will also be used in follow-on changes to rework the locking. Fixes: ddaf144c61da ("irqdomain: Refactor irq_domain_associate_many()") Signed-off-by: Johan Hovold --- kernel/irq/irqdomain.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index dfd60bd49109..b2087f55a1ac 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -558,8 +558,8 @@ static void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq) irq_domain_clear_mapping(domain, hwirq); } -int irq_domain_associate(struct irq_domain *domain, unsigned int virq, - irq_hw_number_t hwirq) +static int __irq_domain_associate(struct irq_domain *domain, unsigned int virq, + irq_hw_number_t hwirq) { struct irq_data *irq_data = irq_get_irq_data(virq); int ret; @@ -572,7 +572,6 @@ int irq_domain_associate(struct irq_domain *domain, unsigned int virq, if (WARN(irq_data->domain, "error: virq%i is already associated", virq)) return -EINVAL; - mutex_lock(&irq_domain_mutex); irq_data->hwirq = hwirq; irq_data->domain = domain; if (domain->ops->map) { @@ -589,19 +588,29 @@ int irq_domain_associate(struct irq_domain *domain, unsigned int virq, } irq_data->domain = NULL; irq_data->hwirq = 0; - mutex_unlock(&irq_domain_mutex); return ret; } } domain->mapcount++; irq_domain_set_mapping(domain, hwirq, irq_data); - mutex_unlock(&irq_domain_mutex); irq_clear_status_flags(virq, IRQ_NOREQUEST); return 0; } + +int irq_domain_associate(struct irq_domain *domain, unsigned int virq, + irq_hw_number_t hwirq) +{ + int ret; + + mutex_lock(&irq_domain_mutex); + ret = __irq_domain_associate(domain, virq, hwirq); + mutex_unlock(&irq_domain_mutex); + + return ret; +} EXPORT_SYMBOL_GPL(irq_domain_associate); void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,