Skip to content

Commit 3891b6a

Browse files
Yinghai Lubjorn-helgaas
authored andcommitted
PCI: Stop all children first, before removing all children
This restores the previous behavior of stopping all child devices before removing any of them. The current SR-IOV design, where removing the PF also drops references on all the VFs, depends on having the VFs continue to exist after having been stopped. [bhelgaas: changelog] Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 94bb346 commit 3891b6a

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

‎drivers/pci/remove.c‎

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,58 @@ void pci_remove_bus(struct pci_bus *bus)
5656
}
5757
EXPORT_SYMBOL(pci_remove_bus);
5858

59-
/**
60-
* pci_stop_and_remove_bus_device - remove a PCI device and any children
61-
* @dev: the device to remove
62-
*
63-
* Remove a PCI device from the device lists, informing the drivers
64-
* that the device has been removed. We also remove any subordinate
65-
* buses and children in a depth-first manner.
66-
*
67-
* For each device we remove, delete the device structure from the
68-
* device lists, remove the /proc entry, and notify userspace
69-
* (/sbin/hotplug).
70-
*/
71-
void pci_stop_and_remove_bus_device(struct pci_dev *dev)
59+
static void pci_stop_bus_device(struct pci_dev *dev)
7260
{
7361
struct pci_bus *bus = dev->subordinate;
7462
struct pci_dev *child, *tmp;
7563

7664
/*
77-
* Removing an SR-IOV PF device removes all the associated VFs,
65+
* Stopping an SR-IOV PF device removes all the associated VFs,
7866
* which will update the bus->devices list and confuse the
7967
* iterator. Therefore, iterate in reverse so we remove the VFs
8068
* first, then the PF.
8169
*/
8270
if (bus) {
8371
list_for_each_entry_safe_reverse(child, tmp,
8472
&bus->devices, bus_list)
85-
pci_stop_and_remove_bus_device(child);
73+
pci_stop_bus_device(child);
74+
}
75+
76+
pci_stop_dev(dev);
77+
}
78+
79+
static void pci_remove_bus_device(struct pci_dev *dev)
80+
{
81+
struct pci_bus *bus = dev->subordinate;
82+
struct pci_dev *child, *tmp;
83+
84+
if (bus) {
85+
list_for_each_entry_safe(child, tmp,
86+
&bus->devices, bus_list)
87+
pci_remove_bus_device(child);
8688

8789
pci_remove_bus(bus);
8890
dev->subordinate = NULL;
8991
}
9092

91-
pci_stop_dev(dev);
9293
pci_destroy_dev(dev);
9394
}
95+
96+
/**
97+
* pci_stop_and_remove_bus_device - remove a PCI device and any children
98+
* @dev: the device to remove
99+
*
100+
* Remove a PCI device from the device lists, informing the drivers
101+
* that the device has been removed. We also remove any subordinate
102+
* buses and children in a depth-first manner.
103+
*
104+
* For each device we remove, delete the device structure from the
105+
* device lists, remove the /proc entry, and notify userspace
106+
* (/sbin/hotplug).
107+
*/
108+
void pci_stop_and_remove_bus_device(struct pci_dev *dev)
109+
{
110+
pci_stop_bus_device(dev);
111+
pci_remove_bus_device(dev);
112+
}
94113
EXPORT_SYMBOL(pci_stop_and_remove_bus_device);

0 commit comments

Comments
 (0)