mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 07:33:19 +02:00
PCI: Make pci_stop_dev() concurrent safe
Use the atomic ADDED flag to ensure concurrent callers can't attempt to stop the device multiple times. Callers should currently all be holding the pci_rescan_remove_lock, so there shouldn't be an existing race. But that global lock can cause lock dependency issues, so this is preparing to reduce reliance on that lock by using the existing existing atomic bit ops. Link: https://lore.kernel.org/r/20241022224851.340648-2-kbusch@meta.com Signed-off-by: Keith Busch <kbusch@kernel.org> [bhelgaas: squash https://lore.kernel.org/r/20241111180659.3321671-1-kbusch@meta.com] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
9852d85ec9
commit
93093ea1f0
|
|
@ -348,7 +348,7 @@ void pci_bus_add_device(struct pci_dev *dev)
|
|||
if (retval < 0 && retval != -EPROBE_DEFER)
|
||||
pci_warn(dev, "device attach failed (%d)\n", retval);
|
||||
|
||||
pci_dev_assign_added(dev, true);
|
||||
pci_dev_assign_added(dev);
|
||||
|
||||
if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
|
||||
retval = of_platform_populate(dev_of_node(&dev->dev), NULL, NULL,
|
||||
|
|
|
|||
|
|
@ -470,9 +470,16 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
|
|||
#define PCI_DPC_RECOVERED 1
|
||||
#define PCI_DPC_RECOVERING 2
|
||||
|
||||
static inline void pci_dev_assign_added(struct pci_dev *dev, bool added)
|
||||
static inline void pci_dev_assign_added(struct pci_dev *dev)
|
||||
{
|
||||
assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added);
|
||||
smp_mb__before_atomic();
|
||||
set_bit(PCI_DEV_ADDED, &dev->priv_flags);
|
||||
smp_mb__after_atomic();
|
||||
}
|
||||
|
||||
static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev)
|
||||
{
|
||||
return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags);
|
||||
}
|
||||
|
||||
static inline bool pci_dev_is_added(const struct pci_dev *dev)
|
||||
|
|
|
|||
|
|
@ -33,16 +33,15 @@ static void pci_stop_dev(struct pci_dev *dev)
|
|||
{
|
||||
pci_pme_active(dev, false);
|
||||
|
||||
if (pci_dev_is_added(dev)) {
|
||||
device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev),
|
||||
pci_pwrctl_unregister);
|
||||
device_release_driver(&dev->dev);
|
||||
pci_proc_detach_device(dev);
|
||||
pci_remove_sysfs_dev_files(dev);
|
||||
of_pci_remove_node(dev);
|
||||
if (!pci_dev_test_and_clear_added(dev))
|
||||
return;
|
||||
|
||||
pci_dev_assign_added(dev, false);
|
||||
}
|
||||
device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev),
|
||||
pci_pwrctl_unregister);
|
||||
device_release_driver(&dev->dev);
|
||||
pci_proc_detach_device(dev);
|
||||
pci_remove_sysfs_dev_files(dev);
|
||||
of_pci_remove_node(dev);
|
||||
}
|
||||
|
||||
static void pci_destroy_dev(struct pci_dev *dev)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user