History

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()

Linus Torvalds committed 7 years ago

Commit 523634d2 parents 5168afe 87a30e114 files · +343 −156Browse files

Unified · Split

14 files
  1. drivers/acpi/nfit/core.c +14 −14
  2. drivers/acpi/nfit/nfit.h +24 −0
  3. drivers/base/core.c +22 −8
  4. drivers/nvdimm/btt_devs.c +8 −8
  5. drivers/nvdimm/bus.c +140 −70
  6. drivers/nvdimm/core.c +5 −5
  7. drivers/nvdimm/dimm_devs.c +2 −2
  8. drivers/nvdimm/namespace_devs.c +18 −18
  9. drivers/nvdimm/nd-core.h +70 −1
  10. drivers/nvdimm/pfn_devs.c +12 −12
  11. drivers/nvdimm/pmem.c +2 −2
  12. drivers/nvdimm/region.c +12 −12
  13. drivers/nvdimm/region_devs.c +8 −4
  14. include/linux/device.h +6 −0
drivers/acpi/nfit/core.c+14−14
@@ -1282,7 +1282,7 @@ static ssize_t hw_error_scrub_store(struct device *dev, · 1281 unmodified lines
12821282 if (rc)
12831283 return rc;
12841284
1285− device_lock(dev);
1285+ nfit_device_lock(dev);
12861286 nd_desc = dev_get_drvdata(dev);
12871287 if (nd_desc) {
12881288 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, · 10 unmodified lines
12991299 break;
13001300 }
13011301 }
1302− device_unlock(dev);
1302+ nfit_device_unlock(dev);
13031303 if (rc)
13041304 return rc;
13051305 return size;
@@ -1319,7 +1319,7 @@ static ssize_t scrub_show(struct device *dev, · 13 unmodified lines
13191319 ssize_t rc = -ENXIO;
13201320 bool busy;
13211321
1322− device_lock(dev);
1322+ nfit_device_lock(dev);
13231323 nd_desc = dev_get_drvdata(dev);
13241324 if (!nd_desc) {
13251325 device_unlock(dev);
@@ -1339,7 +1339,7 @@ static ssize_t scrub_show(struct device *dev, · 13 unmodified lines
13391339 }
13401340
13411341 mutex_unlock(&acpi_desc->init_mutex);
1342− device_unlock(dev);
1342+ nfit_device_unlock(dev);
13431343 return rc;
13441344 }
13451345
@@ -1356,14 +1356,14 @@ static ssize_t scrub_store(struct device *dev, · 10 unmodified lines
13561356 if (val != 1)
13571357 return -EINVAL;
13581358
1359− device_lock(dev);
1359+ nfit_device_lock(dev);
13601360 nd_desc = dev_get_drvdata(dev);
13611361 if (nd_desc) {
13621362 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
13631363
13641364 rc = acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG);
13651365 }
1366− device_unlock(dev);
1366+ nfit_device_unlock(dev);
13671367 if (rc)
13681368 return rc;
13691369 return size;
@@ -1749,9 +1749,9 @@ static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data) · 379 unmodified lines
17491749 struct acpi_device *adev = data;
17501750 struct device *dev = &adev->dev;
17511751
1752− device_lock(dev->parent);
1752+ nfit_device_lock(dev->parent);
17531753 __acpi_nvdimm_notify(dev, event);
1754− device_unlock(dev->parent);
1754+ nfit_device_unlock(dev->parent);
17551755 }
17561756
17571757 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) · 1699 unmodified lines
34573457 struct device *dev = acpi_desc->dev;
34583458
34593459 /* Bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */
3460− device_lock(dev);
3461− device_unlock(dev);
3460+ nfit_device_lock(dev);
3461+ nfit_device_unlock(dev);
34623462
34633463 /* Bounce the init_mutex to complete initial registration */
34643464 mutex_lock(&acpi_desc->init_mutex);
@@ -3602,8 +3602,8 @@ void acpi_nfit_shutdown(void *data) · 137 unmodified lines
36023602 * acpi_nfit_ars_rescan() submissions have had a chance to
36033603 * either submit or see ->cancel set.
36043604 */
3605− device_lock(bus_dev);
3606− device_unlock(bus_dev);
3605+ nfit_device_lock(bus_dev);
3606+ nfit_device_unlock(bus_dev);
36073607
36083608 flush_workqueue(nfit_wq);
36093609 }
@@ -3746,9 +3746,9 @@ EXPORT_SYMBOL_GPL(__acpi_nfit_notify); · 136 unmodified lines
37463746
37473747 static void acpi_nfit_notify(struct acpi_device *adev, u32 event)
37483748 {
3749− device_lock(&adev->dev);
3749+ nfit_device_lock(&adev->dev);
37503750 __acpi_nfit_notify(&adev->dev, adev->handle, event);
3751− device_unlock(&adev->dev);
3751+ nfit_device_unlock(&adev->dev);
37523752 }
37533753
37543754 static const struct acpi_device_id acpi_nfit_ids[] = {
drivers/acpi/nfit/nfit.h+24−0
@@ -312,6 +312,30 @@ static inline struct acpi_nfit_desc *to_acpi_desc( · 311 unmodified lines
312312 return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
313313 }
314314
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+
315339 const guid_t *to_nfit_uuid(enum nfit_uuids id);
316340 int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
317341 void acpi_nfit_shutdown(void *data);
drivers/base/core.c+22−8
@@ -1663,6 +1663,9 @@ void device_initialize(struct device *dev) · 1662 unmodified lines
16631663 kobject_init(&dev->kobj, &device_ktype);
16641664 INIT_LIST_HEAD(&dev->dma_pools);
16651665 mutex_init(&dev->mutex);
1666+#ifdef CONFIG_PROVE_LOCKING
1667+ mutex_init(&dev->lockdep_mutex);
1668+#endif
16661669 lockdep_set_novalidate_class(&dev->mutex);
16671670 spin_lock_init(&dev->devres_lock);
16681671 INIT_LIST_HEAD(&dev->devres_head);
@@ -2211,6 +2214,24 @@ void put_device(struct device *dev) · 542 unmodified lines
22112214 }
22122215 EXPORT_SYMBOL_GPL(put_device);
22132216
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+
22142235 /**
22152236 * device_del - delete device from system.
22162237 * @dev: device.
@@ -2230,15 +2251,8 @@ void device_del(struct device *dev) · 13 unmodified lines
22302251 struct kobject *glue_dir = NULL;
22312252 struct class_interface *class_intf;
22322253
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− */
22402254 device_lock(dev);
2241− dev->p->dead = true;
2255+ kill_device(dev);
22422256 device_unlock(dev);
22432257
22442258 /* Notify clients of device removal. This call must come
drivers/nvdimm/btt_devs.c+8−8
@@ -62,14 +62,14 @@ static ssize_t sector_size_store(struct device *dev, · 61 unmodified lines
6262 struct nd_btt *nd_btt = to_nd_btt(dev);
6363 ssize_t rc;
6464
65− device_lock(dev);
65+ nd_device_lock(dev);
6666 nvdimm_bus_lock(dev);
6767 rc = nd_size_select_store(dev, buf, &nd_btt->lbasize,
6868 btt_lbasize_supported);
6969 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
7070 buf[len - 1] == '\n' ? "" : "\n");
7171 nvdimm_bus_unlock(dev);
72− device_unlock(dev);
72+ nd_device_unlock(dev);
7373
7474 return rc ? rc : len;
7575 }
@@ -91,11 +91,11 @@ static ssize_t uuid_store(struct device *dev, · 15 unmodified lines
9191 struct nd_btt *nd_btt = to_nd_btt(dev);
9292 ssize_t rc;
9393
94− device_lock(dev);
94+ nd_device_lock(dev);
9595 rc = nd_uuid_store(dev, &nd_btt->uuid, buf, len);
9696 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
9797 buf[len - 1] == '\n' ? "" : "\n");
98− device_unlock(dev);
98+ nd_device_unlock(dev);
9999
100100 return rc ? rc : len;
101101 }
@@ -120,13 +120,13 @@ static ssize_t namespace_store(struct device *dev, · 18 unmodified lines
120120 struct nd_btt *nd_btt = to_nd_btt(dev);
121121 ssize_t rc;
122122
123− device_lock(dev);
123+ nd_device_lock(dev);
124124 nvdimm_bus_lock(dev);
125125 rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len);
126126 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
127127 buf[len - 1] == '\n' ? "" : "\n");
128128 nvdimm_bus_unlock(dev);
129− device_unlock(dev);
129+ nd_device_unlock(dev);
130130
131131 return rc;
132132 }
@@ -138,14 +138,14 @@ static ssize_t size_show(struct device *dev, · 5 unmodified lines
138138 struct nd_btt *nd_btt = to_nd_btt(dev);
139139 ssize_t rc;
140140
141− device_lock(dev);
141+ nd_device_lock(dev);
142142 if (dev->driver)
143143 rc = sprintf(buf, "%llu\n", nd_btt->size);
144144 else {
145145 /* no size to convey if the btt instance is disabled */
146146 rc = -ENXIO;
147147 }
148− device_unlock(dev);
148+ nd_device_unlock(dev);
149149
150150 return rc;
151151 }
drivers/nvdimm/bus.c+140−70
@@ -26,7 +26,7 @@ · 25 unmodified lines
2626
2727 int nvdimm_major;
2828 static int nvdimm_bus_major;
29−static struct class *nd_class;
29+struct class *nd_class;
3030 static DEFINE_IDA(nd_ida);
3131
3232 static int to_nd_device_type(struct device *dev)
@@ -73,7 +73,7 @@ static void nvdimm_bus_probe_end(struct nvdimm_bus *nvdimm_bus) · 40 unmodified lines
7373 {
7474 nvdimm_bus_lock(&nvdimm_bus->dev);
7575 if (--nvdimm_bus->probe_active == 0)
76− wake_up(&nvdimm_bus->probe_wait);
76+ wake_up(&nvdimm_bus->wait);
7777 nvdimm_bus_unlock(&nvdimm_bus->dev);
7878 }
7979
@@ -91,7 +91,10 @@ static int nvdimm_bus_probe(struct device *dev) · 11 unmodified lines
9191 dev->driver->name, dev_name(dev));
9292
9393 nvdimm_bus_probe_start(nvdimm_bus);
94+ debug_nvdimm_lock(dev);
9495 rc = nd_drv->probe(dev);
96+ debug_nvdimm_unlock(dev);
97+
9598 if (rc == 0)
9699 nd_region_probe_success(nvdimm_bus, dev);
97100 else
@@ -113,8 +116,11 @@ static int nvdimm_bus_remove(struct device *dev) · 15 unmodified lines
113116 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
114117 int rc = 0;
115118
116− if (nd_drv->remove)
119+ if (nd_drv->remove) {
120+ debug_nvdimm_lock(dev);
117121 rc = nd_drv->remove(dev);
122+ debug_nvdimm_unlock(dev);
123+ }
118124 nd_region_disable(nvdimm_bus, dev);
119125
120126 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) · 19 unmodified lines
140146
141147 void nd_device_notify(struct device *dev, enum nvdimm_event event)
142148 {
143− device_lock(dev);
149+ nd_device_lock(dev);
144150 if (dev->driver) {
145151 struct nd_device_driver *nd_drv;
146152
@@ -148,7 +154,7 @@ void nd_device_notify(struct device *dev, enum nvdimm_event event) · 1 unmodified line
148154 if (nd_drv->notify)
149155 nd_drv->notify(dev, event);
150156 }
151− device_unlock(dev);
157+ nd_device_unlock(dev);
152158 }
153159 EXPORT_SYMBOL(nd_device_notify);
154160
@@ -296,7 +302,7 @@ static void nvdimm_bus_release(struct device *dev) · 141 unmodified lines
296302 kfree(nvdimm_bus);
297303 }
298304
299−static bool is_nvdimm_bus(struct device *dev)
305+bool is_nvdimm_bus(struct device *dev)
300306 {
301307 return dev->release == nvdimm_bus_release;
302308 }
@@ -341,7 +347,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent, · 38 unmodified lines
341347 return NULL;
342348 INIT_LIST_HEAD(&nvdimm_bus->list);
343349 INIT_LIST_HEAD(&nvdimm_bus->mapping_list);
344− init_waitqueue_head(&nvdimm_bus->probe_wait);
350+ init_waitqueue_head(&nvdimm_bus->wait);
345351 nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL);
346352 if (nvdimm_bus->id < 0) {
347353 kfree(nvdimm_bus);
@@ -426,6 +432,9 @@ static int nd_bus_remove(struct device *dev) · 78 unmodified lines
426432 list_del_init(&nvdimm_bus->list);
427433 mutex_unlock(&nvdimm_bus_list_mutex);
428434
435+ wait_event(nvdimm_bus->wait,
436+ atomic_read(&nvdimm_bus->ioctl_active) == 0);
437+
429438 nd_synchronize();
430439 device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister);
431440
@@ -547,13 +556,38 @@ EXPORT_SYMBOL(nd_device_register); · 115 unmodified lines
547556
548557 void nd_device_unregister(struct device *dev, enum nd_async_mode mode)
549558 {
559+ bool killed;
560+
550561 switch (mode) {
551562 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+
552572 get_device(dev);
553573 async_schedule_domain(nd_async_device_unregister, dev,
554574 &nd_async_domain);
555575 break;
556576 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+
557591 nd_synchronize();
558592 device_unregister(dev);
559593 break;
@@ -859,10 +893,12 @@ void wait_nvdimm_bus_probe_idle(struct device *dev) · 299 unmodified lines
859893 do {
860894 if (nvdimm_bus->probe_active == 0)
861895 break;
862− nvdimm_bus_unlock(&nvdimm_bus->dev);
863− wait_event(nvdimm_bus->probe_wait,
896+ nvdimm_bus_unlock(dev);
897+ nd_device_unlock(dev);
898+ wait_event(nvdimm_bus->wait,
864899 nvdimm_bus->probe_active == 0);
865− nvdimm_bus_lock(&nvdimm_bus->dev);
900+ nd_device_lock(dev);
901+ nvdimm_bus_lock(dev);
866902 } while (true);
867903 }
868904
@@ -945,20 +981,19 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 76 unmodified lines
945981 int read_only, unsigned int ioctl_cmd, unsigned long arg)
946982 {
947983 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];
950984 const struct nd_cmd_desc *desc = NULL;
951985 unsigned int cmd = _IOC_NR(ioctl_cmd);
952986 struct device *dev = &nvdimm_bus->dev;
953987 void __user *p = (void __user *) arg;
988+ char *out_env = NULL, *in_env = NULL;
954989 const char *cmd_name, *dimm_name;
955990 u32 in_len = 0, out_len = 0;
956991 unsigned int func = cmd;
957992 unsigned long cmd_mask;
958993 struct nd_cmd_pkg pkg;
959994 int rc, i, cmd_rc;
995+ void *buf = NULL;
960996 u64 buf_len = 0;
961− void *buf;
962997
963998 if (nvdimm) {
964999 desc = nd_cmd_dimm_desc(cmd);
@@ -989,7 +1024,7 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 24 unmodified lines
9891024 case ND_CMD_ARS_START:
9901025 case ND_CMD_CLEAR_ERROR:
9911026 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",
9931028 nvdimm ? nvdimm_cmd_name(cmd)
9941029 : nvdimm_bus_cmd_name(cmd));
9951030 return -EPERM;
@@ -998,6 +1033,9 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 2 unmodified lines
9981033 }
9991034
10001035 /* process an input envelope */
1036+ in_env = kzalloc(ND_CMD_MAX_ENVELOPE, GFP_KERNEL);
1037+ if (!in_env)
1038+ return -ENOMEM;
10011039 for (i = 0; i < desc->in_num; i++) {
10021040 u32 in_size, copy;
10031041
@@ -1005,14 +1043,17 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 1 unmodified line
10051043 if (in_size == UINT_MAX) {
10061044 dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n",
10071045 __func__, dimm_name, cmd_name, i);
1008− return -ENXIO;
1046+ rc = -ENXIO;
1047+ goto out;
10091048 }
1010− if (in_len < sizeof(in_env))
1011− copy = min_t(u32, sizeof(in_env) - in_len, in_size);
1049+ if (in_len < ND_CMD_MAX_ENVELOPE)
1050+ copy = min_t(u32, ND_CMD_MAX_ENVELOPE - in_len, in_size);
10121051 else
10131052 copy = 0;
1014− if (copy && copy_from_user(&in_env[in_len], p + in_len, copy))
1015− return -EFAULT;
1053+ if (copy && copy_from_user(&in_env[in_len], p + in_len, copy)) {
1054+ rc = -EFAULT;
1055+ goto out;
1056+ }
10161057 in_len += in_size;
10171058 }
10181059
@@ -1024,6 +1065,12 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 5 unmodified lines
10241065 }
10251066
10261067 /* 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+
10271074 for (i = 0; i < desc->out_num; i++) {
10281075 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i,
10291076 (u32 *) in_env, (u32 *) out_env, 0);
@@ -1032,15 +1079,18 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 2 unmodified lines
10321079 if (out_size == UINT_MAX) {
10331080 dev_dbg(dev, "%s unknown output size cmd: %s field: %d\n",
10341081 dimm_name, cmd_name, i);
1035− return -EFAULT;
1082+ rc = -EFAULT;
1083+ goto out;
10361084 }
1037− if (out_len < sizeof(out_env))
1038− copy = min_t(u32, sizeof(out_env) - out_len, out_size);
1085+ if (out_len < ND_CMD_MAX_ENVELOPE)
1086+ copy = min_t(u32, ND_CMD_MAX_ENVELOPE - out_len, out_size);
10391087 else
10401088 copy = 0;
10411089 if (copy && copy_from_user(&out_env[out_len],
1042− p + in_len + out_len, copy))
1043− return -EFAULT;
1090+ p + in_len + out_len, copy)) {
1091+ rc = -EFAULT;
1092+ goto out;
1093+ }
10441094 out_len += out_size;
10451095 }
10461096
@@ -1048,19 +1098,23 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 1 unmodified line
10481098 if (buf_len > ND_IOCTL_MAX_BUFLEN) {
10491099 dev_dbg(dev, "%s cmd: %s buf_len: %llu > %d\n", dimm_name,
10501100 cmd_name, buf_len, ND_IOCTL_MAX_BUFLEN);
1051− return -EINVAL;
1101+ rc = -EINVAL;
1102+ goto out;
10521103 }
10531104
10541105 buf = vmalloc(buf_len);
1055− if (!buf)
1056− return -ENOMEM;
1106+ if (!buf) {
1107+ rc = -ENOMEM;
1108+ goto out;
1109+ }
10571110
10581111 if (copy_from_user(buf, p, buf_len)) {
10591112 rc = -EFAULT;
10601113 goto out;
10611114 }
10621115
1063− nvdimm_bus_lock(&nvdimm_bus->dev);
1116+ nd_device_lock(dev);
1117+ nvdimm_bus_lock(dev);
10641118 rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf);
10651119 if (rc)
10661120 goto out_unlock;
@@ -1075,39 +1129,24 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 8 unmodified lines
10751129 nvdimm_account_cleared_poison(nvdimm_bus, clear_err->address,
10761130 clear_err->cleared);
10771131 }
1078− nvdimm_bus_unlock(&nvdimm_bus->dev);
10791132
10801133 if (copy_to_user(p, buf, buf_len))
10811134 rc = -EFAULT;
10821135
1083− vfree(buf);
1084− return rc;
1085−
1086− out_unlock:
1087− nvdimm_bus_unlock(&nvdimm_bus->dev);
1088− out:
1136+out_unlock:
1137+ nvdimm_bus_unlock(dev);
1138+ nd_device_unlock(dev);
1139+out:
1140+ kfree(in_env);
1141+ kfree(out_env);
10891142 vfree(buf);
10901143 return rc;
10911144 }
10921145
1093−static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1094−{
1095− long id = (long) file->private_data;
1096− int rc = -ENXIO, ro;
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−}
1146+enum nd_ioctl_mode {
1147+ BUS_IOCTL,
1148+ DIMM_IOCTL,
1149+};
11111150
11121151 static int match_dimm(struct device *dev, void *data)
11131152 {
@@ -1122,31 +1161,62 @@ static int match_dimm(struct device *dev, void *data) · 8 unmodified lines
11221161 return 0;
11231162 }
11241163
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+
11261167 {
1127− int rc = -ENXIO, ro;
1128− struct nvdimm_bus *nvdimm_bus;
1168+ struct nvdimm_bus *nvdimm_bus, *found = NULL;
1169+ long id = (long) file->private_data;
1170+ struct nvdimm *nvdimm = NULL;
1171+ int rc, ro;
11291172
11301173 ro = ((file->f_flags & O_ACCMODE) == O_RDONLY);
11311174 mutex_lock(&nvdimm_bus_list_mutex);
11321175 list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
1133− struct device *dev = device_find_child(&nvdimm_bus->dev,
1134− file->private_data, match_dimm);
1135− struct nvdimm *nvdimm;
1136−
1137− if (!dev)
1138− continue;
1176+ if (mode == DIMM_IOCTL) {
1177+ struct device *dev;
1178+
1179+ dev = device_find_child(&nvdimm_bus->dev,
1180+ file->private_data, match_dimm);
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+ }
11391188
1140− nvdimm = to_nvdimm(dev);
1141− rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg);
1142− put_device(dev);
1143− break;
1189+ if (found) {
1190+ atomic_inc(&nvdimm_bus->ioctl_active);
1191+ break;
1192+ }
11441193 }
11451194 mutex_unlock(&nvdimm_bus_list_mutex);
11461195
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+
11471207 return rc;
11481208 }
11491209
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+
11501220 static int nd_open(struct inode *inode, struct file *file)
11511221 {
11521222 long minor = iminor(inode);
@@ -1158,16 +1228,16 @@ static int nd_open(struct inode *inode, struct file *file) · 5 unmodified lines
11581228 static const struct file_operations nvdimm_bus_fops = {
11591229 .owner = THIS_MODULE,
11601230 .open = nd_open,
1161− .unlocked_ioctl = nd_ioctl,
1162− .compat_ioctl = nd_ioctl,
1231+ .unlocked_ioctl = bus_ioctl,
1232+ .compat_ioctl = bus_ioctl,
11631233 .llseek = noop_llseek,
11641234 };
11651235
11661236 static const struct file_operations nvdimm_fops = {
11671237 .owner = THIS_MODULE,
11681238 .open = nd_open,
1169− .unlocked_ioctl = nvdimm_ioctl,
1170− .compat_ioctl = nvdimm_ioctl,
1239+ .unlocked_ioctl = dimm_ioctl,
1240+ .compat_ioctl = dimm_ioctl,
11711241 .llseek = noop_llseek,
11721242 };
11731243
drivers/nvdimm/core.c+5−5
@@ -246,7 +246,7 @@ static int nd_uuid_parse(struct device *dev, u8 *uuid_out, const char *buf, · 245 unmodified lines
246246 *
247247 * Enforce that uuids can only be changed while the device is disabled
248248 * (driver detached)
249− * LOCKING: expects device_lock() is held on entry
249+ * LOCKING: expects nd_device_lock() is held on entry
250250 */
251251 int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf,
252252 size_t len)
@@ -347,15 +347,15 @@ static DEVICE_ATTR_RO(provider); · 94 unmodified lines
347347
348348 static int flush_namespaces(struct device *dev, void *data)
349349 {
350− device_lock(dev);
351− device_unlock(dev);
350+ nd_device_lock(dev);
351+ nd_device_unlock(dev);
352352 return 0;
353353 }
354354
355355 static int flush_regions_dimms(struct device *dev, void *data)
356356 {
357− device_lock(dev);
358− device_unlock(dev);
357+ nd_device_lock(dev);
358+ nd_device_unlock(dev);
359359 device_for_each_child(dev, NULL, flush_namespaces);
360360 return 0;
361361 }
drivers/nvdimm/dimm_devs.c+2−2
@@ -484,12 +484,12 @@ static ssize_t security_store(struct device *dev, · 483 unmodified lines
484484 * done while probing is idle and the DIMM is not in active use
485485 * in any region.
486486 */
487− device_lock(dev);
487+ nd_device_lock(dev);
488488 nvdimm_bus_lock(dev);
489489 wait_nvdimm_bus_probe_idle(dev);
490490 rc = __security_store(dev, buf, len);
491491 nvdimm_bus_unlock(dev);
492− device_unlock(dev);
492+ nd_device_unlock(dev);
493493
494494 return rc;
495495 }
drivers/nvdimm/namespace_devs.c+18−18
@@ -410,7 +410,7 @@ static ssize_t alt_name_store(struct device *dev, · 409 unmodified lines
410410 struct nd_region *nd_region = to_nd_region(dev->parent);
411411 ssize_t rc;
412412
413− device_lock(dev);
413+ nd_device_lock(dev);
414414 nvdimm_bus_lock(dev);
415415 wait_nvdimm_bus_probe_idle(dev);
416416 rc = __alt_name_store(dev, buf, len);
@@ -418,7 +418,7 @@ static ssize_t alt_name_store(struct device *dev, · 1 unmodified line
418418 rc = nd_namespace_label_update(nd_region, dev);
419419 dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
420420 nvdimm_bus_unlock(dev);
421− device_unlock(dev);
421+ nd_device_unlock(dev);
422422
423423 return rc < 0 ? rc : len;
424424 }
@@ -1077,7 +1077,7 @@ static ssize_t size_store(struct device *dev, · 652 unmodified lines
10771077 if (rc)
10781078 return rc;
10791079
1080− device_lock(dev);
1080+ nd_device_lock(dev);
10811081 nvdimm_bus_lock(dev);
10821082 wait_nvdimm_bus_probe_idle(dev);
10831083 rc = __size_store(dev, val);
@@ -1103,7 +1103,7 @@ static ssize_t size_store(struct device *dev, · 19 unmodified lines
11031103 dev_dbg(dev, "%llx %s (%d)\n", val, rc < 0 ? "fail" : "success", rc);
11041104
11051105 nvdimm_bus_unlock(dev);
1106− device_unlock(dev);
1106+ nd_device_unlock(dev);
11071107
11081108 return rc < 0 ? rc : len;
11091109 }
@@ -1286,7 +1286,7 @@ static ssize_t uuid_store(struct device *dev, · 176 unmodified lines
12861286 } else
12871287 return -ENXIO;
12881288
1289− device_lock(dev);
1289+ nd_device_lock(dev);
12901290 nvdimm_bus_lock(dev);
12911291 wait_nvdimm_bus_probe_idle(dev);
12921292 if (to_ndns(dev)->claim)
@@ -1302,7 +1302,7 @@ static ssize_t uuid_store(struct device *dev, · 9 unmodified lines
13021302 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
13031303 buf[len - 1] == '\n' ? "" : "\n");
13041304 nvdimm_bus_unlock(dev);
1305− device_unlock(dev);
1305+ nd_device_unlock(dev);
13061306
13071307 return rc < 0 ? rc : len;
13081308 }
@@ -1376,7 +1376,7 @@ static ssize_t sector_size_store(struct device *dev, · 67 unmodified lines
13761376 } else
13771377 return -ENXIO;
13781378
1379− device_lock(dev);
1379+ nd_device_lock(dev);
13801380 nvdimm_bus_lock(dev);
13811381 if (to_ndns(dev)->claim)
13821382 rc = -EBUSY;
@@ -1387,7 +1387,7 @@ static ssize_t sector_size_store(struct device *dev, · 4 unmodified lines
13871387 dev_dbg(dev, "result: %zd %s: %s%s", rc, rc < 0 ? "tried" : "wrote",
13881388 buf, buf[len - 1] == '\n' ? "" : "\n");
13891389 nvdimm_bus_unlock(dev);
1390− device_unlock(dev);
1390+ nd_device_unlock(dev);
13911391
13921392 return rc ? rc : len;
13931393 }
@@ -1502,9 +1502,9 @@ static ssize_t holder_show(struct device *dev, · 108 unmodified lines
15021502 struct nd_namespace_common *ndns = to_ndns(dev);
15031503 ssize_t rc;
15041504
1505− device_lock(dev);
1505+ nd_device_lock(dev);
15061506 rc = sprintf(buf, "%s\n", ndns->claim ? dev_name(ndns->claim) : "");
1507− device_unlock(dev);
1507+ nd_device_unlock(dev);
15081508
15091509 return rc;
15101510 }
@@ -1541,7 +1541,7 @@ static ssize_t holder_class_store(struct device *dev, · 30 unmodified lines
15411541 struct nd_region *nd_region = to_nd_region(dev->parent);
15421542 ssize_t rc;
15431543
1544− device_lock(dev);
1544+ nd_device_lock(dev);
15451545 nvdimm_bus_lock(dev);
15461546 wait_nvdimm_bus_probe_idle(dev);
15471547 rc = __holder_class_store(dev, buf);
@@ -1549,7 +1549,7 @@ static ssize_t holder_class_store(struct device *dev, · 1 unmodified line
15491549 rc = nd_namespace_label_update(nd_region, dev);
15501550 dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
15511551 nvdimm_bus_unlock(dev);
1552− device_unlock(dev);
1552+ nd_device_unlock(dev);
15531553
15541554 return rc < 0 ? rc : len;
15551555 }
@@ -1560,7 +1560,7 @@ static ssize_t holder_class_show(struct device *dev, · 4 unmodified lines
15601560 struct nd_namespace_common *ndns = to_ndns(dev);
15611561 ssize_t rc;
15621562
1563− device_lock(dev);
1563+ nd_device_lock(dev);
15641564 if (ndns->claim_class == NVDIMM_CCLASS_NONE)
15651565 rc = sprintf(buf, "\n");
15661566 else if ((ndns->claim_class == NVDIMM_CCLASS_BTT) ||
@@ -1572,7 +1572,7 @@ static ssize_t holder_class_show(struct device *dev, · 5 unmodified lines
15721572 rc = sprintf(buf, "dax\n");
15731573 else
15741574 rc = sprintf(buf, "<unknown>\n");
1575− device_unlock(dev);
1575+ nd_device_unlock(dev);
15761576
15771577 return rc;
15781578 }
@@ -1586,7 +1586,7 @@ static ssize_t mode_show(struct device *dev, · 7 unmodified lines
15861586 char *mode;
15871587 ssize_t rc;
15881588
1589− device_lock(dev);
1589+ nd_device_lock(dev);
15901590 claim = ndns->claim;
15911591 if (claim && is_nd_btt(claim))
15921592 mode = "safe";
@@ -1599,7 +1599,7 @@ static ssize_t mode_show(struct device *dev, · 6 unmodified lines
15991599 else
16001600 mode = "raw";
16011601 rc = sprintf(buf, "%s\n", mode);
1602− device_unlock(dev);
1602+ nd_device_unlock(dev);
16031603
16041604 return rc;
16051605 }
@@ -1703,8 +1703,8 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev) · 97 unmodified lines
17031703 * Flush any in-progess probes / removals in the driver
17041704 * for the raw personality of this namespace.
17051705 */
1706− device_lock(&ndns->dev);
1707− device_unlock(&ndns->dev);
1706+ nd_device_lock(&ndns->dev);
1707+ nd_device_unlock(&ndns->dev);
17081708 if (ndns->dev.driver) {
17091709 dev_dbg(&ndns->dev, "is active, can't bind %s\n",
17101710 dev_name(dev));
drivers/nvdimm/nd-core.h+70−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <linux/sizes.h>
1010 #include <linux/mutex.h>
1111 #include <linux/nd.h>
12+#include "nd.h"
1213
1314 extern struct list_head nvdimm_bus_list;
1415 extern struct mutex nvdimm_bus_list_mutex;
@@ -17,10 +18,11 @@ extern struct workqueue_struct *nvdimm_wq; · 2 unmodified lines
1718
1819 struct nvdimm_bus {
1920 struct nvdimm_bus_descriptor *nd_desc;
20− wait_queue_head_t probe_wait;
21+ wait_queue_head_t wait;
2122 struct list_head list;
2223 struct device dev;
2324 int id, probe_active;
25+ atomic_t ioctl_active;
2426 struct list_head mapping_list;
2527 struct mutex reconfig_mutex;
2628 struct badrange badrange;
@@ -181,4 +183,71 @@ ssize_t nd_namespace_store(struct device *dev, · 154 unmodified lines
181183 struct nd_namespace_common **_ndns, const char *buf,
182184 size_t len);
183185 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
184253 #endif /* __ND_CORE_H__ */
drivers/nvdimm/pfn_devs.c+12−12
@@ -67,7 +67,7 @@ static ssize_t mode_store(struct device *dev, · 66 unmodified lines
6767 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
6868 ssize_t rc = 0;
6969
70− device_lock(dev);
70+ nd_device_lock(dev);
7171 nvdimm_bus_lock(dev);
7272 if (dev->driver)
7373 rc = -EBUSY;
@@ -89,7 +89,7 @@ static ssize_t mode_store(struct device *dev, · 15 unmodified lines
8989 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
9090 buf[len - 1] == '\n' ? "" : "\n");
9191 nvdimm_bus_unlock(dev);
92− device_unlock(dev);
92+ nd_device_unlock(dev);
9393
9494 return rc ? rc : len;
9595 }
@@ -132,14 +132,14 @@ static ssize_t align_store(struct device *dev, · 36 unmodified lines
132132 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
133133 ssize_t rc;
134134
135− device_lock(dev);
135+ nd_device_lock(dev);
136136 nvdimm_bus_lock(dev);
137137 rc = nd_size_select_store(dev, buf, &nd_pfn->align,
138138 nd_pfn_supported_alignments());
139139 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
140140 buf[len - 1] == '\n' ? "" : "\n");
141141 nvdimm_bus_unlock(dev);
142− device_unlock(dev);
142+ nd_device_unlock(dev);
143143
144144 return rc ? rc : len;
145145 }
@@ -161,11 +161,11 @@ static ssize_t uuid_store(struct device *dev, · 15 unmodified lines
161161 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
162162 ssize_t rc;
163163
164− device_lock(dev);
164+ nd_device_lock(dev);
165165 rc = nd_uuid_store(dev, &nd_pfn->uuid, buf, len);
166166 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
167167 buf[len - 1] == '\n' ? "" : "\n");
168− device_unlock(dev);
168+ nd_device_unlock(dev);
169169
170170 return rc ? rc : len;
171171 }
@@ -190,13 +190,13 @@ static ssize_t namespace_store(struct device *dev, · 18 unmodified lines
190190 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
191191 ssize_t rc;
192192
193− device_lock(dev);
193+ nd_device_lock(dev);
194194 nvdimm_bus_lock(dev);
195195 rc = nd_namespace_store(dev, &nd_pfn->ndns, buf, len);
196196 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf,
197197 buf[len - 1] == '\n' ? "" : "\n");
198198 nvdimm_bus_unlock(dev);
199− device_unlock(dev);
199+ nd_device_unlock(dev);
200200
201201 return rc;
202202 }
@@ -208,7 +208,7 @@ static ssize_t resource_show(struct device *dev, · 5 unmodified lines
208208 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
209209 ssize_t rc;
210210
211− device_lock(dev);
211+ nd_device_lock(dev);
212212 if (dev->driver) {
213213 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
214214 u64 offset = __le64_to_cpu(pfn_sb->dataoff);
@@ -222,7 +222,7 @@ static ssize_t resource_show(struct device *dev, · 7 unmodified lines
222222 /* no address to convey if the pfn instance is disabled */
223223 rc = -ENXIO;
224224 }
225− device_unlock(dev);
225+ nd_device_unlock(dev);
226226
227227 return rc;
228228 }
@@ -234,7 +234,7 @@ static ssize_t size_show(struct device *dev, · 5 unmodified lines
234234 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
235235 ssize_t rc;
236236
237− device_lock(dev);
237+ nd_device_lock(dev);
238238 if (dev->driver) {
239239 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
240240 u64 offset = __le64_to_cpu(pfn_sb->dataoff);
@@ -250,7 +250,7 @@ static ssize_t size_show(struct device *dev, · 9 unmodified lines
250250 /* no size to convey if the pfn instance is disabled */
251251 rc = -ENXIO;
252252 }
253− device_unlock(dev);
253+ nd_device_unlock(dev);
254254
255255 return rc;
256256 }
drivers/nvdimm/pmem.c+2−2
@@ -522,8 +522,8 @@ static int nd_pmem_remove(struct device *dev) · 521 unmodified lines
522522 nvdimm_namespace_detach_btt(to_nd_btt(dev));
523523 else {
524524 /*
525− * Note, this assumes device_lock() context to not race
526− * nd_pmem_notify()
525+ * Note, this assumes nd_device_lock() context to not
526+ * race nd_pmem_notify()
527527 */
528528 sysfs_put(pmem->bb_state);
529529 pmem->bb_state = NULL;
drivers/nvdimm/region.c+12−12
@@ -34,17 +34,6 @@ static int nd_region_probe(struct device *dev) · 33 unmodified lines
3434 if (rc)
3535 return rc;
3636
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−
4837 if (is_nd_pmem(&nd_region->dev)) {
4938 struct resource ndr_res;
5039
@@ -60,6 +49,17 @@ static int nd_region_probe(struct device *dev) · 9 unmodified lines
6049 nvdimm_badblocks_populate(nd_region, &nd_region->bb, &ndr_res);
6150 }
6251
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+
6363 nd_region->btt_seed = nd_btt_create(nd_region);
6464 nd_region->pfn_seed = nd_pfn_create(nd_region);
6565 nd_region->dax_seed = nd_dax_create(nd_region);
@@ -102,7 +102,7 @@ static int nd_region_remove(struct device *dev) · 36 unmodified lines
102102 nvdimm_bus_unlock(dev);
103103
104104 /*
105− * Note, this assumes device_lock() context to not race
105+ * Note, this assumes nd_device_lock() context to not race
106106 * nd_region_notify()
107107 */
108108 sysfs_put(nd_region->bb_state);
drivers/nvdimm/region_devs.c+8−4
@@ -331,7 +331,7 @@ static ssize_t set_cookie_show(struct device *dev, · 330 unmodified lines
331331 * the v1.1 namespace label cookie definition. To read all this
332332 * data we need to wait for probing to settle.
333333 */
334− device_lock(dev);
334+ nd_device_lock(dev);
335335 nvdimm_bus_lock(dev);
336336 wait_nvdimm_bus_probe_idle(dev);
337337 if (nd_region->ndr_mappings) {
@@ -348,7 +348,7 @@ static ssize_t set_cookie_show(struct device *dev, · 10 unmodified lines
348348 }
349349 }
350350 nvdimm_bus_unlock(dev);
351− device_unlock(dev);
351+ nd_device_unlock(dev);
352352
353353 if (rc)
354354 return rc;
@@ -424,10 +424,12 @@ static ssize_t available_size_show(struct device *dev, · 69 unmodified lines
424424 * memory nvdimm_bus_lock() is dropped, but that's userspace's
425425 * problem to not race itself.
426426 */
427+ nd_device_lock(dev);
427428 nvdimm_bus_lock(dev);
428429 wait_nvdimm_bus_probe_idle(dev);
429430 available = nd_region_available_dpa(nd_region);
430431 nvdimm_bus_unlock(dev);
432+ nd_device_unlock(dev);
431433
432434 return sprintf(buf, "%llu\n", available);
433435 }
@@ -439,10 +441,12 @@ static ssize_t max_available_extent_show(struct device *dev, · 5 unmodified lines
439441 struct nd_region *nd_region = to_nd_region(dev);
440442 unsigned long long available = 0;
441443
444+ nd_device_lock(dev);
442445 nvdimm_bus_lock(dev);
443446 wait_nvdimm_bus_probe_idle(dev);
444447 available = nd_region_allocatable_dpa(nd_region);
445448 nvdimm_bus_unlock(dev);
449+ nd_device_unlock(dev);
446450
447451 return sprintf(buf, "%llu\n", available);
448452 }
@@ -561,12 +565,12 @@ static ssize_t region_badblocks_show(struct device *dev, · 112 unmodified lines
561565 struct nd_region *nd_region = to_nd_region(dev);
562566 ssize_t rc;
563567
564− device_lock(dev);
568+ nd_device_lock(dev);
565569 if (dev->driver)
566570 rc = badblocks_show(&nd_region->bb, buf, 0);
567571 else
568572 rc = -ENXIO;
569− device_unlock(dev);
573+ nd_device_unlock(dev);
570574
571575 return rc;
572576 }
include/linux/device.h+6−0
@@ -915,6 +915,8 @@ struct dev_links_info { · 914 unmodified lines
915915 * This identifies the device type and carries type-specific
916916 * information.
917917 * @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.
918920 * @bus: Type of bus device is on.
919921 * @driver: Which driver has allocated this
920922 * @platform_data: Platform data specific to the device.
@@ -998,6 +1000,9 @@ struct device { · 77 unmodified lines
9981000 core doesn't touch it */
9991001 void *driver_data; /* Driver data, set and get with
10001002 dev_set_drvdata/dev_get_drvdata */
1003+#ifdef CONFIG_PROVE_LOCKING
1004+ struct mutex lockdep_mutex;
1005+#endif
10011006 struct mutex mutex; /* mutex to synchronize calls to
10021007 * its driver.
10031008 */
@@ -1383,6 +1388,7 @@ extern int (*platform_notify_remove)(struct device *dev); · 379 unmodified lines
13831388 */
13841389 extern struct device *get_device(struct device *dev);
13851390 extern void put_device(struct device *dev);
1391+extern bool kill_device(struct device *dev);
13861392
13871393 #ifdef CONFIG_DEVTMPFS
13881394 extern int devtmpfs_create_node(struct device *dev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t