Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp997110lqt; Tue, 19 Mar 2024 09:43:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNuMx+SZzOUWNSX1ZtsZSx+VE2ikAgQaHjwpiwOSpJ63GYX7MFdivTPfYDPmr2JG2CKda8+oCHGfsedLEdFkz+wLwSFwnBIB1UeNdD8g== X-Google-Smtp-Source: AGHT+IHg6nQ/oiSCUrhpaPympOtZGBV7Om7xaLBqFH3QMc9Xjg5asOu1wrlNENBl4FVY0OAbxYUD X-Received: by 2002:a17:90b:302:b0:29f:88ad:f40e with SMTP id ay2-20020a17090b030200b0029f88adf40emr3149690pjb.42.1710866639732; Tue, 19 Mar 2024 09:43:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710866639; cv=pass; d=google.com; s=arc-20160816; b=AcL1+GZx3XkoRlD1wyDMBkkqk4Sj9hsM8m3j+UgBSTjzG/WTu6ausr1MEs9IfxX1iY 7w7XJArxEmGJStFcX/OvumsjTmLPyCYf8eudaBZzSsmGPPnyyKycAp8Fc9qFVNwTLlJr qBhCArFvqjAbSx2p6WbgGwLJJeclKBaZoSXjxJyNXg4Xo25FGs7VeeaDwAM7TBZ6loep cmJYDKy97zk3WDFZcQnKF2m8IowFe52abjAzkt91e/9IHe4zQc2X9jFTKOTUyr057LK0 CIIzGKQb4NTCBgmEz+Z3R5bhmoPke6cjNaLD6ffszdfOaRt+i2+TJ5c40vRKDpAb9EmU 6snw== 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=oYIimeHKwBqqC6DKuj5E7MDRAp7vlcQ07WCRWyQmkBA=; fh=ha8BnHCjsz/7do7LU9m306ax6mNgp0kNl1u84k6KRGU=; b=MLG7IOwN41Gk4KMh0zZHCKoDphpdYdMWlyIoaKXacpA3qDkvfpxRMIfKYfJ5LoLRk7 5Rkwb/LfdrKr+ObaP4JNDpOWaZE4CDpSGX2/dDgVi9RuOYITRHw8m7hN816B2bisbmN2 k69lfbyhW2EZtQbEQVeiZO4oXu7piZOn/WTRKDl+S8jmQLUAKwTse+XSW9zWL1OrG8Hf 0JtbSZcIvExAN2QfNqV/zBY/MPwh/rY/KaHWS2tVYGdmnFjyg2PIjR01eabvGO8+N4RM jQGSRGhauL8tC4j9jXJblQPFreDct4FuWnnuvIGLUvqe4seONp4qAX81yaUaiQkWdpK0 icpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=pj9QGjAT; 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-107843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o23-20020a17090ac71700b0029dd7d357a5si10626223pjt.46.2024.03.19.09.43.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 09:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=pj9QGjAT; 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-107843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107843-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B9AC1B245F8 for ; Tue, 19 Mar 2024 16:34:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D5DDF4FC; Tue, 19 Mar 2024 16:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="pj9QGjAT" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 1C6948489; Tue, 19 Mar 2024 16:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710866054; cv=none; b=C6iUU9LZgSr7uz19G0EmFA2xixd9VOx57QTLtNKOGV5KVWMwL00ioJ7SReBhEgBU5mQhIfq/3r2F46z50mUhrSz3k4Iqnw2jfy5QLYpLi3TED5ki2paQxbEuJtLGjd2Q6NDxMznEedk5l3EO9X4EQd0NEFxhbJhFFlNOQCqRpi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710866054; c=relaxed/simple; bh=YlAPJJDgoDVZ9sazmRhBUOaRf5OWOWpXawB/hpsB/qI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RtnmAkycay5Mnbnu2pSfZwOMkuQ5a3Ti0BNUNR0c/wImiV4CsOHC321h9jAbz/fSQOa2acOcLXk3m8q+xJm8O6ie9SksZZUpiaWTbZN6M6mbgKCsG83v0lCxSzTmC5QN3hQxZpeBN26vctM2WjVqhJo6NkgOgaV6bNjIzTzMBaI= 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=pj9QGjAT; arc=none smtp.client-ip=217.70.183.201 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 7C1171BF208; Tue, 19 Mar 2024 16:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1710866048; 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=oYIimeHKwBqqC6DKuj5E7MDRAp7vlcQ07WCRWyQmkBA=; b=pj9QGjATc1a0H5dialB43VBvVSKpAUdAGAbcNJmUivGu3/45f0JBnQklJhy26AxveZhfsD NzjZudfp6zuWrMW3Uvy2cRbQ80GsLLjRHp46mGzWbD0LkH09L3Awtj1pmKcwHVNVieULO0 4Nk4ZmgiCOMY8hUJp9RTM8ErwdVdo/opIrcJ9tBwzl7ntXYGl7uD1Yp0emCUd9uMTAYnlW D0GiVrXJ16XsRT9lqrigkoh+xvxEcMW+dKZ8hdlbXFT9prZIt/F6MBr6QP/OYO6H1k1/Jn kyAlMFeWGqux+z3dYUmLwZPOvaQS8eFXMzcN80Ytl9qjJ3IvRPNkRhCbwdMN2A== Date: Tue, 19 Mar 2024 17:34:04 +0100 From: Herve Codina To: Bjorn Helgaas Cc: Rob Herring , 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: <20240319173404.019b424a@bootlin.com> In-Reply-To: <20240319152513.GA1227721@bhelgaas> References: <20231215145207.0cf098e5@bootlin.com> <20240319152513.GA1227721@bhelgaas> 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 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. Best regards, Hervé -- Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com