Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5017322rwb; Mon, 31 Jul 2023 16:51:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFlXtvt/qiOcaD0ZcnYGLxVTfiWyCaYsYcTzynxxKdGmk2mbj089fCjCHsR0R0STaAwj0S X-Received: by 2002:a17:907:2cd2:b0:99b:50ea:2f96 with SMTP id hg18-20020a1709072cd200b0099b50ea2f96mr1365359ejc.12.1690847484986; Mon, 31 Jul 2023 16:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690847484; cv=none; d=google.com; s=arc-20160816; b=MENIRCD59fkfCyyqriPJzozIdGSSEt8UBvQDEcNP+MrahjSudlXq8Wm1fWrZmMwlOT B4qj3Bwt8eY5tZ9PEF1gonKIr+rjd3clrRhoOlzNpP1mL0RAfgl3pdzC2GSQHs3PKo9Z eJns9g+d6qqAO/PAEdxSHGjEomqx/THaVEbUeYp3reCLaKYBguthrsrQSpIr9+y5TM3F ndoQnsSBRCbG0FCvtW1Nlv0dF9S49kf4kkB11D3Q7NDXPWbGEqFJ+EZ3tmrgRihJoqgO JFBPnMXlVtISU2+j6qjHRPwIm8MJ5+0rugQOciCJOBlxOxwm5ZOopQbCvjFtbWqdbBbQ wGUA== 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=f+AIHmE7oMcVDIaLyodBp7uGa5xny2PwR/DXm6zChdo=; fh=Ec3muTOsMKowk6R8FeeXr7q1QGyvuk1uuJajuzWR+6M=; b=aMB25jNcvX2nWDKJofh+UXdKJiZeWUzcTipVj6atBRgTlR98KsyJzI4hqm2Zey+27J Uj6IcInZIJIvW+m0bvMUfOnUeCuKA9+BcuDxc+5FQ9VLVoQd8htZDKNxynj7pr6JVA+f kBUEdUhaADuNmf4EoPR8TiY1TNRZ/bmoIq3x090HGi0xcKs6INuoHlJ0PHsEX31Dwv2X L5796R65UWBw3osXtQFg3TTPTHm3C0tDNyLO22eIpdt8tzmsh9EQBfXzuUIGfYIBt5qM cHv/WkcBl6mh2nCgKBkL2jjbTgA6lsafXumzt2koNHeq0W+23arcdzbUaiKPc8wHXQ4X hM/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=BDK7Ld3d; 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 x18-20020a1709065ad200b00988907e3aaesi7267320ejs.428.2023.07.31.16.51.01; Mon, 31 Jul 2023 16:51:24 -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=BDK7Ld3d; 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 S230424AbjGaWuU (ORCPT + 99 others); Mon, 31 Jul 2023 18:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjGaWuS (ORCPT ); Mon, 31 Jul 2023 18:50:18 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACBAC1BD9; Mon, 31 Jul 2023 15:50:08 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RFD313l6jzCY; Tue, 1 Aug 2023 00:50:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1690843805; bh=0tPOp+JS5ixYfQHrHF0O6mJvd9r7PaF0dMi6lLuDr9k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BDK7Ld3dgMmPUsyXfLAEJHARvKa6QywWLiAMVNRmjE1JQmKHTa+eu4ZBa8Kav5DtK PS1ZB4wmwnAg1H3KcLhD/sV4g5/+p+xmtMzlRyXEKRc2WcZTn1MdbWiPM41l15zEqO umVDhKyd0AApiCw8JujYem19aM31ROvCw4s1AemV0/N68LdEpS3MzkImLI9fVLIGwK cgZEi/qI/D9XomueW1b4wGiRLXyLWU8OdvtUHh81jTyI4O6aqU3OzQcPOciHyP/+YJ ilXlfw7DX5lUIcUXAjlp3gHSTtA10UqkUvibgmg/fHtUnzheYJSgqeXIgQVA1hOTh5 7Lb2WILHGddPA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Tue, 1 Aug 2023 00:50:03 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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, T_SCC_BODY_TEXT_LINE 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 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) > >>> > >>> Could you elaborate on what is unsafe in using devm with shared > >>> interrupts (as compared to non-shared or not devm-managed)? > >>> > >>> The remove function is indeed reversing the order of cleanup. The > >>> shutdown path can be fixed by removing `remove()` and adding > >>> `devm_add_action_or_reset(...deactivate)` before the IRQ is registered. > >> Shared interrupt might be triggered easily by other device between > >> remove() and irq release function (devm_free_irq() or whatever it is > >> called). > > > > This is no different tham a non-shared interrupt that can be triggered > > by the device being removed. Since devres will release the IRQ first, > > before freeing the driver data, the interrupt hander will see consistent > > driver-internal state. (The difference between remove() and devres > > release phase is that for the latter sysfs files are already removed.) > > 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 about conversions of RTC drivers to use devres. [1] IIRC the issue was then that the drivers requested IRQs before fully initializing the state (as many still do). Back to the original question: what is the risk in using devres with shared interrupts? (Let's assume the probe() is already fixed and remove() removed.) BTW, We have devres doc [2] in the kernel tree that, among other things, lists IRQs as a managed resource and mentions no warnings nor restictions for driver authors. I'd expect that if devm_request_threaded_irq() for shared iterrupts was indeed deprecated, it should be documented in a way easy to refer to. [1] https://groups.google.com/g/linux.kernel/c/yi2ueo-sNJs [2] Documentation/udriver-api/driver-model/devres.rst Best Regards Micha? Miros?aw