Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp1382455rwb; Sat, 5 Aug 2023 13:49:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDH9t+qKsrNL0fA5QllLG913twh0q0HWjiutaJPL4uwTmGRJ4LLZYAGgET/7dtJ4apSgpg X-Received: by 2002:a17:906:1c7:b0:99b:eca2:47a8 with SMTP id 7-20020a17090601c700b0099beca247a8mr4686355ejj.38.1691268573154; Sat, 05 Aug 2023 13:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691268573; cv=none; d=google.com; s=arc-20160816; b=0us62Cgo6cdQB+K4A3tzEiMHUh7DgwTKLBX16ekX8VL2iaDPZv4yCUDlTukgVh9g95 fRaZznqSKviNFFNO5hA52hCoylkM9aS6RhkXuxiT3Ml+nIkYZjOe6AyMwI0+iu6k/qA4 3cTmfLjFErVxeF/D8kJUOG5sGkZQ9G2f9BPiGXpZkpEpustWWArsXKpDxKVMGZ6jv3uE TSPGkv/oxlkxvKEpU8HwxyEruCBvk6DeNpvZYCNDuXiQhAOq203GS830SGQL2cVRsh6V 3TqMb8qkCkCzprzRNhjPbJfRN7y4cM3ExcCAEgYvSEj77JxYK/W8gFpJ1D7uIsoTn0gf PvRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=pLetrPMUxW70aX6gSCrtBgQAGRigxfAIMPJ2cuSXx58=; fh=W+dBki0gAtsdynKUnp9cRt34//eqyUngbC6emtOLcOo=; b=hCtl+BnAdK+/HXlhNgn6LNm0b3giwxkbyI56UOIVQ8u5GHc3orB1l2Ja+dTReloeGX 9ZCGG2GhXccZgerrHt8uXbUsYQ7yEW+1brhvYnM9VrCHeHnQrLzYHwfksng4o9TH/QIB eVQVH6mTMHNQWZs0wKbYn9uB8fQD9hI841+euWaTIkTTDB4bG2VAGFfH6CgNfAhGJd5K HWB9506fPwedGxymvXP1bmpm6tbNL+QA25l13cwLfmGJllVe6Ty4drRf7s2oXQNqRxvV B/aSlP0K35isF4bROI7PQnfFWxtsP8Z0bReWqCpLHBCVqAoxROAxIFtQfymHYhh71rsw FY2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jEqhntM5; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq21-20020a170906d0d500b0099304c10fd0si3696511ejb.991.2023.08.05.13.49.04; Sat, 05 Aug 2023 13:49:33 -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=@linaro.org header.s=google header.b=jEqhntM5; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjHETR7 (ORCPT + 99 others); Sat, 5 Aug 2023 15:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230143AbjHETR5 (ORCPT ); Sat, 5 Aug 2023 15:17:57 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF952180 for ; Sat, 5 Aug 2023 12:17:54 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fe389d6f19so5251464e87.3 for ; Sat, 05 Aug 2023 12:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691263073; x=1691867873; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pLetrPMUxW70aX6gSCrtBgQAGRigxfAIMPJ2cuSXx58=; b=jEqhntM5C2UDE4r3yEIdxu+EAMV0lsKAZH2Vikk8WAQYSMcf1RH3hOxV0+bNnkcqHx iVeSEEaa0g1RkL1UNSa/tU1RbTf9TEHiT/5TUynNgUkDEZRcH3Q5ROty8UjCU87aDe+G yARpxSDZNJ1YcuREslFDQ5CjznPhNk7G15ZbQfKVYUiu257XHbSNkCA36PPs5Q196C2V HlfiynFuMucSK/ftPjFYkW/edcihJLq70YKJNbiwGBQGDzZvEAHhBaG2L2FHdrxTHJ0c B3IBVSaxWF1jdwOsPKTtIhKIKqQKtvqHUNBGBHczJC0p9NY3jf3+H8kZD1gqjdaho5Ip f96Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691263073; x=1691867873; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pLetrPMUxW70aX6gSCrtBgQAGRigxfAIMPJ2cuSXx58=; b=Au+18zrA5OqP9+qqqxK05PNGjvzAdHf4LLPGVBmT1rF+je6yxpMC0lKH4CJamEO8Id kQKKpnPuxJN6QOzpqABqAQEK2zduoi6IHOcumgD6NNjVPzuxe/TWGLIIji3Qd32GH2BS UNwMbMIN1KESKbOLIwM0Lu6U1fcRdjnFd9aK0jetWIp5x1zFJI/h9KVN22Ht+dCwhSlu XU8AyWec7C8hk49j54sZC9a5LMQVmlW5WSnlo1h4lMcu56Y77+Au9dRxZ8UxBdfB5cru A+uTi43kSvkwULnz3I7dSt0sR2OlSH0YCiN6CAZVUKzNpmlFq07TtHTlo0t/uweLOuMg luEw== X-Gm-Message-State: AOJu0YwNM3GFTdA7+87pNmwYS1gyhdAro24cX/jo+dD7G9RsCzbILKfz z3WCfkH9IRPXffq6Ha8OL45AAA== X-Received: by 2002:a05:6512:3a82:b0:4fb:8bab:48b6 with SMTP id q2-20020a0565123a8200b004fb8bab48b6mr3659917lfu.52.1691263073104; Sat, 05 Aug 2023 12:17:53 -0700 (PDT) Received: from [192.168.1.20] ([178.197.222.245]) by smtp.gmail.com with ESMTPSA id n9-20020aa7db49000000b0051e2cde9e3esm2997260edt.75.2023.08.05.12.17.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Aug 2023 12:17:52 -0700 (PDT) Message-ID: <249e806a-f094-9514-9c83-e74e7b1f00ba@linaro.org> Date: Sat, 5 Aug 2023 21:17:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v3 2/2] i2c: Add GPIO-based hotplug gate Content-Language: en-US To: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= 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 References: <20230729160857.6332-1-clamor95@gmail.com> <20230729160857.6332-3-clamor95@gmail.com> <25858c22-ef92-2136-67ef-0d27364c1600@linaro.org> From: Krzysztof Kozlowski In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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: X-Mailing-List: linux-kernel@vger.kernel.org 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) >>>>> >>>>> 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 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/ > 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 That's not really an argument. For some reason we have CONFIG_DEBUG_SHIRQ, right? If you think documentation is missing, everyone is encouraged to fix it, but lack of documentation is not a proof of some correct code pattern. Best regards, Krzysztof