[PATCH V1 1/4] PCI/CXL: Don't offer 'cxl_bus' reset where a bus reset can't work

From: Vidya Sagar

Date: Thu Nov 19 2026 - 05:07:36 EST


cxl_reset_bus_function() reports the "cxl_bus" reset method as supported
whenever the device's upstream bridge has a CXL Port DVSEC. The reset
itself goes through pci_reset_bus_function(), which can only reset the
device through a hotplug slot or a Secondary Bus Reset of the parent
bridge. It returns -ENOTTY when neither is possible, e.g., when other
functions share the device's bus, when the device is a bridge, or when it
has PCI_DEV_FLAGS_NO_BUS_RESET.

"cxl_bus" is then listed in "reset_method" but always fails. For example,
on function 1 of a 4-function ConnectX-8 below a CXL-capable Root Port
without a hotplug slot, "bus" is correctly not offered, but "cxl_bus" is:

# cat /sys/bus/pci/devices/0001:01:00.1/reset_method
flr cxl_bus
# echo cxl_bus > /sys/bus/pci/devices/0001:01:00.1/reset_method
# echo 1 > /sys/bus/pci/devices/0001:01:00.1/reset
bash: echo: write error: Inappropriate ioctl for device

Each attempt still temporarily sets "Unmask SBR" in the Root Port and runs
the IOMMU reset prepare/done hooks, although no reset happens.

Move the slot and parent bus reset from pci_reset_bus_function() into a
new __pci_reset_bus_function() and use it for the "cxl_bus" probe. The
probe now makes the same slot and parent-bus checks as the "bus" probe.
"cxl_bus" is then offered under the same conditions as "bus", except for
the CXL SBR mask that "cxl_bus" exists to clear.

Fixes: 53c49b6e6dd2 ("PCI/CXL: Add 'cxl_bus' reset method for devices below CXL Ports")
Signed-off-by: Vidya Sagar <vidyas@xxxxxxxxxx>
---
drivers/pci/pci.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..921d076c4c1d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5030,6 +5030,21 @@ static bool cxl_sbr_masked(struct pci_dev *dev)
return true;
}

+/*
+ * Reset "dev" through its hotplug slot or, failing that, a Secondary Bus
+ * Reset of its parent bridge. Callers deal with CXL SBR masking.
+ */
+static int __pci_reset_bus_function(struct pci_dev *dev, bool probe)
+{
+ int rc;
+
+ rc = pci_dev_reset_slot_function(dev, probe);
+ if (rc != -ENOTTY)
+ return rc;
+
+ return pci_parent_bus_reset(dev, probe);
+}
+
static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
{
struct pci_dev *bridge = pci_upstream_bridge(dev);
@@ -5048,12 +5063,8 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
return rc;
}

- rc = pci_dev_reset_slot_function(dev, probe);
- if (rc != -ENOTTY)
- goto done;
+ rc = __pci_reset_bus_function(dev, probe);

- rc = pci_parent_bus_reset(dev, probe);
-done:
pci_dev_reset_iommu_done(dev);
return rc;
}
@@ -5072,8 +5083,12 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
if (!dvsec)
return -ENOTTY;

+ /*
+ * Unmasking SBR only helps if a slot or bus reset can reach "dev" at
+ * all, e.g., not when other functions share its bus.
+ */
if (probe)
- return 0;
+ return __pci_reset_bus_function(dev, probe);

rc = pci_read_config_word(bridge, dvsec + PCI_DVSEC_CXL_PORT_CTL, &reg);
if (rc)
--
2.43.0