diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-27 11:25:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-27 11:25:51 -0400 |
commit | 523634db145a22cd5562714d4c59ea74686afe38 (patch) | |
tree | 14f3fa773866d9afe83af9257ff0dffac84e25ac | |
parent | 5168afe6ef596eaf2ff7a533b780c79ce14445e4 (diff) | |
parent | 87a30e1f05d73a34e6d1895065541369131aaf1c (diff) |
Merge tag 'libnvdimm-fixes-5.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm fixes from Dan Williams:
"A collection of locking and async operations fixes for v5.3-rc2. These
had been soaking in a branch targeting the merge window, but missed
due to a regression hunt. This fixed up version has otherwise been in
-next this past week with no reported issues.
In order to gain confidence in the locking changes the pull also
includes a debug / instrumentation patch to enable lockdep coverage
for libnvdimm subsystem operations that depend on the device_lock for
exclusion. As mentioned in the changelog it is a hack, but it works
and documents the locking expectations of the sub-system in a way that
others can use lockdep to verify. The driver core touches got an ack
from Greg.
Summary:
- Fix duplicate device_unregister() calls (multiple threads competing
to do unregister work when scheduling device removal from a sysfs
attribute of the self-same device).
- Fix badblocks registration order bug. Ensure region badblocks are
initialized in advance of namespace registration.
- Fix a deadlock between the bus lock and probe operations.
- Export device-core infrastructure to coordinate async operations
via the device ->dead state.
- Add device-core infrastructure to validate device_lock() usage with
lockdep"
* tag 'libnvdimm-fixes-5.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm:
driver-core, libnvdimm: Let device subsystems add local lockdep coverage
libnvdimm/bus: Fix wait_nvdimm_bus_probe_idle() ABBA deadlock
libnvdimm/bus: Stop holding nvdimm_bus_list_mutex over __nd_ioctl()
libnvdimm/bus: Prepare the nd_ioctl() path to be re-entrant
libnvdimm/region: Register badblocks before namespaces
libnvdimm/bus: Prevent duplicate device_unregister() calls
drivers/base: Introduce kill_device()
-rw-r--r-- | drivers/acpi/nfit/core.c | 28 | ||||
-rw-r--r-- | drivers/acpi/nfit/nfit.h | 24 | ||||
-rw-r--r-- | drivers/base/core.c | 30 | ||||
-rw-r--r-- | drivers/nvdimm/btt_devs.c | 16 | ||||
-rw-r--r-- | drivers/nvdimm/bus.c | 210 | ||||
-rw-r--r-- | drivers/nvdimm/core.c | 10 | ||||
-rw-r--r-- | drivers/nvdimm/dimm_devs.c | 4 | ||||
-rw-r--r-- | drivers/nvdimm/namespace_devs.c | 36 | ||||
-rw-r--r-- | drivers/nvdimm/nd-core.h | 71 | ||||
-rw-r--r-- | drivers/nvdimm/pfn_devs.c | 24 | ||||
-rw-r--r-- | drivers/nvdimm/pmem.c | 4 | ||||
-rw-r--r-- | drivers/nvdimm/region.c | 24 | ||||
-rw-r--r-- | drivers/nvdimm/region_devs.c | 12 | ||||
-rw-r--r-- | include/linux/device.h | 6 |
14 files changed, 343 insertions, 156 deletions
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index c02fa27dd3f3..1413324982f0 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c | |||
@@ -1282,7 +1282,7 @@ static ssize_t hw_error_scrub_store(struct device *dev, | |||
1282 | if (rc) | 1282 | if (rc) |
1283 | return rc; | 1283 | return rc; |
1284 | 1284 | ||
1285 | device_lock(dev); | 1285 | nfit_device_lock(dev); |
1286 | nd_desc = dev_get_drvdata(dev); | 1286 | nd_desc = dev_get_drvdata(dev); |
1287 | if (nd_desc) { | 1287 | if (nd_desc) { |
1288 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); | 1288 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
@@ -1299,7 +1299,7 @@ static ssize_t hw_error_scrub_store(struct device *dev, | |||
1299 | break; | 1299 | break; |
1300 | } | 1300 | } |
1301 | } | 1301 | } |
1302 | device_unlock(dev); | 1302 | nfit_device_unlock(dev); |
1303 | if (rc) | 1303 | if (rc) |
1304 | return rc; | 1304 | return rc; |
1305 | return size; | 1305 | return size; |
@@ -1319,7 +1319,7 @@ static ssize_t scrub_show(struct device *dev, | |||
1319 | ssize_t rc = -ENXIO; | 1319 | ssize_t rc = -ENXIO; |
1320 | bool busy; | 1320 | bool busy; |
1321 | 1321 | ||
1322 | device_lock(dev); | 1322 | nfit_device_lock(dev); |
1323 | nd_desc = dev_get_drvdata(dev); | 1323 | nd_desc = dev_get_drvdata(dev); |
1324 | if (!nd_desc) { | 1324 | if (!nd_desc) { |
1325 | device_unlock(dev); | 1325 | device_unlock(dev); |
@@ -1339,7 +1339,7 @@ static ssize_t scrub_show(struct device *dev, | |||
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | mutex_unlock(&acpi_desc->init_mutex); | 1341 | mutex_unlock(&acpi_desc->init_mutex); |
1342 | device_unlock(dev); | 1342 | nfit_device_unlock(dev); |
1343 | return rc; | 1343 | return rc; |
1344 | } | 1344 | } |
1345 | 1345 | ||
@@ -1356,14 +1356,14 @@ static ssize_t scrub_store(struct device *dev, | |||
1356 | if (val != 1) | 1356 | if (val != 1) |
1357 | return -EINVAL; | 1357 | return -EINVAL; |
1358 | 1358 | ||
1359 | device_lock(dev); | 1359 | nfit_device_lock(dev); |
1360 | nd_desc = dev_get_drvdata(dev); | 1360 | nd_desc = dev_get_drvdata(dev); |
1361 | if (nd_desc) { | 1361 | if (nd_desc) { |
1362 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); | 1362 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
1363 | 1363 | ||
1364 | rc = acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG); | 1364 | rc = acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG); |
1365 | } | 1365 | } |
1366 | device_unlock(dev); | 1366 | nfit_device_unlock(dev); |
1367 | if (rc) | 1367 | if (rc) |
1368 | return rc; | 1368 | return rc; |
1369 | return size; | 1369 | return size; |
@@ -1749,9 +1749,9 @@ static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data) | |||
1749 | struct acpi_device *adev = data; | 1749 | struct acpi_device *adev = data; |
1750 | struct device *dev = &adev->dev; | 1750 | struct device *dev = &adev->dev; |
1751 | 1751 | ||
1752 | device_lock(dev->parent); | 1752 | nfit_device_lock(dev->parent); |
1753 | __acpi_nvdimm_notify(dev, event); | 1753 | __acpi_nvdimm_notify(dev, event); |
1754 | device_unlock(dev->parent); | 1754 | nfit_device_unlock(dev->parent); |
1755 | } | 1755 | } |
1756 | 1756 | ||
1757 | static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method) | 1757 | static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method) |
@@ -3457,8 +3457,8 @@ static int acpi_nfit_flush_probe(struct nvdimm_bus_descriptor *nd_desc) | |||
3457 | struct device *dev = acpi_desc->dev; | 3457 | struct device *dev = acpi_desc->dev; |
3458 | 3458 | ||
3459 | /* Bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */ | 3459 | /* Bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */ |
3460 | device_lock(dev); | 3460 | nfit_device_lock(dev); |
3461 | device_unlock(dev); | 3461 | nfit_device_unlock(dev); |
3462 | 3462 | ||
3463 | /* Bounce the init_mutex to complete initial registration */ | 3463 | /* Bounce the init_mutex to complete initial registration */ |
3464 | mutex_lock(&acpi_desc->init_mutex); | 3464 | mutex_lock(&acpi_desc->init_mutex); |
@@ -3602,8 +3602,8 @@ void acpi_nfit_shutdown(void *data) | |||
3602 | * acpi_nfit_ars_rescan() submissions have had a chance to | 3602 | * acpi_nfit_ars_rescan() submissions have had a chance to |
3603 | * either submit or see ->cancel set. | 3603 | * either submit or see ->cancel set. |
3604 | */ | 3604 | */ |
3605 | device_lock(bus_dev); | 3605 | nfit_device_lock(bus_dev); |
3606 | device_unlock(bus_dev); | 3606 | nfit_device_unlock(bus_dev); |
3607 | 3607 | ||
3608 | flush_workqueue(nfit_wq); | 3608 | flush_workqueue(nfit_wq); |
3609 | } | 3609 | } |
@@ -3746,9 +3746,9 @@ EXPORT_SYMBOL_GPL(__acpi_nfit_notify); | |||
3746 | 3746 | ||
3747 | static void acpi_nfit_notify(struct acpi_device *adev, u32 event) | 3747 | static void acpi_nfit_notify(struct acpi_device *adev, u32 event) |
3748 | { | 3748 | { |
3749 | device_lock(&adev->dev); | 3749 | nfit_device_lock(&adev->dev); |
3750 | __acpi_nfit_notify(&adev->dev, adev->handle, event); | 3750 | __acpi_nfit_notify(&adev->dev, adev->handle, event); |
3751 | device_unlock(&adev->dev); | 3751 | nfit_device_unlock(&adev->dev); |
3752 | } | 3752 | } |
3753 | 3753 | ||
3754 | static const struct acpi_device_id acpi_nfit_ids[] = { | 3754 | static const struct acpi_device_id acpi_nfit_ids[] = { |
diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h index 6ee2b02af73e..24241941181c 100644 --- a/drivers/acpi/nfit/nfit.h +++ b/drivers/acpi/nfit/nfit.h | |||
@@ -312,6 +312,30 @@ static inline struct acpi_nfit_desc *to_acpi_desc( | |||
312 | return container_of(nd_desc, struct acpi_nfit_desc, nd_desc); | 312 | return container_of(nd_desc, struct acpi_nfit_desc, nd_desc); |
313 | } | 313 | } |
314 | 314 | ||
315 | #ifdef CONFIG_PROVE_LOCKING | ||
316 | static inline void nfit_device_lock(struct device *dev) | ||
317 | { | ||
318 | device_lock(dev); | ||
319 | mutex_lock(&dev->lockdep_mutex); | ||
320 | } | ||
321 | |||
322 | static inline void nfit_device_unlock(struct device *dev) | ||
323 | { | ||
324 | mutex_unlock(&dev->lockdep_mutex); | ||
325 | device_unlock(dev); | ||
326 | } | ||
327 | #else | ||
328 | static inline void nfit_device_lock(struct device *dev) | ||
329 | { | ||
330 | device_lock(dev); | ||
331 | } | ||
332 | |||
333 | static inline void nfit_device_unlock(struct device *dev) | ||
334 | { | ||
335 | device_unlock(dev); | ||
336 | } | ||
337 | #endif | ||
338 | |||
315 | const guid_t *to_nfit_uuid(enum nfit_uuids id); | 339 | const guid_t *to_nfit_uuid(enum nfit_uuids id); |
316 | int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz); | 340 | int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz); |
317 | void acpi_nfit_shutdown(void *data); | 341 | void acpi_nfit_shutdown(void *data); |
diff --git a/drivers/base/core.c b/drivers/base/core.c index da84a73f2ba6..636058bbf48a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1663,6 +1663,9 @@ void device_initialize(struct device *dev) | |||
1663 | kobject_init(&dev->kobj, &device_ktype); | 1663 | kobject_init(&dev->kobj, &device_ktype); |
1664 | INIT_LIST_HEAD(&dev->dma_pools); | 1664 | INIT_LIST_HEAD(&dev->dma_pools); |
1665 | mutex_init(&dev->mutex); | 1665 | mutex_init(&dev->mutex); |
1666 | #ifdef CONFIG_PROVE_LOCKING | ||
1667 | mutex_init(&dev->lockdep_mutex); | ||
1668 | #endif | ||
1666 | lockdep_set_novalidate_class(&dev->mutex); | 1669 | lockdep_set_novalidate_class(&dev->mutex); |
1667 | spin_lock_init(&dev->devres_lock); | 1670 | spin_lock_init(&dev->devres_lock); |
1668 | INIT_LIST_HEAD(&dev->devres_head); | 1671 | INIT_LIST_HEAD(&dev->devres_head); |
@@ -2211,6 +2214,24 @@ void put_device(struct device *dev) | |||
2211 | } | 2214 | } |
2212 | EXPORT_SYMBOL_GPL(put_device); | 2215 | EXPORT_SYMBOL_GPL(put_device); |
2213 | 2216 | ||
2217 | bool kill_device(struct device *dev) | ||
2218 | { | ||
2219 | /* | ||
2220 | * Require the device lock and set the "dead" flag to guarantee that | ||
2221 | * the update behavior is consistent with the other bitfields near | ||
2222 | * it and that we cannot have an asynchronous probe routine trying | ||
2223 | * to run while we are tearing out the bus/class/sysfs from | ||
2224 | * underneath the device. | ||
2225 | */ | ||
2226 | lockdep_assert_held(&dev->mutex); | ||
2227 | |||
2228 | if (dev->p->dead) | ||
2229 | return false; | ||
2230 | dev->p->dead = true; | ||
2231 | return true; | ||
2232 | } | ||
2233 | EXPORT_SYMBOL_GPL(kill_device); | ||
2234 | |||
2214 | /** | 2235 | /** |
2215 | * device_del - delete device from system. | 2236 | * device_del - delete device from system. |
2216 | * @dev: device. | 2237 | * @dev: device. |
@@ -2230,15 +2251,8 @@ void device_del(struct device *dev) | |||
2230 | struct kobject *glue_dir = NULL; | 2251 | struct kobject *glue_dir = NULL; |
2231 | struct class_interface *class_intf; | 2252 | struct class_interface *class_intf; |
2232 | 2253 | ||
2233 | /* | ||
2234 | * Hold the device lock and set the "dead" flag to guarantee that | ||
2235 | * the update behavior is consistent with the other bitfields near | ||
2236 | * it and that we cannot have an asynchronous probe routine trying | ||
2237 | * to run while we are tearing out the bus/class/sysfs from | ||
2238 | * underneath the device. | ||
2239 | */ | ||
2240 | device_lock(dev); | 2254 | device_lock(dev); |
2241 | dev->p->dead = true; | 2255 | kill_device(dev); |
2242 | device_unlock(dev); | 2256 | device_unlock(dev); |
2243 | 2257 | ||
2244 | /* Notify clients of device removal. This call must come | 2258 | /* Notify clients of device removal. This call must come |
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index 62d00fffa4af..3508a79110c7 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c | |||
@@ -62,14 +62,14 @@ static ssize_t sector_size_store(struct device *dev, | |||
62 | struct nd_btt *nd_btt = to_nd_btt(dev); | 62 | struct nd_btt *nd_btt = to_nd_btt(dev); |
63 | ssize_t rc; | 63 | ssize_t rc; |
64 | 64 | ||
65 | device_lock(dev); | 65 | nd_device_lock(dev); |
66 | nvdimm_bus_lock(dev); | 66 | nvdimm_bus_lock(dev); |
67 | rc = nd_size_select_store(dev, buf, &nd_btt->lbasize, | 67 | rc = nd_size_select_store(dev, buf, &nd_btt->lbasize, |
68 | btt_lbasize_supported); | 68 | btt_lbasize_supported); |
69 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 69 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
70 | buf[len - 1] == '\n' ? "" : "\n"); | 70 | buf[len - 1] == '\n' ? "" : "\n"); |
71 | nvdimm_bus_unlock(dev); | 71 | nvdimm_bus_unlock(dev); |
72 | device_unlock(dev); | 72 | nd_device_unlock(dev); |
73 | 73 | ||
74 | return rc ? rc : len; | 74 | return rc ? rc : len; |
75 | } | 75 | } |
@@ -91,11 +91,11 @@ static ssize_t uuid_store(struct device *dev, | |||
91 | struct nd_btt *nd_btt = to_nd_btt(dev); | 91 | struct nd_btt *nd_btt = to_nd_btt(dev); |
92 | ssize_t rc; | 92 | ssize_t rc; |
93 | 93 | ||
94 | device_lock(dev); | 94 | nd_device_lock(dev); |
95 | rc = nd_uuid_store(dev, &nd_btt->uuid, buf, len); | 95 | rc = nd_uuid_store(dev, &nd_btt->uuid, buf, len); |
96 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 96 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
97 | buf[len - 1] == '\n' ? "" : "\n"); | 97 | buf[len - 1] == '\n' ? "" : "\n"); |
98 | device_unlock(dev); | 98 | nd_device_unlock(dev); |
99 | 99 | ||
100 | return rc ? rc : len; | 100 | return rc ? rc : len; |
101 | } | 101 | } |
@@ -120,13 +120,13 @@ static ssize_t namespace_store(struct device *dev, | |||
120 | struct nd_btt *nd_btt = to_nd_btt(dev); | 120 | struct nd_btt *nd_btt = to_nd_btt(dev); |
121 | ssize_t rc; | 121 | ssize_t rc; |
122 | 122 | ||
123 | device_lock(dev); | 123 | nd_device_lock(dev); |
124 | nvdimm_bus_lock(dev); | 124 | nvdimm_bus_lock(dev); |
125 | rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len); | 125 | rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len); |
126 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 126 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
127 | buf[len - 1] == '\n' ? "" : "\n"); | 127 | buf[len - 1] == '\n' ? "" : "\n"); |
128 | nvdimm_bus_unlock(dev); | 128 | nvdimm_bus_unlock(dev); |
129 | device_unlock(dev); | 129 | nd_device_unlock(dev); |
130 | 130 | ||
131 | return rc; | 131 | return rc; |
132 | } | 132 | } |
@@ -138,14 +138,14 @@ static ssize_t size_show(struct device *dev, | |||
138 | struct nd_btt *nd_btt = to_nd_btt(dev); | 138 | struct nd_btt *nd_btt = to_nd_btt(dev); |
139 | ssize_t rc; | 139 | ssize_t rc; |
140 | 140 | ||
141 | device_lock(dev); | 141 | nd_device_lock(dev); |
142 | if (dev->driver) | 142 | if (dev->driver) |
143 | rc = sprintf(buf, "%llu\n", nd_btt->size); | 143 | rc = sprintf(buf, "%llu\n", nd_btt->size); |
144 | else { | 144 | else { |
145 | /* no size to convey if the btt instance is disabled */ | 145 | /* no size to convey if the btt instance is disabled */ |
146 | rc = -ENXIO; | 146 | rc = -ENXIO; |
147 | } | 147 | } |
148 | device_unlock(dev); | 148 | nd_device_unlock(dev); |
149 | 149 | ||
150 | return rc; | 150 | return rc; |
151 | } | 151 | } |
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 2dca3034fee0..798c5c4aea9c 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | int nvdimm_major; | 27 | int nvdimm_major; |
28 | static int nvdimm_bus_major; | 28 | static int nvdimm_bus_major; |
29 | static struct class *nd_class; | 29 | struct class *nd_class; |
30 | static DEFINE_IDA(nd_ida); | 30 | static DEFINE_IDA(nd_ida); |
31 | 31 | ||
32 | static int to_nd_device_type(struct device *dev) | 32 | static int to_nd_device_type(struct device *dev) |
@@ -73,7 +73,7 @@ static void nvdimm_bus_probe_end(struct nvdimm_bus *nvdimm_bus) | |||
73 | { | 73 | { |
74 | nvdimm_bus_lock(&nvdimm_bus->dev); | 74 | nvdimm_bus_lock(&nvdimm_bus->dev); |
75 | if (--nvdimm_bus->probe_active == 0) | 75 | if (--nvdimm_bus->probe_active == 0) |
76 | wake_up(&nvdimm_bus->probe_wait); | 76 | wake_up(&nvdimm_bus->wait); |
77 | nvdimm_bus_unlock(&nvdimm_bus->dev); | 77 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
78 | } | 78 | } |
79 | 79 | ||
@@ -91,7 +91,10 @@ static int nvdimm_bus_probe(struct device *dev) | |||
91 | dev->driver->name, dev_name(dev)); | 91 | dev->driver->name, dev_name(dev)); |
92 | 92 | ||
93 | nvdimm_bus_probe_start(nvdimm_bus); | 93 | nvdimm_bus_probe_start(nvdimm_bus); |
94 | debug_nvdimm_lock(dev); | ||
94 | rc = nd_drv->probe(dev); | 95 | rc = nd_drv->probe(dev); |
96 | debug_nvdimm_unlock(dev); | ||
97 | |||
95 | if (rc == 0) | 98 | if (rc == 0) |
96 | nd_region_probe_success(nvdimm_bus, dev); | 99 | nd_region_probe_success(nvdimm_bus, dev); |
97 | else | 100 | else |
@@ -113,8 +116,11 @@ static int nvdimm_bus_remove(struct device *dev) | |||
113 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); | 116 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); |
114 | int rc = 0; | 117 | int rc = 0; |
115 | 118 | ||
116 | if (nd_drv->remove) | 119 | if (nd_drv->remove) { |
120 | debug_nvdimm_lock(dev); | ||
117 | rc = nd_drv->remove(dev); | 121 | rc = nd_drv->remove(dev); |
122 | debug_nvdimm_unlock(dev); | ||
123 | } | ||
118 | nd_region_disable(nvdimm_bus, dev); | 124 | nd_region_disable(nvdimm_bus, dev); |
119 | 125 | ||
120 | dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name, | 126 | dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name, |
@@ -140,7 +146,7 @@ static void nvdimm_bus_shutdown(struct device *dev) | |||
140 | 146 | ||
141 | void nd_device_notify(struct device *dev, enum nvdimm_event event) | 147 | void nd_device_notify(struct device *dev, enum nvdimm_event event) |
142 | { | 148 | { |
143 | device_lock(dev); | 149 | nd_device_lock(dev); |
144 | if (dev->driver) { | 150 | if (dev->driver) { |
145 | struct nd_device_driver *nd_drv; | 151 | struct nd_device_driver *nd_drv; |
146 | 152 | ||
@@ -148,7 +154,7 @@ void nd_device_notify(struct device *dev, enum nvdimm_event event) | |||
148 | if (nd_drv->notify) | 154 | if (nd_drv->notify) |
149 | nd_drv->notify(dev, event); | 155 | nd_drv->notify(dev, event); |
150 | } | 156 | } |
151 | device_unlock(dev); | 157 | nd_device_unlock(dev); |
152 | } | 158 | } |
153 | EXPORT_SYMBOL(nd_device_notify); | 159 | EXPORT_SYMBOL(nd_device_notify); |
154 | 160 | ||
@@ -296,7 +302,7 @@ static void nvdimm_bus_release(struct device *dev) | |||
296 | kfree(nvdimm_bus); | 302 | kfree(nvdimm_bus); |
297 | } | 303 | } |
298 | 304 | ||
299 | static bool is_nvdimm_bus(struct device *dev) | 305 | bool is_nvdimm_bus(struct device *dev) |
300 | { | 306 | { |
301 | return dev->release == nvdimm_bus_release; | 307 | return dev->release == nvdimm_bus_release; |
302 | } | 308 | } |
@@ -341,7 +347,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent, | |||
341 | return NULL; | 347 | return NULL; |
342 | INIT_LIST_HEAD(&nvdimm_bus->list); | 348 | INIT_LIST_HEAD(&nvdimm_bus->list); |
343 | INIT_LIST_HEAD(&nvdimm_bus->mapping_list); | 349 | INIT_LIST_HEAD(&nvdimm_bus->mapping_list); |
344 | init_waitqueue_head(&nvdimm_bus->probe_wait); | 350 | init_waitqueue_head(&nvdimm_bus->wait); |
345 | nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL); | 351 | nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL); |
346 | if (nvdimm_bus->id < 0) { | 352 | if (nvdimm_bus->id < 0) { |
347 | kfree(nvdimm_bus); | 353 | kfree(nvdimm_bus); |
@@ -426,6 +432,9 @@ static int nd_bus_remove(struct device *dev) | |||
426 | list_del_init(&nvdimm_bus->list); | 432 | list_del_init(&nvdimm_bus->list); |
427 | mutex_unlock(&nvdimm_bus_list_mutex); | 433 | mutex_unlock(&nvdimm_bus_list_mutex); |
428 | 434 | ||
435 | wait_event(nvdimm_bus->wait, | ||
436 | atomic_read(&nvdimm_bus->ioctl_active) == 0); | ||
437 | |||
429 | nd_synchronize(); | 438 | nd_synchronize(); |
430 | device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister); | 439 | device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister); |
431 | 440 | ||
@@ -547,13 +556,38 @@ EXPORT_SYMBOL(nd_device_register); | |||
547 | 556 | ||
548 | void nd_device_unregister(struct device *dev, enum nd_async_mode mode) | 557 | void nd_device_unregister(struct device *dev, enum nd_async_mode mode) |
549 | { | 558 | { |
559 | bool killed; | ||
560 | |||
550 | switch (mode) { | 561 | switch (mode) { |
551 | case ND_ASYNC: | 562 | case ND_ASYNC: |
563 | /* | ||
564 | * In the async case this is being triggered with the | ||
565 | * device lock held and the unregistration work needs to | ||
566 | * be moved out of line iff this is thread has won the | ||
567 | * race to schedule the deletion. | ||
568 | */ | ||
569 | if (!kill_device(dev)) | ||
570 | return; | ||
571 | |||
552 | get_device(dev); | 572 | get_device(dev); |
553 | async_schedule_domain(nd_async_device_unregister, dev, | 573 | async_schedule_domain(nd_async_device_unregister, dev, |
554 | &nd_async_domain); | 574 | &nd_async_domain); |
555 | break; | 575 | break; |
556 | case ND_SYNC: | 576 | case ND_SYNC: |
577 | /* | ||
578 | * In the sync case the device is being unregistered due | ||
579 | * to a state change of the parent. Claim the kill state | ||
580 | * to synchronize against other unregistration requests, | ||
581 | * or otherwise let the async path handle it if the | ||
582 | * unregistration was already queued. | ||
583 | */ | ||
584 | nd_device_lock(dev); | ||
585 | killed = kill_device(dev); | ||
586 | nd_device_unlock(dev); | ||
587 | |||
588 | if (!killed) | ||
589 | return; | ||
590 | |||
557 | nd_synchronize(); | 591 | nd_synchronize(); |
558 | device_unregister(dev); | 592 | device_unregister(dev); |
559 | break; | 593 | break; |
@@ -859,10 +893,12 @@ void wait_nvdimm_bus_probe_idle(struct device *dev) | |||
859 | do { | 893 | do { |
860 | if (nvdimm_bus->probe_active == 0) | 894 | if (nvdimm_bus->probe_active == 0) |
861 | break; | 895 | break; |
862 | nvdimm_bus_unlock(&nvdimm_bus->dev); | 896 | nvdimm_bus_unlock(dev); |
863 | wait_event(nvdimm_bus->probe_wait, | 897 | nd_device_unlock(dev); |
898 | wait_event(nvdimm_bus->wait, | ||
864 | nvdimm_bus->probe_active == 0); | 899 | nvdimm_bus->probe_active == 0); |
865 | nvdimm_bus_lock(&nvdimm_bus->dev); | 900 | nd_device_lock(dev); |
901 | nvdimm_bus_lock(dev); | ||
866 | } while (true); | 902 | } while (true); |
867 | } | 903 | } |
868 | 904 | ||
@@ -945,20 +981,19 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
945 | int read_only, unsigned int ioctl_cmd, unsigned long arg) | 981 | int read_only, unsigned int ioctl_cmd, unsigned long arg) |
946 | { | 982 | { |
947 | struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; | 983 | struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; |
948 | static char out_env[ND_CMD_MAX_ENVELOPE]; | ||
949 | static char in_env[ND_CMD_MAX_ENVELOPE]; | ||
950 | const struct nd_cmd_desc *desc = NULL; | 984 | const struct nd_cmd_desc *desc = NULL; |
951 | unsigned int cmd = _IOC_NR(ioctl_cmd); | 985 | unsigned int cmd = _IOC_NR(ioctl_cmd); |
952 | struct device *dev = &nvdimm_bus->dev; | 986 | struct device *dev = &nvdimm_bus->dev; |
953 | void __user *p = (void __user *) arg; | 987 | void __user *p = (void __user *) arg; |
988 | char *out_env = NULL, *in_env = NULL; | ||
954 | const char *cmd_name, *dimm_name; | 989 | const char *cmd_name, *dimm_name; |
955 | u32 in_len = 0, out_len = 0; | 990 | u32 in_len = 0, out_len = 0; |
956 | unsigned int func = cmd; | 991 | unsigned int func = cmd; |
957 | unsigned long cmd_mask; | 992 | unsigned long cmd_mask; |
958 | struct nd_cmd_pkg pkg; | 993 | struct nd_cmd_pkg pkg; |
959 | int rc, i, cmd_rc; | 994 | int rc, i, cmd_rc; |
995 | void *buf = NULL; | ||
960 | u64 buf_len = 0; | 996 | u64 buf_len = 0; |
961 | void *buf; | ||
962 | 997 | ||
963 | if (nvdimm) { | 998 | if (nvdimm) { |
964 | desc = nd_cmd_dimm_desc(cmd); | 999 | desc = nd_cmd_dimm_desc(cmd); |
@@ -989,7 +1024,7 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
989 | case ND_CMD_ARS_START: | 1024 | case ND_CMD_ARS_START: |
990 | case ND_CMD_CLEAR_ERROR: | 1025 | case ND_CMD_CLEAR_ERROR: |
991 | case ND_CMD_CALL: | 1026 | case ND_CMD_CALL: |
992 | dev_dbg(&nvdimm_bus->dev, "'%s' command while read-only.\n", | 1027 | dev_dbg(dev, "'%s' command while read-only.\n", |
993 | nvdimm ? nvdimm_cmd_name(cmd) | 1028 | nvdimm ? nvdimm_cmd_name(cmd) |
994 | : nvdimm_bus_cmd_name(cmd)); | 1029 | : nvdimm_bus_cmd_name(cmd)); |
995 | return -EPERM; | 1030 | return -EPERM; |
@@ -998,6 +1033,9 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
998 | } | 1033 | } |
999 | 1034 | ||
1000 | /* process an input envelope */ | 1035 | /* process an input envelope */ |
1036 | in_env = kzalloc(ND_CMD_MAX_ENVELOPE, GFP_KERNEL); | ||
1037 | if (!in_env) | ||
1038 | return -ENOMEM; | ||
1001 | for (i = 0; i < desc->in_num; i++) { | 1039 | for (i = 0; i < desc->in_num; i++) { |
1002 | u32 in_size, copy; | 1040 | u32 in_size, copy; |
1003 | 1041 | ||
@@ -1005,14 +1043,17 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
1005 | if (in_size == UINT_MAX) { | 1043 | if (in_size == UINT_MAX) { |
1006 | dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n", | 1044 | dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n", |
1007 | __func__, dimm_name, cmd_name, i); | 1045 | __func__, dimm_name, cmd_name, i); |
1008 | return -ENXIO; | 1046 | rc = -ENXIO; |
1047 | goto out; | ||
1009 | } | 1048 | } |
1010 | if (in_len < sizeof(in_env)) | 1049 | if (in_len < ND_CMD_MAX_ENVELOPE) |
1011 | copy = min_t(u32, sizeof(in_env) - in_len, in_size); | 1050 | copy = min_t(u32, ND_CMD_MAX_ENVELOPE - in_len, in_size); |
1012 | else | 1051 | else |
1013 | copy = 0; | 1052 | copy = 0; |
1014 | if (copy && copy_from_user(&in_env[in_len], p + in_len, copy)) | 1053 | if (copy && copy_from_user(&in_env[in_len], p + in_len, copy)) { |
1015 | return -EFAULT; | 1054 | rc = -EFAULT; |
1055 | goto out; | ||
1056 | } | ||
1016 | in_len += in_size; | 1057 | in_len += in_size; |
1017 | } | 1058 | } |
1018 | 1059 | ||
@@ -1024,6 +1065,12 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
1024 | } | 1065 | } |
1025 | 1066 | ||
1026 | /* process an output envelope */ | 1067 | /* process an output envelope */ |
1068 | out_env = kzalloc(ND_CMD_MAX_ENVELOPE, GFP_KERNEL); | ||
1069 | if (!out_env) { | ||
1070 | rc = -ENOMEM; | ||
1071 | goto out; | ||
1072 | } | ||
1073 | |||
1027 | for (i = 0; i < desc->out_num; i++) { | 1074 | for (i = 0; i < desc->out_num; i++) { |
1028 | u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, | 1075 | u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, |
1029 | (u32 *) in_env, (u32 *) out_env, 0); | 1076 | (u32 *) in_env, (u32 *) out_env, 0); |
@@ -1032,15 +1079,18 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
1032 | if (out_size == UINT_MAX) { | 1079 | if (out_size == UINT_MAX) { |
1033 | dev_dbg(dev, "%s unknown output size cmd: %s field: %d\n", | 1080 | dev_dbg(dev, "%s unknown output size cmd: %s field: %d\n", |
1034 | dimm_name, cmd_name, i); | 1081 | dimm_name, cmd_name, i); |
1035 | return -EFAULT; | 1082 | rc = -EFAULT; |
1083 | goto out; | ||
1036 | } | 1084 | } |
1037 | if (out_len < sizeof(out_env)) | 1085 | if (out_len < ND_CMD_MAX_ENVELOPE) |
1038 | copy = min_t(u32, sizeof(out_env) - out_len, out_size); | 1086 | copy = min_t(u32, ND_CMD_MAX_ENVELOPE - out_len, out_size); |
1039 | else | 1087 | else |
1040 | copy = 0; | 1088 | copy = 0; |
1041 | if (copy && copy_from_user(&out_env[out_len], | 1089 | if (copy && copy_from_user(&out_env[out_len], |
1042 | p + in_len + out_len, copy)) | 1090 | p + in_len + out_len, copy)) { |
1043 | return -EFAULT; | 1091 | rc = -EFAULT; |
1092 | goto out; | ||
1093 | } | ||
1044 | out_len += out_size; | 1094 | out_len += out_size; |
1045 | } | 1095 | } |
1046 | 1096 | ||
@@ -1048,19 +1098,23 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
1048 | if (buf_len > ND_IOCTL_MAX_BUFLEN) { | 1098 | if (buf_len > ND_IOCTL_MAX_BUFLEN) { |
1049 | dev_dbg(dev, "%s cmd: %s buf_len: %llu > %d\n", dimm_name, | 1099 | dev_dbg(dev, "%s cmd: %s buf_len: %llu > %d\n", dimm_name, |
1050 | cmd_name, buf_len, ND_IOCTL_MAX_BUFLEN); | 1100 | cmd_name, buf_len, ND_IOCTL_MAX_BUFLEN); |
1051 | return -EINVAL; | 1101 | rc = -EINVAL; |
1102 | goto out; | ||
1052 | } | 1103 | } |
1053 | 1104 | ||
1054 | buf = vmalloc(buf_len); | 1105 | buf = vmalloc(buf_len); |
1055 | if (!buf) | 1106 | if (!buf) { |
1056 | return -ENOMEM; | 1107 | rc = -ENOMEM; |
1108 | goto out; | ||
1109 | } | ||
1057 | 1110 | ||
1058 | if (copy_from_user(buf, p, buf_len)) { | 1111 | if (copy_from_user(buf, p, buf_len)) { |
1059 | rc = -EFAULT; | 1112 | rc = -EFAULT; |
1060 | goto out; | 1113 | goto out; |
1061 | } | 1114 | } |
1062 | 1115 | ||
1063 | nvdimm_bus_lock(&nvdimm_bus->dev); | 1116 | nd_device_lock(dev); |
1117 | nvdimm_bus_lock(dev); | ||
1064 | rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf); | 1118 | rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf); |
1065 | if (rc) | 1119 | if (rc) |
1066 | goto out_unlock; | 1120 | goto out_unlock; |
@@ -1075,39 +1129,24 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, | |||
1075 | nvdimm_account_cleared_poison(nvdimm_bus, clear_err->address, | 1129 | nvdimm_account_cleared_poison(nvdimm_bus, clear_err->address, |
1076 | clear_err->cleared); | 1130 | clear_err->cleared); |
1077 | } | 1131 | } |
1078 | nvdimm_bus_unlock(&nvdimm_bus->dev); | ||
1079 | 1132 | ||
1080 | if (copy_to_user(p, buf, buf_len)) | 1133 | if (copy_to_user(p, buf, buf_len)) |
1081 | rc = -EFAULT; | 1134 | rc = -EFAULT; |
1082 | 1135 | ||
1083 | vfree(buf); | 1136 | out_unlock: |
1084 | return rc; | 1137 | nvdimm_bus_unlock(dev); |
1085 | 1138 | nd_device_unlock(dev); | |
1086 | out_unlock: | 1139 | out: |
1087 | nvdimm_bus_unlock(&nvdimm_bus->dev); | 1140 | kfree(in_env); |
1088 | out: | 1141 | kfree(out_env); |
1089 | vfree(buf); | 1142 | vfree(buf); |
1090 | return rc; | 1143 | return rc; |
1091 | } | 1144 | } |
1092 | 1145 | ||
1093 | static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 1146 | enum nd_ioctl_mode { |
1094 | { | 1147 | BUS_IOCTL, |
1095 | long id = (long) file->private_data; | 1148 | DIMM_IOCTL, |
1096 | int rc = -ENXIO, ro; | 1149 | }; |
1097 | struct nvdimm_bus *nvdimm_bus; | ||
1098 | |||
1099 | ro = ((file->f_flags & O_ACCMODE) == O_RDONLY); | ||
1100 | mutex_lock(&nvdimm_bus_list_mutex); | ||
1101 | list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { | ||
1102 | if (nvdimm_bus->id == id) { | ||
1103 | rc = __nd_ioctl(nvdimm_bus, NULL, ro, cmd, arg); | ||
1104 | break; | ||
1105 | } | ||
1106 | } | ||
1107 | mutex_unlock(&nvdimm_bus_list_mutex); | ||
1108 | |||
1109 | return rc; | ||
1110 | } | ||
1111 | 1150 | ||
1112 | static int match_dimm(struct device *dev, void *data) | 1151 | static int match_dimm(struct device *dev, void *data) |
1113 | { | 1152 | { |
@@ -1122,31 +1161,62 @@ static int match_dimm(struct device *dev, void *data) | |||
1122 | return 0; | 1161 | return 0; |
1123 | } | 1162 | } |
1124 | 1163 | ||
1125 | static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 1164 | static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg, |
1165 | enum nd_ioctl_mode mode) | ||
1166 | |||
1126 | { | 1167 | { |
1127 | int rc = -ENXIO, ro; | 1168 | struct nvdimm_bus *nvdimm_bus, *found = NULL; |
1128 | struct nvdimm_bus *nvdimm_bus; | 1169 | long id = (long) file->private_data; |
1170 | struct nvdimm *nvdimm = NULL; | ||
1171 | int rc, ro; | ||
1129 | 1172 | ||
1130 | ro = ((file->f_flags & O_ACCMODE) == O_RDONLY); | 1173 | ro = ((file->f_flags & O_ACCMODE) == O_RDONLY); |
1131 | mutex_lock(&nvdimm_bus_list_mutex); | 1174 | mutex_lock(&nvdimm_bus_list_mutex); |
1132 | list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { | 1175 | list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { |
1133 | struct device *dev = device_find_child(&nvdimm_bus->dev, | 1176 | if (mode == DIMM_IOCTL) { |
1134 | file->private_data, match_dimm); | 1177 | struct device *dev; |
1135 | struct nvdimm *nvdimm; | 1178 | |
1136 | 1179 | dev = device_find_child(&nvdimm_bus->dev, | |
1137 | if (!dev) | 1180 | file->private_data, match_dimm); |
1138 | continue; | 1181 | if (!dev) |
1182 | continue; | ||
1183 | nvdimm = to_nvdimm(dev); | ||
1184 | found = nvdimm_bus; | ||
1185 | } else if (nvdimm_bus->id == id) { | ||
1186 | found = nvdimm_bus; | ||
1187 | } | ||
1139 | 1188 | ||
1140 | nvdimm = to_nvdimm(dev); | 1189 | if (found) { |
1141 | rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg); | 1190 | atomic_inc(&nvdimm_bus->ioctl_active); |
1142 | put_device(dev); | 1191 | break; |
1143 | break; | 1192 | } |
1144 | } | 1193 | } |
1145 | mutex_unlock(&nvdimm_bus_list_mutex); | 1194 | mutex_unlock(&nvdimm_bus_list_mutex); |
1146 | 1195 | ||
1196 | if (!found) | ||
1197 | return -ENXIO; | ||
1198 | |||
1199 | nvdimm_bus = found; | ||
1200 | rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg); | ||
1201 | |||
1202 | if (nvdimm) | ||
1203 | put_device(&nvdimm->dev); | ||
1204 | if (atomic_dec_and_test(&nvdimm_bus->ioctl_active)) | ||
1205 | wake_up(&nvdimm_bus->wait); | ||
1206 | |||
1147 | return rc; | 1207 | return rc; |
1148 | } | 1208 | } |
1149 | 1209 | ||
1210 | static long bus_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
1211 | { | ||
1212 | return nd_ioctl(file, cmd, arg, BUS_IOCTL); | ||
1213 | } | ||
1214 | |||
1215 | static long dimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
1216 | { | ||
1217 | return nd_ioctl(file, cmd, arg, DIMM_IOCTL); | ||
1218 | } | ||
1219 | |||
1150 | static int nd_open(struct inode *inode, struct file *file) | 1220 | static int nd_open(struct inode *inode, struct file *file) |
1151 | { | 1221 | { |
1152 | long minor = iminor(inode); | 1222 | long minor = iminor(inode); |
@@ -1158,16 +1228,16 @@ static int nd_open(struct inode *inode, struct file *file) | |||
1158 | static const struct file_operations nvdimm_bus_fops = { | 1228 | static const struct file_operations nvdimm_bus_fops = { |
1159 | .owner = THIS_MODULE, | 1229 | .owner = THIS_MODULE, |
1160 | .open = nd_open, | 1230 | .open = nd_open, |
1161 | .unlocked_ioctl = nd_ioctl, | 1231 | .unlocked_ioctl = bus_ioctl, |
1162 | .compat_ioctl = nd_ioctl, | 1232 | .compat_ioctl = bus_ioctl, |
1163 | .llseek = noop_llseek, | 1233 | .llseek = noop_llseek, |
1164 | }; | 1234 | }; |
1165 | 1235 | ||
1166 | static const struct file_operations nvdimm_fops = { | 1236 | static const struct file_operations nvdimm_fops = { |
1167 | .owner = THIS_MODULE, | 1237 | .owner = THIS_MODULE, |
1168 | .open = nd_open, | 1238 | .open = nd_open, |
1169 | .unlocked_ioctl = nvdimm_ioctl, | 1239 | .unlocked_ioctl = dimm_ioctl, |
1170 | .compat_ioctl = nvdimm_ioctl, | 1240 | .compat_ioctl = dimm_ioctl, |
1171 | .llseek = noop_llseek, | 1241 | .llseek = noop_llseek, |
1172 | }; | 1242 | }; |
1173 | 1243 | ||
diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c index 5e1f060547bf..9204f1e9fd14 100644 --- a/drivers/nvdimm/core.c +++ b/drivers/nvdimm/core.c | |||
@@ -246,7 +246,7 @@ static int nd_uuid_parse(struct device *dev, u8 *uuid_out, const char *buf, | |||
246 | * | 246 | * |
247 | * Enforce that uuids can only be changed while the device is disabled | 247 | * Enforce that uuids can only be changed while the device is disabled |
248 | * (driver detached) | 248 | * (driver detached) |
249 | * LOCKING: expects device_lock() is held on entry | 249 | * LOCKING: expects nd_device_lock() is held on entry |
250 | */ | 250 | */ |
251 | int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf, | 251 | int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf, |
252 | size_t len) | 252 | size_t len) |
@@ -347,15 +347,15 @@ static DEVICE_ATTR_RO(provider); | |||
347 | 347 | ||
348 | static int flush_namespaces(struct device *dev, void *data) | 348 | static int flush_namespaces(struct device *dev, void *data) |
349 | { | 349 | { |
350 | device_lock(dev); | 350 | nd_device_lock(dev); |
351 | device_unlock(dev); | 351 | nd_device_unlock(dev); |
352 | return 0; | 352 | return 0; |
353 | } | 353 | } |
354 | 354 | ||
355 | static int flush_regions_dimms(struct device *dev, void *data) | 355 | static int flush_regions_dimms(struct device *dev, void *data) |
356 | { | 356 | { |
357 | device_lock(dev); | 357 | nd_device_lock(dev); |
358 | device_unlock(dev); | 358 | nd_device_unlock(dev); |
359 | device_for_each_child(dev, NULL, flush_namespaces); | 359 | device_for_each_child(dev, NULL, flush_namespaces); |
360 | return 0; | 360 | return 0; |
361 | } | 361 | } |
diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index dfecd6e17043..29a065e769ea 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c | |||
@@ -484,12 +484,12 @@ static ssize_t security_store(struct device *dev, | |||
484 | * done while probing is idle and the DIMM is not in active use | 484 | * done while probing is idle and the DIMM is not in active use |
485 | * in any region. | 485 | * in any region. |
486 | */ | 486 | */ |
487 | device_lock(dev); | 487 | nd_device_lock(dev); |
488 | nvdimm_bus_lock(dev); | 488 | nvdimm_bus_lock(dev); |
489 | wait_nvdimm_bus_probe_idle(dev); | 489 | wait_nvdimm_bus_probe_idle(dev); |
490 | rc = __security_store(dev, buf, len); | 490 | rc = __security_store(dev, buf, len); |
491 | nvdimm_bus_unlock(dev); | 491 | nvdimm_bus_unlock(dev); |
492 | device_unlock(dev); | 492 | nd_device_unlock(dev); |
493 | 493 | ||
494 | return rc; | 494 | return rc; |
495 | } | 495 | } |
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 2d8d7e554877..a16e52251a30 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c | |||
@@ -410,7 +410,7 @@ static ssize_t alt_name_store(struct device *dev, | |||
410 | struct nd_region *nd_region = to_nd_region(dev->parent); | 410 | struct nd_region *nd_region = to_nd_region(dev->parent); |
411 | ssize_t rc; | 411 | ssize_t rc; |
412 | 412 | ||
413 | device_lock(dev); | 413 | nd_device_lock(dev); |
414 | nvdimm_bus_lock(dev); | 414 | nvdimm_bus_lock(dev); |
415 | wait_nvdimm_bus_probe_idle(dev); | 415 | wait_nvdimm_bus_probe_idle(dev); |
416 | rc = __alt_name_store(dev, buf, len); | 416 | rc = __alt_name_store(dev, buf, len); |
@@ -418,7 +418,7 @@ static ssize_t alt_name_store(struct device *dev, | |||
418 | rc = nd_namespace_label_update(nd_region, dev); | 418 | rc = nd_namespace_label_update(nd_region, dev); |
419 | dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); | 419 | dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); |
420 | nvdimm_bus_unlock(dev); | 420 | nvdimm_bus_unlock(dev); |
421 | device_unlock(dev); | 421 | nd_device_unlock(dev); |
422 | 422 | ||
423 | return rc < 0 ? rc : len; | 423 | return rc < 0 ? rc : len; |
424 | } | 424 | } |
@@ -1077,7 +1077,7 @@ static ssize_t size_store(struct device *dev, | |||
1077 | if (rc) | 1077 | if (rc) |
1078 | return rc; | 1078 | return rc; |
1079 | 1079 | ||
1080 | device_lock(dev); | 1080 | nd_device_lock(dev); |
1081 | nvdimm_bus_lock(dev); | 1081 | nvdimm_bus_lock(dev); |
1082 | wait_nvdimm_bus_probe_idle(dev); | 1082 | wait_nvdimm_bus_probe_idle(dev); |
1083 | rc = __size_store(dev, val); | 1083 | rc = __size_store(dev, val); |
@@ -1103,7 +1103,7 @@ static ssize_t size_store(struct device *dev, | |||
1103 | dev_dbg(dev, "%llx %s (%d)\n", val, rc < 0 ? "fail" : "success", rc); | 1103 | dev_dbg(dev, "%llx %s (%d)\n", val, rc < 0 ? "fail" : "success", rc); |
1104 | 1104 | ||
1105 | nvdimm_bus_unlock(dev); | 1105 | nvdimm_bus_unlock(dev); |
1106 | device_unlock(dev); | 1106 | nd_device_unlock(dev); |
1107 | 1107 | ||
1108 | return rc < 0 ? rc : len; | 1108 | return rc < 0 ? rc : len; |
1109 | } | 1109 | } |
@@ -1286,7 +1286,7 @@ static ssize_t uuid_store(struct device *dev, | |||
1286 | } else | 1286 | } else |
1287 | return -ENXIO; | 1287 | return -ENXIO; |
1288 | 1288 | ||
1289 | device_lock(dev); | 1289 | nd_device_lock(dev); |
1290 | nvdimm_bus_lock(dev); | 1290 | nvdimm_bus_lock(dev); |
1291 | wait_nvdimm_bus_probe_idle(dev); | 1291 | wait_nvdimm_bus_probe_idle(dev); |
1292 | if (to_ndns(dev)->claim) | 1292 | if (to_ndns(dev)->claim) |
@@ -1302,7 +1302,7 @@ static ssize_t uuid_store(struct device *dev, | |||
1302 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 1302 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
1303 | buf[len - 1] == '\n' ? "" : "\n"); | 1303 | buf[len - 1] == '\n' ? "" : "\n"); |
1304 | nvdimm_bus_unlock(dev); | 1304 | nvdimm_bus_unlock(dev); |
1305 | device_unlock(dev); | 1305 | nd_device_unlock(dev); |
1306 | 1306 | ||
1307 | return rc < 0 ? rc : len; | 1307 | return rc < 0 ? rc : len; |
1308 | } | 1308 | } |
@@ -1376,7 +1376,7 @@ static ssize_t sector_size_store(struct device *dev, | |||
1376 | } else | 1376 | } else |
1377 | return -ENXIO; | 1377 | return -ENXIO; |
1378 | 1378 | ||
1379 | device_lock(dev); | 1379 | nd_device_lock(dev); |
1380 | nvdimm_bus_lock(dev); | 1380 | nvdimm_bus_lock(dev); |
1381 | if (to_ndns(dev)->claim) | 1381 | if (to_ndns(dev)->claim) |
1382 | rc = -EBUSY; | 1382 | rc = -EBUSY; |
@@ -1387,7 +1387,7 @@ static ssize_t sector_size_store(struct device *dev, | |||
1387 | dev_dbg(dev, "result: %zd %s: %s%s", rc, rc < 0 ? "tried" : "wrote", | 1387 | dev_dbg(dev, "result: %zd %s: %s%s", rc, rc < 0 ? "tried" : "wrote", |
1388 | buf, buf[len - 1] == '\n' ? "" : "\n"); | 1388 | buf, buf[len - 1] == '\n' ? "" : "\n"); |
1389 | nvdimm_bus_unlock(dev); | 1389 | nvdimm_bus_unlock(dev); |
1390 | device_unlock(dev); | 1390 | nd_device_unlock(dev); |
1391 | 1391 | ||
1392 | return rc ? rc : len; | 1392 | return rc ? rc : len; |
1393 | } | 1393 | } |
@@ -1502,9 +1502,9 @@ static ssize_t holder_show(struct device *dev, | |||
1502 | struct nd_namespace_common *ndns = to_ndns(dev); | 1502 | struct nd_namespace_common *ndns = to_ndns(dev); |
1503 | ssize_t rc; | 1503 | ssize_t rc; |
1504 | 1504 | ||
1505 | device_lock(dev); | 1505 | nd_device_lock(dev); |
1506 | rc = sprintf(buf, "%s\n", ndns->claim ? dev_name(ndns->claim) : ""); | 1506 | rc = sprintf(buf, "%s\n", ndns->claim ? dev_name(ndns->claim) : ""); |
1507 | device_unlock(dev); | 1507 | nd_device_unlock(dev); |
1508 | 1508 | ||
1509 | return rc; | 1509 | return rc; |
1510 | } | 1510 | } |
@@ -1541,7 +1541,7 @@ static ssize_t holder_class_store(struct device *dev, | |||
1541 | struct nd_region *nd_region = to_nd_region(dev->parent); | 1541 | struct nd_region *nd_region = to_nd_region(dev->parent); |
1542 | ssize_t rc; | 1542 | ssize_t rc; |
1543 | 1543 | ||
1544 | device_lock(dev); | 1544 | nd_device_lock(dev); |
1545 | nvdimm_bus_lock(dev); | 1545 | nvdimm_bus_lock(dev); |
1546 | wait_nvdimm_bus_probe_idle(dev); | 1546 | wait_nvdimm_bus_probe_idle(dev); |
1547 | rc = __holder_class_store(dev, buf); | 1547 | rc = __holder_class_store(dev, buf); |
@@ -1549,7 +1549,7 @@ static ssize_t holder_class_store(struct device *dev, | |||
1549 | rc = nd_namespace_label_update(nd_region, dev); | 1549 | rc = nd_namespace_label_update(nd_region, dev); |
1550 | dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); | 1550 | dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); |
1551 | nvdimm_bus_unlock(dev); | 1551 | nvdimm_bus_unlock(dev); |
1552 | device_unlock(dev); | 1552 | nd_device_unlock(dev); |
1553 | 1553 | ||
1554 | return rc < 0 ? rc : len; | 1554 | return rc < 0 ? rc : len; |
1555 | } | 1555 | } |
@@ -1560,7 +1560,7 @@ static ssize_t holder_class_show(struct device *dev, | |||
1560 | struct nd_namespace_common *ndns = to_ndns(dev); | 1560 | struct nd_namespace_common *ndns = to_ndns(dev); |
1561 | ssize_t rc; | 1561 | ssize_t rc; |
1562 | 1562 | ||
1563 | device_lock(dev); | 1563 | nd_device_lock(dev); |
1564 | if (ndns->claim_class == NVDIMM_CCLASS_NONE) | 1564 | if (ndns->claim_class == NVDIMM_CCLASS_NONE) |
1565 | rc = sprintf(buf, "\n"); | 1565 | rc = sprintf(buf, "\n"); |
1566 | else if ((ndns->claim_class == NVDIMM_CCLASS_BTT) || | 1566 | else if ((ndns->claim_class == NVDIMM_CCLASS_BTT) || |
@@ -1572,7 +1572,7 @@ static ssize_t holder_class_show(struct device *dev, | |||
1572 | rc = sprintf(buf, "dax\n"); | 1572 | rc = sprintf(buf, "dax\n"); |
1573 | else | 1573 | else |
1574 | rc = sprintf(buf, "<unknown>\n"); | 1574 | rc = sprintf(buf, "<unknown>\n"); |
1575 | device_unlock(dev); | 1575 | nd_device_unlock(dev); |
1576 | 1576 | ||
1577 | return rc; | 1577 | return rc; |
1578 | } | 1578 | } |
@@ -1586,7 +1586,7 @@ static ssize_t mode_show(struct device *dev, | |||
1586 | char *mode; | 1586 | char *mode; |
1587 | ssize_t rc; | 1587 | ssize_t rc; |
1588 | 1588 | ||
1589 | device_lock(dev); | 1589 | nd_device_lock(dev); |
1590 | claim = ndns->claim; | 1590 | claim = ndns->claim; |
1591 | if (claim && is_nd_btt(claim)) | 1591 | if (claim && is_nd_btt(claim)) |
1592 | mode = "safe"; | 1592 | mode = "safe"; |
@@ -1599,7 +1599,7 @@ static ssize_t mode_show(struct device *dev, | |||
1599 | else | 1599 | else |
1600 | mode = "raw"; | 1600 | mode = "raw"; |
1601 | rc = sprintf(buf, "%s\n", mode); | 1601 | rc = sprintf(buf, "%s\n", mode); |
1602 | device_unlock(dev); | 1602 | nd_device_unlock(dev); |
1603 | 1603 | ||
1604 | return rc; | 1604 | return rc; |
1605 | } | 1605 | } |
@@ -1703,8 +1703,8 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev) | |||
1703 | * Flush any in-progess probes / removals in the driver | 1703 | * Flush any in-progess probes / removals in the driver |
1704 | * for the raw personality of this namespace. | 1704 | * for the raw personality of this namespace. |
1705 | */ | 1705 | */ |
1706 | device_lock(&ndns->dev); | 1706 | nd_device_lock(&ndns->dev); |
1707 | device_unlock(&ndns->dev); | 1707 | nd_device_unlock(&ndns->dev); |
1708 | if (ndns->dev.driver) { | 1708 | if (ndns->dev.driver) { |
1709 | dev_dbg(&ndns->dev, "is active, can't bind %s\n", | 1709 | dev_dbg(&ndns->dev, "is active, can't bind %s\n", |
1710 | dev_name(dev)); | 1710 | dev_name(dev)); |
diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index 391e88de3a29..0ac52b6eb00e 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/sizes.h> | 9 | #include <linux/sizes.h> |
10 | #include <linux/mutex.h> | 10 | #include <linux/mutex.h> |
11 | #include <linux/nd.h> | 11 | #include <linux/nd.h> |
12 | #include "nd.h" | ||
12 | 13 | ||
13 | extern struct list_head nvdimm_bus_list; | 14 | extern struct list_head nvdimm_bus_list; |
14 | extern struct mutex nvdimm_bus_list_mutex; | 15 | extern struct mutex nvdimm_bus_list_mutex; |
@@ -17,10 +18,11 @@ extern struct workqueue_struct *nvdimm_wq; | |||
17 | 18 | ||
18 | struct nvdimm_bus { | 19 | struct nvdimm_bus { |
19 | struct nvdimm_bus_descriptor *nd_desc; | 20 | struct nvdimm_bus_descriptor *nd_desc; |
20 | wait_queue_head_t probe_wait; | 21 | wait_queue_head_t wait; |
21 | struct list_head list; | 22 | struct list_head list; |
22 | struct device dev; | 23 | struct device dev; |
23 | int id, probe_active; | 24 | int id, probe_active; |
25 | atomic_t ioctl_active; | ||
24 | struct list_head mapping_list; | 26 | struct list_head mapping_list; |
25 | struct mutex reconfig_mutex; | 27 | struct mutex reconfig_mutex; |
26 | struct badrange badrange; | 28 | struct badrange badrange; |
@@ -181,4 +183,71 @@ ssize_t nd_namespace_store(struct device *dev, | |||
181 | struct nd_namespace_common **_ndns, const char *buf, | 183 | struct nd_namespace_common **_ndns, const char *buf, |
182 | size_t len); | 184 | size_t len); |
183 | struct nd_pfn *to_nd_pfn_safe(struct device *dev); | 185 | struct nd_pfn *to_nd_pfn_safe(struct device *dev); |
186 | bool is_nvdimm_bus(struct device *dev); | ||
187 | |||
188 | #ifdef CONFIG_PROVE_LOCKING | ||
189 | extern struct class *nd_class; | ||
190 | |||
191 | enum { | ||
192 | LOCK_BUS, | ||
193 | LOCK_NDCTL, | ||
194 | LOCK_REGION, | ||
195 | LOCK_DIMM = LOCK_REGION, | ||
196 | LOCK_NAMESPACE, | ||
197 | LOCK_CLAIM, | ||
198 | }; | ||
199 | |||
200 | static inline void debug_nvdimm_lock(struct device *dev) | ||
201 | { | ||
202 | if (is_nd_region(dev)) | ||
203 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_REGION); | ||
204 | else if (is_nvdimm(dev)) | ||
205 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_DIMM); | ||
206 | else if (is_nd_btt(dev) || is_nd_pfn(dev) || is_nd_dax(dev)) | ||
207 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_CLAIM); | ||
208 | else if (dev->parent && (is_nd_region(dev->parent))) | ||
209 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_NAMESPACE); | ||
210 | else if (is_nvdimm_bus(dev)) | ||
211 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_BUS); | ||
212 | else if (dev->class && dev->class == nd_class) | ||
213 | mutex_lock_nested(&dev->lockdep_mutex, LOCK_NDCTL); | ||
214 | else | ||
215 | dev_WARN(dev, "unknown lock level\n"); | ||
216 | } | ||
217 | |||
218 | static inline void debug_nvdimm_unlock(struct device *dev) | ||
219 | { | ||
220 | mutex_unlock(&dev->lockdep_mutex); | ||
221 | } | ||
222 | |||
223 | static inline void nd_device_lock(struct device *dev) | ||
224 | { | ||
225 | device_lock(dev); | ||
226 | debug_nvdimm_lock(dev); | ||
227 | } | ||
228 | |||
229 | static inline void nd_device_unlock(struct device *dev) | ||
230 | { | ||
231 | debug_nvdimm_unlock(dev); | ||
232 | device_unlock(dev); | ||
233 | } | ||
234 | #else | ||
235 | static inline void nd_device_lock(struct device *dev) | ||
236 | { | ||
237 | device_lock(dev); | ||
238 | } | ||
239 | |||
240 | static inline void nd_device_unlock(struct device *dev) | ||
241 | { | ||
242 | device_unlock(dev); | ||
243 | } | ||
244 | |||
245 | static inline void debug_nvdimm_lock(struct device *dev) | ||
246 | { | ||
247 | } | ||
248 | |||
249 | static inline void debug_nvdimm_unlock(struct device *dev) | ||
250 | { | ||
251 | } | ||
252 | #endif | ||
184 | #endif /* __ND_CORE_H__ */ | 253 | #endif /* __ND_CORE_H__ */ |
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index df2bdbd22450..3e7b11cf1aae 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c | |||
@@ -67,7 +67,7 @@ static ssize_t mode_store(struct device *dev, | |||
67 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 67 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
68 | ssize_t rc = 0; | 68 | ssize_t rc = 0; |
69 | 69 | ||
70 | device_lock(dev); | 70 | nd_device_lock(dev); |
71 | nvdimm_bus_lock(dev); | 71 | nvdimm_bus_lock(dev); |
72 | if (dev->driver) | 72 | if (dev->driver) |
73 | rc = -EBUSY; | 73 | rc = -EBUSY; |
@@ -89,7 +89,7 @@ static ssize_t mode_store(struct device *dev, | |||
89 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 89 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
90 | buf[len - 1] == '\n' ? "" : "\n"); | 90 | buf[len - 1] == '\n' ? "" : "\n"); |
91 | nvdimm_bus_unlock(dev); | 91 | nvdimm_bus_unlock(dev); |
92 | device_unlock(dev); | 92 | nd_device_unlock(dev); |
93 | 93 | ||
94 | return rc ? rc : len; | 94 | return rc ? rc : len; |
95 | } | 95 | } |
@@ -132,14 +132,14 @@ static ssize_t align_store(struct device *dev, | |||
132 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 132 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
133 | ssize_t rc; | 133 | ssize_t rc; |
134 | 134 | ||
135 | device_lock(dev); | 135 | nd_device_lock(dev); |
136 | nvdimm_bus_lock(dev); | 136 | nvdimm_bus_lock(dev); |
137 | rc = nd_size_select_store(dev, buf, &nd_pfn->align, | 137 | rc = nd_size_select_store(dev, buf, &nd_pfn->align, |
138 | nd_pfn_supported_alignments()); | 138 | nd_pfn_supported_alignments()); |
139 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 139 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
140 | buf[len - 1] == '\n' ? "" : "\n"); | 140 | buf[len - 1] == '\n' ? "" : "\n"); |
141 | nvdimm_bus_unlock(dev); | 141 | nvdimm_bus_unlock(dev); |
142 | device_unlock(dev); | 142 | nd_device_unlock(dev); |
143 | 143 | ||
144 | return rc ? rc : len; | 144 | return rc ? rc : len; |
145 | } | 145 | } |
@@ -161,11 +161,11 @@ static ssize_t uuid_store(struct device *dev, | |||
161 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 161 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
162 | ssize_t rc; | 162 | ssize_t rc; |
163 | 163 | ||
164 | device_lock(dev); | 164 | nd_device_lock(dev); |
165 | rc = nd_uuid_store(dev, &nd_pfn->uuid, buf, len); | 165 | rc = nd_uuid_store(dev, &nd_pfn->uuid, buf, len); |
166 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 166 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
167 | buf[len - 1] == '\n' ? "" : "\n"); | 167 | buf[len - 1] == '\n' ? "" : "\n"); |
168 | device_unlock(dev); | 168 | nd_device_unlock(dev); |
169 | 169 | ||
170 | return rc ? rc : len; | 170 | return rc ? rc : len; |
171 | } | 171 | } |
@@ -190,13 +190,13 @@ static ssize_t namespace_store(struct device *dev, | |||
190 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 190 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
191 | ssize_t rc; | 191 | ssize_t rc; |
192 | 192 | ||
193 | device_lock(dev); | 193 | nd_device_lock(dev); |
194 | nvdimm_bus_lock(dev); | 194 | nvdimm_bus_lock(dev); |
195 | rc = nd_namespace_store(dev, &nd_pfn->ndns, buf, len); | 195 | rc = nd_namespace_store(dev, &nd_pfn->ndns, buf, len); |
196 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, | 196 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
197 | buf[len - 1] == '\n' ? "" : "\n"); | 197 | buf[len - 1] == '\n' ? "" : "\n"); |
198 | nvdimm_bus_unlock(dev); | 198 | nvdimm_bus_unlock(dev); |
199 | device_unlock(dev); | 199 | nd_device_unlock(dev); |
200 | 200 | ||
201 | return rc; | 201 | return rc; |
202 | } | 202 | } |
@@ -208,7 +208,7 @@ static ssize_t resource_show(struct device *dev, | |||
208 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 208 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
209 | ssize_t rc; | 209 | ssize_t rc; |
210 | 210 | ||
211 | device_lock(dev); | 211 | nd_device_lock(dev); |
212 | if (dev->driver) { | 212 | if (dev->driver) { |
213 | struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; | 213 | struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; |
214 | u64 offset = __le64_to_cpu(pfn_sb->dataoff); | 214 | u64 offset = __le64_to_cpu(pfn_sb->dataoff); |
@@ -222,7 +222,7 @@ static ssize_t resource_show(struct device *dev, | |||
222 | /* no address to convey if the pfn instance is disabled */ | 222 | /* no address to convey if the pfn instance is disabled */ |
223 | rc = -ENXIO; | 223 | rc = -ENXIO; |
224 | } | 224 | } |
225 | device_unlock(dev); | 225 | nd_device_unlock(dev); |
226 | 226 | ||
227 | return rc; | 227 | return rc; |
228 | } | 228 | } |
@@ -234,7 +234,7 @@ static ssize_t size_show(struct device *dev, | |||
234 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); | 234 | struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); |
235 | ssize_t rc; | 235 | ssize_t rc; |
236 | 236 | ||
237 | device_lock(dev); | 237 | nd_device_lock(dev); |
238 | if (dev->driver) { | 238 | if (dev->driver) { |
239 | struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; | 239 | struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; |
240 | u64 offset = __le64_to_cpu(pfn_sb->dataoff); | 240 | u64 offset = __le64_to_cpu(pfn_sb->dataoff); |
@@ -250,7 +250,7 @@ static ssize_t size_show(struct device *dev, | |||
250 | /* no size to convey if the pfn instance is disabled */ | 250 | /* no size to convey if the pfn instance is disabled */ |
251 | rc = -ENXIO; | 251 | rc = -ENXIO; |
252 | } | 252 | } |
253 | device_unlock(dev); | 253 | nd_device_unlock(dev); |
254 | 254 | ||
255 | return rc; | 255 | return rc; |
256 | } | 256 | } |
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 2bf3acd69613..4c121dd03dd9 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c | |||
@@ -522,8 +522,8 @@ static int nd_pmem_remove(struct device *dev) | |||
522 | nvdimm_namespace_detach_btt(to_nd_btt(dev)); | 522 | nvdimm_namespace_detach_btt(to_nd_btt(dev)); |
523 | else { | 523 | else { |
524 | /* | 524 | /* |
525 | * Note, this assumes device_lock() context to not race | 525 | * Note, this assumes nd_device_lock() context to not |
526 | * nd_pmem_notify() | 526 | * race nd_pmem_notify() |
527 | */ | 527 | */ |
528 | sysfs_put(pmem->bb_state); | 528 | sysfs_put(pmem->bb_state); |
529 | pmem->bb_state = NULL; | 529 | pmem->bb_state = NULL; |
diff --git a/drivers/nvdimm/region.c b/drivers/nvdimm/region.c index ef46cc3a71ae..37bf8719a2a4 100644 --- a/drivers/nvdimm/region.c +++ b/drivers/nvdimm/region.c | |||
@@ -34,17 +34,6 @@ static int nd_region_probe(struct device *dev) | |||
34 | if (rc) | 34 | if (rc) |
35 | return rc; | 35 | return rc; |
36 | 36 | ||
37 | rc = nd_region_register_namespaces(nd_region, &err); | ||
38 | if (rc < 0) | ||
39 | return rc; | ||
40 | |||
41 | ndrd = dev_get_drvdata(dev); | ||
42 | ndrd->ns_active = rc; | ||
43 | ndrd->ns_count = rc + err; | ||
44 | |||
45 | if (rc && err && rc == err) | ||
46 | return -ENODEV; | ||
47 | |||
48 | if (is_nd_pmem(&nd_region->dev)) { | 37 | if (is_nd_pmem(&nd_region->dev)) { |
49 | struct resource ndr_res; | 38 | struct resource ndr_res; |
50 | 39 | ||
@@ -60,6 +49,17 @@ static int nd_region_probe(struct device *dev) | |||
60 | nvdimm_badblocks_populate(nd_region, &nd_region->bb, &ndr_res); | 49 | nvdimm_badblocks_populate(nd_region, &nd_region->bb, &ndr_res); |
61 | } | 50 | } |
62 | 51 | ||
52 | rc = nd_region_register_namespaces(nd_region, &err); | ||
53 | if (rc < 0) | ||
54 | return rc; | ||
55 | |||
56 | ndrd = dev_get_drvdata(dev); | ||
57 | ndrd->ns_active = rc; | ||
58 | ndrd->ns_count = rc + err; | ||
59 | |||
60 | if (rc && err && rc == err) | ||
61 | return -ENODEV; | ||
62 | |||
63 | nd_region->btt_seed = nd_btt_create(nd_region); | 63 | nd_region->btt_seed = nd_btt_create(nd_region); |
64 | nd_region->pfn_seed = nd_pfn_create(nd_region); | 64 | nd_region->pfn_seed = nd_pfn_create(nd_region); |
65 | nd_region->dax_seed = nd_dax_create(nd_region); | 65 | nd_region->dax_seed = nd_dax_create(nd_region); |
@@ -102,7 +102,7 @@ static int nd_region_remove(struct device *dev) | |||
102 | nvdimm_bus_unlock(dev); | 102 | nvdimm_bus_unlock(dev); |
103 | 103 | ||
104 | /* | 104 | /* |
105 | * Note, this assumes device_lock() context to not race | 105 | * Note, this assumes nd_device_lock() context to not race |
106 | * nd_region_notify() | 106 | * nd_region_notify() |
107 | */ | 107 | */ |
108 | sysfs_put(nd_region->bb_state); | 108 | sysfs_put(nd_region->bb_state); |
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 56f2227f192a..af30cbe7a8ea 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c | |||
@@ -331,7 +331,7 @@ static ssize_t set_cookie_show(struct device *dev, | |||
331 | * the v1.1 namespace label cookie definition. To read all this | 331 | * the v1.1 namespace label cookie definition. To read all this |
332 | * data we need to wait for probing to settle. | 332 | * data we need to wait for probing to settle. |
333 | */ | 333 | */ |
334 | device_lock(dev); | 334 | nd_device_lock(dev); |
335 | nvdimm_bus_lock(dev); | 335 | nvdimm_bus_lock(dev); |
336 | wait_nvdimm_bus_probe_idle(dev); | 336 | wait_nvdimm_bus_probe_idle(dev); |
337 | if (nd_region->ndr_mappings) { | 337 | if (nd_region->ndr_mappings) { |
@@ -348,7 +348,7 @@ static ssize_t set_cookie_show(struct device *dev, | |||
348 | } | 348 | } |
349 | } | 349 | } |
350 | nvdimm_bus_unlock(dev); | 350 | nvdimm_bus_unlock(dev); |
351 | device_unlock(dev); | 351 | nd_device_unlock(dev); |
352 | 352 | ||
353 | if (rc) | 353 | if (rc) |
354 | return rc; | 354 | return rc; |
@@ -424,10 +424,12 @@ static ssize_t available_size_show(struct device *dev, | |||
424 | * memory nvdimm_bus_lock() is dropped, but that's userspace's | 424 | * memory nvdimm_bus_lock() is dropped, but that's userspace's |
425 | * problem to not race itself. | 425 | * problem to not race itself. |
426 | */ | 426 | */ |
427 | nd_device_lock(dev); | ||
427 | nvdimm_bus_lock(dev); | 428 | nvdimm_bus_lock(dev); |
428 | wait_nvdimm_bus_probe_idle(dev); | 429 | wait_nvdimm_bus_probe_idle(dev); |
429 | available = nd_region_available_dpa(nd_region); | 430 | available = nd_region_available_dpa(nd_region); |
430 | nvdimm_bus_unlock(dev); | 431 | nvdimm_bus_unlock(dev); |
432 | nd_device_unlock(dev); | ||
431 | 433 | ||
432 | return sprintf(buf, "%llu\n", available); | 434 | return sprintf(buf, "%llu\n", available); |
433 | } | 435 | } |
@@ -439,10 +441,12 @@ static ssize_t max_available_extent_show(struct device *dev, | |||
439 | struct nd_region *nd_region = to_nd_region(dev); | 441 | struct nd_region *nd_region = to_nd_region(dev); |
440 | unsigned long long available = 0; | 442 | unsigned long long available = 0; |
441 | 443 | ||
444 | nd_device_lock(dev); | ||
442 | nvdimm_bus_lock(dev); | 445 | nvdimm_bus_lock(dev); |
443 | wait_nvdimm_bus_probe_idle(dev); | 446 | wait_nvdimm_bus_probe_idle(dev); |
444 | available = nd_region_allocatable_dpa(nd_region); | 447 | available = nd_region_allocatable_dpa(nd_region); |
445 | nvdimm_bus_unlock(dev); | 448 | nvdimm_bus_unlock(dev); |
449 | nd_device_unlock(dev); | ||
446 | 450 | ||
447 | return sprintf(buf, "%llu\n", available); | 451 | return sprintf(buf, "%llu\n", available); |
448 | } | 452 | } |
@@ -561,12 +565,12 @@ static ssize_t region_badblocks_show(struct device *dev, | |||
561 | struct nd_region *nd_region = to_nd_region(dev); | 565 | struct nd_region *nd_region = to_nd_region(dev); |
562 | ssize_t rc; | 566 | ssize_t rc; |
563 | 567 | ||
564 | device_lock(dev); | 568 | nd_device_lock(dev); |
565 | if (dev->driver) | 569 | if (dev->driver) |
566 | rc = badblocks_show(&nd_region->bb, buf, 0); | 570 | rc = badblocks_show(&nd_region->bb, buf, 0); |
567 | else | 571 | else |
568 | rc = -ENXIO; | 572 | rc = -ENXIO; |
569 | device_unlock(dev); | 573 | nd_device_unlock(dev); |
570 | 574 | ||
571 | return rc; | 575 | return rc; |
572 | } | 576 | } |
diff --git a/include/linux/device.h b/include/linux/device.h index c330b75c6c57..6717adee33f0 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -915,6 +915,8 @@ struct dev_links_info { | |||
915 | * This identifies the device type and carries type-specific | 915 | * This identifies the device type and carries type-specific |
916 | * information. | 916 | * information. |
917 | * @mutex: Mutex to synchronize calls to its driver. | 917 | * @mutex: Mutex to synchronize calls to its driver. |
918 | * @lockdep_mutex: An optional debug lock that a subsystem can use as a | ||
919 | * peer lock to gain localized lockdep coverage of the device_lock. | ||
918 | * @bus: Type of bus device is on. | 920 | * @bus: Type of bus device is on. |
919 | * @driver: Which driver has allocated this | 921 | * @driver: Which driver has allocated this |
920 | * @platform_data: Platform data specific to the device. | 922 | * @platform_data: Platform data specific to the device. |
@@ -998,6 +1000,9 @@ struct device { | |||
998 | core doesn't touch it */ | 1000 | core doesn't touch it */ |
999 | void *driver_data; /* Driver data, set and get with | 1001 | void *driver_data; /* Driver data, set and get with |
1000 | dev_set_drvdata/dev_get_drvdata */ | 1002 | dev_set_drvdata/dev_get_drvdata */ |
1003 | #ifdef CONFIG_PROVE_LOCKING | ||
1004 | struct mutex lockdep_mutex; | ||
1005 | #endif | ||
1001 | struct mutex mutex; /* mutex to synchronize calls to | 1006 | struct mutex mutex; /* mutex to synchronize calls to |
1002 | * its driver. | 1007 | * its driver. |
1003 | */ | 1008 | */ |
@@ -1383,6 +1388,7 @@ extern int (*platform_notify_remove)(struct device *dev); | |||
1383 | */ | 1388 | */ |
1384 | extern struct device *get_device(struct device *dev); | 1389 | extern struct device *get_device(struct device *dev); |
1385 | extern void put_device(struct device *dev); | 1390 | extern void put_device(struct device *dev); |
1391 | extern bool kill_device(struct device *dev); | ||
1386 | 1392 | ||
1387 | #ifdef CONFIG_DEVTMPFS | 1393 | #ifdef CONFIG_DEVTMPFS |
1388 | extern int devtmpfs_create_node(struct device *dev); | 1394 | extern int devtmpfs_create_node(struct device *dev); |