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 ADB9CC433EF for ; Sun, 24 Jul 2022 09:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbiGXJ2X (ORCPT ); Sun, 24 Jul 2022 05:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiGXJ2W (ORCPT ); Sun, 24 Jul 2022 05:28:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A22A813E24 for ; Sun, 24 Jul 2022 02:28:21 -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 36CD061008 for ; Sun, 24 Jul 2022 09:28:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97A83C3411E; Sun, 24 Jul 2022 09:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658654900; bh=NDzBsW9ur+CcGwAVly55VGLogeTqqif58aQnV0nszwM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WA4fIn4I0yzTiPq66Cgc/4xZz1QZv0c9VFbkxwHyS/fmNhF+G+4Q6/RTl94t4+7F4 Kf1e63Wyzt09jHplA53IbebDhRH3GQXbXkg6czcjcu6q15ztyAEMZbNyWArllXsVbN oyNefDcfwjaivkWujhgeTR7P4ZDhCAiTySpl+AGcdTNiNM0ZcRDfSyxAXBHD/ikWPD 0+pYbM5br5AjWGhVFCMIFBtxXb3i0ozJ1y030gEOfsmu0MrdGnLnZA0fXtbbPW3gXz 6FSaCJHMUom4XtWNBmA4fjm6Q8smU4HyIVCrPjRSuKOTA2YURqhgqMZ9yX7opPf/km kemrNxWdAJyeg== Received: from sofa.misterjones.org ([185.219.108.64] 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 1oFXuM-009f6W-Ah; Sun, 24 Jul 2022 10:28:18 +0100 Date: Sun, 24 Jul 2022 10:28:14 +0100 Message-ID: <878roidfm9.wl-maz@kernel.org> From: Marc Zyngier To: Marek Vasut Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski , Linus Walleij , Loic Poulain Subject: Re: [PATCH v2] gpio: mxc: Always set GPIOs used as interrupt source to INPUT mode In-Reply-To: <20220724023418.441899-1-marex@denx.de> References: <20220724023418.441899-1-marex@denx.de> 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.219.108.64 X-SA-Exim-Rcpt-To: marex@denx.de, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org, loic.poulain@linaro.org 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-gpio@vger.kernel.org On Sun, 24 Jul 2022 03:34:18 +0100, Marek Vasut wrote: > > Always configure GPIO pins which are used as interrupt source as INPUTs. > In case the default pin configuration is OUTPUT, or the prior stage does > configure the pins as OUTPUT, then Linux will not reconfigure the pin as > INPUT and no interrupts are received. > > Always configure interrupt source GPIO pin as input to fix the above case. > > Signed-off-by: Marek Vasut > Cc: Bartosz Golaszewski > Cc: Linus Walleij > Cc: Loic Poulain > Cc: Marc Zyngier > --- > V2: Actually update and clear bits in GDIR register > --- > drivers/gpio/gpio-mxc.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c > index c871602fc5ba9..ed58441627d92 100644 > --- a/drivers/gpio/gpio-mxc.c > +++ b/drivers/gpio/gpio-mxc.c > @@ -147,7 +147,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type) > { > struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); > struct mxc_gpio_port *port = gc->private; > - u32 bit, val; > + u32 bit, val, dir; > u32 gpio_idx = d->hwirq; > int edge; > void __iomem *reg = port->base; > @@ -204,6 +204,10 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type) > > writel(1 << gpio_idx, port->base + GPIO_ISR); > > + dir = readl(port->base + GPIO_GDIR); > + dir &= ~BIT(gpio_idx); > + writel(dir, port->base + GPIO_GDIR); > + This is obviously extremely racy, as another CPU could be doing the same thing in parallel for a line that shares the same register. Looking at the driver, it is clear that it was all written at a time when SMP was only a pretty distant concern (i.e. the authors never considered it a possibility). I'd be fine with it if there was no SMP platform using this, but there is at least one (imx7d). So please fix this first (placing all RMW sequences behind a lock), and only then add this change. Thanks, M. -- Without deviation from the norm, progress is not possible.