]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
PCI: Add 'reset_subordinate' to reset hierarchy below bridge
authorKeith Busch <kbusch@kernel.org>
Fri, 25 Oct 2024 22:27:54 +0000 (15:27 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 14 Dec 2024 18:54:48 +0000 (19:54 +0100)
[ Upstream commit 2fa046449a82a7d0f6d9721dd83e348816038444 ]

The "bus" and "cxl_bus" reset methods reset a device by asserting Secondary
Bus Reset on the bridge leading to the device.  These only work if the
device is the only device below the bridge.

Add a sysfs 'reset_subordinate' attribute on bridges that can assert
Secondary Bus Reset regardless of how many devices are below the bridge.

This resets all the devices below a bridge in a single command, including
the locking and config space save/restore that reset methods normally do.

This may be the only way to reset devices that don't support other reset
methods (ACPI, FLR, PM reset, etc).

Link: https://lore.kernel.org/r/20241025222755.3756162-1-kbusch@meta.com
Signed-off-by: Keith Busch <kbusch@kernel.org>
[bhelgaas: commit log, add capable(CAP_SYS_ADMIN) check]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Amey Narkhede <ameynarkhede03@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Documentation/ABI/testing/sysfs-bus-pci
drivers/pci/pci-sysfs.c
drivers/pci/pci.c
drivers/pci/pci.h

index 840727fc75dcf90347455225ca1df58dc80400ea..6c5ca95a94105362010b5921692440b125882489 100644 (file)
@@ -163,6 +163,17 @@ Description:
                will be present in sysfs.  Writing 1 to this file
                will perform reset.
 
+What:          /sys/bus/pci/devices/.../reset_subordinate
+Date:          October 2024
+Contact:       linux-pci@vger.kernel.org
+Description:
+               This is visible only for bridge devices. If you want to reset
+               all devices attached through the subordinate bus of a specific
+               bridge device, writing 1 to this will try to do it.  This will
+               affect all devices attached to the system through this bridge
+               similiar to writing 1 to their individual "reset" file, so use
+               with caution.
+
 What:          /sys/bus/pci/devices/.../vpd
 Date:          February 2008
 Contact:       Ben Hutchings <bwh@kernel.org>
index df1c44a5c886c5135cb04904517afbb6acd06318..e1a980179dc146b0fe6b8190608b1b23a4a5fb11 100644 (file)
@@ -517,6 +517,31 @@ static ssize_t bus_rescan_store(struct device *dev,
 static struct device_attribute dev_attr_bus_rescan = __ATTR(rescan, 0200, NULL,
                                                            bus_rescan_store);
 
+static ssize_t reset_subordinate_store(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct pci_bus *bus = pdev->subordinate;
+       unsigned long val;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       if (kstrtoul(buf, 0, &val) < 0)
+               return -EINVAL;
+
+       if (val) {
+               int ret = __pci_reset_bus(bus);
+
+               if (ret)
+                       return ret;
+       }
+
+       return count;
+}
+static DEVICE_ATTR_WO(reset_subordinate);
+
 #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
 static ssize_t d3cold_allowed_store(struct device *dev,
                                    struct device_attribute *attr,
@@ -621,6 +646,7 @@ static struct attribute *pci_dev_attrs[] = {
 static struct attribute *pci_bridge_attrs[] = {
        &dev_attr_subordinate_bus_number.attr,
        &dev_attr_secondary_bus_number.attr,
+       &dev_attr_reset_subordinate.attr,
        NULL,
 };
 
index e08354b811073f497003d09f5cb901f068fafd23..8a35a9887302df3b49cb2a14aae06f547e45840f 100644 (file)
@@ -5933,7 +5933,7 @@ EXPORT_SYMBOL_GPL(pci_probe_reset_bus);
  *
  * Same as above except return -EAGAIN if the bus cannot be locked
  */
-static int __pci_reset_bus(struct pci_bus *bus)
+int __pci_reset_bus(struct pci_bus *bus)
 {
        int rc;
 
index 5d5813aa5b45895e9effaf8c3c6a3587a34e33c9..38ad75ce52c3204a77ddc4bf62e58449825a28c3 100644 (file)
@@ -37,6 +37,7 @@ bool pci_reset_supported(struct pci_dev *dev);
 void pci_init_reset_methods(struct pci_dev *dev);
 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
 int pci_bus_error_reset(struct pci_dev *dev);
+int __pci_reset_bus(struct pci_bus *bus);
 
 struct pci_cap_saved_data {
        u16             cap_nr;