|
13 | 13 | #include <linux/stat.h>
|
14 | 14 | #include <linux/pci.h>
|
15 | 15 |
|
| 16 | +#include "../../../drivers/pci/pci.h" |
| 17 | + |
16 | 18 | #include <asm/sclp.h>
|
17 | 19 |
|
18 | 20 | #define zpci_attr(name, fmt, member) \
|
@@ -49,31 +51,50 @@ static DEVICE_ATTR_RO(mio_enabled);
|
49 | 51 | static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
|
50 | 52 | const char *buf, size_t count)
|
51 | 53 | {
|
| 54 | + struct kernfs_node *kn; |
52 | 55 | struct pci_dev *pdev = to_pci_dev(dev);
|
53 | 56 | struct zpci_dev *zdev = to_zpci(pdev);
|
54 |
| - int ret; |
55 |
| - |
56 |
| - if (!device_remove_file_self(dev, attr)) |
57 |
| - return count; |
58 |
| - |
| 57 | + int ret = 0; |
| 58 | + |
| 59 | + /* Can't use device_remove_self() here as that would lead us to lock |
| 60 | + * the pci_rescan_remove_lock while holding the device' kernfs lock. |
| 61 | + * This would create a possible deadlock with disable_slot() which is |
| 62 | + * not directly protected by the device' kernfs lock but takes it |
| 63 | + * during the device removal which happens under |
| 64 | + * pci_rescan_remove_lock. |
| 65 | + * |
| 66 | + * This is analogous to sdev_store_delete() in |
| 67 | + * drivers/scsi/scsi_sysfs.c |
| 68 | + */ |
| 69 | + kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); |
| 70 | + WARN_ON_ONCE(!kn); |
| 71 | + /* device_remove_file() serializes concurrent calls ignoring all but |
| 72 | + * the first |
| 73 | + */ |
| 74 | + device_remove_file(dev, attr); |
| 75 | + |
| 76 | + /* A concurrent call to recover_store() may slip between |
| 77 | + * sysfs_break_active_protection() and the sysfs file removal. |
| 78 | + * Once it unblocks from pci_lock_rescan_remove() the original pdev |
| 79 | + * will already be removed. |
| 80 | + */ |
59 | 81 | pci_lock_rescan_remove();
|
60 |
| - pci_stop_and_remove_bus_device(pdev); |
61 |
| - ret = zpci_disable_device(zdev); |
62 |
| - if (ret) |
63 |
| - goto error; |
64 |
| - |
65 |
| - ret = zpci_enable_device(zdev); |
66 |
| - if (ret) |
67 |
| - goto error; |
68 |
| - |
69 |
| - pci_rescan_bus(zdev->bus); |
| 82 | + if (pci_dev_is_added(pdev)) { |
| 83 | + pci_stop_and_remove_bus_device(pdev); |
| 84 | + ret = zpci_disable_device(zdev); |
| 85 | + if (ret) |
| 86 | + goto out; |
| 87 | + |
| 88 | + ret = zpci_enable_device(zdev); |
| 89 | + if (ret) |
| 90 | + goto out; |
| 91 | + pci_rescan_bus(zdev->bus); |
| 92 | + } |
| 93 | +out: |
70 | 94 | pci_unlock_rescan_remove();
|
71 |
| - |
72 |
| - return count; |
73 |
| - |
74 |
| -error: |
75 |
| - pci_unlock_rescan_remove(); |
76 |
| - return ret; |
| 95 | + if (kn) |
| 96 | + sysfs_unbreak_active_protection(kn); |
| 97 | + return ret ? ret : count; |
77 | 98 | }
|
78 | 99 | static DEVICE_ATTR_WO(recover);
|
79 | 100 |
|
|
0 commit comments