Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp270111rdf; Tue, 21 Nov 2023 02:07:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCtMlLC/iPrRWYZHMfJqL5Icqjlvsznkc4FYLPYtXWg8HfMtXzS7yKYLDJcmMGFjf76Efx X-Received: by 2002:a17:90b:3b47:b0:27d:4b6e:b405 with SMTP id ot7-20020a17090b3b4700b0027d4b6eb405mr11207277pjb.33.1700561245095; Tue, 21 Nov 2023 02:07:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561245; cv=none; d=google.com; s=arc-20160816; b=AHH4DIHFBsZcSGHdXM5z2BzDMu8szfnmEQ7Upt88XkEs37skzF/Y5Yk6BAchsYDb/M Ogz0Hcuib/4ml02RffkPQuOIw9lZJ6JHJ7wN2xr0yN9WBxPwN05sc5taCd8DdgjqmmV7 +zNJyNhxVih1igsEAndMJBaOaz+U/gJwepONdCvJdLuW8mMjeFmWSJMhLG1fbBgMQwOZ E1NdO6nRhEZdXJEb/KHJrkja2v04AFSp/WBrCTMz16ypyLQoLXCXhSn+5KSh01oF+vnL 2RvcKYt+i+k6lDg9IAJWcmV3B/mVRFc1OUSG89lP6XsBa7fUkajy871SN4ffBbNNK8Os EihQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9GVF+LG5FcUnk8Y9j01RJ8xwOSd+kWA0lh9J+UwcGDE=; fh=RlAsHCcQ5fo+91fRYPxhOtvOCo9F6pylvZpXqt29mx4=; b=P8qi65vGLdrW3q+eWdS5wzB1eXMXkR+qDkPjA6b0MM/u2L7pMJUuwjAYu5EkHGfrTb 8pyG8xW7mNZJpPAOzIcg1qCGgVYVlNRgZAMvaWa9kxnF/SabGnQDp3es/LJl6a3gPO7C zwQJK1IWmMMS+RffK3e960KhR4aYMuhmVJBSLX+Uo6jL8MircDeWoDcN3aG0SA6fXgug LKh1x7YT9zzyQ8R5yADZMR0x2RBTNYjJtq7ZPJbLDJRLmvYQgjg1KUwyEyLcAj9qIGLV ny8tdAlJSpUjoTS0lyW0DCRa27WObl9TKVcn+oTJlgbaOkdCKZNGNGE7+f9I2lUItpIl Wjaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b="PHaX/6T2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id y1-20020a17090aa40100b002839bc84a0esi9088213pjp.139.2023.11.21.02.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:07:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b="PHaX/6T2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 16CD980792EB; Tue, 21 Nov 2023 02:05:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234140AbjKUKFV (ORCPT + 99 others); Tue, 21 Nov 2023 05:05:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233228AbjKUKFU (ORCPT ); Tue, 21 Nov 2023 05:05:20 -0500 Received: from mail-ua1-x929.google.com (mail-ua1-x929.google.com [IPv6:2607:f8b0:4864:20::929]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F01B9 for ; Tue, 21 Nov 2023 02:05:15 -0800 (PST) Received: by mail-ua1-x929.google.com with SMTP id a1e0cc1a2514c-7c4233cebddso198995241.1 for ; Tue, 21 Nov 2023 02:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1700561115; x=1701165915; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9GVF+LG5FcUnk8Y9j01RJ8xwOSd+kWA0lh9J+UwcGDE=; b=PHaX/6T27UdWZQkTvQf6Hw560FpHFL6lB95cBeDovh7Bfa/ZFXJr2TTQCaCXZYRMdc LjNu4dfJla+glp385Ido7CzP9UqxkRbXBFTCnA5UdxB63FvtRQi4/ylD/db4AJ2OsKfC qac6stGgdo+tDjtqBCuZQQct1fvVmw/e6wmyCqQaTxFh7K4vE7Qrbwd68LmTsAgUnEcb KDmgWKoQ2hQCy819wg9nkMYrof0HMzuZK7Lsz+cO/ezcZ35TCLTe/8Rd2dyFngxKFvyx Hm/onh3BLNFIdqzYh0O6gIRu4Pz28Eh9kaGxVvwSH+t9+ZxKakLGEy4NEJTBb13H5n9/ KFsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700561115; x=1701165915; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9GVF+LG5FcUnk8Y9j01RJ8xwOSd+kWA0lh9J+UwcGDE=; b=el3jOq8ZE3KszsuRGRVPBwQhQgV95cHPbwpVuuXbU3j079Lm3kOfbPFFR4wOPvBw39 iz4pB+RUk2VWtsoQtj/2K4LmeBvjDaAiQhMKgGH0wDKMu0ureYbyjLu6+oqaA18kdn0N fRPX6dVhrQVdJbH81hjTktm14MW6VYcDrrU8S1aD+CcgClMeodDrA4rL1BKjFD1+U4RA 0Iz2p6yIi1qD9J2neaVst7QD0n6eWD6ZfMaPhkGblAZU36ORpouVY4MN/sUTGR8PLkWG iuNqQbi3ICNxyCg3woEbkFu6e6jjpcia4cF8moPhBSYx0WsbBpN8wiVQDa/gimAn4mC2 KHSQ== X-Gm-Message-State: AOJu0YwaQywAtB5k4zrOJHxyiZy1kNABs4E1WuAj9Sjz2Dw/4N23CW2+ CBYpVdGOMSGZ8uumkFwkg54Ap3xkN2Ut4AL4J0gyEg== X-Received: by 2002:a05:6102:330f:b0:462:866e:2f2f with SMTP id v15-20020a056102330f00b00462866e2f2fmr5527316vsc.9.1700561114639; Tue, 21 Nov 2023 02:05:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bartosz Golaszewski Date: Tue, 21 Nov 2023 11:05:03 +0100 Message-ID: Subject: Re: Device links between providers and consumers To: Saravana Kannan Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , LKML , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:05:22 -0800 (PST) On Tue, Nov 21, 2023 at 5:53=E2=80=AFAM Saravana Kannan wrote: > > Hi Bartosz, > > Adding LKML so that others are aware of what the issue is and it'll be > easier when I get to my TODO patches and send them out. I'm hoping > that's okay with you because we didn't discuss anything confidential > here. > That's alright, thanks for starting the public conversation. > On Mon, Nov 20, 2023 at 2:21=E2=80=AFPM Saravana Kannan wrote: > > > > On Mon, Nov 20, 2023 at 12:38=E2=80=AFPM Bartosz Golaszewski wrote: > > > > > > Hi Saravana, > > > > > > As I suspected, I couldn't observe the behavior you described during > > > our discussion at the LPC event. I have a DT GPIO provider and a > > > consumer referencing it by phandle. I'm unbinding the provider and th= e > > > consumer keeps on living, if it tries to use the GPIO, then it will > > > enter the regular code path in GPIO for checking if the provider is > > > there or not. > > > > > > Could you point me in the right direction here? > > > > Thanks for trying it out! Based on the code it should unbind the > > consumers. I haven't ever tried it myself (no need for it). > > I took a closer look to show you where the consumer unbind is supposed > to be done, but in doing so I think I know what issue you are hitting. > One of my TODO items for device links should fix your problem. > > The force unbinding of consumers when the supplier is unbound is > supposed to happen here: > device_driver_detach() > -> device_release_driver_internal() > -> __device_release_driver() > -> device_links_unbind_consumers() > -> for all "active" consumer -> device_release_driver_internal() > > However the problem is the "if (drv)" check in __device_release_driver(). > > This problem also exists for "class" device suppliers that don't have > a drv. Fixing managed device links for "class" suppliers (and now, bus > suppliers without drv) has been in my TODO list for a while. > > The gpio device is one of the cases of a "bus" device probing without > a driver. A while ago, I implemented a gpio_bus_match() that'll probe > the gpio device (so consumer probing isn't blocked) and I was trying > to keep the boilerplate code minimalistic. So, for your test case, a > quick test hack would be to implement an actual stub driver instead of > using a stub bus match. That should fix your problem with the > consumers not unbinding. I'll put up a proper fix sometime soon > (hopefully over the holiday lulls). > But I don't even see any code referring to device_link in drivers/gpio/. I see that if you get a regulator, there is a link created between the regulator device and the consumer device in _regulator_get() but nothing like that in GPIO. > Btw, when we were talking in person at the LPC dinner, you were asking > "what would you do if the supplier was an optional supplier but you > forcefully unbound the consumer?" I have a nice answer now: > Actually, my question was: "what if a resource is optional and the provider of that resource gets unbound". But below you still did answer this question. :) > After a force unbind, we need to add all these consumers to the > deferred probe list and trigger another deferred probe attempt. If the > supplier was optional, the consumer would probe again. This also has > the nice property that the consumer doesn't advertise something to > userspace that it can't deliver (because the supplier has gone > missing) and it makes the error handling easier for drivers. They > don't have to worry about suppliers vanishing in every part of their > code. Once they get the supplier and probe successfully, they > shouldn't have to worry about it vanishing underneath them. > Let me rephrase it to see if I understand it: 1. Provider is probed. 2. Consumer is probed and gets the resource from provider. 3. Provider is unbound. 4. As a result, the consumer is unbound. 5. Consumer is put into the deferred probe list. 6. Consumer binds again to its driver but this time doesn't get the resourc= e. It makes some sense I guess but then you have to deal with the device disappearing for a brief moment in whatever code uses it so it's not like it has no price over handling the provider unbind in consumers. If you're exposing anything to user-space, you're offloading that handling to it. There are also two approaches to handling the providers unbinding: returning an error from API calls vs returning 0 and doing nothing in which case most of the consumer code can remain the same. This is what GPIO does ATM. > Cheers, > Saravana > Is there a way for a driver to alter the behavior? For instance tell the device core that it should not unbind it if the provider is detached? The behavior in general makes sense but it only applies to platform devices on DT systems and has some corner-cases that would need to be ironed out. What I proposed is more generic as it also covers resources exposed to drivers or user-space from discoverable devices. Bart > > > > > Let's start with making sure the basic functionality is working in your= case. > > > > Can you check /sys/class/devlink to see if you see a folder with the > > following name? > > -- > > > > Once you find it, can you cat all the file contents and tell me what > > it says before you unbind it? > > > > The "status" should be "available". And "sync_state_only" should be fal= se. > > > > Also, how are you unbinding the supplier? And does the board you are > > playing with something that's upstream? Should we take this discussion > > to LKML? > > > > -Saravana