powerpc/eeh: Fix race when freeing PDNs
When hot-adding devices we rely on the hotplug driver to create pci_dn's for the devices under the hotplug slot. Converse, when hot-removing the driver will remove the pci_dn's that it created. This is a problem because the pci_dev is still live until it's refcount drops to zero. This can happen if the driver is slow to tear down it's internal state. Ideally, the driver would not attempt to perform any config accesses to the device once it's been marked as removed, but sometimes it happens. As a result, we might attempt to access the pci_dn for a device that has been torn down and the kernel may crash as a result. To fix this, don't free the pci_dn unless the corresponding pci_dev has been released. If the pci_dev is still live, then we mark the pci_dn with a flag that indicates the pci_dev's release function should free it. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20190903101605.2890-3-oohall@gmail.com
This commit is contained in:

committed by
Michael Ellerman

parent
799abe283e
commit
5ef753ae43
@@ -55,11 +55,18 @@ EXPORT_SYMBOL_GPL(pci_find_bus_by_node);
|
||||
void pcibios_release_device(struct pci_dev *dev)
|
||||
{
|
||||
struct pci_controller *phb = pci_bus_to_host(dev->bus);
|
||||
struct pci_dn *pdn = pci_get_pdn(dev);
|
||||
|
||||
eeh_remove_device(dev);
|
||||
|
||||
if (phb->controller_ops.release_device)
|
||||
phb->controller_ops.release_device(dev);
|
||||
|
||||
/* free()ing the pci_dn has been deferred to us, do it now */
|
||||
if (pdn && (pdn->flags & PCI_DN_FLAG_DEAD)) {
|
||||
pci_dbg(dev, "freeing dead pdn\n");
|
||||
kfree(pdn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user