[PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope
From: Srirangan Madhavan
Date: Fri Dec 04 2026 - 23:16:32 EST
The per-device PCI reset interface must not reset sibling functions.
Reject cxl_reset and cxl_bus for VFs, multifunction devices, including
function 0 of an ARI device that has other functions, and PFs with enabled
VFs.
Suggested-by: Alex Williamson <alwilliamson@xxxxxxxxxx>
Link: https://lore.kernel.org/linux-cxl/20260626160846.426e71b6@xxxxxxxxxx/
Link: https://lore.kernel.org/linux-cxl/6a50441e2bb5e_3cabcb1003e@djbw-dev.notmuch/
Signed-off-by: Srirangan Madhavan <smadhavan@xxxxxxxxxx>
Acked-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Reviewed-by: Richard Cheng <icheng@xxxxxxxxxx>
---
Changes in v18:
- Also reject function 0 of an ARI device when other functions share the
bus, since ->multifunction is not set for it (Sashiko)
https://sashiko.dev/#/patchset/20261105185917.2667656-1-smadhavan@xxxxxxxxxx?part=14
- Check for ARI siblings only when the reset executes. While reset methods
are probed, the device is not on its bus list yet and its siblings are not
enumerated, so the check could not tell whether siblings exist and rejected
cxl_reset and cxl_bus for the first device on an ARI-forwarding bus. Found
while testing on an ARM64 system with a CXL Type 2 device.
- Keep Bjorn's Acked-by and Richard's Reviewed-by, since only the point
where the sibling check runs changed
---
drivers/pci/cxl.c | 10 ++++++++++
drivers/pci/pci.c | 13 +++++++++++++
2 files changed, 23 insertions(+)
diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c
index c90715c5a6d5..0c60f6d7bb4f 100644
--- a/drivers/pci/cxl.c
+++ b/drivers/pci/cxl.c
@@ -579,6 +579,16 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
u16 dvsec, cap, ctrl;
int rc;
+ /*
+ * ->multifunction is not set for function 0 of an ARI device, so look
+ * for siblings on the bus. Skip this when probing: @pdev is not on the
+ * bus list yet and its siblings are not enumerated.
+ */
+ if (pdev->is_virtfn || pdev->multifunction || pci_num_vf(pdev) ||
+ (!probe && pci_ari_enabled(pdev->bus) &&
+ !list_is_singular(&pdev->bus->devices)))
+ return -ENOTTY;
+
rc = cxl_pci_device_dvsec(pdev, &dvsec, &cap);
if (rc)
return rc;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..5a8338340d23 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5064,6 +5064,19 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
u16 dvsec, reg, val;
int rc;
+ /*
+ * Reject VFs and multifunction devices before walking the bridge's
+ * capabilities: every VF behind the same bridge would repeat the walk.
+ *
+ * ->multifunction is not set for function 0 of an ARI device, so look
+ * for siblings on the bus. Skip this when probing: @dev is not on the
+ * bus list yet and its siblings are not enumerated.
+ */
+ if (dev->is_virtfn || dev->multifunction || pci_num_vf(dev) ||
+ (!probe && pci_ari_enabled(dev->bus) &&
+ !list_is_singular(&dev->bus->devices)))
+ return -ENOTTY;
+
bridge = pci_upstream_bridge(dev);
if (!bridge)
return -ENOTTY;
--
2.43.0