Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2085440ybj; Sun, 22 Sep 2019 19:28:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJN1wsN8ia7rW7iJA0dBFP8k4Y7NfYkrtT23zb7W4Ji2sxefJsXome/wYONi+x0XZ9D5MK X-Received: by 2002:a05:6402:7c1:: with SMTP id u1mr20279796edy.198.1569205726479; Sun, 22 Sep 2019 19:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569205726; cv=none; d=google.com; s=arc-20160816; b=tNW+xzEv+vNSmuW4YiDihAbcqHG72MlAnRqTA84/W9B0KOAf8lAF5/RxTtasjFawo6 aGPf60FDKfL7VLQqB4S627VEOigY1FfMwabvaBdQ3oXgZd8qmFegCOqA6fowTTdCXm2c 4ogtz71u9KOp6qHY56GLyJ9gWvGCluuRdCJUqGeZ18PI7KVkodQIgytawjLgnV0p15nm kfqIUfPyGj24sA7g4e+jNSNdqgchK2YFKIyKXlWgS+Z3KWgbg3pu4KiFhyUbNVURpx+g v65JEiL6gd4EwZqety+S9rlymzeqez1s5D/OgQnrQLEWz3PW2LjeloI4xahIc1hQJkjN pWYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=V8h1lZedd4G0t65QA+YCGJdjgd4Dwgm0+ylZenKQhgU=; b=0r9yQS7T3iXt9GLz4CTZKNx7lQQ/T7KRlq0DPyCvWcg/6WvsouQuxFpkdPiP0++ZfW Ota42HQlpB3czOmMGlgUNELs0qhrBRdQSPZF4rR7Uij0o0iW/S4aUpc4A/hkXRM1F14t GVN3B17AfqSkZ2ol8rGEDMDf35eHPFYzNXaQm0z8Pkchc/siO69VVOY5megLQJwig1pj RxhIRQZo9I5oVfHwWeQnSJ0K9yRdeaK8E8F7y1iAJ8+jngWg2LxCNp4geTRfGsCOSYYr KTWhUbBfUmoBdFWJqPOIgrpZDXJtMkQdkpccBYyD1PondJ84nXk9z+IIiIV2h7sNE5Kp vp+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w14si4102425ejv.112.2019.09.22.19.28.23; Sun, 22 Sep 2019 19:28:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404137AbfITPht (ORCPT + 99 others); Fri, 20 Sep 2019 11:37:49 -0400 Received: from foss.arm.com ([217.140.110.172]:46486 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404128AbfITPhs (ORCPT ); Fri, 20 Sep 2019 11:37:48 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EDA7C337; Fri, 20 Sep 2019 08:37:47 -0700 (PDT) Received: from [10.1.197.61] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CDB743F575; Fri, 20 Sep 2019 08:37:46 -0700 (PDT) Subject: Re: [PATCH 1/3] genirq/irqdomain: Check for existing mapping in irq_domain_associate() To: "Sverdlin, Alexander (Nokia - DE/Ulm)" , Thomas Gleixner , "linux-kernel@vger.kernel.org" , Grant Likely Cc: Mark Brown , Jon Hunter , "Glavinic-Pecotic, Matija (EXT - DE/Ulm)" , "Adamski, Krzysztof (Nokia - PL/Wroclaw)" , "stable@vger.kernel.org" References: <20190912094343.5480-1-alexander.sverdlin@nokia.com> <20190912094343.5480-2-alexander.sverdlin@nokia.com> From: Marc Zyngier Organization: Approximate Message-ID: <3f12b315-b7bf-e0c3-7105-4c9c9536f52f@kernel.org> Date: Fri, 20 Sep 2019 16:37:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20190912094343.5480-2-alexander.sverdlin@nokia.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/09/2019 10:44, Sverdlin, Alexander (Nokia - DE/Ulm) wrote: > From: Alexander Sverdlin > > irq_domain_associate() is the only place where irq_find_mapping() can be > used reliably (under irq_domain_mutex) to make a decision if the mapping > shall be created or not. Other calls to irq_find_mapping() (not under > any lock) cannot be used for this purpose and lead to race conditions in > particular inside irq_create_mapping(). > > Give the callers of irq_domain_associate() an ability to detect existing > domain reliably by examining the return value. > > Cc: stable@vger.kernel.org > Signed-off-by: Alexander Sverdlin > --- > kernel/irq/irqdomain.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c > index 3078d0e..7bc07b6 100644 > --- a/kernel/irq/irqdomain.c > +++ b/kernel/irq/irqdomain.c > @@ -532,6 +532,7 @@ 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); > + unsigned int eirq; > int ret; > > if (WARN(hwirq >= domain->hwirq_max, > @@ -543,6 +544,16 @@ int irq_domain_associate(struct irq_domain *domain, unsigned int virq, > return -EINVAL; > > mutex_lock(&irq_domain_mutex); > + > + /* Check if mapping already exists */ > + eirq = irq_find_mapping(domain, hwirq); > + if (eirq) { nit: Just have if (irq_find_mapping(...)) { and get rid the extra variable, given that it's not used for anything. > + mutex_unlock(&irq_domain_mutex); > + pr_debug("%s: conflicting mapping for hwirq 0x%x\n", > + domain->name, (int)hwirq); > + return -EBUSY; I'm overall OK with this, although I'd rather we return -EEXIST rather than -EBUSY. > + } > + > irq_data->hwirq = hwirq; > irq_data->domain = domain; > if (domain->ops->map) { > Thanks, M. -- Jazz is not dead, it just smells funny...