From patchwork Thu Feb 9 13:23:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 54961 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp334212wrn; Thu, 9 Feb 2023 05:32:01 -0800 (PST) X-Google-Smtp-Source: AK7set8HF2jEV9VRtRXPg0e6xgQiK4P0qNntvBwY0CYmt2z6D0cU8aGtSFhp6raXpM7AiTmPEQ2q X-Received: by 2002:a17:90b:3506:b0:22c:ad11:af3d with SMTP id ls6-20020a17090b350600b0022cad11af3dmr12644227pjb.4.1675949521409; Thu, 09 Feb 2023 05:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675949521; cv=none; d=google.com; s=arc-20160816; b=vErcBfJdEakrsZ+I596t/6KtjVja3Wl8eefp18ASg8wbw8wKWsLPADaCPI7Q4pmXkg IrsxPTB0rm50sVq1PN+/vT8rfXERMAWSBkB0lH4txAgX4myGkaFQsYo8JJswpgcFCOQT 66YDiEfJb8OZkqMhe/EfrJ688xJXcneY65mHTvoH2AA7FS+o4o6jRVAlYI6q3tLrNnLX TIIV+ZU915KXjbOK+0ol8rjd0aYwvHJPosSuN0MkDEtGovWOe0jypCt5ppaHPIH21HSd PVWEfRz61YiYqQ7g/4PeBX+PqPFqmMuDkma/Uvh+KtOeH6F999NYfCjx21+eIV+TyNZS wtKg== 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=8OVyPa/IKpEabnBKb/Clqp3KrZUv96VCot6h2E6BWXk=; b=EB3E+YsH2A35FG+1xHHSdhjcAV6a9PFPV+dHx32XiPpvK9ustsXEjB0eqotG5gM/Qm gIFTK0bPLCj48NOBxd6oVAAU0QGxFgtFHBx/54pgKn7X345Xe+LSoCuBGL4CiRLBotmc s8zpEEbKJ10LnshIxg8vctTJLOyXMw7cxgSad/8OX4HDfniOmS8ITesKInYvmRPm7aOu eqvS62rWsTk02QZFsqy9AaparpwBWqqth9tiyC+5UeFGNkww9/8kR6iYnD0EOiJxeXXW 0wsn6EIG0egt4TVWK8547w858V1tm7sfAVoxnKRSoTrb6oJLkOJTxxrDBZhNyQAivyDe VxVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TeA1pbon; 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 ls11-20020a17090b350b00b00232f57260c1si1056264pjb.1.2023.02.09.05.31.46; Thu, 09 Feb 2023 05:32:01 -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=TeA1pbon; 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 S230294AbjBINbN (ORCPT + 99 others); Thu, 9 Feb 2023 08:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjBINaq (ORCPT ); Thu, 9 Feb 2023 08:30:46 -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 9D51EFF0B; Thu, 9 Feb 2023 05:30:45 -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 2AC43B82138; Thu, 9 Feb 2023 13:30:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8B9AC4339E; Thu, 9 Feb 2023 13:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675949442; bh=tBqk6KgtGtAPTVEMAxcaZIoN23hQcgfod3xymk/Evn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeA1pbonScrBm0NCQzRGyJ3tlpcXySd1ejnAVbqKqPBVM6OHV49cOLP+zJ3t1NVJs hPOpfXJALcAjzFWFzl5XoN3jLzWOeHgjyDhh/DpCM5cHGfP0IJLyhBjqysRzlSSHUP F6NXWivqhs8rjF414ZgK0MVZXftxG2VZcJ9vU1bNs/RzUSubGFMuut9Xbc5/r3SxEu VIWpTdySZPGv9lIoo9YIxtjFX7WrcgGQAZm3yKG+zQu0QwyQBJAjpJ4C+ktNYe9vPQ 0VFGEN3/aMfSOffu2VFHU+6YvE3hweyFIU1hfqR/2I7272YnF18U/W6znDwK6UN0TI 0Ejz3VTg42ojw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pQ71G-0001Kh-4e; Thu, 09 Feb 2023 14:31:22 +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 , stable@vger.kernel.org, Hsin-Yi Wang , Mark-PK Tsai Subject: [PATCH v5 01/19] irqdomain: Fix association race Date: Thu, 9 Feb 2023 14:23:05 +0100 Message-Id: <20230209132323.4599-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230209132323.4599-1-johan+linaro@kernel.org> References: <20230209132323.4599-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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?1757360445291796371?= X-GMAIL-MSGID: =?utf-8?q?1757360445291796371?= The sanity check for an already mapped virq is done outside of the irq_domain_mutex-protected section which means that an (unlikely) racing association may not be detected. Fix this by factoring out the association implementation, which will also be used in a follow-on change to fix a shared-interrupt mapping race. Fixes: ddaf144c61da ("irqdomain: Refactor irq_domain_associate_many()") Cc: stable@vger.kernel.org # 3.11 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 798a9042421f..561689a3f050 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -559,8 +559,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_locked(struct irq_domain *domain, unsigned int virq, + irq_hw_number_t hwirq) { struct irq_data *irq_data = irq_get_irq_data(virq); int ret; @@ -573,7 +573,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) { @@ -590,7 +589,6 @@ 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; } @@ -601,12 +599,23 @@ int irq_domain_associate(struct irq_domain *domain, unsigned int virq, 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_locked(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,