FAILED: patch "[PATCH] PCI/sysfs: Ensure devices are powered for config reads" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 48991e4935078b05f80616c75d1ee2ea3ae18e58
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025101636-tartar-brethren-067c@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 48991e4935078b05f80616c75d1ee2ea3ae18e58 Mon Sep 17 00:00:00 2001
From: Brian Norris <[email protected]>
Date: Wed, 24 Sep 2025 09:57:11 -0700
Subject: [PATCH] PCI/sysfs: Ensure devices are powered for config reads
The "max_link_width", "current_link_speed", "current_link_width", "secondary_bus_number", and "subordinate_bus_number" sysfs files all access config registers, but they don't check the runtime PM state. If the device is in D3cold or a parent bridge is suspended, we may see -EINVAL, bogus values, or worse, depending on implementation details.
Wrap these access in pci_config_pm_runtime_{get,put}() like most of the rest of the similar sysfs attributes.
Notably, "max_link_speed" does not access config registers; it returns a cached value since d2bd39c0456b ("PCI: Store all PCIe Supported Link Speeds").
drivers/pci/pci-sysfs.c +19 -1
@@ -201,8 +201,14 @@ static ssize_t max_link_width_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); +ssize_t ret; -return sysfs_emit (buf,"%u\n" ,pcie_get_width_cap (pdev)); +/* We read PCI_EXP_LNKCAP, so we need the device to be accessible. */ +pci_config_pm_runtime_get (pdev); + ret =sysfs_emit (buf,"%u\n" ,pcie_get_width_cap (pdev)); +pci_config_pm_runtime_put (pdev); + +return ret; }static DEVICE_ATTR_RO (max_link_width);
@@ -214,7 +220,10 @@ static ssize_t current_link_speed_show(struct device *dev,int err;enum pci_bus_speed speed; +pci_config_pm_runtime_get (pci_dev); err =pcie_capability_read_word (pci_dev,PCI_EXP_LNKSTA , &linkstat); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -231,7 +240,10 @@ static ssize_t current_link_width_show(struct device *dev,u16 linkstat;int err; +pci_config_pm_runtime_get (pci_dev); err =pcie_capability_read_word (pci_dev,PCI_EXP_LNKSTA , &linkstat); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -247,7 +259,10 @@ static ssize_t secondary_bus_number_show(struct device *dev,u8 sec_bus;int err; +pci_config_pm_runtime_get (pci_dev); err =pci_read_config_byte (pci_dev,PCI_SECONDARY_BUS , &sec_bus); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -263,7 +278,10 @@ static ssize_t subordinate_bus_number_show(struct device *dev,u8 sub_bus;int err; +pci_config_pm_runtime_get (pci_dev); err =pci_read_config_byte (pci_dev,PCI_SUBORDINATE_BUS , &sub_bus); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
Sasha Levin
maintainerPATCH 1/3 PCI: Add sysfs attribute for device power state
From: Maximilian Luz <[email protected]>
[ Upstream commit 80a129afb75cba8434fc5071bd6919172442315c ]
While PCI power states D0-D3hot can be queried from user-space via lspci, D3cold cannot. lspci cannot provide an accurate value when the device is in D3cold as it has to restore the device to D0 before it can access its power state via the configuration space, leading to it reporting D0 or another on-state. Thus lspci cannot be used to diagnose power consumption issues for devices that can enter D3cold or to ensure that devices properly enter D3cold at all.
Add a new sysfs device attribute for the PCI power state, showing the current power state as seen by the kernel.
Stable-dep-of: 48991e493507 ("PCI/sysfs: Ensure devices are powered for config reads")
--- Documentation/ABI/testing/sysfs-bus-pci | 9 +++++++++ drivers/pci/pci-sysfs.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
Documentation/ABI/testing/sysfs-bus-pci +9 -0
@@ -377,3 +377,12 @@ Contact: Heiner Kallweit <[email protected]> Description: If ASPM is supported for an endpoint, these files can be used to disable or enable the individual power management states. Write y/1/on to enable, n/0/off to disable. + +What: /sys/bus/pci/devices/.../power_state +Date: November 2020 +Contact: Linux PCI developers <[email protected]> +Description: + This file contains the current PCI power state of the device. + The value comes from the PCI kernel device state and can be one + of: "unknown", "error", "D0", D1", "D2", "D3hot", "D3cold". + The file is read only.
drivers/pci/pci-sysfs.c +10 -0
@@ -124,6 +124,15 @@ static ssize_t cpulistaffinity_show(struct device *dev, }static DEVICE_ATTR_RO (cpulistaffinity); +static ssize_t power_state_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); + +return sprintf (buf,"%s\n" ,pci_power_name (pdev->current_state)); +} +static DEVICE_ATTR_RO (power_state); +/* show resources */ static ssize_t resource_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -603,6 +612,7 @@ static ssize_t driver_override_show(struct device *dev,static DEVICE_ATTR_RW (driver_override);static struct attribute *pci_dev_attrs[] = { + &dev_attr_power_state.attr, &dev_attr_resource.attr, &dev_attr_vendor.attr, &dev_attr_device.attr,
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/3 PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit ad025f8e46f3dbf09b1bf8d7a5b4ce858df74544 ]
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1].
Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer.
No functional change intended.
[1] Documentation/filesystems/sysfs.rst
Stable-dep-of: 48991e493507 ("PCI/sysfs: Ensure devices are powered for config reads")
--- drivers/pci/pci-label.c | 10 +++--- drivers/pci/pci-sysfs.c | 72 ++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 42 deletions(-)
drivers/pci/pci-label.c +4 -6
@@ -62,13 +62,11 @@ static size_t find_smbios_instance_string(struct pci_dev *pdev, char *buf, donboard->devfn == devfn) {if (buf) {if (attribute ==SMBIOS_ATTR_INSTANCE_SHOW ) -return scnprintf (buf,PAGE_SIZE , -"%d\n" , - donboard->instance); +return sysfs_emit (buf,"%d\n" , + donboard->instance);else if (attribute ==SMBIOS_ATTR_LABEL_SHOW ) -return scnprintf (buf,PAGE_SIZE , -"%s\n" , - dmi->name); +return sysfs_emit (buf,"%s\n" , + dmi->name); }return strlen (dmi->name); }
drivers/pci/pci-sysfs.c +36 -36
209 lines not on this page · raw message
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 3/3 PCI/sysfs: Ensure devices are powered for config reads
In reply to Sasha LevinFrom: Brian Norris <[email protected]>
[ Upstream commit 48991e4935078b05f80616c75d1ee2ea3ae18e58 ]
The "max_link_width", "current_link_speed", "current_link_width", "secondary_bus_number", and "subordinate_bus_number" sysfs files all access config registers, but they don't check the runtime PM state. If the device is in D3cold or a parent bridge is suspended, we may see -EINVAL, bogus values, or worse, depending on implementation details.
Wrap these access in pci_config_pm_runtime_{get,put}() like most of the rest of the similar sysfs attributes.
Notably, "max_link_speed" does not access config registers; it returns a cached value since d2bd39c0456b ("PCI: Store all PCIe Supported Link Speeds").
--- drivers/pci/pci-sysfs.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/pci/pci-sysfs.c +19 -1
@@ -174,8 +174,14 @@ static ssize_t max_link_width_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); +ssize_t ret; -return sysfs_emit (buf,"%u\n" ,pcie_get_width_cap (pdev)); +/* We read PCI_EXP_LNKCAP, so we need the device to be accessible. */ +pci_config_pm_runtime_get (pdev); + ret =sysfs_emit (buf,"%u\n" ,pcie_get_width_cap (pdev)); +pci_config_pm_runtime_put (pdev); + +return ret; }static DEVICE_ATTR_RO (max_link_width);
@@ -187,7 +193,10 @@ static ssize_t current_link_speed_show(struct device *dev,int err;enum pci_bus_speed speed; +pci_config_pm_runtime_get (pci_dev); err =pcie_capability_read_word (pci_dev,PCI_EXP_LNKSTA , &linkstat); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -204,7 +213,10 @@ static ssize_t current_link_width_show(struct device *dev,u16 linkstat;int err; +pci_config_pm_runtime_get (pci_dev); err =pcie_capability_read_word (pci_dev,PCI_EXP_LNKSTA , &linkstat); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -221,7 +233,10 @@ static ssize_t secondary_bus_number_show(struct device *dev,u8 sec_bus;int err; +pci_config_pm_runtime_get (pci_dev); err =pci_read_config_byte (pci_dev,PCI_SECONDARY_BUS , &sec_bus); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
@@ -237,7 +252,10 @@ static ssize_t subordinate_bus_number_show(struct device *dev,u8 sub_bus;int err; +pci_config_pm_runtime_get (pci_dev); err =pci_read_config_byte (pci_dev,PCI_SUBORDINATE_BUS , &sub_bus); +pci_config_pm_runtime_put (pci_dev); +if (err)return -EINVAL ;
Signature · 1 line
2.51.0