Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvdimm: Drop nd_device_lock()

Now that all NVDIMM subsystem locking is validated with custom lock
classes, there is no need for the custom usage of the lockdep_mutex.

Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/r/165055521979.3745911.10751769706032029999.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+66 -155
+8 -8
drivers/nvdimm/btt_devs.c
··· 50 50 struct nd_btt *nd_btt = to_nd_btt(dev); 51 51 ssize_t rc; 52 52 53 - nd_device_lock(dev); 53 + device_lock(dev); 54 54 nvdimm_bus_lock(dev); 55 55 rc = nd_size_select_store(dev, buf, &nd_btt->lbasize, 56 56 btt_lbasize_supported); 57 57 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 58 58 buf[len - 1] == '\n' ? "" : "\n"); 59 59 nvdimm_bus_unlock(dev); 60 - nd_device_unlock(dev); 60 + device_unlock(dev); 61 61 62 62 return rc ? rc : len; 63 63 } ··· 79 79 struct nd_btt *nd_btt = to_nd_btt(dev); 80 80 ssize_t rc; 81 81 82 - nd_device_lock(dev); 82 + device_lock(dev); 83 83 rc = nd_uuid_store(dev, &nd_btt->uuid, buf, len); 84 84 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 85 85 buf[len - 1] == '\n' ? "" : "\n"); 86 - nd_device_unlock(dev); 86 + device_unlock(dev); 87 87 88 88 return rc ? rc : len; 89 89 } ··· 108 108 struct nd_btt *nd_btt = to_nd_btt(dev); 109 109 ssize_t rc; 110 110 111 - nd_device_lock(dev); 111 + device_lock(dev); 112 112 nvdimm_bus_lock(dev); 113 113 rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len); 114 114 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 115 115 buf[len - 1] == '\n' ? "" : "\n"); 116 116 nvdimm_bus_unlock(dev); 117 - nd_device_unlock(dev); 117 + device_unlock(dev); 118 118 119 119 return rc; 120 120 } ··· 126 126 struct nd_btt *nd_btt = to_nd_btt(dev); 127 127 ssize_t rc; 128 128 129 - nd_device_lock(dev); 129 + device_lock(dev); 130 130 if (dev->driver) 131 131 rc = sprintf(buf, "%llu\n", nd_btt->size); 132 132 else { 133 133 /* no size to convey if the btt instance is disabled */ 134 134 rc = -ENXIO; 135 135 } 136 - nd_device_unlock(dev); 136 + device_unlock(dev); 137 137 138 138 return rc; 139 139 }
+9 -15
drivers/nvdimm/bus.c
··· 88 88 dev->driver->name, dev_name(dev)); 89 89 90 90 nvdimm_bus_probe_start(nvdimm_bus); 91 - debug_nvdimm_lock(dev); 92 91 rc = nd_drv->probe(dev); 93 - debug_nvdimm_unlock(dev); 94 - 95 92 if ((rc == 0 || rc == -EOPNOTSUPP) && 96 93 dev->parent && is_nd_region(dev->parent)) 97 94 nd_region_advance_seeds(to_nd_region(dev->parent), dev); ··· 108 111 struct module *provider = to_bus_provider(dev); 109 112 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 110 113 111 - if (nd_drv->remove) { 112 - debug_nvdimm_lock(dev); 114 + if (nd_drv->remove) 113 115 nd_drv->remove(dev); 114 - debug_nvdimm_unlock(dev); 115 - } 116 116 117 117 dev_dbg(&nvdimm_bus->dev, "%s.remove(%s)\n", dev->driver->name, 118 118 dev_name(dev)); ··· 133 139 134 140 void nd_device_notify(struct device *dev, enum nvdimm_event event) 135 141 { 136 - nd_device_lock(dev); 142 + device_lock(dev); 137 143 if (dev->driver) { 138 144 struct nd_device_driver *nd_drv; 139 145 ··· 141 147 if (nd_drv->notify) 142 148 nd_drv->notify(dev, event); 143 149 } 144 - nd_device_unlock(dev); 150 + device_unlock(dev); 145 151 } 146 152 EXPORT_SYMBOL(nd_device_notify); 147 153 ··· 563 569 * or otherwise let the async path handle it if the 564 570 * unregistration was already queued. 565 571 */ 566 - nd_device_lock(dev); 572 + device_lock(dev); 567 573 killed = kill_device(dev); 568 - nd_device_unlock(dev); 574 + device_unlock(dev); 569 575 570 576 if (!killed) 571 577 return; ··· 924 930 if (nvdimm_bus->probe_active == 0) 925 931 break; 926 932 nvdimm_bus_unlock(dev); 927 - nd_device_unlock(dev); 933 + device_unlock(dev); 928 934 wait_event(nvdimm_bus->wait, 929 935 nvdimm_bus->probe_active == 0); 930 - nd_device_lock(dev); 936 + device_lock(dev); 931 937 nvdimm_bus_lock(dev); 932 938 } while (true); 933 939 } ··· 1161 1167 goto out; 1162 1168 } 1163 1169 1164 - nd_device_lock(dev); 1170 + device_lock(dev); 1165 1171 nvdimm_bus_lock(dev); 1166 1172 rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf); 1167 1173 if (rc) ··· 1183 1189 1184 1190 out_unlock: 1185 1191 nvdimm_bus_unlock(dev); 1186 - nd_device_unlock(dev); 1192 + device_unlock(dev); 1187 1193 out: 1188 1194 kfree(in_env); 1189 1195 kfree(out_env);
+5 -5
drivers/nvdimm/core.c
··· 215 215 * 216 216 * Enforce that uuids can only be changed while the device is disabled 217 217 * (driver detached) 218 - * LOCKING: expects nd_device_lock() is held on entry 218 + * LOCKING: expects device_lock() is held on entry 219 219 */ 220 220 int nd_uuid_store(struct device *dev, uuid_t **uuid_out, const char *buf, 221 221 size_t len) ··· 316 316 317 317 static int flush_namespaces(struct device *dev, void *data) 318 318 { 319 - nd_device_lock(dev); 320 - nd_device_unlock(dev); 319 + device_lock(dev); 320 + device_unlock(dev); 321 321 return 0; 322 322 } 323 323 324 324 static int flush_regions_dimms(struct device *dev, void *data) 325 325 { 326 - nd_device_lock(dev); 327 - nd_device_unlock(dev); 326 + device_lock(dev); 327 + device_unlock(dev); 328 328 device_for_each_child(dev, NULL, flush_namespaces); 329 329 return 0; 330 330 }
+4 -4
drivers/nvdimm/dimm_devs.c
··· 341 341 { 342 342 ssize_t rc; 343 343 344 - nd_device_lock(dev); 344 + device_lock(dev); 345 345 rc = __available_slots_show(dev_get_drvdata(dev), buf); 346 - nd_device_unlock(dev); 346 + device_unlock(dev); 347 347 348 348 return rc; 349 349 } ··· 386 386 * done while probing is idle and the DIMM is not in active use 387 387 * in any region. 388 388 */ 389 - nd_device_lock(dev); 389 + device_lock(dev); 390 390 nvdimm_bus_lock(dev); 391 391 wait_nvdimm_bus_probe_idle(dev); 392 392 rc = nvdimm_security_store(dev, buf, len); 393 393 nvdimm_bus_unlock(dev); 394 - nd_device_unlock(dev); 394 + device_unlock(dev); 395 395 396 396 return rc; 397 397 }
+18 -18
drivers/nvdimm/namespace_devs.c
··· 264 264 struct nd_region *nd_region = to_nd_region(dev->parent); 265 265 ssize_t rc; 266 266 267 - nd_device_lock(dev); 267 + device_lock(dev); 268 268 nvdimm_bus_lock(dev); 269 269 wait_nvdimm_bus_probe_idle(dev); 270 270 rc = __alt_name_store(dev, buf, len); ··· 272 272 rc = nd_namespace_label_update(nd_region, dev); 273 273 dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); 274 274 nvdimm_bus_unlock(dev); 275 - nd_device_unlock(dev); 275 + device_unlock(dev); 276 276 277 277 return rc < 0 ? rc : len; 278 278 } ··· 846 846 if (rc) 847 847 return rc; 848 848 849 - nd_device_lock(dev); 849 + device_lock(dev); 850 850 nvdimm_bus_lock(dev); 851 851 wait_nvdimm_bus_probe_idle(dev); 852 852 rc = __size_store(dev, val); ··· 868 868 dev_dbg(dev, "%llx %s (%d)\n", val, rc < 0 ? "fail" : "success", rc); 869 869 870 870 nvdimm_bus_unlock(dev); 871 - nd_device_unlock(dev); 871 + device_unlock(dev); 872 872 873 873 return rc < 0 ? rc : len; 874 874 } ··· 1043 1043 } else 1044 1044 return -ENXIO; 1045 1045 1046 - nd_device_lock(dev); 1046 + device_lock(dev); 1047 1047 nvdimm_bus_lock(dev); 1048 1048 wait_nvdimm_bus_probe_idle(dev); 1049 1049 if (to_ndns(dev)->claim) ··· 1059 1059 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 1060 1060 buf[len - 1] == '\n' ? "" : "\n"); 1061 1061 nvdimm_bus_unlock(dev); 1062 - nd_device_unlock(dev); 1062 + device_unlock(dev); 1063 1063 1064 1064 return rc < 0 ? rc : len; 1065 1065 } ··· 1118 1118 } else 1119 1119 return -ENXIO; 1120 1120 1121 - nd_device_lock(dev); 1121 + device_lock(dev); 1122 1122 nvdimm_bus_lock(dev); 1123 1123 if (to_ndns(dev)->claim) 1124 1124 rc = -EBUSY; ··· 1129 1129 dev_dbg(dev, "result: %zd %s: %s%s", rc, rc < 0 ? "tried" : "wrote", 1130 1130 buf, buf[len - 1] == '\n' ? "" : "\n"); 1131 1131 nvdimm_bus_unlock(dev); 1132 - nd_device_unlock(dev); 1132 + device_unlock(dev); 1133 1133 1134 1134 return rc ? rc : len; 1135 1135 } ··· 1239 1239 struct nd_namespace_common *ndns = to_ndns(dev); 1240 1240 ssize_t rc; 1241 1241 1242 - nd_device_lock(dev); 1242 + device_lock(dev); 1243 1243 rc = sprintf(buf, "%s\n", ndns->claim ? dev_name(ndns->claim) : ""); 1244 - nd_device_unlock(dev); 1244 + device_unlock(dev); 1245 1245 1246 1246 return rc; 1247 1247 } ··· 1278 1278 struct nd_region *nd_region = to_nd_region(dev->parent); 1279 1279 int rc; 1280 1280 1281 - nd_device_lock(dev); 1281 + device_lock(dev); 1282 1282 nvdimm_bus_lock(dev); 1283 1283 wait_nvdimm_bus_probe_idle(dev); 1284 1284 rc = __holder_class_store(dev, buf); ··· 1286 1286 rc = nd_namespace_label_update(nd_region, dev); 1287 1287 dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc); 1288 1288 nvdimm_bus_unlock(dev); 1289 - nd_device_unlock(dev); 1289 + device_unlock(dev); 1290 1290 1291 1291 return rc < 0 ? rc : len; 1292 1292 } ··· 1297 1297 struct nd_namespace_common *ndns = to_ndns(dev); 1298 1298 ssize_t rc; 1299 1299 1300 - nd_device_lock(dev); 1300 + device_lock(dev); 1301 1301 if (ndns->claim_class == NVDIMM_CCLASS_NONE) 1302 1302 rc = sprintf(buf, "\n"); 1303 1303 else if ((ndns->claim_class == NVDIMM_CCLASS_BTT) || ··· 1309 1309 rc = sprintf(buf, "dax\n"); 1310 1310 else 1311 1311 rc = sprintf(buf, "<unknown>\n"); 1312 - nd_device_unlock(dev); 1312 + device_unlock(dev); 1313 1313 1314 1314 return rc; 1315 1315 } ··· 1323 1323 char *mode; 1324 1324 ssize_t rc; 1325 1325 1326 - nd_device_lock(dev); 1326 + device_lock(dev); 1327 1327 claim = ndns->claim; 1328 1328 if (claim && is_nd_btt(claim)) 1329 1329 mode = "safe"; ··· 1336 1336 else 1337 1337 mode = "raw"; 1338 1338 rc = sprintf(buf, "%s\n", mode); 1339 - nd_device_unlock(dev); 1339 + device_unlock(dev); 1340 1340 1341 1341 return rc; 1342 1342 } ··· 1456 1456 * Flush any in-progess probes / removals in the driver 1457 1457 * for the raw personality of this namespace. 1458 1458 */ 1459 - nd_device_lock(&ndns->dev); 1460 - nd_device_unlock(&ndns->dev); 1459 + device_lock(&ndns->dev); 1460 + device_unlock(&ndns->dev); 1461 1461 if (ndns->dev.driver) { 1462 1462 dev_dbg(&ndns->dev, "is active, can't bind %s\n", 1463 1463 dev_name(dev));
-66
drivers/nvdimm/nd-core.h
··· 161 161 { 162 162 } 163 163 #endif 164 - 165 - #ifdef CONFIG_PROVE_NVDIMM_LOCKING 166 - extern struct class *nd_class; 167 - 168 - enum { 169 - LOCK_BUS, 170 - LOCK_NDCTL, 171 - LOCK_REGION, 172 - LOCK_DIMM = LOCK_REGION, 173 - LOCK_NAMESPACE, 174 - LOCK_CLAIM, 175 - }; 176 - 177 - static inline void debug_nvdimm_lock(struct device *dev) 178 - { 179 - if (is_nd_region(dev)) 180 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_REGION); 181 - else if (is_nvdimm(dev)) 182 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_DIMM); 183 - else if (is_nd_btt(dev) || is_nd_pfn(dev) || is_nd_dax(dev)) 184 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_CLAIM); 185 - else if (dev->parent && (is_nd_region(dev->parent))) 186 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_NAMESPACE); 187 - else if (is_nvdimm_bus(dev)) 188 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_BUS); 189 - else if (dev->class && dev->class == nd_class) 190 - mutex_lock_nested(&dev->lockdep_mutex, LOCK_NDCTL); 191 - else 192 - dev_WARN(dev, "unknown lock level\n"); 193 - } 194 - 195 - static inline void debug_nvdimm_unlock(struct device *dev) 196 - { 197 - mutex_unlock(&dev->lockdep_mutex); 198 - } 199 - 200 - static inline void nd_device_lock(struct device *dev) 201 - { 202 - device_lock(dev); 203 - debug_nvdimm_lock(dev); 204 - } 205 - 206 - static inline void nd_device_unlock(struct device *dev) 207 - { 208 - debug_nvdimm_unlock(dev); 209 - device_unlock(dev); 210 - } 211 - #else 212 - static inline void nd_device_lock(struct device *dev) 213 - { 214 - device_lock(dev); 215 - } 216 - 217 - static inline void nd_device_unlock(struct device *dev) 218 - { 219 - device_unlock(dev); 220 - } 221 - 222 - static inline void debug_nvdimm_lock(struct device *dev) 223 - { 224 - } 225 - 226 - static inline void debug_nvdimm_unlock(struct device *dev) 227 - { 228 - } 229 - #endif 230 164 #endif /* __ND_CORE_H__ */
+12 -12
drivers/nvdimm/pfn_devs.c
··· 55 55 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); 56 56 ssize_t rc = 0; 57 57 58 - nd_device_lock(dev); 58 + device_lock(dev); 59 59 nvdimm_bus_lock(dev); 60 60 if (dev->driver) 61 61 rc = -EBUSY; ··· 77 77 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 78 78 buf[len - 1] == '\n' ? "" : "\n"); 79 79 nvdimm_bus_unlock(dev); 80 - nd_device_unlock(dev); 80 + device_unlock(dev); 81 81 82 82 return rc ? rc : len; 83 83 } ··· 123 123 unsigned long aligns[MAX_NVDIMM_ALIGN] = { [0] = 0, }; 124 124 ssize_t rc; 125 125 126 - nd_device_lock(dev); 126 + device_lock(dev); 127 127 nvdimm_bus_lock(dev); 128 128 rc = nd_size_select_store(dev, buf, &nd_pfn->align, 129 129 nd_pfn_supported_alignments(aligns)); 130 130 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 131 131 buf[len - 1] == '\n' ? "" : "\n"); 132 132 nvdimm_bus_unlock(dev); 133 - nd_device_unlock(dev); 133 + device_unlock(dev); 134 134 135 135 return rc ? rc : len; 136 136 } ··· 152 152 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); 153 153 ssize_t rc; 154 154 155 - nd_device_lock(dev); 155 + device_lock(dev); 156 156 rc = nd_uuid_store(dev, &nd_pfn->uuid, buf, len); 157 157 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 158 158 buf[len - 1] == '\n' ? "" : "\n"); 159 - nd_device_unlock(dev); 159 + device_unlock(dev); 160 160 161 161 return rc ? rc : len; 162 162 } ··· 181 181 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); 182 182 ssize_t rc; 183 183 184 - nd_device_lock(dev); 184 + device_lock(dev); 185 185 nvdimm_bus_lock(dev); 186 186 rc = nd_namespace_store(dev, &nd_pfn->ndns, buf, len); 187 187 dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, 188 188 buf[len - 1] == '\n' ? "" : "\n"); 189 189 nvdimm_bus_unlock(dev); 190 - nd_device_unlock(dev); 190 + device_unlock(dev); 191 191 192 192 return rc; 193 193 } ··· 199 199 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); 200 200 ssize_t rc; 201 201 202 - nd_device_lock(dev); 202 + device_lock(dev); 203 203 if (dev->driver) { 204 204 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; 205 205 u64 offset = __le64_to_cpu(pfn_sb->dataoff); ··· 213 213 /* no address to convey if the pfn instance is disabled */ 214 214 rc = -ENXIO; 215 215 } 216 - nd_device_unlock(dev); 216 + device_unlock(dev); 217 217 218 218 return rc; 219 219 } ··· 225 225 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); 226 226 ssize_t rc; 227 227 228 - nd_device_lock(dev); 228 + device_lock(dev); 229 229 if (dev->driver) { 230 230 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; 231 231 u64 offset = __le64_to_cpu(pfn_sb->dataoff); ··· 241 241 /* no size to convey if the pfn instance is disabled */ 242 242 rc = -ENXIO; 243 243 } 244 - nd_device_unlock(dev); 244 + device_unlock(dev); 245 245 246 246 return rc; 247 247 }
+1 -1
drivers/nvdimm/pmem.c
··· 573 573 nvdimm_namespace_detach_btt(to_nd_btt(dev)); 574 574 else { 575 575 /* 576 - * Note, this assumes nd_device_lock() context to not 576 + * Note, this assumes device_lock() context to not 577 577 * race nd_pmem_notify() 578 578 */ 579 579 sysfs_put(pmem->bb_state);
+1 -1
drivers/nvdimm/region.c
··· 95 95 nvdimm_bus_unlock(dev); 96 96 97 97 /* 98 - * Note, this assumes nd_device_lock() context to not race 98 + * Note, this assumes device_lock() context to not race 99 99 * nd_region_notify() 100 100 */ 101 101 sysfs_put(nd_region->bb_state);
+8 -8
drivers/nvdimm/region_devs.c
··· 279 279 * the v1.1 namespace label cookie definition. To read all this 280 280 * data we need to wait for probing to settle. 281 281 */ 282 - nd_device_lock(dev); 282 + device_lock(dev); 283 283 nvdimm_bus_lock(dev); 284 284 wait_nvdimm_bus_probe_idle(dev); 285 285 if (nd_region->ndr_mappings) { ··· 296 296 } 297 297 } 298 298 nvdimm_bus_unlock(dev); 299 - nd_device_unlock(dev); 299 + device_unlock(dev); 300 300 301 301 if (rc) 302 302 return rc; ··· 353 353 * memory nvdimm_bus_lock() is dropped, but that's userspace's 354 354 * problem to not race itself. 355 355 */ 356 - nd_device_lock(dev); 356 + device_lock(dev); 357 357 nvdimm_bus_lock(dev); 358 358 wait_nvdimm_bus_probe_idle(dev); 359 359 available = nd_region_available_dpa(nd_region); 360 360 nvdimm_bus_unlock(dev); 361 - nd_device_unlock(dev); 361 + device_unlock(dev); 362 362 363 363 return sprintf(buf, "%llu\n", available); 364 364 } ··· 370 370 struct nd_region *nd_region = to_nd_region(dev); 371 371 unsigned long long available = 0; 372 372 373 - nd_device_lock(dev); 373 + device_lock(dev); 374 374 nvdimm_bus_lock(dev); 375 375 wait_nvdimm_bus_probe_idle(dev); 376 376 available = nd_region_allocatable_dpa(nd_region); 377 377 nvdimm_bus_unlock(dev); 378 - nd_device_unlock(dev); 378 + device_unlock(dev); 379 379 380 380 return sprintf(buf, "%llu\n", available); 381 381 } ··· 549 549 struct nd_region *nd_region = to_nd_region(dev); 550 550 ssize_t rc; 551 551 552 - nd_device_lock(dev); 552 + device_lock(dev); 553 553 if (dev->driver) 554 554 rc = badblocks_show(&nd_region->bb, buf, 0); 555 555 else 556 556 rc = -ENXIO; 557 - nd_device_unlock(dev); 557 + device_unlock(dev); 558 558 559 559 return rc; 560 560 }
-17
lib/Kconfig.debug
··· 1544 1544 include the IPI handler function currently executing (if any) 1545 1545 and relevant stack traces. 1546 1546 1547 - choice 1548 - prompt "Lock debugging: prove subsystem device_lock() correctness" 1549 - depends on PROVE_LOCKING 1550 - help 1551 - For subsystems that have instrumented their usage of the device_lock() 1552 - with nested annotations, enable lock dependency checking. The locking 1553 - hierarchy 'subclass' identifiers are not compatible across 1554 - sub-systems, so only one can be enabled at a time. 1555 - 1556 - config PROVE_NVDIMM_LOCKING 1557 - bool "NVDIMM" 1558 - depends on LIBNVDIMM 1559 - help 1560 - Enable lockdep to validate nd_device_lock() usage. 1561 - 1562 - endchoice 1563 - 1564 1547 endmenu # lock debugging 1565 1548 1566 1549 config TRACE_IRQFLAGS