From patchwork Mon Jan 16 13:50:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 44168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1203184wrn; Mon, 16 Jan 2023 05:55:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXvm9Kh4NnoKUkPlZnzfcp1wjFzSF0HRlpYYDFdatRU8T74HFPQEx0qA3j9Tl6nZ1GxNj5Yi X-Received: by 2002:a17:907:1316:b0:863:e08e:2ac3 with SMTP id vj22-20020a170907131600b00863e08e2ac3mr11331925ejb.63.1673877323169; Mon, 16 Jan 2023 05:55:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673877323; cv=none; d=google.com; s=arc-20160816; b=bDh+PDJGaao4EBwHczPfiMGf/9RalLnGwlQUFd04b16Z0ENpis38gchZ1wasfbdd5H WMsbFS/rXnsJK6oqaNSJkSlJ9BNqKIVJ9iwKtUxXdvcYitzMUAPKpPoPKzaii3gMUfNV dtYXkhUR3SkP/OJo0TKSD2xmA3ss4qM+aDLi+TdP90ziMeQTs5rW7H9bz2S0N83E9uL2 hieQ3QSKbcg7iOgFnSoF6F47X+Bu7dEpxlOsGxTGHkHXrG9MW17MvUBqL4oM48zq0ge+ osvIX9VY7xkq0ZBWDcVqajQsSsnm/6mWalaBhQW3fkCUG6oL+vx1epenVa4UZnAdkEqY 6P8g== 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=4HhbBTJ/7ktfAg+IIgIwDczQOzDd5EpoFDj3t071iJk=; b=OlhAKd//KfH0c7AoItk7j4kyXZYJ0bKykQXx87OWYreO65h353gNjVO1UA8CqY2Pv1 loIa4OMXV3ZCrwO2YpjUJSg/I5Vr2ZL78KIzke3TsheUdqLz/fklBuUj3q+OQfO4NUcl jmwFAayMMCfdqMiNM4Pj3SyGdpRUIA6XslyjvgsmOVOq/SpBlFMwPS3/Si8HkhqweSNc xFEOM/teLl/vUrAbmhQxahdWBNX2IhSIT27cJCuFPNFKdfW1L49HlmpbqEVAeZCbvZ6B i6xMGWDQRLEnDdKpTcsKneyy1ERpWX+xQbWe+8LDbwM58ek2fN1rK/YCT/eB3aAPWfKz 0lGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fbViRa0D; 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 qa31-20020a170907869f00b0086ffd881d1esi4967033ejc.290.2023.01.16.05.54.59; Mon, 16 Jan 2023 05:55:23 -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=fbViRa0D; 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 S231431AbjAPNvA (ORCPT + 99 others); Mon, 16 Jan 2023 08:51:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231527AbjAPNun (ORCPT ); Mon, 16 Jan 2023 08:50:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2951421970; Mon, 16 Jan 2023 05:50:42 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B7D2B60FD1; Mon, 16 Jan 2023 13:50:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97BC7C43398; 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=J9DOyi4U5wMa0WhON2OLMaU73RLt5W1A5vcDhDcrvxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbViRa0DmWJ5ahdcpXurCQDjfkGK425ybWw3sSGBJ1zmY/AG6Uk+eytmfgMM6YL0q 4778CvnjzZcU/tQgx2balKxXO0I2NNzjn1WjyrI9GibUMu2reduMD9qco27qUyW1QC FM12dJP2KMoqElMTqBARlqNW5Z5MFHMHoX050RFywMQJMg79korNDYINV0vPNlh5wj a2k2iiglX359OHBOFv22+4oAQ5P8DVuM0OctnpDRlhIY7PhtfCVNHOScO2VVJXEt4m AHBS81XrkNrIn5q+7kqZwmL/RvG4WSireyHrUfOhtje/ZdxDxswRH4xFFmwOekHjd+ t9JFUNNOCZ0+w== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pHPt5-0003ur-QJ; Mon, 16 Jan 2023 14:50:59 +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 04/19] irqdomain: Fix association race Date: Mon, 16 Jan 2023 14:50:29 +0100 Message-Id: <20230116135044.14998-5-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?1755187588072292557?= X-GMAIL-MSGID: =?utf-8?q?1755187588072292557?= 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()") Tested-by: Hsin-Yi Wang Tested-by: Mark-PK Tsai 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,