Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1130298rwl; Wed, 29 Mar 2023 13:09:40 -0700 (PDT) X-Google-Smtp-Source: AKy350aSe4EEpNPhgO3L9PRgXMhU/LS/0pbm8WrNu3d/S6NX9EHewv6n0L5NUTYqTf/ux0yy+ULN X-Received: by 2002:a17:903:5c8:b0:1a1:e33e:2606 with SMTP id kf8-20020a17090305c800b001a1e33e2606mr17413950plb.25.1680120580632; Wed, 29 Mar 2023 13:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680120580; cv=none; d=google.com; s=arc-20160816; b=vc2aU7OQpq8rL2rEsuj+e62/SyufWDB4K7HXIMO1PHtJjhXZyd410I5x37iY/z6bcx XDN635c7cJQVhdTAs1Ybx9FLAhfunNTMsMfQMJd5qtC7tJX4ttDT7HeyqmixeBybVn97 Y+HhPAK54rmOqtJALXH13TLWjfjc+ABaiK3Y1EbcQIe4alBI0Rx4Xaz+AlRNn/VHsSBS gHLwLONlCZpblpzAXxwWpmF1sOdXxkxPKE6opcCcE1aUWYxMVLbljA+4FDoUa2pYCzwA nswWIW14kUF5Cn4lct00C0SmV/H84TOyO67xIDZIlzN6ZjLh9LlexGGqpd9pLJSZ+d7i BphA== 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=JkwwcSBRqgS30KhR49UM83c3a69MioP60clbUh2HjpA=; b=xEPJkMkViI1GDlQvJuB+vRZCRnVl1SF54NNO0mySFW3PM6mMSFRCP7TNgvPFTHKUim 0vecHyczt+myFwKx6XTQIX7ubXH40AFO3BeRaImrGOwqruM4CIYqTXWA1hIe4IN4GvUC 4SZWTmmOvhXZvtOC09AZjghphwLbUQ8OMCfPoGcbzFWpg7F6qUNhy8SNJqYPkBWJ1wnp ljua28k9xiEv+bh4vpPE1m1CNAk2Bvu06hVBF2P08yVLmOzFrk63Vq/mN5r94MlTEjYK c/gUBZwxsqDu58NZCk/eKhrFJBSzrsB/kdngwtZ9nHK3VYtQqIw7L56eozGZDLcj+Gbo VNRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Vjb3xT/s"; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a631d45000000b0050bc1502fb9si31915766pgm.704.2023.03.29.13.09.28; Wed, 29 Mar 2023 13:09:40 -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=@google.com header.s=20210112 header.b="Vjb3xT/s"; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbjC2TuB (ORCPT + 99 others); Wed, 29 Mar 2023 15:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjC2Tt7 (ORCPT ); Wed, 29 Mar 2023 15:49:59 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC0D6A4B for ; Wed, 29 Mar 2023 12:49:37 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id d22so9992513pgw.2 for ; Wed, 29 Mar 2023 12:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680119288; 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=JkwwcSBRqgS30KhR49UM83c3a69MioP60clbUh2HjpA=; b=Vjb3xT/s1/m7g9V+3JodYQd0vQRs0RZgGOezedG8oJudOay6pylk3yYQ2+36Ew/UIb juTMRwfNvT2SCrUDOGBXYX2WfGtnySA1/ElIFRA6/PZ1aW8c0mBQPLG/1HbonvmAuKVG nuqXcKmGBfCFd+ChSg3orAS1fWQva0XBc7rql8PaZSQWvOxbKW2mCTGOVJBfhPPDs4I+ oDs22vkzvITKKvdb66iqt7sHk2sh/Dw5IjGWFsr13+Z6j/cSH1OFYWDYq/a+0eDGiSi1 bs/aib9lMbj++PKL/Ym1cxuKbiGmWO+xSCPycd19WBQwnO/pZd6zU6iI9pOdvNqn/YaR Bowg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680119288; 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=JkwwcSBRqgS30KhR49UM83c3a69MioP60clbUh2HjpA=; b=S8K+fl9G8ROnumTBvqOurQdK6rbnZwWp45HDvdmUcSHX/0JH3zlweNfRTvgbdnHJSh UlC1eJqOjQOLYwf5jdnnK1IL8+f7eGm9VbX190GqLuRoxAZDNhvtQRjz9wYL/j8SCl13 FzISLVlGSph/ODgoBJWB9E99TyzTlhFZoElA9MTmQpah8ssLKMHNVH3+zdIzK2A7bmb0 dSmFmxxFZanxQi+roMZGDMYtncxgnfvs8OEYUcChH6MbsYct48L8i37p+6w97VMxTQ1j vNaNMi9RQrp4/S9LXDrhrDoBolpaEep99pDsn7r/0Flz+xG820CDBPqiTpczWMSaEyxT CpeA== X-Gm-Message-State: AAQBX9cUFa7Kn8Aw2/yVzjbbEESzhTZgH7qCXmWlsr5TJwCsD7SbUsaM w2oPJExaf8ODQT4014WJhCFN8oTjE/JIvJMeBPgg1A== X-Received: by 2002:a63:5a47:0:b0:513:2523:1b5f with SMTP id k7-20020a635a47000000b0051325231b5fmr5501254pgm.3.1680119287530; Wed, 29 Mar 2023 12:48:07 -0700 (PDT) MIME-Version: 1.0 References: <240155f20aae47e9f7461e2b7416120ba6238886.1679650087.git.geert+renesas@glider.be> In-Reply-To: <240155f20aae47e9f7461e2b7416120ba6238886.1679650087.git.geert+renesas@glider.be> From: Saravana Kannan Date: Wed, 29 Mar 2023 12:47:31 -0700 Message-ID: Subject: Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays To: geert+renesas@glider.be Cc: Greg Kroah-Hartman , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Wolfram Sang , Rob Herring , Frank Rowand , Mark Brown , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 Fri, Mar 24, 2023 at 2:30=E2=80=AFAM Geert Uytterhoeven wrote: > I saw all the other replies. Let me give more details on the commit text and inline comments so it's clearer and not a "he said he said" > When loading a DT overlay that creates a device, the device is not > instantiated, IIRC I think the devices are instantiated, but not probed. > unless the DT overlay is unloaded and reloaded again. > > Saravana explains: > Basically for all overlays (I hope the function is only used for > overlays) we assume all nodes are NOT devices until they actually > get added as a device. This comment was about what the patch is doing. I think a better commit text would be something like below. Feel free to reword as you see fit. After the recent refactor to improve fw_devlink[1], it no longer depends on "compatible" property to identify which device tree nodes will become struct device. fw_devlink now picks up dangling consumers (consumers pointing to descendent device tree nodes of a device that aren't converted to child devices) when a device is successfully bound to a driver. See __fw_devlink_pickup_dangling_consumers(). However, during DT overlay, a device's device tree node can have sub-nodes added/removed without unbinding/rebinding the driver. This difference in behavior between the normal device instantiation and probing flow vs the DT overlay flow has a bunch of implications that are pointed out elsewhere[2]. One of them is that the fw_devlink logic to pick up dangling consumers is never exercised. This patch solves the fw_devlink issue by marking all DT nodes added by DT overlay with FWNODE_FLAG_NOT_DEVICE (fwnode that won't become device) and then clearing the flag when a struct device is actually created for the DT node. This way, fw_devlink knows not to have consumers waiting on these newly added DT nodes and to propagate the dependency to an ancestor DT node that has corresponding struct device. [1] - https://lore.kernel.org/lkml/20230207014207.1678715-1-saravanak@googl= e.com/ [2] - https://lore.kernel.org/lkml/CAGETcx_bkuFaLCiPrAWCPQz+w79ccDp6=3D9e88= 1qmK=3Dvx3hBMyg@mail.gmail.com/#t > Based on a patch by Saravana Kannan, which covered only platform and spi > devices. You can keep this in the commit text. > Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()") > Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=3DrWYnkC= Z6z5bGX-wj4w@mail.gmail.com > Signed-off-by: Geert Uytterhoeven > Acked-by: Mark Brown > --- > v2: > - Add Acked-by, > - Drop RFC. > --- > drivers/bus/imx-weim.c | 1 + > drivers/i2c/i2c-core-of.c | 1 + > drivers/of/dynamic.c | 1 + > drivers/of/platform.c | 1 + > drivers/spi/spi.c | 1 + > 5 files changed, 5 insertions(+) > > diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c > index 36d42484142aede2..898e23a4231400fa 100644 > --- a/drivers/bus/imx-weim.c > +++ b/drivers/bus/imx-weim.c > @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, = unsigned long action, > "Failed to setup timing for '%pOF'\n", r= d->dn); > > if (!of_node_check_flag(rd->dn, OF_POPULATED)) { It's important this flag clearing is done before the device is added. So, can you please add a comment before all these clear flag lines that's something like: /* Clear the flag before adding the device so that fw_devlink doesn't skip adding consumers to this device. */ Thanks, Saravana > + rd->dn->fwnode.flags &=3D ~FWNODE_FLAG_NOT_DEVICE= ; > if (!of_platform_device_create(rd->dn, NULL, &pde= v->dev)) { > dev_err(&pdev->dev, > "Failed to create child device '%= pOF'\n", > diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c > index aa93467784c29c89..303f9003562eed3d 100644 > --- a/drivers/i2c/i2c-core-of.c > +++ b/drivers/i2c/i2c-core-of.c > @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, u= nsigned long action, > return NOTIFY_OK; > } > > + rd->dn->fwnode.flags &=3D ~FWNODE_FLAG_NOT_DEVICE; > client =3D of_i2c_register_device(adap, rd->dn); > if (IS_ERR(client)) { > dev_err(&adap->dev, "failed to create client for = '%pOF'\n", > diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c > index 07d93753b12f5f4d..e311d406b1705306 100644 > --- a/drivers/of/dynamic.c > +++ b/drivers/of/dynamic.c > @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np) > np->sibling =3D np->parent->child; > np->parent->child =3D np; > of_node_clear_flag(np, OF_DETACHED); > + np->fwnode.flags |=3D FWNODE_FLAG_NOT_DEVICE; > } > > /** > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > index b2bd2e783445dd78..17c92cbfb62ee3ef 100644 > --- a/drivers/of/platform.c > +++ b/drivers/of/platform.c > @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *= nb, > if (of_node_check_flag(rd->dn, OF_POPULATED)) > return NOTIFY_OK; > > + rd->dn->fwnode.flags &=3D ~FWNODE_FLAG_NOT_DEVICE; > /* pdev_parent may be NULL when no bus platform device */ > pdev_parent =3D of_find_device_by_node(rd->dn->parent); > pdev =3D of_platform_device_create(rd->dn, NULL, > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index 8e8af148b1dc371e..66ac67580d2a473b 100644 > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb,= unsigned long action, > return NOTIFY_OK; > } > > + rd->dn->fwnode.flags &=3D ~FWNODE_FLAG_NOT_DEVICE; > spi =3D of_register_spi_device(ctlr, rd->dn); > put_device(&ctlr->dev); > > -- > 2.34.1 >