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 35197C433EF for ; Mon, 25 Jul 2022 23:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbiGYXx6 (ORCPT ); Mon, 25 Jul 2022 19:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbiGYXx5 (ORCPT ); Mon, 25 Jul 2022 19:53:57 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDC4D27CF0 for ; Mon, 25 Jul 2022 16:53:55 -0700 (PDT) Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 670EB838BB; Tue, 26 Jul 2022 01:53:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1658793232; bh=USg2SBlbQoh16pBWxF3vDkzgcWzi//L1aTeRgEspIOg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=jnUmTPkiFvGWNSwUQysuemtr3rkfn+/+W0Iuj5Glv6iJJ6cA3weVXMfe2oApK47Eo tN0QkrkxKW/yK28BlHpVKbf1t5Zog+apRaD1nsWHqLl1T8vxMJt7YEtXTS49mIKPpD jUkgHzGhfAg4yCJb/H7DNlzKfN3j7R4TMZXtGMZhm4McwZxiX8inBSE+Ao1/1m15LP 8DmxZEveUjS6IcpsUuY4OnAAx6aMfTvPCmqFbCh0IepNnOFlFMUTLnPeoAN1BYzC4v e17Nx/TxnUK6d6kAxOjVm/cfgfv3eUWQMluWAC9gxSEn9YombSed8zHtsqjZeGwYjN qPb5/lhGOsysA== Message-ID: <5a3addbd-505e-799c-78d2-3cd1fa8e2640@denx.de> Date: Tue, 26 Jul 2022 01:53:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v4 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock Content-Language: en-US To: Linus Walleij , Andy Shevchenko Cc: "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Loic Poulain , Marc Zyngier , NXP Linux Team , Peng Fan , Shawn Guo References: <20220724224943.294057-1-marex@denx.de> From: Marek Vasut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On 7/26/22 00:30, Linus Walleij wrote: > On Mon, Jul 25, 2022 at 10:38 PM Andy Shevchenko > wrote: >> On Mon, Jul 25, 2022 at 12:51 AM Marek Vasut wrote: >>> >>> The driver currently performs register read-modify-write without locking >>> in its irqchip part, this could lead to a race condition when configuring >>> interrupt mode setting. Add the missing bgpio spinlock lock/unlock around >>> the register read-modify-write. >> >> ... >> >>> + spin_lock_irqsave(&port->gc.bgpio_lock, flags); >> >> To my surprise, is bgpio_lock not a raw spin lock?! How is it possible >> to work on RT? > > It's a spinlock that is used both for the GPIO and irqchips, so if the > GPIO doesn't have an irqchip it works fine, as only IRQs are > problematic. > > If the registers used by the irqchip are separate from the registers > used by the GPIO access, I think it is wise to use a separate > raw spinlock to just protect the IRQ registers. > > They really only need to share a spinlock if they use the same > registers and the gpiochip and irqchip risk stepping on each > others toes. That doesn't seem to be the case here? > > Marek: could you see if the irqchip part of the driver could > use its own raw spinlock? It cannot, because of the GDIR register which is shared between the gpiochip and irqchip.