Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2721177rdb; Mon, 4 Dec 2023 05:59:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj0ipy2PXmyf8RWeri52XIdHdz1JvKIqYz9M8Rf602ctjxRonmzpmit4Zo6/7wvjjXpocu X-Received: by 2002:a05:6358:f1c2:b0:170:17eb:378e with SMTP id kr2-20020a056358f1c200b0017017eb378emr4801126rwb.54.1701698377223; Mon, 04 Dec 2023 05:59:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701698377; cv=none; d=google.com; s=arc-20160816; b=wn7KJmKLkcBM1Tyl0Nry5A5whwvKeVWcHFs4lFUPrWQkl6olxIP3ipPBqQrfDGuCB8 /35QxSOhEGUiwrEwi2qVtXQwPjarIcBBEwSBCjngI5nFaF37bOHcJ3r+eaaw2AuXV7oA UXZJpKfkEbV5GSe3LVncqa3ZRStDD5wOJPujG+QPQNSd6bglJv1+1OQvGv+l8I5GTbRF X2pkp9rL4h+fi/ZJbjjcyR8/S1uikG/N0xv8ysRWt51VQcK53k/TMM+iOSt+XOGDUtBf t5C7KRKdA0AUqCJVwH/dCg6EZiiev6a4ioDJERkRdB+f8F+EyIGIYL75kyderj0pum7S EU4A== 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=yF7DBDfH9YDygDoqF+ctCkhbF1Bo9YSnNZxmsoHUO98=; fh=dKD0V+qARsvbtedAJivV5fCwUL1NkvPJzUfFW07lA2k=; b=Otf2ez3HuyDGaQKcBRSxulDllb7JgiQKJSaXS0+uL+JmHNnt1dp4u87KmrT2Mp+ouL SS+RTARuTa+W5HQvYD1qTz8VYjBx8YdqdGsUHJgqxRBWDuSK5KaecxuMtkiEuo3VJr6W TSIA3tDI/QrGLoW6UPRGSar2cNh+FYCwG8Yx2fOReefOrrxpdfnkU9vd0IeH/Q9N7A+X Hp3noZYBjiqaXEwnrVLej3tIoBDC0d7GnyVO4mknJLZ/GOqaxpvV0KjWcu8mAyfSi1X7 BWGOMOvdwNoNJun1/u2RdGBH8wHmnCFjMKJSc6A2krUn7i66t1bGzreK9CSSw8PVdz5C J1Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dvUKm6gE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a21-20020a656415000000b005c668c65401si3456613pgv.480.2023.12.04.05.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 05:59:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dvUKm6gE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 21CB28061369; Mon, 4 Dec 2023 05:59:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344823AbjLDN7S (ORCPT + 99 others); Mon, 4 Dec 2023 08:59:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233871AbjLDN7R (ORCPT ); Mon, 4 Dec 2023 08:59:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A3C101 for ; Mon, 4 Dec 2023 05:59:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 896D7C433CB; Mon, 4 Dec 2023 13:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701698363; bh=bYySYTrY6km8QqIBfS1jsCvf7BxtvotE514DmN2BI3g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dvUKm6gEnRW/J2hJ2oXjEQevmQcNzI85MBDgq1ep44eZv3hCnekO1VJHRylY64pBZ +kkCz/e1jnXaI+mV0ssMZRFKAMLRxiM/YJTjAGhY14jDoswMm2pNyCC6SXyjQEBVAK avfydmD6j5hKbP2YrwYdrmghVLgS98T5Me9Tf/URFMSd07P5BRQXIi2/MKU0dOGvBB m00W6gakm4+Z0Ombnbn+/zyWp8ehNyYIh88kfsKLXOizXam0s709XNJyFTcCnj8akb XX7HH62V4I4j/u4ZN+QL+6zWky9HeFSZ05yMHcwGAfNom8KOFikiRnnlbElvddsKKt a+nI1ZVO8x8Cw== Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-50be0f13aa6so2389491e87.1; Mon, 04 Dec 2023 05:59:23 -0800 (PST) X-Gm-Message-State: AOJu0Yx8T3rX1fCjod1rF4edzuf4DHrpqW/+gQkv1P+IBOqyRuiWf7UW PS2XmSFKxGL1uETuss/NgjT7if6C/hxp9zNQCA== X-Received: by 2002:a05:6512:3711:b0:50b:ffd7:d7b8 with SMTP id z17-20020a056512371100b0050bffd7d7b8mr57741lfr.21.1701698361702; Mon, 04 Dec 2023 05:59:21 -0800 (PST) MIME-Version: 1.0 References: <20231130165700.685764-1-herve.codina@bootlin.com> <20231204134335.3ded3d46@bootlin.com> In-Reply-To: <20231204134335.3ded3d46@bootlin.com> From: Rob Herring Date: Mon, 4 Dec 2023 07:59:09 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/2] Attach DT nodes to existing PCI devices To: Herve Codina Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Lizhi Hou , Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , "linux-kernel@vger.kernel.org" , PCI , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 04 Dec 2023 05:59:34 -0800 (PST) On Mon, Dec 4, 2023 at 6:43=E2=80=AFAM Herve Codina wrote: > > Hi Rob, > > On Fri, 1 Dec 2023 16:26:45 -0600 > Rob Herring wrote: > > > On Thu, Nov 30, 2023 at 10:57=E2=80=AFAM Herve Codina wrote: > > > > > > Hi, > > > > > > The commit 407d1a51921e ("PCI: Create device tree node for bridge") > > > creates of_node for PCI devices. > > > During the insertion handling of these new DT nodes done by of_platfo= rm, > > > new devices (struct device) are created. > > > For each PCI devices a struct device is already present (created and > > > handled by the PCI core). > > > Creating a new device from a DT node leads to some kind of wrong stru= ct > > > device duplication to represent the exact same PCI device. > > > > > > This patch series first introduces device_{add,remove}_of_node() in > > > order to add or remove a newly created of_node to an already existing > > > device. > > > Then it fixes the DT node creation for PCI devices to add or remove t= he > > > created node to the existing PCI device without any new device creati= on. > > > > I think the simpler solution is to get the DT node created earlier. We > > are just asking for pain if the DT node is set for the device at > > different times compared to static DT nodes. > > > > The following fixes the lack of of_node link. The DT unittest fails > > with the change though and I don't see why. > > > > Also, no idea if the bridge part works because my qemu setup doesn't > > create bridges (anyone got a magic cmdline to create them?). > > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > index 9c2137dae429..46b252bbe500 100644 > > --- a/drivers/pci/bus.c > > +++ b/drivers/pci/bus.c > > @@ -342,8 +342,6 @@ void pci_bus_add_device(struct pci_dev *dev) > > */ > > pcibios_bus_add_device(dev); > > pci_fixup_device(pci_fixup_final, dev); > > - if (pci_is_bridge(dev)) > > - of_pci_make_dev_node(dev); > > pci_create_sysfs_dev_files(dev); > > pci_proc_attach_device(dev); > > pci_bridge_d3_update(dev); > > diff --git a/drivers/pci/of.c b/drivers/pci/of.c > > index 51e3dd0ea5ab..e15eaf0127fc 100644 > > --- a/drivers/pci/of.c > > +++ b/drivers/pci/of.c > > @@ -31,6 +31,8 @@ int pci_set_of_node(struct pci_dev *dev) > > return 0; > > > > node =3D of_pci_find_child_device(dev->bus->dev.of_node, dev->d= evfn); > > + if (!node && pci_is_bridge(dev)) > > + of_pci_make_dev_node(dev); > > if (!node) > > return 0; > > Maybe it is too early. > of_pci_make_dev_node() creates a node and fills some properties based on > some already set values available in the PCI device such as its struct re= source > values. > We need to have some values set by the PCI infra in order to create our D= T node > with correct values. Indeed, that's probably the issue I'm having. In that case, DECLARE_PCI_FIXUP_HEADER should work. That's later, but still before device_add(). I think modifying sysfs after device_add() is going to race with userspace. Userspace is notified of a new device, and then the of_node link may or may not be there when it reads sysfs. Also, not sure if we'll need DT modaliases with PCI devices, but they won't work if the DT node is not set before device_add(). Rob