From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81406C46467 for ; Mon, 16 Jan 2023 13:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uIB3mI3985NzQq8e1wp7fIRuY6h8o9PcByIW6rhputc=; b=ZpdhcVtafi7Nmb M7IJ//UssqqrehdSea9xhn4RpcOTcBHxRVT8apGF1Sjfzs+FaeC8yyvzmGAm3THxOIXOurwc5hlcv 4EwiPqgE5770AKy6rF3UVXIwp1XQOg+mX0so2qLsC+SAwEcBy2+1yBY/JDWACpHX9tZxtbPdqvVAx 8shNfLSeCmVr5Vi2IwPuJoR5j4RfejdhbkW3Uxp//ynefucxUfC5dq/U+I7OCGrHEWwipwXtJrlGA L75+gdHF0G78BtxGI85moxsklxFEahqWDa/5/gI2qC2tSEYPiA+Zp6K6WdqF9FjagDBG8P2CASDIq a1sbcWdTb92wJDfCZw1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHPuO-00AbpA-J0; Mon, 16 Jan 2023 13:52:20 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHPsq-00Ab1N-H7 for linux-arm-kernel@lists.infradead.org; Mon, 16 Jan 2023 13:50:50 +0000 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 255F2B80F4B; Mon, 16 Jan 2023 13:50:43 +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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230116_055044_890279_BD25F8C1 X-CRM114-Status: GOOD ( 14.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, -- 2.38.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel