Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
lockdep: fix debug_lock_alloc
lockdep: increase MAX_LOCKDEP_KEYS
generic-ipi: fix stack and rcu interaction bug in smp_call_function_mask()
lockdep: fix overflow in the hlock shrinkage code
lockdep: rename map_[acquire|release]() => lock_map_[acquire|release]()
lockdep: handle chains involving classes defined in modules
mm: fix mm_take_all_locks() locking order
lockdep: annotate mm_take_all_locks()
lockdep: spin_lock_nest_lock()
lockdep: lock protection locks
lockdep: map_acquire
lockdep: shrink held_lock structure
lockdep: re-annotate scheduler runqueues
lockdep: lock_set_subclass - reset a held lock's subclass
lockdep: change scheduler annotation
debug_locks: set oops_in_progress if we will log messages.
lockdep: fix combinatorial explosion in lock subgraph traversal

+413 -153
+2 -2
fs/jbd/transaction.c
··· 291 291 goto out; 292 292 } 293 293 294 - lock_acquire(&handle->h_lockdep_map, 0, 0, 0, 2, _THIS_IP_); 294 + lock_map_acquire(&handle->h_lockdep_map); 295 295 296 296 out: 297 297 return handle; ··· 1448 1448 spin_unlock(&journal->j_state_lock); 1449 1449 } 1450 1450 1451 - lock_release(&handle->h_lockdep_map, 1, _THIS_IP_); 1451 + lock_map_release(&handle->h_lockdep_map); 1452 1452 1453 1453 jbd_free_handle(handle); 1454 1454 return err;
+2 -2
fs/jbd2/transaction.c
··· 301 301 goto out; 302 302 } 303 303 304 - lock_acquire(&handle->h_lockdep_map, 0, 0, 0, 2, _THIS_IP_); 304 + lock_map_acquire(&handle->h_lockdep_map); 305 305 out: 306 306 return handle; 307 307 } ··· 1279 1279 spin_unlock(&journal->j_state_lock); 1280 1280 } 1281 1281 1282 - lock_release(&handle->h_lockdep_map, 1, _THIS_IP_); 1282 + lock_map_release(&handle->h_lockdep_map); 1283 1283 1284 1284 jbd2_free_handle(handle); 1285 1285 return err;
+49 -21
include/linux/lockdep.h
··· 89 89 90 90 struct lockdep_subclass_key *key; 91 91 unsigned int subclass; 92 + unsigned int dep_gen_id; 92 93 93 94 /* 94 95 * IRQ/softirq usage tracking bits: ··· 190 189 u64 chain_key; 191 190 }; 192 191 192 + #define MAX_LOCKDEP_KEYS_BITS 13 193 + /* 194 + * Subtract one because we offset hlock->class_idx by 1 in order 195 + * to make 0 mean no class. This avoids overflowing the class_idx 196 + * bitfield and hitting the BUG in hlock_class(). 197 + */ 198 + #define MAX_LOCKDEP_KEYS ((1UL << MAX_LOCKDEP_KEYS_BITS) - 1) 199 + 193 200 struct held_lock { 194 201 /* 195 202 * One-way hash of the dependency chain up to this point. We ··· 214 205 * with zero), here we store the previous hash value: 215 206 */ 216 207 u64 prev_chain_key; 217 - struct lock_class *class; 218 208 unsigned long acquire_ip; 219 209 struct lockdep_map *instance; 220 - 210 + struct lockdep_map *nest_lock; 221 211 #ifdef CONFIG_LOCK_STAT 222 212 u64 waittime_stamp; 223 213 u64 holdtime_stamp; 224 214 #endif 215 + unsigned int class_idx:MAX_LOCKDEP_KEYS_BITS; 225 216 /* 226 217 * The lock-stack is unified in that the lock chains of interrupt 227 218 * contexts nest ontop of process context chains, but we 'separate' ··· 235 226 * The following field is used to detect when we cross into an 236 227 * interrupt context: 237 228 */ 238 - int irq_context; 239 - int trylock; 240 - int read; 241 - int check; 242 - int hardirqs_off; 229 + unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */ 230 + unsigned int trylock:1; 231 + unsigned int read:2; /* see lock_acquire() comment */ 232 + unsigned int check:2; /* see lock_acquire() comment */ 233 + unsigned int hardirqs_off:1; 243 234 }; 244 235 245 236 /* ··· 303 294 * 2: full validation 304 295 */ 305 296 extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, 306 - int trylock, int read, int check, unsigned long ip); 297 + int trylock, int read, int check, 298 + struct lockdep_map *nest_lock, unsigned long ip); 307 299 308 300 extern void lock_release(struct lockdep_map *lock, int nested, 309 301 unsigned long ip); 302 + 303 + extern void lock_set_subclass(struct lockdep_map *lock, unsigned int subclass, 304 + unsigned long ip); 310 305 311 306 # define INIT_LOCKDEP .lockdep_recursion = 0, 312 307 ··· 326 313 { 327 314 } 328 315 329 - # define lock_acquire(l, s, t, r, c, i) do { } while (0) 316 + # define lock_acquire(l, s, t, r, c, n, i) do { } while (0) 330 317 # define lock_release(l, n, i) do { } while (0) 318 + # define lock_set_subclass(l, s, i) do { } while (0) 331 319 # define lockdep_init() do { } while (0) 332 320 # define lockdep_info() do { } while (0) 333 321 # define lockdep_init_map(lock, name, key, sub) do { (void)(key); } while (0) ··· 414 400 415 401 #ifdef CONFIG_DEBUG_LOCK_ALLOC 416 402 # ifdef CONFIG_PROVE_LOCKING 417 - # define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i) 403 + # define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, NULL, i) 404 + # define spin_acquire_nest(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i) 418 405 # else 419 - # define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i) 406 + # define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, NULL, i) 407 + # define spin_acquire_nest(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, NULL, i) 420 408 # endif 421 409 # define spin_release(l, n, i) lock_release(l, n, i) 422 410 #else ··· 428 412 429 413 #ifdef CONFIG_DEBUG_LOCK_ALLOC 430 414 # ifdef CONFIG_PROVE_LOCKING 431 - # define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i) 432 - # define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 2, i) 415 + # define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, NULL, i) 416 + # define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 2, NULL, i) 433 417 # else 434 - # define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i) 435 - # define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 1, i) 418 + # define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, NULL, i) 419 + # define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 1, NULL, i) 436 420 # endif 437 421 # define rwlock_release(l, n, i) lock_release(l, n, i) 438 422 #else ··· 443 427 444 428 #ifdef CONFIG_DEBUG_LOCK_ALLOC 445 429 # ifdef CONFIG_PROVE_LOCKING 446 - # define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i) 430 + # define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, NULL, i) 447 431 # else 448 - # define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i) 432 + # define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, NULL, i) 449 433 # endif 450 434 # define mutex_release(l, n, i) lock_release(l, n, i) 451 435 #else ··· 455 439 456 440 #ifdef CONFIG_DEBUG_LOCK_ALLOC 457 441 # ifdef CONFIG_PROVE_LOCKING 458 - # define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i) 459 - # define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 2, i) 442 + # define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, NULL, i) 443 + # define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 2, NULL, i) 460 444 # else 461 - # define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i) 462 - # define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 1, i) 445 + # define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, NULL, i) 446 + # define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 1, NULL, i) 463 447 # endif 464 448 # define rwsem_release(l, n, i) lock_release(l, n, i) 465 449 #else 466 450 # define rwsem_acquire(l, s, t, i) do { } while (0) 467 451 # define rwsem_acquire_read(l, s, t, i) do { } while (0) 468 452 # define rwsem_release(l, n, i) do { } while (0) 453 + #endif 454 + 455 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 456 + # ifdef CONFIG_PROVE_LOCKING 457 + # define lock_map_acquire(l) lock_acquire(l, 0, 0, 0, 2, NULL, _THIS_IP_) 458 + # else 459 + # define lock_map_acquire(l) lock_acquire(l, 0, 0, 0, 1, NULL, _THIS_IP_) 460 + # endif 461 + # define lock_map_release(l) lock_release(l, 1, _THIS_IP_) 462 + #else 463 + # define lock_map_acquire(l) do { } while (0) 464 + # define lock_map_release(l) do { } while (0) 469 465 #endif 470 466 471 467 #endif /* __LINUX_LOCKDEP_H */
+1 -1
include/linux/rcuclassic.h
··· 117 117 #ifdef CONFIG_DEBUG_LOCK_ALLOC 118 118 extern struct lockdep_map rcu_lock_map; 119 119 # define rcu_read_acquire() \ 120 - lock_acquire(&rcu_lock_map, 0, 0, 2, 1, _THIS_IP_) 120 + lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) 121 121 # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_) 122 122 #else 123 123 # define rcu_read_acquire() do { } while (0)
+6
include/linux/spinlock.h
··· 183 183 184 184 #ifdef CONFIG_DEBUG_LOCK_ALLOC 185 185 # define spin_lock_nested(lock, subclass) _spin_lock_nested(lock, subclass) 186 + # define spin_lock_nest_lock(lock, nest_lock) \ 187 + do { \ 188 + typecheck(struct lockdep_map *, &(nest_lock)->dep_map);\ 189 + _spin_lock_nest_lock(lock, &(nest_lock)->dep_map); \ 190 + } while (0) 186 191 #else 187 192 # define spin_lock_nested(lock, subclass) _spin_lock(lock) 193 + # define spin_lock_nest_lock(lock, nest_lock) _spin_lock(lock) 188 194 #endif 189 195 190 196 #define write_lock(lock) _write_lock(lock)
+2
include/linux/spinlock_api_smp.h
··· 22 22 void __lockfunc _spin_lock(spinlock_t *lock) __acquires(lock); 23 23 void __lockfunc _spin_lock_nested(spinlock_t *lock, int subclass) 24 24 __acquires(lock); 25 + void __lockfunc _spin_lock_nest_lock(spinlock_t *lock, struct lockdep_map *map) 26 + __acquires(lock); 25 27 void __lockfunc _read_lock(rwlock_t *lock) __acquires(lock); 26 28 void __lockfunc _write_lock(rwlock_t *lock) __acquires(lock); 27 29 void __lockfunc _spin_lock_bh(spinlock_t *lock) __acquires(lock);
+239 -56
kernel/lockdep.c
··· 124 124 unsigned long nr_lock_classes; 125 125 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; 126 126 127 + static inline struct lock_class *hlock_class(struct held_lock *hlock) 128 + { 129 + if (!hlock->class_idx) { 130 + DEBUG_LOCKS_WARN_ON(1); 131 + return NULL; 132 + } 133 + return lock_classes + hlock->class_idx - 1; 134 + } 135 + 127 136 #ifdef CONFIG_LOCK_STAT 128 137 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], lock_stats); 129 138 ··· 231 222 232 223 holdtime = sched_clock() - hlock->holdtime_stamp; 233 224 234 - stats = get_lock_stats(hlock->class); 225 + stats = get_lock_stats(hlock_class(hlock)); 235 226 if (hlock->read) 236 227 lock_time_inc(&stats->read_holdtime, holdtime); 237 228 else ··· 381 372 unsigned int max_lockdep_depth; 382 373 unsigned int max_recursion_depth; 383 374 375 + static unsigned int lockdep_dependency_gen_id; 376 + 377 + static bool lockdep_dependency_visit(struct lock_class *source, 378 + unsigned int depth) 379 + { 380 + if (!depth) 381 + lockdep_dependency_gen_id++; 382 + if (source->dep_gen_id == lockdep_dependency_gen_id) 383 + return true; 384 + source->dep_gen_id = lockdep_dependency_gen_id; 385 + return false; 386 + } 387 + 384 388 #ifdef CONFIG_DEBUG_LOCKDEP 385 389 /* 386 390 * We cannot printk in early bootup code. Not even early_printk() ··· 527 505 528 506 static void print_lock(struct held_lock *hlock) 529 507 { 530 - print_lock_name(hlock->class); 508 + print_lock_name(hlock_class(hlock)); 531 509 printk(", at: "); 532 510 print_ip_sym(hlock->acquire_ip); 533 511 } ··· 579 557 static void print_lock_dependencies(struct lock_class *class, int depth) 580 558 { 581 559 struct lock_list *entry; 560 + 561 + if (lockdep_dependency_visit(class, depth)) 562 + return; 582 563 583 564 if (DEBUG_LOCKS_WARN_ON(depth >= 20)) 584 565 return; ··· 957 932 if (debug_locks_silent) 958 933 return 0; 959 934 960 - this.class = check_source->class; 935 + this.class = hlock_class(check_source); 961 936 if (!save_trace(&this.trace)) 962 937 return 0; 963 938 ··· 984 959 return 0; 985 960 } 986 961 962 + unsigned long __lockdep_count_forward_deps(struct lock_class *class, 963 + unsigned int depth) 964 + { 965 + struct lock_list *entry; 966 + unsigned long ret = 1; 967 + 968 + if (lockdep_dependency_visit(class, depth)) 969 + return 0; 970 + 971 + /* 972 + * Recurse this class's dependency list: 973 + */ 974 + list_for_each_entry(entry, &class->locks_after, entry) 975 + ret += __lockdep_count_forward_deps(entry->class, depth + 1); 976 + 977 + return ret; 978 + } 979 + 980 + unsigned long lockdep_count_forward_deps(struct lock_class *class) 981 + { 982 + unsigned long ret, flags; 983 + 984 + local_irq_save(flags); 985 + __raw_spin_lock(&lockdep_lock); 986 + ret = __lockdep_count_forward_deps(class, 0); 987 + __raw_spin_unlock(&lockdep_lock); 988 + local_irq_restore(flags); 989 + 990 + return ret; 991 + } 992 + 993 + unsigned long __lockdep_count_backward_deps(struct lock_class *class, 994 + unsigned int depth) 995 + { 996 + struct lock_list *entry; 997 + unsigned long ret = 1; 998 + 999 + if (lockdep_dependency_visit(class, depth)) 1000 + return 0; 1001 + /* 1002 + * Recurse this class's dependency list: 1003 + */ 1004 + list_for_each_entry(entry, &class->locks_before, entry) 1005 + ret += __lockdep_count_backward_deps(entry->class, depth + 1); 1006 + 1007 + return ret; 1008 + } 1009 + 1010 + unsigned long lockdep_count_backward_deps(struct lock_class *class) 1011 + { 1012 + unsigned long ret, flags; 1013 + 1014 + local_irq_save(flags); 1015 + __raw_spin_lock(&lockdep_lock); 1016 + ret = __lockdep_count_backward_deps(class, 0); 1017 + __raw_spin_unlock(&lockdep_lock); 1018 + local_irq_restore(flags); 1019 + 1020 + return ret; 1021 + } 1022 + 987 1023 /* 988 1024 * Prove that the dependency graph starting at <entry> can not 989 1025 * lead to <target>. Print an error and return 0 if it does. ··· 1053 967 check_noncircular(struct lock_class *source, unsigned int depth) 1054 968 { 1055 969 struct lock_list *entry; 970 + 971 + if (lockdep_dependency_visit(source, depth)) 972 + return 1; 1056 973 1057 974 debug_atomic_inc(&nr_cyclic_check_recursions); 1058 975 if (depth > max_recursion_depth) ··· 1066 977 * Check this lock's dependency list: 1067 978 */ 1068 979 list_for_each_entry(entry, &source->locks_after, entry) { 1069 - if (entry->class == check_target->class) 980 + if (entry->class == hlock_class(check_target)) 1070 981 return print_circular_bug_header(entry, depth+1); 1071 982 debug_atomic_inc(&nr_cyclic_checks); 1072 983 if (!check_noncircular(entry->class, depth+1)) ··· 1099 1010 { 1100 1011 struct lock_list *entry; 1101 1012 int ret; 1013 + 1014 + if (lockdep_dependency_visit(source, depth)) 1015 + return 1; 1102 1016 1103 1017 if (depth > max_recursion_depth) 1104 1018 max_recursion_depth = depth; ··· 1142 1050 struct lock_list *entry; 1143 1051 int ret; 1144 1052 1053 + if (lockdep_dependency_visit(source, depth)) 1054 + return 1; 1055 + 1145 1056 if (!__raw_spin_is_locked(&lockdep_lock)) 1146 1057 return DEBUG_LOCKS_WARN_ON(1); 1147 1058 ··· 1157 1062 if (source->usage_mask & (1 << find_usage_bit)) { 1158 1063 backwards_match = source; 1159 1064 return 2; 1065 + } 1066 + 1067 + if (!source && debug_locks_off_graph_unlock()) { 1068 + WARN_ON(1); 1069 + return 0; 1160 1070 } 1161 1071 1162 1072 /* ··· 1203 1103 printk("\nand this task is already holding:\n"); 1204 1104 print_lock(prev); 1205 1105 printk("which would create a new lock dependency:\n"); 1206 - print_lock_name(prev->class); 1106 + print_lock_name(hlock_class(prev)); 1207 1107 printk(" ->"); 1208 - print_lock_name(next->class); 1108 + print_lock_name(hlock_class(next)); 1209 1109 printk("\n"); 1210 1110 1211 1111 printk("\nbut this new dependency connects a %s-irq-safe lock:\n", ··· 1246 1146 1247 1147 find_usage_bit = bit_backwards; 1248 1148 /* fills in <backwards_match> */ 1249 - ret = find_usage_backwards(prev->class, 0); 1149 + ret = find_usage_backwards(hlock_class(prev), 0); 1250 1150 if (!ret || ret == 1) 1251 1151 return ret; 1252 1152 1253 1153 find_usage_bit = bit_forwards; 1254 - ret = find_usage_forwards(next->class, 0); 1154 + ret = find_usage_forwards(hlock_class(next), 0); 1255 1155 if (!ret || ret == 1) 1256 1156 return ret; 1257 1157 /* ret == 2 */ ··· 1372 1272 struct lockdep_map *next_instance, int read) 1373 1273 { 1374 1274 struct held_lock *prev; 1275 + struct held_lock *nest = NULL; 1375 1276 int i; 1376 1277 1377 1278 for (i = 0; i < curr->lockdep_depth; i++) { 1378 1279 prev = curr->held_locks + i; 1379 - if (prev->class != next->class) 1280 + 1281 + if (prev->instance == next->nest_lock) 1282 + nest = prev; 1283 + 1284 + if (hlock_class(prev) != hlock_class(next)) 1380 1285 continue; 1286 + 1381 1287 /* 1382 1288 * Allow read-after-read recursion of the same 1383 1289 * lock class (i.e. read_lock(lock)+read_lock(lock)): 1384 1290 */ 1385 1291 if ((read == 2) && prev->read) 1386 1292 return 2; 1293 + 1294 + /* 1295 + * We're holding the nest_lock, which serializes this lock's 1296 + * nesting behaviour. 1297 + */ 1298 + if (nest) 1299 + return 2; 1300 + 1387 1301 return print_deadlock_bug(curr, prev, next); 1388 1302 } 1389 1303 return 1; ··· 1443 1329 */ 1444 1330 check_source = next; 1445 1331 check_target = prev; 1446 - if (!(check_noncircular(next->class, 0))) 1332 + if (!(check_noncircular(hlock_class(next), 0))) 1447 1333 return print_circular_bug_tail(); 1448 1334 1449 1335 if (!check_prev_add_irq(curr, prev, next)) ··· 1467 1353 * chains - the second one will be new, but L1 already has 1468 1354 * L2 added to its dependency list, due to the first chain.) 1469 1355 */ 1470 - list_for_each_entry(entry, &prev->class->locks_after, entry) { 1471 - if (entry->class == next->class) { 1356 + list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { 1357 + if (entry->class == hlock_class(next)) { 1472 1358 if (distance == 1) 1473 1359 entry->distance = 1; 1474 1360 return 2; ··· 1479 1365 * Ok, all validations passed, add the new lock 1480 1366 * to the previous lock's dependency list: 1481 1367 */ 1482 - ret = add_lock_to_list(prev->class, next->class, 1483 - &prev->class->locks_after, next->acquire_ip, distance); 1368 + ret = add_lock_to_list(hlock_class(prev), hlock_class(next), 1369 + &hlock_class(prev)->locks_after, 1370 + next->acquire_ip, distance); 1484 1371 1485 1372 if (!ret) 1486 1373 return 0; 1487 1374 1488 - ret = add_lock_to_list(next->class, prev->class, 1489 - &next->class->locks_before, next->acquire_ip, distance); 1375 + ret = add_lock_to_list(hlock_class(next), hlock_class(prev), 1376 + &hlock_class(next)->locks_before, 1377 + next->acquire_ip, distance); 1490 1378 if (!ret) 1491 1379 return 0; 1492 1380 1493 1381 /* 1494 1382 * Debugging printouts: 1495 1383 */ 1496 - if (verbose(prev->class) || verbose(next->class)) { 1384 + if (verbose(hlock_class(prev)) || verbose(hlock_class(next))) { 1497 1385 graph_unlock(); 1498 1386 printk("\n new dependency: "); 1499 - print_lock_name(prev->class); 1387 + print_lock_name(hlock_class(prev)); 1500 1388 printk(" => "); 1501 - print_lock_name(next->class); 1389 + print_lock_name(hlock_class(next)); 1502 1390 printk("\n"); 1503 1391 dump_stack(); 1504 1392 return graph_lock(); ··· 1597 1481 struct held_lock *hlock, 1598 1482 u64 chain_key) 1599 1483 { 1600 - struct lock_class *class = hlock->class; 1484 + struct lock_class *class = hlock_class(hlock); 1601 1485 struct list_head *hash_head = chainhashentry(chain_key); 1602 1486 struct lock_chain *chain; 1603 1487 struct held_lock *hlock_curr, *hlock_next; ··· 1670 1554 if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) { 1671 1555 chain->base = cn; 1672 1556 for (j = 0; j < chain->depth - 1; j++, i++) { 1673 - int lock_id = curr->held_locks[i].class - lock_classes; 1557 + int lock_id = curr->held_locks[i].class_idx - 1; 1674 1558 chain_hlocks[chain->base + j] = lock_id; 1675 1559 } 1676 1560 chain_hlocks[chain->base + j] = class - lock_classes; ··· 1766 1650 WARN_ON(1); 1767 1651 return; 1768 1652 } 1769 - id = hlock->class - lock_classes; 1653 + id = hlock->class_idx - 1; 1770 1654 if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) 1771 1655 return; 1772 1656 ··· 1811 1695 print_lock(this); 1812 1696 1813 1697 printk("{%s} state was registered at:\n", usage_str[prev_bit]); 1814 - print_stack_trace(this->class->usage_traces + prev_bit, 1); 1698 + print_stack_trace(hlock_class(this)->usage_traces + prev_bit, 1); 1815 1699 1816 1700 print_irqtrace_events(curr); 1817 1701 printk("\nother info that might help us debug this:\n"); ··· 1830 1714 valid_state(struct task_struct *curr, struct held_lock *this, 1831 1715 enum lock_usage_bit new_bit, enum lock_usage_bit bad_bit) 1832 1716 { 1833 - if (unlikely(this->class->usage_mask & (1 << bad_bit))) 1717 + if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit))) 1834 1718 return print_usage_bug(curr, this, bad_bit, new_bit); 1835 1719 return 1; 1836 1720 } ··· 1869 1753 lockdep_print_held_locks(curr); 1870 1754 1871 1755 printk("\nthe first lock's dependencies:\n"); 1872 - print_lock_dependencies(this->class, 0); 1756 + print_lock_dependencies(hlock_class(this), 0); 1873 1757 1874 1758 printk("\nthe second lock's dependencies:\n"); 1875 1759 print_lock_dependencies(other, 0); ··· 1892 1776 1893 1777 find_usage_bit = bit; 1894 1778 /* fills in <forwards_match> */ 1895 - ret = find_usage_forwards(this->class, 0); 1779 + ret = find_usage_forwards(hlock_class(this), 0); 1896 1780 if (!ret || ret == 1) 1897 1781 return ret; 1898 1782 ··· 1911 1795 1912 1796 find_usage_bit = bit; 1913 1797 /* fills in <backwards_match> */ 1914 - ret = find_usage_backwards(this->class, 0); 1798 + ret = find_usage_backwards(hlock_class(this), 0); 1915 1799 if (!ret || ret == 1) 1916 1800 return ret; 1917 1801 ··· 1977 1861 LOCK_ENABLED_HARDIRQS_READ, "hard-read")) 1978 1862 return 0; 1979 1863 #endif 1980 - if (hardirq_verbose(this->class)) 1864 + if (hardirq_verbose(hlock_class(this))) 1981 1865 ret = 2; 1982 1866 break; 1983 1867 case LOCK_USED_IN_SOFTIRQ: ··· 2002 1886 LOCK_ENABLED_SOFTIRQS_READ, "soft-read")) 2003 1887 return 0; 2004 1888 #endif 2005 - if (softirq_verbose(this->class)) 1889 + if (softirq_verbose(hlock_class(this))) 2006 1890 ret = 2; 2007 1891 break; 2008 1892 case LOCK_USED_IN_HARDIRQ_READ: ··· 2015 1899 if (!check_usage_forwards(curr, this, 2016 1900 LOCK_ENABLED_HARDIRQS, "hard")) 2017 1901 return 0; 2018 - if (hardirq_verbose(this->class)) 1902 + if (hardirq_verbose(hlock_class(this))) 2019 1903 ret = 2; 2020 1904 break; 2021 1905 case LOCK_USED_IN_SOFTIRQ_READ: ··· 2028 1912 if (!check_usage_forwards(curr, this, 2029 1913 LOCK_ENABLED_SOFTIRQS, "soft")) 2030 1914 return 0; 2031 - if (softirq_verbose(this->class)) 1915 + if (softirq_verbose(hlock_class(this))) 2032 1916 ret = 2; 2033 1917 break; 2034 1918 case LOCK_ENABLED_HARDIRQS: ··· 2054 1938 LOCK_USED_IN_HARDIRQ_READ, "hard-read")) 2055 1939 return 0; 2056 1940 #endif 2057 - if (hardirq_verbose(this->class)) 1941 + if (hardirq_verbose(hlock_class(this))) 2058 1942 ret = 2; 2059 1943 break; 2060 1944 case LOCK_ENABLED_SOFTIRQS: ··· 2080 1964 LOCK_USED_IN_SOFTIRQ_READ, "soft-read")) 2081 1965 return 0; 2082 1966 #endif 2083 - if (softirq_verbose(this->class)) 1967 + if (softirq_verbose(hlock_class(this))) 2084 1968 ret = 2; 2085 1969 break; 2086 1970 case LOCK_ENABLED_HARDIRQS_READ: ··· 2095 1979 LOCK_USED_IN_HARDIRQ, "hard")) 2096 1980 return 0; 2097 1981 #endif 2098 - if (hardirq_verbose(this->class)) 1982 + if (hardirq_verbose(hlock_class(this))) 2099 1983 ret = 2; 2100 1984 break; 2101 1985 case LOCK_ENABLED_SOFTIRQS_READ: ··· 2110 1994 LOCK_USED_IN_SOFTIRQ, "soft")) 2111 1995 return 0; 2112 1996 #endif 2113 - if (softirq_verbose(this->class)) 1997 + if (softirq_verbose(hlock_class(this))) 2114 1998 ret = 2; 2115 1999 break; 2116 2000 default: ··· 2426 2310 * If already set then do not dirty the cacheline, 2427 2311 * nor do any checks: 2428 2312 */ 2429 - if (likely(this->class->usage_mask & new_mask)) 2313 + if (likely(hlock_class(this)->usage_mask & new_mask)) 2430 2314 return 1; 2431 2315 2432 2316 if (!graph_lock()) ··· 2434 2318 /* 2435 2319 * Make sure we didnt race: 2436 2320 */ 2437 - if (unlikely(this->class->usage_mask & new_mask)) { 2321 + if (unlikely(hlock_class(this)->usage_mask & new_mask)) { 2438 2322 graph_unlock(); 2439 2323 return 1; 2440 2324 } 2441 2325 2442 - this->class->usage_mask |= new_mask; 2326 + hlock_class(this)->usage_mask |= new_mask; 2443 2327 2444 - if (!save_trace(this->class->usage_traces + new_bit)) 2328 + if (!save_trace(hlock_class(this)->usage_traces + new_bit)) 2445 2329 return 0; 2446 2330 2447 2331 switch (new_bit) { ··· 2521 2405 */ 2522 2406 static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, 2523 2407 int trylock, int read, int check, int hardirqs_off, 2524 - unsigned long ip) 2408 + struct lockdep_map *nest_lock, unsigned long ip) 2525 2409 { 2526 2410 struct task_struct *curr = current; 2527 2411 struct lock_class *class = NULL; ··· 2575 2459 return 0; 2576 2460 2577 2461 hlock = curr->held_locks + depth; 2578 - 2579 - hlock->class = class; 2462 + if (DEBUG_LOCKS_WARN_ON(!class)) 2463 + return 0; 2464 + hlock->class_idx = class - lock_classes + 1; 2580 2465 hlock->acquire_ip = ip; 2581 2466 hlock->instance = lock; 2467 + hlock->nest_lock = nest_lock; 2582 2468 hlock->trylock = trylock; 2583 2469 hlock->read = read; 2584 2470 hlock->check = check; ··· 2692 2574 return 1; 2693 2575 } 2694 2576 2577 + static int 2578 + __lock_set_subclass(struct lockdep_map *lock, 2579 + unsigned int subclass, unsigned long ip) 2580 + { 2581 + struct task_struct *curr = current; 2582 + struct held_lock *hlock, *prev_hlock; 2583 + struct lock_class *class; 2584 + unsigned int depth; 2585 + int i; 2586 + 2587 + depth = curr->lockdep_depth; 2588 + if (DEBUG_LOCKS_WARN_ON(!depth)) 2589 + return 0; 2590 + 2591 + prev_hlock = NULL; 2592 + for (i = depth-1; i >= 0; i--) { 2593 + hlock = curr->held_locks + i; 2594 + /* 2595 + * We must not cross into another context: 2596 + */ 2597 + if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) 2598 + break; 2599 + if (hlock->instance == lock) 2600 + goto found_it; 2601 + prev_hlock = hlock; 2602 + } 2603 + return print_unlock_inbalance_bug(curr, lock, ip); 2604 + 2605 + found_it: 2606 + class = register_lock_class(lock, subclass, 0); 2607 + hlock->class_idx = class - lock_classes + 1; 2608 + 2609 + curr->lockdep_depth = i; 2610 + curr->curr_chain_key = hlock->prev_chain_key; 2611 + 2612 + for (; i < depth; i++) { 2613 + hlock = curr->held_locks + i; 2614 + if (!__lock_acquire(hlock->instance, 2615 + hlock_class(hlock)->subclass, hlock->trylock, 2616 + hlock->read, hlock->check, hlock->hardirqs_off, 2617 + hlock->nest_lock, hlock->acquire_ip)) 2618 + return 0; 2619 + } 2620 + 2621 + if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) 2622 + return 0; 2623 + return 1; 2624 + } 2625 + 2695 2626 /* 2696 2627 * Remove the lock to the list of currently held locks in a 2697 2628 * potentially non-nested (out of order) manner. This is a ··· 2791 2624 for (i++; i < depth; i++) { 2792 2625 hlock = curr->held_locks + i; 2793 2626 if (!__lock_acquire(hlock->instance, 2794 - hlock->class->subclass, hlock->trylock, 2627 + hlock_class(hlock)->subclass, hlock->trylock, 2795 2628 hlock->read, hlock->check, hlock->hardirqs_off, 2796 - hlock->acquire_ip)) 2629 + hlock->nest_lock, hlock->acquire_ip)) 2797 2630 return 0; 2798 2631 } 2799 2632 ··· 2836 2669 2837 2670 #ifdef CONFIG_DEBUG_LOCKDEP 2838 2671 hlock->prev_chain_key = 0; 2839 - hlock->class = NULL; 2672 + hlock->class_idx = 0; 2840 2673 hlock->acquire_ip = 0; 2841 2674 hlock->irq_context = 0; 2842 2675 #endif ··· 2905 2738 #endif 2906 2739 } 2907 2740 2741 + void 2742 + lock_set_subclass(struct lockdep_map *lock, 2743 + unsigned int subclass, unsigned long ip) 2744 + { 2745 + unsigned long flags; 2746 + 2747 + if (unlikely(current->lockdep_recursion)) 2748 + return; 2749 + 2750 + raw_local_irq_save(flags); 2751 + current->lockdep_recursion = 1; 2752 + check_flags(flags); 2753 + if (__lock_set_subclass(lock, subclass, ip)) 2754 + check_chain_key(current); 2755 + current->lockdep_recursion = 0; 2756 + raw_local_irq_restore(flags); 2757 + } 2758 + 2759 + EXPORT_SYMBOL_GPL(lock_set_subclass); 2760 + 2908 2761 /* 2909 2762 * We are not always called with irqs disabled - do that here, 2910 2763 * and also avoid lockdep recursion: 2911 2764 */ 2912 2765 void lock_acquire(struct lockdep_map *lock, unsigned int subclass, 2913 - int trylock, int read, int check, unsigned long ip) 2766 + int trylock, int read, int check, 2767 + struct lockdep_map *nest_lock, unsigned long ip) 2914 2768 { 2915 2769 unsigned long flags; 2916 - 2917 - if (unlikely(!lock_stat && !prove_locking)) 2918 - return; 2919 2770 2920 2771 if (unlikely(current->lockdep_recursion)) 2921 2772 return; ··· 2943 2758 2944 2759 current->lockdep_recursion = 1; 2945 2760 __lock_acquire(lock, subclass, trylock, read, check, 2946 - irqs_disabled_flags(flags), ip); 2761 + irqs_disabled_flags(flags), nest_lock, ip); 2947 2762 current->lockdep_recursion = 0; 2948 2763 raw_local_irq_restore(flags); 2949 2764 } ··· 2954 2769 unsigned long ip) 2955 2770 { 2956 2771 unsigned long flags; 2957 - 2958 - if (unlikely(!lock_stat && !prove_locking)) 2959 - return; 2960 2772 2961 2773 if (unlikely(current->lockdep_recursion)) 2962 2774 return; ··· 3027 2845 found_it: 3028 2846 hlock->waittime_stamp = sched_clock(); 3029 2847 3030 - point = lock_contention_point(hlock->class, ip); 2848 + point = lock_contention_point(hlock_class(hlock), ip); 3031 2849 3032 - stats = get_lock_stats(hlock->class); 2850 + stats = get_lock_stats(hlock_class(hlock)); 3033 2851 if (point < ARRAY_SIZE(stats->contention_point)) 3034 2852 stats->contention_point[i]++; 3035 2853 if (lock->cpu != smp_processor_id()) ··· 3075 2893 hlock->holdtime_stamp = now; 3076 2894 } 3077 2895 3078 - stats = get_lock_stats(hlock->class); 2896 + stats = get_lock_stats(hlock_class(hlock)); 3079 2897 if (waittime) { 3080 2898 if (hlock->read) 3081 2899 lock_time_inc(&stats->read_waittime, waittime); ··· 3170 2988 list_del_rcu(&class->hash_entry); 3171 2989 list_del_rcu(&class->lock_entry); 3172 2990 2991 + class->key = NULL; 3173 2992 } 3174 2993 3175 2994 static inline int within(const void *addr, void *start, unsigned long size)
+3 -3
kernel/lockdep_internals.h
··· 17 17 */ 18 18 #define MAX_LOCKDEP_ENTRIES 8192UL 19 19 20 - #define MAX_LOCKDEP_KEYS_BITS 11 21 - #define MAX_LOCKDEP_KEYS (1UL << MAX_LOCKDEP_KEYS_BITS) 22 - 23 20 #define MAX_LOCKDEP_CHAINS_BITS 14 24 21 #define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) 25 22 ··· 49 52 extern unsigned int nr_process_chains; 50 53 extern unsigned int max_lockdep_depth; 51 54 extern unsigned int max_recursion_depth; 55 + 56 + extern unsigned long lockdep_count_forward_deps(struct lock_class *); 57 + extern unsigned long lockdep_count_backward_deps(struct lock_class *); 52 58 53 59 #ifdef CONFIG_DEBUG_LOCKDEP 54 60 /*
+6 -31
kernel/lockdep_proc.c
··· 63 63 { 64 64 } 65 65 66 - static unsigned long count_forward_deps(struct lock_class *class) 67 - { 68 - struct lock_list *entry; 69 - unsigned long ret = 1; 70 - 71 - /* 72 - * Recurse this class's dependency list: 73 - */ 74 - list_for_each_entry(entry, &class->locks_after, entry) 75 - ret += count_forward_deps(entry->class); 76 - 77 - return ret; 78 - } 79 - 80 - static unsigned long count_backward_deps(struct lock_class *class) 81 - { 82 - struct lock_list *entry; 83 - unsigned long ret = 1; 84 - 85 - /* 86 - * Recurse this class's dependency list: 87 - */ 88 - list_for_each_entry(entry, &class->locks_before, entry) 89 - ret += count_backward_deps(entry->class); 90 - 91 - return ret; 92 - } 93 - 94 66 static void print_name(struct seq_file *m, struct lock_class *class) 95 67 { 96 68 char str[128]; ··· 96 124 #ifdef CONFIG_DEBUG_LOCKDEP 97 125 seq_printf(m, " OPS:%8ld", class->ops); 98 126 #endif 99 - nr_forward_deps = count_forward_deps(class); 127 + nr_forward_deps = lockdep_count_forward_deps(class); 100 128 seq_printf(m, " FD:%5ld", nr_forward_deps); 101 129 102 - nr_backward_deps = count_backward_deps(class); 130 + nr_backward_deps = lockdep_count_backward_deps(class); 103 131 seq_printf(m, " BD:%5ld", nr_backward_deps); 104 132 105 133 get_usage_chars(class, &c1, &c2, &c3, &c4); ··· 201 229 202 230 for (i = 0; i < chain->depth; i++) { 203 231 class = lock_chain_get_class(chain, i); 232 + if (!class->key) 233 + continue; 234 + 204 235 seq_printf(m, "[%p] ", class->key); 205 236 print_name(m, class); 206 237 seq_puts(m, "\n"); ··· 325 350 if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ) 326 351 nr_hardirq_read_unsafe++; 327 352 328 - sum_forward_deps += count_forward_deps(class); 353 + sum_forward_deps += lockdep_count_forward_deps(class); 329 354 } 330 355 #ifdef CONFIG_DEBUG_LOCKDEP 331 356 DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused);
+13 -8
kernel/sched.c
··· 600 600 /* BKL stats */ 601 601 unsigned int bkl_count; 602 602 #endif 603 - struct lock_class_key rq_lock_key; 604 603 }; 605 604 606 605 static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); ··· 2758 2759 } else { 2759 2760 if (rq1 < rq2) { 2760 2761 spin_lock(&rq1->lock); 2761 - spin_lock(&rq2->lock); 2762 + spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING); 2762 2763 } else { 2763 2764 spin_lock(&rq2->lock); 2764 - spin_lock(&rq1->lock); 2765 + spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); 2765 2766 } 2766 2767 } 2767 2768 update_rq_clock(rq1); ··· 2804 2805 if (busiest < this_rq) { 2805 2806 spin_unlock(&this_rq->lock); 2806 2807 spin_lock(&busiest->lock); 2807 - spin_lock(&this_rq->lock); 2808 + spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING); 2808 2809 ret = 1; 2809 2810 } else 2810 - spin_lock(&busiest->lock); 2811 + spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING); 2811 2812 } 2812 2813 return ret; 2814 + } 2815 + 2816 + static void double_unlock_balance(struct rq *this_rq, struct rq *busiest) 2817 + __releases(busiest->lock) 2818 + { 2819 + spin_unlock(&busiest->lock); 2820 + lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); 2813 2821 } 2814 2822 2815 2823 /* ··· 3643 3637 ld_moved = move_tasks(this_rq, this_cpu, busiest, 3644 3638 imbalance, sd, CPU_NEWLY_IDLE, 3645 3639 &all_pinned); 3646 - spin_unlock(&busiest->lock); 3640 + double_unlock_balance(this_rq, busiest); 3647 3641 3648 3642 if (unlikely(all_pinned)) { 3649 3643 cpu_clear(cpu_of(busiest), *cpus); ··· 3758 3752 else 3759 3753 schedstat_inc(sd, alb_failed); 3760 3754 } 3761 - spin_unlock(&target_rq->lock); 3755 + double_unlock_balance(busiest_rq, target_rq); 3762 3756 } 3763 3757 3764 3758 #ifdef CONFIG_NO_HZ ··· 8006 8000 8007 8001 rq = cpu_rq(i); 8008 8002 spin_lock_init(&rq->lock); 8009 - lockdep_set_class(&rq->lock, &rq->rq_lock_key); 8010 8003 rq->nr_running = 0; 8011 8004 init_cfs_rq(&rq->cfs, rq); 8012 8005 init_rt_rq(&rq->rt, rq);
+5 -3
kernel/sched_rt.c
··· 861 861 #define RT_MAX_TRIES 3 862 862 863 863 static int double_lock_balance(struct rq *this_rq, struct rq *busiest); 864 + static void double_unlock_balance(struct rq *this_rq, struct rq *busiest); 865 + 864 866 static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep); 865 867 866 868 static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) ··· 1024 1022 break; 1025 1023 1026 1024 /* try again */ 1027 - spin_unlock(&lowest_rq->lock); 1025 + double_unlock_balance(rq, lowest_rq); 1028 1026 lowest_rq = NULL; 1029 1027 } 1030 1028 ··· 1093 1091 1094 1092 resched_task(lowest_rq->curr); 1095 1093 1096 - spin_unlock(&lowest_rq->lock); 1094 + double_unlock_balance(rq, lowest_rq); 1097 1095 1098 1096 ret = 1; 1099 1097 out: ··· 1199 1197 1200 1198 } 1201 1199 skip: 1202 - spin_unlock(&src_rq->lock); 1200 + double_unlock_balance(this_rq, src_rq); 1203 1201 } 1204 1202 1205 1203 return ret;
+47 -7
kernel/smp.c
··· 260 260 generic_exec_single(cpu, data); 261 261 } 262 262 263 + /* Dummy function */ 264 + static void quiesce_dummy(void *unused) 265 + { 266 + } 267 + 268 + /* 269 + * Ensure stack based data used in call function mask is safe to free. 270 + * 271 + * This is needed by smp_call_function_mask when using on-stack data, because 272 + * a single call function queue is shared by all CPUs, and any CPU may pick up 273 + * the data item on the queue at any time before it is deleted. So we need to 274 + * ensure that all CPUs have transitioned through a quiescent state after 275 + * this call. 276 + * 277 + * This is a very slow function, implemented by sending synchronous IPIs to 278 + * all possible CPUs. For this reason, we have to alloc data rather than use 279 + * stack based data even in the case of synchronous calls. The stack based 280 + * data is then just used for deadlock/oom fallback which will be very rare. 281 + * 282 + * If a faster scheme can be made, we could go back to preferring stack based 283 + * data -- the data allocation/free is non-zero cost. 284 + */ 285 + static void smp_call_function_mask_quiesce_stack(cpumask_t mask) 286 + { 287 + struct call_single_data data; 288 + int cpu; 289 + 290 + data.func = quiesce_dummy; 291 + data.info = NULL; 292 + data.flags = CSD_FLAG_WAIT; 293 + 294 + for_each_cpu_mask(cpu, mask) 295 + generic_exec_single(cpu, &data); 296 + } 297 + 263 298 /** 264 299 * smp_call_function_mask(): Run a function on a set of other CPUs. 265 300 * @mask: The set of cpus to run on. ··· 320 285 cpumask_t allbutself; 321 286 unsigned long flags; 322 287 int cpu, num_cpus; 288 + int slowpath = 0; 323 289 324 290 /* Can deadlock when called with interrupts disabled */ 325 291 WARN_ON(irqs_disabled()); ··· 342 306 return smp_call_function_single(cpu, func, info, wait); 343 307 } 344 308 345 - if (!wait) { 346 - data = kmalloc(sizeof(*data), GFP_ATOMIC); 347 - if (data) 348 - data->csd.flags = CSD_FLAG_ALLOC; 349 - } 350 - if (!data) { 309 + data = kmalloc(sizeof(*data), GFP_ATOMIC); 310 + if (data) { 311 + data->csd.flags = CSD_FLAG_ALLOC; 312 + if (wait) 313 + data->csd.flags |= CSD_FLAG_WAIT; 314 + } else { 351 315 data = &d; 352 316 data->csd.flags = CSD_FLAG_WAIT; 353 317 wait = 1; 318 + slowpath = 1; 354 319 } 355 320 356 321 spin_lock_init(&data->lock); ··· 368 331 arch_send_call_function_ipi(mask); 369 332 370 333 /* optionally wait for the CPUs to complete */ 371 - if (wait) 334 + if (wait) { 372 335 csd_flag_wait(&data->csd); 336 + if (unlikely(slowpath)) 337 + smp_call_function_mask_quiesce_stack(allbutself); 338 + } 373 339 374 340 return 0; 375 341 }
+11
kernel/spinlock.c
··· 292 292 } 293 293 294 294 EXPORT_SYMBOL(_spin_lock_nested); 295 + 295 296 unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass) 296 297 { 297 298 unsigned long flags; ··· 314 313 } 315 314 316 315 EXPORT_SYMBOL(_spin_lock_irqsave_nested); 316 + 317 + void __lockfunc _spin_lock_nest_lock(spinlock_t *lock, 318 + struct lockdep_map *nest_lock) 319 + { 320 + preempt_disable(); 321 + spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); 322 + LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); 323 + } 324 + 325 + EXPORT_SYMBOL(_spin_lock_nest_lock); 317 326 318 327 #endif 319 328
+12 -12
kernel/workqueue.c
··· 290 290 291 291 BUG_ON(get_wq_data(work) != cwq); 292 292 work_clear_pending(work); 293 - lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); 294 - lock_acquire(&lockdep_map, 0, 0, 0, 2, _THIS_IP_); 293 + lock_map_acquire(&cwq->wq->lockdep_map); 294 + lock_map_acquire(&lockdep_map); 295 295 f(work); 296 - lock_release(&lockdep_map, 1, _THIS_IP_); 297 - lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); 296 + lock_map_release(&lockdep_map); 297 + lock_map_release(&cwq->wq->lockdep_map); 298 298 299 299 if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { 300 300 printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " ··· 413 413 int cpu; 414 414 415 415 might_sleep(); 416 - lock_acquire(&wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); 417 - lock_release(&wq->lockdep_map, 1, _THIS_IP_); 416 + lock_map_acquire(&wq->lockdep_map); 417 + lock_map_release(&wq->lockdep_map); 418 418 for_each_cpu_mask_nr(cpu, *cpu_map) 419 419 flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); 420 420 } ··· 441 441 if (!cwq) 442 442 return 0; 443 443 444 - lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); 445 - lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); 444 + lock_map_acquire(&cwq->wq->lockdep_map); 445 + lock_map_release(&cwq->wq->lockdep_map); 446 446 447 447 prev = NULL; 448 448 spin_lock_irq(&cwq->lock); ··· 536 536 537 537 might_sleep(); 538 538 539 - lock_acquire(&work->lockdep_map, 0, 0, 0, 2, _THIS_IP_); 540 - lock_release(&work->lockdep_map, 1, _THIS_IP_); 539 + lock_map_acquire(&work->lockdep_map); 540 + lock_map_release(&work->lockdep_map); 541 541 542 542 cwq = get_wq_data(work); 543 543 if (!cwq) ··· 872 872 if (cwq->thread == NULL) 873 873 return; 874 874 875 - lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); 876 - lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); 875 + lock_map_acquire(&cwq->wq->lockdep_map); 876 + lock_map_release(&cwq->wq->lockdep_map); 877 877 878 878 flush_cpu_workqueue(cwq); 879 879 /*
+2
lib/debug_locks.c
··· 8 8 * 9 9 * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> 10 10 */ 11 + #include <linux/kernel.h> 11 12 #include <linux/rwsem.h> 12 13 #include <linux/mutex.h> 13 14 #include <linux/module.h> ··· 38 37 { 39 38 if (xchg(&debug_locks, 0)) { 40 39 if (!debug_locks_silent) { 40 + oops_in_progress = 1; 41 41 console_verbose(); 42 42 return 1; 43 43 }
+13 -7
mm/mmap.c
··· 2273 2273 2274 2274 static DEFINE_MUTEX(mm_all_locks_mutex); 2275 2275 2276 - static void vm_lock_anon_vma(struct anon_vma *anon_vma) 2276 + static void vm_lock_anon_vma(struct mm_struct *mm, struct anon_vma *anon_vma) 2277 2277 { 2278 2278 if (!test_bit(0, (unsigned long *) &anon_vma->head.next)) { 2279 2279 /* 2280 2280 * The LSB of head.next can't change from under us 2281 2281 * because we hold the mm_all_locks_mutex. 2282 2282 */ 2283 - spin_lock(&anon_vma->lock); 2283 + spin_lock_nest_lock(&anon_vma->lock, &mm->mmap_sem); 2284 2284 /* 2285 2285 * We can safely modify head.next after taking the 2286 2286 * anon_vma->lock. If some other vma in this mm shares ··· 2296 2296 } 2297 2297 } 2298 2298 2299 - static void vm_lock_mapping(struct address_space *mapping) 2299 + static void vm_lock_mapping(struct mm_struct *mm, struct address_space *mapping) 2300 2300 { 2301 2301 if (!test_bit(AS_MM_ALL_LOCKS, &mapping->flags)) { 2302 2302 /* ··· 2310 2310 */ 2311 2311 if (test_and_set_bit(AS_MM_ALL_LOCKS, &mapping->flags)) 2312 2312 BUG(); 2313 - spin_lock(&mapping->i_mmap_lock); 2313 + spin_lock_nest_lock(&mapping->i_mmap_lock, &mm->mmap_sem); 2314 2314 } 2315 2315 } 2316 2316 ··· 2358 2358 for (vma = mm->mmap; vma; vma = vma->vm_next) { 2359 2359 if (signal_pending(current)) 2360 2360 goto out_unlock; 2361 - if (vma->anon_vma) 2362 - vm_lock_anon_vma(vma->anon_vma); 2363 2361 if (vma->vm_file && vma->vm_file->f_mapping) 2364 - vm_lock_mapping(vma->vm_file->f_mapping); 2362 + vm_lock_mapping(mm, vma->vm_file->f_mapping); 2365 2363 } 2364 + 2365 + for (vma = mm->mmap; vma; vma = vma->vm_next) { 2366 + if (signal_pending(current)) 2367 + goto out_unlock; 2368 + if (vma->anon_vma) 2369 + vm_lock_anon_vma(mm, vma->anon_vma); 2370 + } 2371 + 2366 2372 ret = 0; 2367 2373 2368 2374 out_unlock: