Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp652254rdg; Thu, 10 Aug 2023 15:07:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFd22efY7/pbqJAObQCZKbCDgiRXpiMhyNI/7p07QM5G9EZTqi16oQq9c97DbJuSS5t/FX6 X-Received: by 2002:a19:7716:0:b0:4fc:3755:37d9 with SMTP id s22-20020a197716000000b004fc375537d9mr2273691lfc.68.1691705226050; Thu, 10 Aug 2023 15:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691705226; cv=none; d=google.com; s=arc-20160816; b=yggRYh4okkRK8wbgsU7kwul8mUR/wjg/23lR7sIv5V3nYcFhEoOQTxgSPc2XBcB4GY 7eCoAlMPPEv0EsQDWFSVrRKbuzju4Bft0It3hJQwK2qcWZKrDOVh5tfkTbDRsmDqwrIj zNRGLbRSJZhymD8ClZFMOBrnKznXCQ+nK4t557BjfN5Ql7Ybt3l6tIOhjIiV9hkAbk7b +8lv88v8fc3UE7daWJ3JhlfLN3zIhQVq1y6Nx3cF5hr32/2m8RQm9jC5hGT08RvlEwzh RtuQiAjhg0Ka5TLWxBbgFp83uNe5QVvEJefSfMPUGHuJimG9KEKJXyxNnkOEHTBE66i5 BpQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aa2pO0DIFfrev8B1WuRsG+91XQeI8I3P4EO7r9s5Z24=; fh=Ec3muTOsMKowk6R8FeeXr7q1QGyvuk1uuJajuzWR+6M=; b=j+LvlFtQRVXku/hrKx8liJP8AiBODZU3PP3dpVwvLsGee8Ze6bHGunwJ8Lluss9f9s quXYZjUdIBjM57pQhXid64ksGN/ezUo5qjNXZ/PwNno7BvOd5SrlvgtPx+E8oeFPwlD0 uQ5jtIL1PfwPjmKDGrL8zMqvT9+J8RPWZDL5qZOSb9UPTE3jAuUQpQO2xa3359GmRIg+ PSMhMixKBzqApGyLCRCF9qfW3bIMu+8TN8N3lQXpVf/XVnD5Dhh3mpzeh+roM9y2phA1 fBmY3iJ6EpEqE7vEZkVreg95kvKNPekHD45uk6PuhgdQlndXaArfCxEYVp/+azwgNKY/ Qsrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=VY4dcLEa; 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=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h26-20020a50ed9a000000b005230a22cfa0si2100969edr.331.2023.08.10.15.06.39; Thu, 10 Aug 2023 15:07:06 -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=@rere.qmqm.pl header.s=1 header.b=VY4dcLEa; 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=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbjHJVwY (ORCPT + 99 others); Thu, 10 Aug 2023 17:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjHJVwX (ORCPT ); Thu, 10 Aug 2023 17:52:23 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2DE0ED; Thu, 10 Aug 2023 14:52:22 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RMLHl5VHSz5P; Thu, 10 Aug 2023 23:52:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1691704340; bh=cvtkBHs2Gks5HcJOEm6XCtFkEahUxXNvZRy3lqRniJ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VY4dcLEatS5B3Uk4w6RbZRuustOgM6ZHNg6ZT1ERgi3stzMsQe38WCTEbgrsGSi0S O5DInnSNYvAS48I6TvWSrQLcKRdSQaJQhK26gTrxtusPcm50Ah8y7+br1Zts3gF/Q0 eKleh9I8/DbiDXSZj4WS0pl0pAlyo8/WdMVoPoIdHrTZxmzevWTs+UcI79aInRMiIP mGZ4dg759zYrlJfVdi56EH2DBuIS9xXji81wRna5zGjbX/hZ+EOxAoC21oWhfmNN/A 8xNOb1z/Z8i4Sl0zR7b6Ap73eeN2mQeIuBumezHdTjNoEkVhDZEh4MFo407+dUwE+U 4B/+PYGIRcX6A== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Thu, 10 Aug 2023 23:52:17 +0200 From: =?iso-8859-2?Q?Micha=B3_Miros=B3aw?= To: Krzysztof Kozlowski Cc: Svyatoslav Ryhel , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Wolfram Sang , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] i2c: Add GPIO-based hotplug gate Message-ID: References: <20230729160857.6332-1-clamor95@gmail.com> <20230729160857.6332-3-clamor95@gmail.com> <25858c22-ef92-2136-67ef-0d27364c1600@linaro.org> <249e806a-f094-9514-9c83-e74e7b1f00ba@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <249e806a-f094-9514-9c83-e74e7b1f00ba@linaro.org> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 05, 2023 at 09:17:50PM +0200, Krzysztof Kozlowski wrote: > On 01/08/2023 00:50, Micha? Miros?aw wrote: > > On Mon, Jul 31, 2023 at 02:59:41PM +0200, Krzysztof Kozlowski wrote: > >> On 31/07/2023 10:49, Micha? Miros?aw wrote: > >>> On Mon, Jul 31, 2023 at 08:58:14AM +0200, Krzysztof Kozlowski wrote: > >>>> On 30/07/2023 23:55, Micha? Miros?aw wrote: > >>>>> On Sun, Jul 30, 2023 at 10:30:56PM +0200, Krzysztof Kozlowski wrote: > >>>>>> On 29/07/2023 18:08, Svyatoslav Ryhel wrote: > >>>>>>> From: Micha? Miros?aw > >>>>>>> > >>>>>>> Implement driver for hot-plugged I2C busses, where some devices on > >>>>>>> a bus are hot-pluggable and their presence is indicated by GPIO line. > >>>>> [...] > >>>>>>> + priv->irq = platform_get_irq(pdev, 0); > >>>>>>> + if (priv->irq < 0) > >>>>>>> + return dev_err_probe(&pdev->dev, priv->irq, > >>>>>>> + "failed to get IRQ %d\n", priv->irq); > >>>>>>> + > >>>>>>> + ret = devm_request_threaded_irq(&pdev->dev, priv->irq, NULL, > >>>>>>> + i2c_hotplug_interrupt, > >>>>>>> + IRQF_ONESHOT | IRQF_SHARED, > >>>>>> > >>>>>> Shared IRQ with devm is a recipe for disaster. Are you sure this is a > >>>>>> shared one? You have a remove() function which also points that it is > >>>>>> not safe. You can: > >>>>>> 1. investigate to be sure it is 100% safe (please document why do you > >>>>>> think it is safe) [...] > >> True, therefore non-devm interrupts are recommended also in such case. > >> Maybe one of my solutions is actually not recommended. > >> > >> However if done right, driver with non-shared interrupts, is expected to > >> disable interrupts in remove(), thus there is no risk. We have big > >> discussions in the past about it, so feel free to dig through LKML to > >> read more about. Anyway shared and devm is a clear no go. > > > > Can you share pointers to some of those discussions? Quick search > > about devm_request_irq() and friends found only a thread from 2013 > > Just look at CONFIG_DEBUG_SHIRQ. Some things lore points: > https://lore.kernel.org/all/1592130544-19759-2-git-send-email-krzk@kernel.org/ > https://lore.kernel.org/all/20200616103956.GL4447@sirena.org.uk/ > > I think pretty clear: > https://lore.kernel.org/all/87mu52ca4b.fsf@nanos.tec.linutronix.de/ > https://lore.kernel.org/all/CA+h21hrxQ1fRahyQGFS42Xuop_Q2petE=No1dft4nVb-ijUu2g@mail.gmail.com/ > > Also: > https://lore.kernel.org/all/651c9a33-71e6-c042-58e2-6ad501e984cd@pengutronix.de/ > https://lore.kernel.org/all/36AC4067-78C6-4986-8B97-591F93E266D8@gmail.com/ [...] Thanks! It all looks like a proof by example [1]: a broken driver [2] was converted to devres [3] and allowed a shared interrupt [4] and now is used to back an argument that devres and/or shared IRQs are bad. I have a hard time accepting this line of reasoning. So: sure, if you disable device's clock, you should first disable the interrupt handler one way or another, and if you request a shared interrupt then you have to write the handler expecting spurious invocations anytime between entry to register_irq() and return from free_irq() (BTW, DEBUG_SHIRQ is here to help test exactly this). And, when used correctly, devres can release you from having to write remove() and error paths (but I guess it might be a challenge to find a single driver that is a complete, good and complex-enough example). Coming back from the digression: I gathered following items from the review of the i2c-hotplug-gpio driver: 1. TODO: register i2c_hotplug_deactivate(priv) using devm_add_action_or_reset() before registering the IRQ handler and remove remove(); 2. shared IRQ: it is expected to be an edge-triggered, rarely signalled interrupt and the handler will work fine if called spuriously; it is not required to be shared for my Transformer, but I can't say much about other hardware. Would a comment help? 3. TODO: DT-binding needs an expanded example and fixing some schema issues; 4. question from Andi in another thread: I'll answer shortly. Please correct me if I missed something. Best Regards Micha? Miros?aw [1] https://en.wikipedia.org/wiki/Proof_by_example [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa11e38ce6fe8846fec046a95cecd5d4690c48cd [3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9f8a3e7fd5bd08e3fd9847c04a5a445e2994f6b3 [4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=df0a2fdab0068f7452bf0a97ea9ba0ad69d49a1f