From patchwork Mon Feb 13 19:40:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 56525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2538413wrn; Mon, 13 Feb 2023 11:45:45 -0800 (PST) X-Google-Smtp-Source: AK7set9hif7intDxPEibTfLOY0NYDlNHD17D378ZcRDN6rAi4JrR+uXHTwrCZOKb4QSXBKA9xG2x X-Received: by 2002:a17:906:2518:b0:88f:a236:69e6 with SMTP id i24-20020a170906251800b0088fa23669e6mr154288ejb.7.1676317545034; Mon, 13 Feb 2023 11:45:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676317545; cv=none; d=google.com; s=arc-20160816; b=xhocGUNTptD6fdvVTm42pcvP/2rUkHn3KGVRgMr5Lv/x7/hzEv+gutDwRVyxCPoX8Z kTc8qJ3f3m0ip0WB/hSPahPXBLZuDgCijO6P30gLGq1X5+NWPehQRZLbardK0irZzznd SsagOi9i076JpbEabJ+318cKAkKDVTFkiyOAUKehaEGs0NzquWUVRve343PvtwgBu8tP BbX5wdtm2XPwN7vDlK8e+Ha17fu9K5mdRrch723pL8z/v7xyl5g68wYxS7lKgF1poII/ cnjwH5sE0OXdD1cUbDUhU07sFR5H/PMtTXPcJykBgpxl+3ymVCjv+2yZPwtX9d7/22nI ryew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=Fwa++b7D1fwwyGb87Ce7+hKWeC+R9ZUZd4CRBGUJrrY=; b=vrvSCWY+RO/HPxEp0dZP1cQsJPw3H+39VBfmjjH/zk/MCwEdOpLa5jIC/gKehRvz7S c1tmvloy46bDOhC/wZfLAoESeDbO7qee/sWNBvyL9WjoZ+ZG2KaJJSQ8h9GCu/Efi0Z1 0DNoK14iar/eaiITCWNX5l/wIzD7QJAS306mZaNihaCsq5g1UI9L5mUipW7W4Oig87dR p49x3ulfLRtM1Z+SoMmQCdsjs6JVpSBwyU3FzOpL5897eAvUWh3zqn988Vkrqkj7MuKu ceW8P80zt7R3o0BmvCmz38ZX0NwALPXYmz5i6eiFyIh8c3iDYokR99qiVk4bvsFZiCWa pHLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dOzS5sbJ; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mt17-20020a170907619100b00877da25cb31si15185281ejc.869.2023.02.13.11.45.20; Mon, 13 Feb 2023 11:45:45 -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=@linutronix.de header.s=2020 header.b=dOzS5sbJ; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjBMTld (ORCPT + 99 others); Mon, 13 Feb 2023 14:41:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbjBMTlJ (ORCPT ); Mon, 13 Feb 2023 14:41:09 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7772121A28; Mon, 13 Feb 2023 11:40:50 -0800 (PST) Date: Mon, 13 Feb 2023 19:40:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1676317249; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fwa++b7D1fwwyGb87Ce7+hKWeC+R9ZUZd4CRBGUJrrY=; b=dOzS5sbJDlIawFUV0884goJNWd61paBjjhTbUK4gXZv3+xlbi/k0x3c40dDKXrcaevbwKW 0CkhGjgHTdeECjcd4KpdIMwM4ESaAqo/ZBJybWENOGWLbc+Txqe53FSbfxX+cfH8XjHt80 mEuE9Hz/aM6n9E3F13ss6YW65SCWmK8ok1f75Rc7VVqbhKG41bP/QDGM9O3Dn1XdoekVjh dCaK9LGnyZ0brleiFVZxesQBy/58TKfewsbFKaFJ4tA1UF/QTDoQnmrYJYDplT69kpDQrX ceNLSt9Wv9R/SS8ujGs4GYryCQiHL6WIvdGXVFqI+Z8lOXkCNjh2TCBNwjAAoA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1676317249; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fwa++b7D1fwwyGb87Ce7+hKWeC+R9ZUZd4CRBGUJrrY=; b=FgcSYoK91YwqW9+d8XJwitsjZNKordbyx14yCSyp9obmP/aZXYNdnviM8fuwGpntax9lkG 1+6k3IvhKITTejDg== From: "irqchip-bot for Johan Hovold" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [irqchip: irq/irqchip-next] irqdomain: Fix association race Cc: stable@vger.kernel.org, #@tip-bot2.tec.linutronix.de, 3.11@tip-bot2.tec.linutronix.de, "Hsin-Yi Wang" , "Mark-PK Tsai" , Johan Hovold , Marc Zyngier , tglx@linutronix.de In-Reply-To: <20230213104302.17307-2-johan+linaro@kernel.org> References: <20230213104302.17307-2-johan+linaro@kernel.org> MIME-Version: 1.0 Message-ID: <167631724833.4906.11237978689410775195.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,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?1757712258653621402?= X-GMAIL-MSGID: =?utf-8?q?1757746346187336555?= The following commit has been merged into the irq/irqchip-next branch of irqchip: Commit-ID: b06730a571a9ff1ba5bd6b20bf9e50e5a12f1ec6 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/b06730a571a9ff1ba5bd6b20bf9e50e5a12f1ec6 Author: Johan Hovold AuthorDate: Mon, 13 Feb 2023 11:42:43 +01:00 Committer: Marc Zyngier CommitterDate: Mon, 13 Feb 2023 19:31:24 irqdomain: Fix association race 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 Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20230213104302.17307-2-johan+linaro@kernel.org --- 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 8fe1da9..6661de1 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,