Received: by 10.192.165.148 with SMTP id m20csp5156763imm; Tue, 8 May 2018 23:44:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqVlkA5ZLKnXkxg7xMC/FtvKBpNs48SxTMPi7zEcEvLRRa6HhoCTP7+VzlbnfurX2+FtN+5 X-Received: by 2002:a65:6645:: with SMTP id z5-v6mr31314408pgv.43.1525848245386; Tue, 08 May 2018 23:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525848245; cv=none; d=google.com; s=arc-20160816; b=Hcrs67cqxTKbp11sSSaDJqpApSWQr/w0Ud4R3A2y43Y6zSH7vJMBnp0EAJYVZtmS8D hNGwJQcgPnnlrzP1rgavDhB52CF1puTGEi15nfVWqZpSY03oie3MYaasejTF35zwsj7L sWvGbTffC6kQDJnosU3IO8smM7iUIp67O8sBlZXv6L1iSSpgowqzZ4ZNKlRpmFFp4v3f 5Rn8eskKuNSdtnj6MMagAkgRjOzS2FJ+4WewCL42ulCPrgjJ2U+7/n+Vud8SJ/NbGFXz zenPUlukgf5HR0qIrb6aFDdwfEGAYcApq1VCzyK/38UKTq11s6uh/O0gtPHvXLxTZenS lBmA== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id:arc-authentication-results; bh=lgzGOudMp0MeNsHRsafqa88ARfB3Hw94/jg3f5TPBFU=; b=MLKXcs9pd5hESn+oSdHuAyg3VMkix+bQNdl/n9mVVtQJkBTEQUy4arRgE2RH6hIYZB 0jjQMgpV5cceCH7wNbbW9uYjqqwyzk+DJYj+OBN7yZHFDYPo9fJ4Qn0ANYaWhr6hjH4s RUFT5326yBM+O/Jfgnjsr5nh0cj2O5MLs/+FxnthPXwQ0inG3DCL9cY/MVAuFX9Jz59r T+o9rLb6CopqOlgP178Zp36OqhSR/4uQd1eru2g6F3oTbWcOkXk1F7NYGLFsWMsE/yfj /8SiPrHlue7YBFTCB8ta6pOywkn+lMFurpspBZN0cPee6fR4P5idsYYTQlLJhWgBR362 VKhQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bh5-v6si5645989plb.320.2018.05.08.23.43.50; Tue, 08 May 2018 23:44:05 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755694AbeEIGnM (ORCPT + 99 others); Wed, 9 May 2018 02:43:12 -0400 Received: from regular1.263xmail.com ([211.150.99.137]:56793 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751321AbeEIGnK (ORCPT ); Wed, 9 May 2018 02:43:10 -0400 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.12]) by regular1.263xmail.com (Postfix) with ESMTP id 3EE20DC50; Wed, 9 May 2018 14:42:58 +0800 (CST) X-263anti-spam: KSV:0;BIG:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ADDR-CHECKED4: 1 X-ABS-CHECKED: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from [172.16.22.179] (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id EEAA1308; Wed, 9 May 2018 14:42:07 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: dianders@chromium.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <4b4898535c909a6839f3e8707e269212> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from [172.16.22.179] (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 22366MJUAFI; Wed, 09 May 2018 14:42:55 +0800 (CST) Message-ID: <5AF29818.2010705@rock-chips.com> Date: Wed, 09 May 2018 14:41:28 +0800 From: JeffyChen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20130126 Thunderbird/19.0 MIME-Version: 1.0 To: Doug Anderson CC: Brian Norris , LKML , =?UTF-8?B?SGVpa28gU3TDvGJuZXI=?= , "open list:ARM/Rockchip SoC..." , Linus Walleij , linux-gpio@vger.kernel.org, Linux ARM Subject: Re: [RESEND PATCH] pinctrl: rockchip: Disable interrupt when changing it's capability References: <20180503065553.7762-1-jeffy.chen@rock-chips.com> <20180507221511.GA6448@rodete-desktop-imager.corp.google.com> <5AF0FF18.1050905@rock-chips.com> <20180508015623.GA61455@rodete-desktop-imager.corp.google.com> <5AF25B2E.8080901@rock-chips.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Doug, Thanks for your reply :) On 05/09/2018 01:18 PM, Doug Anderson wrote: >> > >> > >> >right, so we now have 2 cases: rockchip_irq_demux/ rockchip_irq_set_type >> > >> >if i'm right about the spurious irq(only happen when set rising for a high >> >gpio, or set falling for a low gpio), then: >> > >> >1/ rockchip_irq_demux >> >it's important to not losing irqs in this case, maybe we can >> > >> >a) ack irq >> >b) update polarity for edge both irq >> > >> >we don't need to disable irq in b), since we would not hit the spurious irq >> >cases here(always check gpio level to toggle it) > Unless you have some sort of proof that rockchip_irq_demux(), I would > take it as an example of something that works. I remember stress > testing the heck out of it. Do you have some evidence that it's not > working? I think Brian was simply speculating that there might be a > race here, but I don't think anyone has shown it have they? Looking > back at my notes, the thing I really made sure to stress was that we > never got into a situation where we were losing an edge (AKA we were > never configured to look for a falling edge when the line was already > low). I'm not sure I confirmed that we never got an extra interrupt. > > I'm at home right now and I can't add prints and poke at things, but > as I understand it for edge interrupts the usual flow to make sure > interrupts aren't ever lost is: > > 1. See that the interrupt went off > 2. Ack it (clear it) > 3. Call the interrupt handler > > ...presumably in this case rockchip_irq_demux() is called after step > #2 (but I don't know if it's called before or after step #3). If the > line is toggling like crazy while the 3 steps are going on, it's OK if > the interrupt handler is called more than once. In general this could > be considered expected. That's why you Ack before handling--any extra > edges that come in any time after the interrupt handler starts (even > after the very first instruction) need to cause the interrupt handler > to get called again. > > This is different than Brian's understanding since he seemed to think > the Ack was happening later. If you're in front of something where > you can add printouts, maybe you can tell us. I tried to look through > the code and it was too twisted for me to be sure. i think the current edge both irq flow for rk3399 would be: gic_handle_irq //irq-gic-v3.c handle_domain_irq rockchip_irq_demux //pinctrl-rockchip.c toggle polarity generic_handle_irq handle_edge_irq //kernel/irq irq_ack handle_irq_event action->handler so i think the race might actually exist (maybe we can add some delay after toggle polarity to confirm) BTW, checking other drivers, there're quite a few using this kind of toggle edge for edge both, and they go different ways: 1/ toggle it in ack(): mediatek/pinctrl-mtk-common.c gpio-ingenic.c gpio-ep93xx.c 2/ toggle it before handle_irq: pinctrl-rockchip.c pinctrl-armada-37xx.c gpio-ath79.c gpio-mxs.c gpio-omap.c gpio-mvebu.c 3/ toggle it after handle_irq: gpio-dwapb.c gpio-pmic-eic-sprd.c would it make sense to support this kind of emulate edge both irq in some core codes? > > >> >2/ rockchip_irq_set_type >> >it's important to not having spurious irqs >> > >> >so we can disable irq during changing polarity only in these case: >> >((rising && gpio is heigh) || (falling && gpio is low)) >> > >> >i'm still confirming the spurious irq with IC guys. > Hmmm, thinking about all this more, I'm curious how callers expect > this to work. Certainly things are undefined if you have the > following situation: > > Start: rising edge trigger, line is actually high > Request: change to falling edge trigger > Line falls during the request > > In that case it's OK to throw the interrupt away because it can be > argued that the line could have fallen before the request actually > took place. ...but it seems like there could be situations where the > user wouldn't expect interrupts to be thrown away by a call to > irq_set_type(). In other words: > > Start: rising edge trigger, line is actually high > Request: change to falling edge trigger > Line falls, rises, and falls during the request > > ...in that case you'd expect that some sort of interrupt would have > gone off and not be thrown away. No matter what instant in time the > request actually took place it should have caught an edge, right? > > > Said another way: As a client of irq_set_type() I'd expect it to not > throw away interrupts, but I'd expect that the change in type would be > atomic. That is: if the interrupt came in before the type change in > type applied then it should trigger with the old rules. If the > interrupt came in after the type change then it should trigger with > the new rules. > > > I would be tempted to confirm your testing and just clear the spurious > interrupts that you're aware of. AKA: if there's no interrupt pending > and you change the type to "IRQ_TYPE_EDGE_RISING" or > "IRQ_TYPE_EDGE_FALLING" then you should clear the interrupt. It's > still racy, but I guess it's the best you can do unless IC guys come > up with something better. > hmmm, right, clear the spurious irq seems to be a better way, will try to do it in the next version. > > > Anyway, it's past my bedtime. Hopefully some of the above made sense. > I'm sure you'll tell me if it didn't or if I said something > stupid/wrong.:-P > > -Doug > > >