Skip to contentSkip to conversation

PCI: Don't reset a VF through its hotplug slot

PATCH New Samiullah Khawaja 2 participants 2 messages Nov 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Don't reset a VF through its hotplug slot

pci_dev_reset_slot_function() doesn't do a slot reset of a multifunction device, because the reset would also reset the other functions. A VF is not marked as multifunction, so this check doesn't catch it.

A VF on the same bus as its PF gets the PF's hotplug slot, so behind a pciehp port the VF has the "bus" reset method. A slot reset of the VF also resets the PF and all other VFs, and only the VF's state is restored afterwards.

Fixes 10791141a6cf ("PCI: Simplify pci_dev_reset_slot_function()")

---
Tested in QEMU with an igb PF behind a pciehp root port, bound to vfio-pci with two VFs. Without this patch the VFs have "flr bus" in reset_method, and a bus reset of one VF also resets the PF and the other VF. With it the VFs only have "flr".

---
 drivers/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/pci.c +2 -1
index 7c6f2aba8144..16e970d26b51 100644
@@ -4994,7 +4994,8 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, bool probe)
 {
 	if (dev->subordinate || !dev->slot ||
 	    dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET ||
-	    (dev->multifunction && !dev->slot->per_func_slot))
+	    ((dev->multifunction || dev->is_virtfn) &&
+	     !dev->slot->per_func_slot))
 		return -ENOTTY;
 
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb

Signature · 1 line
2.56.1.839.g22a8290db9-goog
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

pci_dev_reset_slot_function() doesn't do a slot reset of a multifunction device, because the reset would also reset the other functions. A VF is not marked as multifunction, so this check doesn't catch it.

Quoted 8 lines

A VF on the same bus as its PF gets the PF's hotplug slot, so behind a pciehp port the VF has the "bus" reset method. A slot reset of the VF also resets the PF and all other VFs, and only the VF's state is restored afterwards.

Fixes 10791141a6cf ("PCI: Simplify pci_dev_reset_slot_function()")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1