mbox series

[0/4] PCI: Convert dynamic PCI resources sysfs objects into static

Message ID 20210825212255.878043-1-kw@linux.com (mailing list archive)
Headers show
Series PCI: Convert dynamic PCI resources sysfs objects into static | expand

Message

Krzysztof Wilczyński Aug. 25, 2021, 9:22 p.m. UTC
Hello,

Currently, a lot of PCI-related sysfs objects are dynamically created
under the "/sys/bus/pci/devices/..." path when either the PCI driver is
initialised or when a new device is hot-added.

When PCI driver loads and the PCI sub-system initialises, the sysfs
attributes are then added when late_initcall() function is called:

    pci_sysfs_init
      sysfs_initialized = 1
      for_each_pci_dev
        pci_create_sysfs_dev_files
          sysfs_create_bin_file

Otherwise, for hot-added devices, the sysfs attributes are then added
when the pci_bus_add_devices() function is called:

  pci_bus_add_devices
    pci_bus_add_device
      pci_create_sysfs_dev_files
        if (!sysfs_initialized)
	  return
        sysfs_create_bin_file

When a device is removed the pci_remove_sysfs_dev_files() function is
called from pci_stop_dev() to remove all the attributes that were
previously added:

  pci_stop_bus_device
    pci_stop_dev
      if (pci_dev_is_added)
        pci_remove_sysfs_dev_files
          sysfs_remove_bin_file

The current implementation is known to cause problems:

  https://lore.kernel.org/linux-pci/1366196798-15929-1-git-send-email-artem.savkov@gmail.com/
  https://lore.kernel.org/linux-pci/20200716110423.xtfyb3n6tn5ixedh@pali/
  https://lore.kernel.org/linux-pci/m3eebg9puj.fsf@t19.piap.pl/
  https://lore.kernel.org/linux-pci/20210507102706.7658-1-danijel.slivka@amd.com/

Most of the PCI-related attributes do not need to be created and removed
dynamically and there is no need to also manage their create and remove
life cycle manually.

The aim is also to first reduce the reliance on using late_initcall() to
eventually remove the need for it completely.

This particular series focusing on PCI resources files on platforms that
provide either the HAVE_PCI_MMAP or ARCH_GENERIC_PCI_MMAP_RESOURCE
definitions (other platforms, such as the Alpha platform, will not be
affected) continues the on-going effort to convert the majority of the
dynamic sysfs objects into static ones so that the PCI driver core can
add and remove sysfs objects and related attributes automatically.

Please note that this series depends on the commits from the following
series to be added prior to applying it:

  https://lore.kernel.org/linux-pci/20210729233235.1508920-1-kw@linux.com/
  https://lore.kernel.org/linux-pci/20210812132144.791268-1-kw@linux.com/

	Krzysztof

Krzysztof Wilczyński (4):
  PCI/sysfs: Add pci_dev_resource_attr_is_visible() helper
  PCI/sysfs: Add pci_dev_resource_attr() macro
  PCI/sysfs: Add pci_dev_resource_group() macro
  PCI/sysfs: Convert PCI resource files to static attributes

 drivers/pci/pci-sysfs.c | 189 ++++++++++++++++++++++------------------
 include/linux/pci.h     |   2 +
 2 files changed, 104 insertions(+), 87 deletions(-)

Comments

Krzysztof Wilczyński Aug. 25, 2021, 11:02 p.m. UTC | #1
[+cc Krzysztof Hałasa, Sasha and Pali for visibility]

Hello Bjorn,

I wanted to add that Krzysztof Hałasa was able to find a bit of spare
time to test this series on his i.MX6 (Gateworks Ventana SBC), and
completed a number of tests (such as power-cycling the SoC, etc.)
without running into previous Oops and panic during boot.

The follow-up to this series will be changes specific to the Alpha
platform and legacy PCI attributes.

But since a majority of hardware platforms aren't really using legacy
PCI attributes these days (unless I am mistaken) and Alpha is not widely
used, fixing race condition in the PCI resource files converting them to
static sysfs objects would be a priority.

This will also make it easier to back-port this and other patches that
paved the way prior to this one the stable and LTS releases, especially
since these are widely used in popular distributions that tend to
back-port a lot too into their stable releases.

	Krzysztof