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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BBE4ECAAD3 for ; Thu, 15 Sep 2022 08:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbiIOIyi (ORCPT ); Thu, 15 Sep 2022 04:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbiIOIye (ORCPT ); Thu, 15 Sep 2022 04:54:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D150CCA for ; Thu, 15 Sep 2022 01:54:29 -0700 (PDT) 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 A3ED1621E4 for ; Thu, 15 Sep 2022 08:54:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 045A4C43470; Thu, 15 Sep 2022 08:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663232068; bh=ezS2lgaFF108n/giCRbF0oi94X5dtCC3EP8mut0wgrA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BOGmUssV5DfD20VkfAp5LmgUGPYty6ZLI3TjbfDTLo+Y6kCBgEwlKnSkivJKy4E6W PH2qmbl5dCXjV2VkfITTN+foDhIXsyjtZQM1FnT6IHojXNT9QYccnCBfH6qEn37r7q EOsXsQOPusr6NzbuSDNXMo2RLnvpe146g84zTkAGDGJ/31CM2HnH0Dx4YdZKAQthh4 W+7IiK+vPfUN/JR7M+EmvH7gU5Z4po7b16Fmpal2YGrjpnwe9Dvy8TaqCDq6xE6fVy IE7U02M0wdPdh8kaeuMcDvCbAekyyCS5h26AzuljZ1OpuopkR+xkd3rwno4eu5x0iK ZvvnNUmRyEatQ== Received: from [185.122.133.20] (helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oYkdd-00ANdj-Nf; Thu, 15 Sep 2022 09:54:25 +0100 Date: Thu, 15 Sep 2022 09:54:25 +0100 Message-ID: <87v8ppkofy.wl-maz@kernel.org> From: Marc Zyngier To: Johan Hovold Cc: Thomas Gleixner , Greg Kroah-Hartman , Rob Herring , linux-kernel@vger.kernel.org, Dmitry Torokhov , Jon Hunter Subject: Re: [PATCH v2 2/4] irqdomain: Fix mapping-creation race In-Reply-To: <20220901142816.13731-3-johan+linaro@kernel.org> References: <20220901142816.13731-1-johan+linaro@kernel.org> <20220901142816.13731-3-johan+linaro@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.122.133.20 X-SA-Exim-Rcpt-To: johan+linaro@kernel.org, tglx@linutronix.de, gregkh@linuxfoundation.org, robh@kernel.org, linux-kernel@vger.kernel.org, dtor@chromium.org, jonathanh@nvidia.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Johan, On Thu, 01 Sep 2022 15:28:14 +0100, Johan Hovold wrote: > > Parallel probing (e.g. due to asynchronous probing) of devices that share > interrupts can currently result in two mappings for the same hardware > interrupt to be created. > > Add a serialising mapping mutex so that looking for an existing mapping > before creating a new one is done atomically. > > Fixes: 765230b5f084 ("driver-core: add asynchronous probing support for drivers") > Fixes: b62b2cf5759b ("irqdomain: Fix handling of type settings for existing mappings") > Cc: Dmitry Torokhov > Cc: Jon Hunter > Link: https://lore.kernel.org/r/YuJXMHoT4ijUxnRb@hovoldconsulting.com > Signed-off-by: Johan Hovold > --- > include/linux/irqdomain.h | 2 ++ > kernel/irq/irqdomain.c | 33 ++++++++++++++++++++++++--------- > 2 files changed, 26 insertions(+), 9 deletions(-) > > diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h > index 00d577f90883..8df9b9586e29 100644 > --- a/include/linux/irqdomain.h > +++ b/include/linux/irqdomain.h > @@ -144,6 +144,7 @@ struct irq_domain_chip_generic; > * core code. > * @flags: host per irq_domain flags > * @mapcount: The number of mapped interrupts > + * @map_mutex: Mapping lock > * > * Optional elements > * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy > @@ -168,6 +169,7 @@ struct irq_domain { > void *host_data; > unsigned int flags; > unsigned int mapcount; > + struct mutex map_mutex; > > /* Optional data */ > struct fwnode_handle *fwnode; > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c > index 24ddd8d9b597..1af1d141e165 100644 > --- a/kernel/irq/irqdomain.c > +++ b/kernel/irq/irqdomain.c > @@ -215,6 +215,7 @@ struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int s > /* Fill structure */ > INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL); > mutex_init(&domain->revmap_mutex); > + mutex_init(&domain->map_mutex); > domain->ops = ops; > domain->host_data = host_data; > domain->hwirq_max = hwirq_max; > @@ -721,14 +722,20 @@ unsigned int irq_create_mapping_affinity(struct irq_domain *domain, > return 0; > } > > + mutex_lock(&domain->map_mutex); > + I must confess I have a hard time figuring out the semantic difference between map_mutex and revmap_mutex. or rather, what is the use of revmap_mutex once map_mutex is taken. They fundamentally overlap, and I have the feeling one should eventually replace the other. If anything, you should absolutely define/document how these two locks interact. Thanks, M. -- Without deviation from the norm, progress is not possible.