Message ID | 20230510001151.3946931-1-chris.packham@alliedtelesis.co.nz |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3283782vqo; Tue, 9 May 2023 18:07:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tSFEMAHC7R8Q2l1gO8sYho7XJ79PCew3Lt2vwyfk8jhzCQVW1yVKIxWhO/pT/7lKoqptG X-Received: by 2002:a05:6a20:3d92:b0:101:a3ec:889b with SMTP id s18-20020a056a203d9200b00101a3ec889bmr2698092pzi.49.1683680876412; Tue, 09 May 2023 18:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683680876; cv=none; d=google.com; s=arc-20160816; b=RPNxzkiMJUox7WTVmYJv0PPymsMLXe72Kgb9r9ev+D+1cuANnMu6M1e2idbAFbCqSD mwGxQk/BWNigw+9wKAT4AVD2h+CipbTlVIlyXlo+c1c6bSm3yYxc6fevP5OZprN1xCip IfNo/Lri73BbM9K8XS5StwpDcdnO0GeaLTa0Mofm6tEzeOt1gkLAJYfVSfLpmwUarNtb OPBQ4TjLGhdPeAqeHF7vpQkkbRA+pltwMQ0/tuyjyrvGjcPk2EqKRgOT+/lciqIb8RQw I50MO0ACsfUUwbEELHK9TSkVpJilfv+tAi1u25QfEFLBIqxIiutqHAmQiWOa23THvhJz JAZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/ksLABzUrIZWsJWJmdsPhQq0uvIaq/7K5AgQ+TMphdE=; b=o/PddmqjfOW2qxL93bSmLgHe8Ve22+un6NiRkjlRF+oLobkJ24GfDgI7bhV7WIycmF ZjuyITcU3KKpl/n9twaZOuUzkX9VZ+7hPiXl61qskFFTGuNH8ku84kUTlOfrkZdVHryt nWoe6hF4fpDcjfTL4agGKsHoVgXyU5fhIWLY/3p9NzDotVaNUJuBGkstHVfQ+rCYtRQe dIA9z/I2dFLP0PqxHBb6UesZlkuXNZRDO7IfJMO9tYufRdORKZ3BREE0gjn86+z7LtMc 8Lb3ma3OgQxuNtIueb6Exako+vPV5YY2xUDlNX25c7CZF7sBjYFEjrV/bW2kDnJaSWpK 8tNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=DrtO7nnl; 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=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020aa79605000000b00644c36e2079si3646257pfg.92.2023.05.09.18.07.42; Tue, 09 May 2023 18:07:56 -0700 (PDT) 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=@alliedtelesis.co.nz header.s=mail181024 header.b=DrtO7nnl; 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=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235162AbjEJAMM (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Tue, 9 May 2023 20:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235140AbjEJAMK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 9 May 2023 20:12:10 -0400 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [IPv6:2001:df5:b000:5::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 576D91BEF for <linux-kernel@vger.kernel.org>; Tue, 9 May 2023 17:12:05 -0700 (PDT) Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 73C0C2C053F; Wed, 10 May 2023 12:12:02 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1683677522; bh=/ksLABzUrIZWsJWJmdsPhQq0uvIaq/7K5AgQ+TMphdE=; h=From:To:Cc:Subject:Date:From; b=DrtO7nnlyuEHL2jVK7UHNqCuW6RYCdHum1WIaThD8BrVlDPTgqbtqi0Qd0vVx1PBf AYK6upxAJvyK5SF0BLflq8kwrCo5S9NlCcKvr33hvrzuIyTZhcA4zO22tg3ERIjxvb JcHDIvpQRVTtgbxKRkOh+A7jRaa59b2FP+2+yKyoHwv4pnrAWW5wwkrRWhcD1WaFIx SPFqzrGCOx4gIYGJNMeipZYeAWCoHY8HrC5WRRShOypWFIp6Orfa/QLqlsSee5zibu g/SXCJ6qqf3vpod+5UiNjiZMpVKLr4YLEB8YFyjPMrbHJF5bMhGD+9RCYmuuWuVnLG hgJ4OU0p9QV2g== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id <B645ae1520000>; Wed, 10 May 2023 12:12:02 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 4EDFF13EE32; Wed, 10 May 2023 12:12:02 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 48E062840D6; Wed, 10 May 2023 12:12:02 +1200 (NZST) From: Chris Packham <chris.packham@alliedtelesis.co.nz> To: linus.walleij@linaro.org, brgl@bgdev.pl, mkshah@codeaurora.org, Ben Brown <ben.brown@alliedtelesis.co.nz> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham <chris.packham@alliedtelesis.co.nz> Subject: [PATCH] gpiolib: Don't implicitly disable irq when masking Date: Wed, 10 May 2023 12:11:51 +1200 Message-Id: <20230510001151.3946931-1-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SEG-SpamProfiler-Analysis: v=2.3 cv=VfuJw2h9 c=1 sm=1 tr=0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=P0xRbXHiH_UA:10 a=nMxpP1W9oJYa0-x6mvsA:9 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765467358340837492?= X-GMAIL-MSGID: =?utf-8?q?1765467358340837492?= |
Series |
gpiolib: Don't implicitly disable irq when masking
|
|
Commit Message
Chris Packham
May 10, 2023, 12:11 a.m. UTC
When preparing to kexec into a new kernel the kexec code will mask all
interrupts for all interrupt domains before disabling them. In the case
of a gpio chip which has a mix of gpio and irq pins a warning would be
triggered as follows
[root@localhost ~]# echo c >/proc/sysrq-trigger
[ 175.677728] sysrq: Trigger a crash
<snip expected dump from SysRq>
[ 175.803409] WARNING: CPU: 1 PID: 2345 at drivers/gpio/gpiolib.c:3284 gpiochip_disable_irq+0x68/0xac
[ 175.918321] CPU: 1 PID: 2345 Comm: sh Kdump: loaded Tainted: G O 5.15.109+ #5
[ 175.926742] Hardware name: Allied Telesis x240-26GHXm (DT)
[ 175.932216] pstate: 804000c9 (Nzcv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 175.939165] pc : gpiochip_disable_irq+0x68/0xac
[ 175.943686] lr : gpiochip_disable_irq+0x58/0xac
[ 175.948208] sp : ffff80000c03ba00
[ 175.951513] x29: ffff80000c03ba00 x28: ffff00002843c4c0 x27: 0000000000000000
[ 175.958638] x26: 0000000000000000 x25: ffff800008df0790 x24: 0000000000000000
[ 175.965763] x23: ffff8000095397f0 x22: ffff800009485178 x21: ffff000016ea38f0
[ 175.972888] x20: ffff000016ea3a20 x19: ffff000016073cc0 x18: ffffffffffffffff
[ 175.980012] x17: 20204f2020202020 x16: 2020202020204720 x15: ffff80008c03b667
[ 175.987136] x14: 0000000000000000 x13: ffff800009415148 x12: 0000000000000555
[ 175.994260] x11: 00000000000001c7 x10: ffff800009415148 x9 : ffff800009415148
[ 176.001385] x8 : 00000000ffffefff x7 : ffff80000946d148 x6 : ffff80000946d148
[ 176.008510] x5 : ffff00003fdc59a0 x4 : 0000000000000000 x3 : 0000000000000000
[ 176.015634] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000007
[ 176.022757] Call trace:
[ 176.025197] gpiochip_disable_irq+0x68/0xac
[ 176.029373] gpiochip_irq_mask+0x30/0x40
[ 176.033289] machine_crash_shutdown+0xb4/0x11c
[ 176.037727] __crash_kexec+0x88/0x16c
[ 176.041384] panic+0x194/0x348
[ 176.044433] sysrq_reset_seq_param_set+0x0/0x90
[ 176.048954] __handle_sysrq+0x8c/0x1a0
[ 176.052695] write_sysrq_trigger+0x88/0xc0
[ 176.056783] proc_reg_write+0xa8/0x100
[ 176.060527] vfs_write+0xf0/0x290
[ 176.063835] ksys_write+0x68/0xf4
[ 176.067144] __arm64_sys_write+0x1c/0x2c
[ 176.071058] invoke_syscall+0x48/0x114
[ 176.074800] el0_svc_common.constprop.0+0x44/0xfc
[ 176.079495] do_el0_svc+0x28/0xa0
[ 176.082803] el0_svc+0x28/0x80
[ 176.085851] el0t_64_sync_handler+0xa4/0x130
[ 176.090112] el0t_64_sync+0x1a0/0x1a4
[ 176.093768] ---[ end trace 486d53a4eb15ab42 ]---
<more warnings for each gpio pin that is not used as an interrupt>
This is because gpiochip_irq_mask was being used to mask all possible
irqs in the domain but gpiochip_disable_irq will WARN if any of those
gpios haven't been requested as interrupts yet. Remove the call to
gpiochip_disable_irq to stop the warning.
Fixes: a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable")
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/gpio/gpiolib.c | 1 -
1 file changed, 1 deletion(-)
Comments
Wed, May 10, 2023 at 12:11:51PM +1200, Chris Packham kirjoitti: > When preparing to kexec into a new kernel the kexec code will mask all > interrupts for all interrupt domains before disabling them. In the case > of a gpio chip which has a mix of gpio and irq pins a warning would be > triggered as follows > [root@localhost ~]# echo c >/proc/sysrq-trigger Besides the very noisy traceback in the commit message (read https://kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages) see below. > This is because gpiochip_irq_mask was being used to mask all possible We refer to the functions in the form as follows gpiochip_irq_mask(). > irqs in the domain but gpiochip_disable_irq will WARN if any of those IRQs gpiochip_disable_irq() > gpios haven't been requested as interrupts yet. Remove the call to GPIOs > gpiochip_disable_irq to stop the warning. gpiochip_disable_irq() > Fixes: a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable") > Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> > --- > drivers/gpio/gpiolib.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 8c041a8dd9d8..903f5185ae55 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -1451,7 +1451,6 @@ static void gpiochip_irq_mask(struct irq_data *d) > > if (gc->irq.irq_mask) > gc->irq.irq_mask(d); > - gpiochip_disable_irq(gc, d->hwirq); > } At the same time the gpiochip_irq_unmask() has the symmetrical call. Why? Also it's obvious that you have used outdated repository. You need to rebase against subsystem tree for-next branch. P.S. It's also makes sense to Cc to Marc Zyngier <maz@kernel.org>.
Hi Andy, On 10/05/23 19:42, andy.shevchenko@gmail.com wrote: > Wed, May 10, 2023 at 12:11:51PM +1200, Chris Packham kirjoitti: >> When preparing to kexec into a new kernel the kexec code will mask all >> interrupts for all interrupt domains before disabling them. In the case >> of a gpio chip which has a mix of gpio and irq pins a warning would be >> triggered as follows >> [root@localhost ~]# echo c >/proc/sysrq-trigger > Besides the very noisy traceback in the commit message (read > https://kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages) > see below. > >> This is because gpiochip_irq_mask was being used to mask all possible > We refer to the functions in the form as follows gpiochip_irq_mask(). > > >> irqs in the domain but gpiochip_disable_irq will WARN if any of those > IRQs > gpiochip_disable_irq() > >> gpios haven't been requested as interrupts yet. Remove the call to > GPIOs > >> gpiochip_disable_irq to stop the warning. > gpiochip_disable_irq() Will take the above points onboard for v2. > >> Fixes: a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable") >> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> >> --- >> drivers/gpio/gpiolib.c | 1 - >> 1 file changed, 1 deletion(-) >> >> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c >> index 8c041a8dd9d8..903f5185ae55 100644 >> --- a/drivers/gpio/gpiolib.c >> +++ b/drivers/gpio/gpiolib.c >> @@ -1451,7 +1451,6 @@ static void gpiochip_irq_mask(struct irq_data *d) >> >> if (gc->irq.irq_mask) >> gc->irq.irq_mask(d); >> - gpiochip_disable_irq(gc, d->hwirq); >> } > At the same time the gpiochip_irq_unmask() has the symmetrical call. Why? Hmm you're right I never noticed that. I think that would also trigger a similar warning if it were ever hit. It's not hit in my use-case because nothing is running through all the irq domains unmasking interrupts. The coupling of gpiochip_irq_mask()/gpiochip_irq_unmask() with gpiochip_disable_irq()/gpiochip_enable_irq() goes back to the same commit a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable"). It's not immediately obvious to me why the coupling is needed. I was hoping that someone seeing my patch would confirm that it's not needed or say why it's needed suggest an alternative approach. > Also it's obvious that you have used outdated repository. You need to rebase > against subsystem tree for-next branch. Yeah that's the tricky part. I'm currently based on lts-5.15 and in order to actually test this I need all of the support for my platform so I can use kdump to demonstrate the issue. I might be able to use a different platform that is already supported in a newer kernel > > P.S. It's also makes sense to Cc to Marc Zyngier <maz@kernel.org>. > Added.
On Wed, May 10, 2023 at 10:59 PM Chris Packham <Chris.Packham@alliedtelesis.co.nz> wrote: > The coupling of gpiochip_irq_mask()/gpiochip_irq_unmask() with > gpiochip_disable_irq()/gpiochip_enable_irq() goes back to the same > commit a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable"). > It's not immediately obvious to me why the coupling is needed. That is just a refactoring of what existed before. The use case is here: drivers/media/cec/platform/cec-gpio/cec-gpio.c The driver needs to switch, at runtime, between actively driving a GPIO line with gpiod_set_value(), and setting the same line into input mode and listening for signalling triggering IRQs on it, and then back to output mode and driving the line again. It's a bidirectional GPIO line. This use case yields a high need of control. > I was > hoping that someone seeing my patch would confirm that it's not needed > or say why it's needed suggest an alternative approach. Which IRQ-enabled gpiochip is this? Has it been converted to be immutable? I think that could be part of the problem. Yours, Linus Walleij
Hi Linus, On 11/05/23 20:00, Linus Walleij wrote: > On Wed, May 10, 2023 at 10:59 PM Chris Packham > <Chris.Packham@alliedtelesis.co.nz> wrote: > >> The coupling of gpiochip_irq_mask()/gpiochip_irq_unmask() with >> gpiochip_disable_irq()/gpiochip_enable_irq() goes back to the same >> commit a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable"). >> It's not immediately obvious to me why the coupling is needed. > That is just a refactoring of what existed before. > > The use case is here: > drivers/media/cec/platform/cec-gpio/cec-gpio.c > > The driver needs to switch, at runtime, between actively driving a GPIO > line with gpiod_set_value(), and setting the same line into input mode > and listening for signalling triggering IRQs on it, and then back to > output mode and driving the line again. It's a bidirectional GPIO line. > This use case yields a high need of control. > >> I was >> hoping that someone seeing my patch would confirm that it's not needed >> or say why it's needed suggest an alternative approach. > Which IRQ-enabled gpiochip is this? Has it been converted to be immutable? > I think that could be part of the problem. For me it's a pca9555. I spent yesterday trying to demonstrate the problem on a newer kernel. Some teething issues aside I can trigger the warning if I have a gpio-button using one of the pca9555 pins as an interrupt and then I export some of the other pins via sysfs. Interestingly the warning isn't triggered if I use a gpio-hog instead of exporting the pins. I haven't figured out why that is but I'm assuming it's something to do with the hogged pins being excluded from the irq domain before it is registered.
On Thu, May 11, 2023 at 10:36 PM Chris Packham <Chris.Packham@alliedtelesis.co.nz> wrote: > I spent yesterday trying to demonstrate the > problem on a newer kernel. Some teething issues aside I can trigger the > warning if I have a gpio-button using one of the pca9555 pins as an > interrupt and then I export some of the other pins via sysfs. > > Interestingly the warning isn't triggered if I use a gpio-hog instead of > exporting the pins. What happens if you use the gpio character device instead of sysfs? Like for example with the tools in tools/gpio or using libgpiod example tools? > I haven't figured out why that is but I'm assuming > it's something to do with the hogged pins being excluded from the irq > domain before it is registered. If you write something to the "edge" file I can easily see things going sidewise. The sysfs is really not a nice tool, which is why it is deprecated. Yours, Linus Walleij
On 12/05/23 08:36, Chris Packham wrote: > Hi Linus, > > On 11/05/23 20:00, Linus Walleij wrote: >> On Wed, May 10, 2023 at 10:59 PM Chris Packham >> <Chris.Packham@alliedtelesis.co.nz> wrote: >> >>> The coupling of gpiochip_irq_mask()/gpiochip_irq_unmask() with >>> gpiochip_disable_irq()/gpiochip_enable_irq() goes back to the same >>> commit a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable"). >>> It's not immediately obvious to me why the coupling is needed. >> That is just a refactoring of what existed before. >> >> The use case is here: >> drivers/media/cec/platform/cec-gpio/cec-gpio.c >> >> The driver needs to switch, at runtime, between actively driving a GPIO >> line with gpiod_set_value(), and setting the same line into input mode >> and listening for signalling triggering IRQs on it, and then back to >> output mode and driving the line again. It's a bidirectional GPIO line. >> This use case yields a high need of control. >> >>> I was >>> hoping that someone seeing my patch would confirm that it's not needed >>> or say why it's needed suggest an alternative approach. >> Which IRQ-enabled gpiochip is this? Has it been converted to be >> immutable? >> I think that could be part of the problem. > > For me it's a pca9555. I spent yesterday trying to demonstrate the > problem on a newer kernel. Some teething issues aside I can trigger > the warning if I have a gpio-button using one of the pca9555 pins as > an interrupt and then I export some of the other pins via sysfs. > > Interestingly the warning isn't triggered if I use a gpio-hog instead > of exporting the pins. I haven't figured out why that is but I'm > assuming it's something to do with the hogged pins being excluded from > the irq domain before it is registered. I'm starting to understand things. When the gpio is exported to userland the irq_desc is created via device_add()/gpio_is_visible()/gpiod_to_irq()/gpiochip_to_irq(). I think that might be a bug because if the user wanted an interrupt they would have said so via edge_store() which also does the gpiod_to_irq() that ultimately creates the irq_desc. Having the gpio turned into an interrupt seems like an odd side-effect of gpio_is_visible().
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 8c041a8dd9d8..903f5185ae55 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1451,7 +1451,6 @@ static void gpiochip_irq_mask(struct irq_data *d) if (gc->irq.irq_mask) gc->irq.irq_mask(d); - gpiochip_disable_irq(gc, d->hwirq); } static void gpiochip_irq_unmask(struct irq_data *d)