Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp421929lqg; Thu, 11 Apr 2024 07:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYLGgANx+Y5uzsw6sWNpJH+ZpTtR4swMvS6HiknLxIlainYC0gd0bxegEl7X3eO0t+pZYDU1Q5NObWnKz9tUNhKFJ/cWIQkamVTz4aog== X-Google-Smtp-Source: AGHT+IH3jKFiS9Hz9RqKHGqr5ahiX1q3IQCMFisBOZyhFejOgKseDem3T50/FOdrLDkXUOYaiviI X-Received: by 2002:a17:907:7246:b0:a52:2274:64af with SMTP id ds6-20020a170907724600b00a52227464afmr1612955ejc.2.1712844447943; Thu, 11 Apr 2024 07:07:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712844447; cv=pass; d=google.com; s=arc-20160816; b=C5l6WASPeQT7djB5Wv2pyRea19G/CdlupaO5RV7rSp5qr978wO1gowUG+BhnYs8DCz WwxzKdJglpprFQNBBxg7cuCnuSbcVX+en6+d9/LUJkApTxDnKC01TuM6gJ+Pt9t3+pm2 gjftvSFAKQZfryLgVHfPM14aGcTZSOsdzIBOSJLByGYp+pnEmC0KGTglArBjTD/ekU48 z7sqM+7Fq8u3e7yp13O5OIR89dS9arP4l/2ZApAlgYpz/k0bgjJXOintzxZRYHy6BsxZ FRsckRfcUQg3DUfiJTLDI055ww0q6iK2Z9aHxlnO57/zCDRmeCXypWdxWdRAIZw5wLqf M5Aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=99XoepWmaxoXSZpnM0X9ck++OvRAJQLOkxrhY2CyXm8=; fh=OGpGInkjO8tgLtCyVnbp/sjnNdHaH0Sli0jhpHMaSws=; b=pB49McJPObC66XnfTgRq2uF0fKw35FQAq58/HKlwD7IHO4bEYMzV7Q76q7Ga26LMtY 0MalRsNF9GhjsAHCiNQdBHPqtfOy0jYd0NIgkRThKdbrk5WeUl3jZr/3VK16i0qAIkyE lWFsMap5BFVCmUaqDpuTGAOrekhfmsLqiGMaGwdXaVzl0ictrAH5F/MawzLjT8uwzdHW qpotTWZORCnn2mYSjo5EFxpRW1SCYQWBQWJSvut+9HnUPmzeJfCUk346dNZyxIvM0kZ+ NCSpoY1UfjydJGj1+NphXA/gOUNRArP2SVzvWu5CUwePkBe5g55NiuJ5/EWEdlTooFDL DhUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=LsjVOHx8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-140598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id k14-20020a1709065fce00b00a522e903c5csi14649ejv.882.2024.04.11.07.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 07:07:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=LsjVOHx8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-140598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 816C31F22AF6 for ; Thu, 11 Apr 2024 14:07:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14C1714F9FC; Thu, 11 Apr 2024 14:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="LsjVOHx8" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C87014D44D; Thu, 11 Apr 2024 14:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712844356; cv=none; b=MtLbTTm9qKWj7TVIYT7Ng6VmafOLyyDRYmXvzebFUkFTMIIYikzsNqD6Mj2H3slFrS1Xr7Ca6BNvHM/v5Kls0aW18Qv25hRu1IpAA8xdtE6ad6cW0KmPjG/tyNFRlT8XEXopGLZRJx4/I5HuKFTMu+T6dVlGOL8NaAxxRdY5U1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712844356; c=relaxed/simple; bh=w02JCMP3BbzdBAjdyFpEXBM6uQChrEYUSHmWMjV3wlo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HC8UrSiI3i67xIBNIGe0FT6DLyAcBiRdJhvFHMLQE+H/WCWKdT0ZvxQmi5zoGfjWPLLRa4U/ylhv/YExxnf5+LqcqBIGteCT3MzZXhXGWG3XaCJgSlg7C8H/kSsMT3Kv+JoEuakRzjJYamSpEnebD3RDSmkfm8/MfLAGWoUIkLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=LsjVOHx8; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 0E6D94000B; Thu, 11 Apr 2024 14:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1712844351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=99XoepWmaxoXSZpnM0X9ck++OvRAJQLOkxrhY2CyXm8=; b=LsjVOHx8DIQnU5iKlRvy7tXAeU70ECSr9FiiBw0siyrjylQ9vLfFpZsyVLhfz3DVKZ1gRT Wx6ANDMv/8DKJNynXoW4e0tuZXR8UlS9nVZPHlypJr2PtsgXjyDvfvJBPoK4sk0jG/ypHr oBsW0UYfEvwYvuw4LVvSkXhPL49LN2YTLXO8LS9rrGzWzBtzRoH1pNsfRQXGShiCGlkoQp NYvZjanqFs+t5jkFihuA/I/C+Z7LR/iV3mIoYntWnvSkjwenZyx+0fk+8IkxLkmn4Nj1UG b596yJmKoyAd6DZb89CaYyMVtX/mHVjPENd86ieCi9bIaszBsP/Ud2XcjXWSrQ== Date: Thu, 11 Apr 2024 16:05:48 +0200 From: Herve Codina To: Rob Herring Cc: Bjorn Helgaas , 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 , Krzysztof =?UTF-8?B?V2lsY3p5xYRza2k=?= Subject: Re: [PATCH v2 0/2] Attach DT nodes to existing PCI devices Message-ID: <20240411160548.06fa9b11@bootlin.com> In-Reply-To: References: <20231215145207.0cf098e5@bootlin.com> <20240319152513.GA1227721@bhelgaas> <20240319173404.019b424a@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com On Wed, 10 Apr 2024 16:41:43 -0500 Rob Herring wrote: > On Tue, Mar 19, 2024 at 11:34 AM Herve Codina wrote: > > > > Hi Bjorn, > > > > On Tue, 19 Mar 2024 10:25:13 -0500 > > Bjorn Helgaas wrote: > > > > > [+cc Krzysztof] > > > > > > On Fri, Dec 15, 2023 at 02:52:07PM +0100, Herve Codina wrote: > > > > On Mon, 4 Dec 2023 07:59:09 -0600 > > > > Rob Herring wrote: > > > > > On Mon, Dec 4, 2023 at 6:43 AM Herve Codina wrote: > > > > > > On Fri, 1 Dec 2023 16:26:45 -0600 > > > > > > Rob Herring wrote: > > > > > > > On Thu, Nov 30, 2023 at 10:57 AM Herve Codina wrote: > > > > > > > ... > > > > > > > > > > --- 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 = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); > > > > > > > + 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 resource > > > > > > values. > > > > > > We need to have some values set by the PCI infra in order to create our DT 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(). > > > > > > > > DECLARE_PCI_FIXUP_HEADER is too early as well as doing the DT node creation > > > > just before the device_add() call. > > > > Indeed, in order to fill the DT properties, resources need to be assigned > > > > (needed for the 'ranges' property used for addresses translation). > > > > The resources assignment is done after the call to device_add(). > > > > > > Do we need to know the actual address *value* before creating the > > > sysfs file, or is it enough to know that the file should *exist*, even > > > if the value may be changed later? > > > > I think, the problematic file is 'of_node'. > > This file is a symlink present in the device directory pointing to the > > node in a device-tree subdir. > > > > How can we create this of_node symlink without having the device-tree > > subdir available ? > > > > > > > > > Some PCI sysfs files are already created after adding the device by the > > > > pci_create_sysfs_dev_files() call: > > > > https://elixir.bootlin.com/linux/v6.6/source/drivers/pci/bus.c#L347 > > > > > > > > Is it really an issue to add the of_node link to sysfs on an already > > > > present device ? > > > > > > Yes, I think this would be an issue. We've been trying to get rid of > > > pci_create_sysfs_dev_files() altogether because there's a long history > > > of race issues related to it: > > > > > > https://lore.kernel.org/r/1271099285.9831.13.camel@localhost/ WARNING: at fs/sysfs/dir.c:451 sysfs_add_one: sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:01.0/slot' > > > https://lore.kernel.org/r/19461.26166.427857.612983@pilspetsen.it.uu.se/ [2.6.35-rc1 regression] sysfs: cannot create duplicate filename ... XVR-600 related? > > > https://lore.kernel.org/r/20200716110423.xtfyb3n6tn5ixedh@pali/ PCI: Race condition in pci_create_sysfs_dev_files > > > https://lore.kernel.org/r/m3eebg9puj.fsf@t19.piap.pl/ PCI: Race condition in pci_create_sysfs_dev_files (can't boot) > > > https://bugzilla.kernel.org/show_bug.cgi?id=215515 sysfs: cannot create duplicate filename '.../0000:e0' > > > > > > And several previous attempts to fix them: > > > > > > https://lore.kernel.org/r/4469eba2-188b-aab7-07d1-5c77313fc42f@gmail.com/ Guard pci_create_sysfs_dev_files with atomic value > > > https://lore.kernel.org/r/20230316103036.1837869-1-alexander.stein@ew.tq-group.com PCI/sysfs: get rid of pci_sysfs_init late_initcall > > > https://lore.kernel.org/r/1702093576-30405-1-git-send-email-ssengar@linux.microsoft.com/ PCI/sysfs: Fix race in pci sysfs creation > > > > > > > I am not sure we are facing in the same kind of issues. > > The ones you mentioned are related to some sysfs duplication. > > In the of_node case, the issue (if any) is that the symlink will be created > > after the other device's file. Not sure that it can lead to some file > > duplication. > > Again, if you notify userspace and it wants to make some decisions > based on of_node, then it has to be there when the notification > happens. As Greg says frequently, you've raced with userspace and > lost. > > I imagine Bjorn won't like it, but may we need another fixup point? > > Rob I'am not sure that a fixup point can fix the issue. In order to have the of_node available before the notification, we need to a have the of_node set and filled before the device_add() call. In order to create the 'ranges' property in the DT node, we need PCI resources computed. These resources are computed after the device_add() call. Hervé