From: Bjorn Helgaas <helgaas@kernel.org>
To: Alexander Stein <alexander.stein@ew.tq-group.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Korneliusz Osmenda <korneliuszo@gmail.com>,
Oliver Neukum <oneukum@suse.com>
Subject: Re: [PATCH 0/3] PCI: Fix race condition upon sysfs init
Date: Thu, 27 Apr 2023 11:14:58 -0500 [thread overview]
Message-ID: <20230427161458.GA249886@bhelgaas> (raw)
In-Reply-To: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com>
On Thu, Apr 27, 2023 at 04:28:58PM +0200, Alexander Stein wrote:
> Hi everyone,
>
> this series is a totally different approach for fixing the sysfs init race
> condition. The initial problem is stated at [1]. Previous proposals were
> rejected ([2] and [3]). Here is what's happening
>
>
> CPU 0 CPU 1
>
> imx6_pcie_probe()
> dw_pcie_host_init()
> pci_host_probe()
> pci_scan_root_bus_bridge()
> pci_scan_child_bus_extend()
> pci_scan_slot()
> pci_scan_single_device()
> pci_device_add()
> pci_sysfs_init() device_add()
> sysfs_initialized = 1; bus_add_device()
> for_each_pci_dev() ...
> pci_create_sysfs_dev_files()
> pci_bus_add_devices()
> pci_bus_add_device()
> pci_create_sysfs_dev_files()
>
> Eventually calling pci_create_sysfs_dev_files() twice on the same pci_dev.
> It's a very tight window, deeper PCIe trees increase that window during
> host probe. Asynchronous PCIe host probe is a necessity
> (PROBE_PREFER_ASYNCHRONOUS).
>
> The first two patches are preparations for the last one actually fixing
> the race. As functions like pci_create_sysfs_dev_files() are called from
> externtal and internal to pci-sysfs, an internal version without checking
> for sysfs_initialized is required.
> For the fix a wait queue is introduced where all callers from external
> callsites (regarding pci-sysfs.c) are waiting until pci_sysfs_init
> initcall has finished and woken up all waiters.
>
> A subtlety is that within __pci_create_sysfs_dev_files the resource files
> (created by pci_sysfs_init) need to be removed, so they can be created
> again from pci_host_probe call.
I'll look at this in more detail, but if there's any way at all that
we could get rid of pci_sysfs_init() completely and do this with
static attributes or some other existing sysfs infrastructure, I would
STRONGLY prefer it because that infrastructure has already solved this
problem.
Maybe that's impossible and we really need to make a one-off solution
just for PCI, but ... I haven't been convinced yet.
> Links:
> [1] https://bugzilla.kernel.org/show_bug.cgi?id=215515
> [2] https://lore.kernel.org/linux-pci/20230316091540.494366-1-alexander.stein@ew.tq-group.com/
> [3] https://lore.kernel.org/linux-pci/20230316103036.1837869-1-alexander.stein@ew.tq-group.com/
>
> Alexander Stein (3):
> PCI/sysfs: sort headers alphabetically
> PCI/sysfs: create private functions for
> pci_create_legacy_files/pci_create_sysfs_dev_files
> PCI/sysfs: Fix sysfs init race condition
>
> drivers/pci/pci-sysfs.c | 87 +++++++++++++++++++++++++----------------
> 1 file changed, 53 insertions(+), 34 deletions(-)
>
> --
> 2.34.1
>
prev parent reply other threads:[~2023-04-27 16:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 14:28 [PATCH 0/3] PCI: Fix race condition upon sysfs init Alexander Stein
2023-04-27 14:28 ` [PATCH 1/3] PCI/sysfs: sort headers alphabetically Alexander Stein
2023-04-27 14:29 ` [PATCH 2/3] PCI/sysfs: create private functions for pci_create_legacy_files/pci_create_sysfs_dev_files Alexander Stein
2023-04-27 20:38 ` kernel test robot
2023-05-07 9:05 ` kernel test robot
2023-04-27 14:29 ` [PATCH 3/3] PCI/sysfs: Fix sysfs init race condition Alexander Stein
2023-04-29 2:42 ` kernel test robot
2023-04-27 16:14 ` Bjorn Helgaas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230427161458.GA249886@bhelgaas \
--to=helgaas@kernel.org \
--cc=alexander.stein@ew.tq-group.com \
--cc=bhelgaas@google.com \
--cc=korneliuszo@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=oneukum@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox