Skip to content

PCI/sysfs: Wait for config access lock in sysfs attributes

Matthew Wood kvm linux-pci lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 4 repliesIn review
  2. v15 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Patch 5: check DSN read errors in serial_number_show() and return -EIO instead of an all-ones serial number
- Collected Reviewed-by from Keith Busch on patches 2-4

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5PCI: Add disconnected device checks to user config readsdrivers/pci/access.c+5 -21 reply
2/5PCI/sysfs: Use user config accessors for bus number attributesdrivers/pci/pci-sysfs.c+2 -20 replies
3/5PCI: Add pcie_capability_user_read_{word,dword}()drivers/pci/access.c drivers/pci/pci.h+52 -00 replies
4/5PCI/sysfs: Use user config accessors for link attributesdrivers/pci/pci-sysfs.c+9 -50 replies
5/5PCI/sysfs: Use user config accessors for serial_numberdrivers/pci/pci-sysfs.c+15 -41 reply

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchNikita VetoshkinKeith Busch
1/5T-b R-b
2/5T-b R-b
3/5T-b R-b
4/5T-b R-b
5/5T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/5] PCI/sysfs: Wait for config access lock in sysfs attributes

Many PCI sysfs attributes that read from config space are using kernel accessors that don't wait for pci_cfg_access_lock() holders before reading:

- serial_number
- max_link_width
- current_link_*
- *_bus_number

If userspace attempts to read from these attributes while config space is not available (e.g. during a reset) there's no telling what values will be
returned: All ones, zeros, or garbage.

Looking at attribute addition history it seems like this was an oversight instead of a specific decision so this series tries to resolve the attributes above to match the sysfs attributes that do use user accessors: config & vpd.

Patch 1 is a prerequisite for the rest of the series. The kernel accessors these attributes use today skip devices marked disconnected but the user accessors don't, so switching over alone would make the attributes start sending config reads to disconnected devices. Patch 1 adds the same pci_dev_is_disconnected() check to the user read accessors.

Note: That check also affects their existing callers. On a disconnected device, VPD reads and writes, VFIO config reads, and VFIO writes to PCI_COMMAND now fail with -ENODEV, rather than returning ~0 data or, for VPD writes, timing out with a "firmware bug" warning. pciconfig_read() fails with -EIO, and the sysfs "config" file and /proc/bus/pci still return ~0 data.

Changes were successfully tested by continuously reading sysfs attributes while a reset was issued.

Changes in v2:
- Patch 5: check DSN read errors in serial_number_show() and return -EIO instead of an all-ones serial number
- Collected Reviewed-by from Keith Busch on patches 2-4

v1: https://lore.kernel.org/linux-pci/[email protected]/

Matthew Wood (5):
PCI: Add disconnected device checks to user config reads PCI/sysfs: Use user config accessors for bus number attributes
PCI: Add pcie_capability_user_read_{word,dword}() PCI/sysfs: Use user config accessors for link attributes PCI/sysfs: Use user config accessors for serial_number

 drivers/pci/access.c    | 57 +++++++++++++++++++++++++++++++++++++++--
 drivers/pci/pci-sysfs.c | 37 ++++++++++++++++++--------
 drivers/pci/pci.h       |  2 ++
 3 files changed, 83 insertions(+), 13 deletions(-)

base-commit: f4319f548f7d8cb595ac1c91bfd459876399eeb3 --
2.53.0-Meta