4 * Runtime locking correctness validator
6 * Started by Ingo Molnar:
8 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
9 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
11 * this code maps all the lock dependencies as they occur in a live kernel
12 * and will warn about the following classes of locking bugs:
14 * - lock inversion scenarios
15 * - circular lock dependencies
16 * - hardirq/softirq safe/unsafe locking bugs
18 * Bugs are reported even if the current locking scenario does not cause
19 * any deadlock at this point.
21 * I.e. if anytime in the past two locks were taken in a different order,
22 * even if it happened for another task, even if those were different
23 * locks (but of the same class as this lock), this code will detect it.
25 * Thanks to Arjan van de Ven for coming up with the initial idea of
26 * mapping lock dependencies runtime.
28 #define DISABLE_BRANCH_PROFILING
29 #include <linux/mutex.h>
30 #include <linux/sched.h>
31 #include <linux/delay.h>
32 #include <linux/module.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/spinlock.h>
36 #include <linux/kallsyms.h>
37 #include <linux/interrupt.h>
38 #include <linux/stacktrace.h>
39 #include <linux/debug_locks.h>
40 #include <linux/irqflags.h>
41 #include <linux/utsname.h>
42 #include <linux/hash.h>
43 #include <linux/ftrace.h>
45 #include <asm/sections.h>
47 #include "lockdep_internals.h"
49 #ifdef CONFIG_PROVE_LOCKING
50 int prove_locking
= 1;
51 module_param(prove_locking
, int, 0644);
53 #define prove_locking 0
56 #ifdef CONFIG_LOCK_STAT
58 module_param(lock_stat
, int, 0644);
64 * lockdep_lock: protects the lockdep graph, the hashes and the
65 * class/list/hash allocators.
67 * This is one of the rare exceptions where it's justified
68 * to use a raw spinlock - we really dont want the spinlock
69 * code to recurse back into the lockdep code...
71 static raw_spinlock_t lockdep_lock
= (raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
73 static int graph_lock(void)
75 __raw_spin_lock(&lockdep_lock
);
77 * Make sure that if another CPU detected a bug while
78 * walking the graph we dont change it (while the other
79 * CPU is busy printing out stuff with the graph lock
83 __raw_spin_unlock(&lockdep_lock
);
86 /* prevent any recursions within lockdep from causing deadlocks */
87 current
->lockdep_recursion
++;
91 static inline int graph_unlock(void)
93 if (debug_locks
&& !__raw_spin_is_locked(&lockdep_lock
))
94 return DEBUG_LOCKS_WARN_ON(1);
96 current
->lockdep_recursion
--;
97 __raw_spin_unlock(&lockdep_lock
);
102 * Turn lock debugging off and return with 0 if it was off already,
103 * and also release the graph lock:
105 static inline int debug_locks_off_graph_unlock(void)
107 int ret
= debug_locks_off();
109 __raw_spin_unlock(&lockdep_lock
);
114 static int lockdep_initialized
;
116 unsigned long nr_list_entries
;
117 static struct lock_list list_entries
[MAX_LOCKDEP_ENTRIES
];
120 * All data structures here are protected by the global debug_lock.
122 * Mutex key structs only get allocated, once during bootup, and never
123 * get freed - this significantly simplifies the debugging code.
125 unsigned long nr_lock_classes
;
126 static struct lock_class lock_classes
[MAX_LOCKDEP_KEYS
];
128 static inline struct lock_class
*hlock_class(struct held_lock
*hlock
)
130 if (!hlock
->class_idx
) {
131 DEBUG_LOCKS_WARN_ON(1);
134 return lock_classes
+ hlock
->class_idx
- 1;
137 #ifdef CONFIG_LOCK_STAT
138 static DEFINE_PER_CPU(struct lock_class_stats
[MAX_LOCKDEP_KEYS
], lock_stats
);
140 static int lock_contention_point(struct lock_class
*class, unsigned long ip
)
144 for (i
= 0; i
< ARRAY_SIZE(class->contention_point
); i
++) {
145 if (class->contention_point
[i
] == 0) {
146 class->contention_point
[i
] = ip
;
149 if (class->contention_point
[i
] == ip
)
156 static void lock_time_inc(struct lock_time
*lt
, s64 time
)
161 if (time
< lt
->min
|| !lt
->min
)
168 static inline void lock_time_add(struct lock_time
*src
, struct lock_time
*dst
)
170 dst
->min
+= src
->min
;
171 dst
->max
+= src
->max
;
172 dst
->total
+= src
->total
;
176 struct lock_class_stats
lock_stats(struct lock_class
*class)
178 struct lock_class_stats stats
;
181 memset(&stats
, 0, sizeof(struct lock_class_stats
));
182 for_each_possible_cpu(cpu
) {
183 struct lock_class_stats
*pcs
=
184 &per_cpu(lock_stats
, cpu
)[class - lock_classes
];
186 for (i
= 0; i
< ARRAY_SIZE(stats
.contention_point
); i
++)
187 stats
.contention_point
[i
] += pcs
->contention_point
[i
];
189 lock_time_add(&pcs
->read_waittime
, &stats
.read_waittime
);
190 lock_time_add(&pcs
->write_waittime
, &stats
.write_waittime
);
192 lock_time_add(&pcs
->read_holdtime
, &stats
.read_holdtime
);
193 lock_time_add(&pcs
->write_holdtime
, &stats
.write_holdtime
);
195 for (i
= 0; i
< ARRAY_SIZE(stats
.bounces
); i
++)
196 stats
.bounces
[i
] += pcs
->bounces
[i
];
202 void clear_lock_stats(struct lock_class
*class)
206 for_each_possible_cpu(cpu
) {
207 struct lock_class_stats
*cpu_stats
=
208 &per_cpu(lock_stats
, cpu
)[class - lock_classes
];
210 memset(cpu_stats
, 0, sizeof(struct lock_class_stats
));
212 memset(class->contention_point
, 0, sizeof(class->contention_point
));
215 static struct lock_class_stats
*get_lock_stats(struct lock_class
*class)
217 return &get_cpu_var(lock_stats
)[class - lock_classes
];
220 static void put_lock_stats(struct lock_class_stats
*stats
)
222 put_cpu_var(lock_stats
);
225 static void lock_release_holdtime(struct held_lock
*hlock
)
227 struct lock_class_stats
*stats
;
233 holdtime
= sched_clock() - hlock
->holdtime_stamp
;
235 stats
= get_lock_stats(hlock_class(hlock
));
237 lock_time_inc(&stats
->read_holdtime
, holdtime
);
239 lock_time_inc(&stats
->write_holdtime
, holdtime
);
240 put_lock_stats(stats
);
243 static inline void lock_release_holdtime(struct held_lock
*hlock
)
249 * We keep a global list of all lock classes. The list only grows,
250 * never shrinks. The list is only accessed with the lockdep
251 * spinlock lock held.
253 LIST_HEAD(all_lock_classes
);
256 * The lockdep classes are in a hash-table as well, for fast lookup:
258 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
259 #define CLASSHASH_SIZE (1UL << CLASSHASH_BITS)
260 #define __classhashfn(key) hash_long((unsigned long)key, CLASSHASH_BITS)
261 #define classhashentry(key) (classhash_table + __classhashfn((key)))
263 static struct list_head classhash_table
[CLASSHASH_SIZE
];
266 * We put the lock dependency chains into a hash-table as well, to cache
269 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
270 #define CHAINHASH_SIZE (1UL << CHAINHASH_BITS)
271 #define __chainhashfn(chain) hash_long(chain, CHAINHASH_BITS)
272 #define chainhashentry(chain) (chainhash_table + __chainhashfn((chain)))
274 static struct list_head chainhash_table
[CHAINHASH_SIZE
];
277 * The hash key of the lock dependency chains is a hash itself too:
278 * it's a hash of all locks taken up to that lock, including that lock.
279 * It's a 64-bit hash, because it's important for the keys to be
282 #define iterate_chain_key(key1, key2) \
283 (((key1) << MAX_LOCKDEP_KEYS_BITS) ^ \
284 ((key1) >> (64-MAX_LOCKDEP_KEYS_BITS)) ^ \
287 void lockdep_off(void)
289 current
->lockdep_recursion
++;
292 EXPORT_SYMBOL(lockdep_off
);
294 void lockdep_on(void)
296 current
->lockdep_recursion
--;
299 EXPORT_SYMBOL(lockdep_on
);
302 * Debugging switches:
306 #define VERY_VERBOSE 0
309 # define HARDIRQ_VERBOSE 1
310 # define SOFTIRQ_VERBOSE 1
312 # define HARDIRQ_VERBOSE 0
313 # define SOFTIRQ_VERBOSE 0
316 #if VERBOSE || HARDIRQ_VERBOSE || SOFTIRQ_VERBOSE
318 * Quick filtering for interesting events:
320 static int class_filter(struct lock_class
*class)
324 if (class->name_version
== 1 &&
325 !strcmp(class->name
, "lockname"))
327 if (class->name_version
== 1 &&
328 !strcmp(class->name
, "&struct->lockfield"))
331 /* Filter everything else. 1 would be to allow everything else */
336 static int verbose(struct lock_class
*class)
339 return class_filter(class);
345 * Stack-trace: tightly packed array of stack backtrace
346 * addresses. Protected by the graph_lock.
348 unsigned long nr_stack_trace_entries
;
349 static unsigned long stack_trace
[MAX_STACK_TRACE_ENTRIES
];
351 static int save_trace(struct stack_trace
*trace
)
353 trace
->nr_entries
= 0;
354 trace
->max_entries
= MAX_STACK_TRACE_ENTRIES
- nr_stack_trace_entries
;
355 trace
->entries
= stack_trace
+ nr_stack_trace_entries
;
359 save_stack_trace(trace
);
361 trace
->max_entries
= trace
->nr_entries
;
363 nr_stack_trace_entries
+= trace
->nr_entries
;
365 if (nr_stack_trace_entries
== MAX_STACK_TRACE_ENTRIES
) {
366 if (!debug_locks_off_graph_unlock())
369 printk("BUG: MAX_STACK_TRACE_ENTRIES too low!\n");
370 printk("turning off the locking correctness validator.\n");
379 unsigned int nr_hardirq_chains
;
380 unsigned int nr_softirq_chains
;
381 unsigned int nr_process_chains
;
382 unsigned int max_lockdep_depth
;
383 unsigned int max_recursion_depth
;
385 static unsigned int lockdep_dependency_gen_id
;
387 static bool lockdep_dependency_visit(struct lock_class
*source
,
391 lockdep_dependency_gen_id
++;
392 if (source
->dep_gen_id
== lockdep_dependency_gen_id
)
394 source
->dep_gen_id
= lockdep_dependency_gen_id
;
398 #ifdef CONFIG_DEBUG_LOCKDEP
400 * We cannot printk in early bootup code. Not even early_printk()
401 * might work. So we mark any initialization errors and printk
402 * about it later on, in lockdep_info().
404 static int lockdep_init_error
;
405 static unsigned long lockdep_init_trace_data
[20];
406 static struct stack_trace lockdep_init_trace
= {
407 .max_entries
= ARRAY_SIZE(lockdep_init_trace_data
),
408 .entries
= lockdep_init_trace_data
,
412 * Various lockdep statistics:
414 atomic_t chain_lookup_hits
;
415 atomic_t chain_lookup_misses
;
416 atomic_t hardirqs_on_events
;
417 atomic_t hardirqs_off_events
;
418 atomic_t redundant_hardirqs_on
;
419 atomic_t redundant_hardirqs_off
;
420 atomic_t softirqs_on_events
;
421 atomic_t softirqs_off_events
;
422 atomic_t redundant_softirqs_on
;
423 atomic_t redundant_softirqs_off
;
424 atomic_t nr_unused_locks
;
425 atomic_t nr_cyclic_checks
;
426 atomic_t nr_cyclic_check_recursions
;
427 atomic_t nr_find_usage_forwards_checks
;
428 atomic_t nr_find_usage_forwards_recursions
;
429 atomic_t nr_find_usage_backwards_checks
;
430 atomic_t nr_find_usage_backwards_recursions
;
431 # define debug_atomic_inc(ptr) atomic_inc(ptr)
432 # define debug_atomic_dec(ptr) atomic_dec(ptr)
433 # define debug_atomic_read(ptr) atomic_read(ptr)
435 # define debug_atomic_inc(ptr) do { } while (0)
436 # define debug_atomic_dec(ptr) do { } while (0)
437 # define debug_atomic_read(ptr) 0
444 static const char *usage_str
[] =
446 [LOCK_USED
] = "initial-use ",
447 [LOCK_USED_IN_HARDIRQ
] = "in-hardirq-W",
448 [LOCK_USED_IN_SOFTIRQ
] = "in-softirq-W",
449 [LOCK_ENABLED_SOFTIRQS
] = "softirq-on-W",
450 [LOCK_ENABLED_HARDIRQS
] = "hardirq-on-W",
451 [LOCK_USED_IN_HARDIRQ_READ
] = "in-hardirq-R",
452 [LOCK_USED_IN_SOFTIRQ_READ
] = "in-softirq-R",
453 [LOCK_ENABLED_SOFTIRQS_READ
] = "softirq-on-R",
454 [LOCK_ENABLED_HARDIRQS_READ
] = "hardirq-on-R",
457 const char * __get_key_name(struct lockdep_subclass_key
*key
, char *str
)
459 return kallsyms_lookup((unsigned long)key
, NULL
, NULL
, NULL
, str
);
463 get_usage_chars(struct lock_class
*class, char *c1
, char *c2
, char *c3
, char *c4
)
465 *c1
= '.', *c2
= '.', *c3
= '.', *c4
= '.';
467 if (class->usage_mask
& LOCKF_USED_IN_HARDIRQ
)
470 if (class->usage_mask
& LOCKF_ENABLED_HARDIRQS
)
473 if (class->usage_mask
& LOCKF_USED_IN_SOFTIRQ
)
476 if (class->usage_mask
& LOCKF_ENABLED_SOFTIRQS
)
479 if (class->usage_mask
& LOCKF_ENABLED_HARDIRQS_READ
)
481 if (class->usage_mask
& LOCKF_USED_IN_HARDIRQ_READ
) {
483 if (class->usage_mask
& LOCKF_ENABLED_HARDIRQS_READ
)
487 if (class->usage_mask
& LOCKF_ENABLED_SOFTIRQS_READ
)
489 if (class->usage_mask
& LOCKF_USED_IN_SOFTIRQ_READ
) {
491 if (class->usage_mask
& LOCKF_ENABLED_SOFTIRQS_READ
)
496 static void print_lock_name(struct lock_class
*class)
498 char str
[KSYM_NAME_LEN
], c1
, c2
, c3
, c4
;
501 get_usage_chars(class, &c1
, &c2
, &c3
, &c4
);
505 name
= __get_key_name(class->key
, str
);
506 printk(" (%s", name
);
508 printk(" (%s", name
);
509 if (class->name_version
> 1)
510 printk("#%d", class->name_version
);
512 printk("/%d", class->subclass
);
514 printk("){%c%c%c%c}", c1
, c2
, c3
, c4
);
517 static void print_lockdep_cache(struct lockdep_map
*lock
)
520 char str
[KSYM_NAME_LEN
];
524 name
= __get_key_name(lock
->key
->subkeys
, str
);
529 static void print_lock(struct held_lock
*hlock
)
531 print_lock_name(hlock_class(hlock
));
533 print_ip_sym(hlock
->acquire_ip
);
536 static void lockdep_print_held_locks(struct task_struct
*curr
)
538 int i
, depth
= curr
->lockdep_depth
;
541 printk("no locks held by %s/%d.\n", curr
->comm
, task_pid_nr(curr
));
544 printk("%d lock%s held by %s/%d:\n",
545 depth
, depth
> 1 ? "s" : "", curr
->comm
, task_pid_nr(curr
));
547 for (i
= 0; i
< depth
; i
++) {
549 print_lock(curr
->held_locks
+ i
);
553 static void print_lock_class_header(struct lock_class
*class, int depth
)
557 printk("%*s->", depth
, "");
558 print_lock_name(class);
559 printk(" ops: %lu", class->ops
);
562 for (bit
= 0; bit
< LOCK_USAGE_STATES
; bit
++) {
563 if (class->usage_mask
& (1 << bit
)) {
566 len
+= printk("%*s %s", depth
, "", usage_str
[bit
]);
567 len
+= printk(" at:\n");
568 print_stack_trace(class->usage_traces
+ bit
, len
);
571 printk("%*s }\n", depth
, "");
573 printk("%*s ... key at: ",depth
,"");
574 print_ip_sym((unsigned long)class->key
);
578 * printk all lock dependencies starting at <entry>:
580 static void print_lock_dependencies(struct lock_class
*class, int depth
)
582 struct lock_list
*entry
;
584 if (lockdep_dependency_visit(class, depth
))
587 if (DEBUG_LOCKS_WARN_ON(depth
>= 20))
590 print_lock_class_header(class, depth
);
592 list_for_each_entry(entry
, &class->locks_after
, entry
) {
593 if (DEBUG_LOCKS_WARN_ON(!entry
->class))
596 print_lock_dependencies(entry
->class, depth
+ 1);
598 printk("%*s ... acquired at:\n",depth
,"");
599 print_stack_trace(&entry
->trace
, 2);
604 static void print_kernel_version(void)
606 printk("%s %.*s\n", init_utsname()->release
,
607 (int)strcspn(init_utsname()->version
, " "),
608 init_utsname()->version
);
611 static int very_verbose(struct lock_class
*class)
614 return class_filter(class);
620 * Is this the address of a static object:
622 static int static_obj(void *obj
)
624 unsigned long start
= (unsigned long) &_stext
,
625 end
= (unsigned long) &_end
,
626 addr
= (unsigned long) obj
;
634 if ((addr
>= start
) && (addr
< end
))
641 for_each_possible_cpu(i
) {
642 start
= (unsigned long) &__per_cpu_start
+ per_cpu_offset(i
);
643 end
= (unsigned long) &__per_cpu_start
+ PERCPU_ENOUGH_ROOM
646 if ((addr
>= start
) && (addr
< end
))
654 return is_module_address(addr
);
658 * To make lock name printouts unique, we calculate a unique
659 * class->name_version generation counter:
661 static int count_matching_names(struct lock_class
*new_class
)
663 struct lock_class
*class;
666 if (!new_class
->name
)
669 list_for_each_entry(class, &all_lock_classes
, lock_entry
) {
670 if (new_class
->key
- new_class
->subclass
== class->key
)
671 return class->name_version
;
672 if (class->name
&& !strcmp(class->name
, new_class
->name
))
673 count
= max(count
, class->name_version
);
680 * Register a lock's class in the hash-table, if the class is not present
681 * yet. Otherwise we look it up. We cache the result in the lock object
682 * itself, so actual lookup of the hash should be once per lock object.
684 static inline struct lock_class
*
685 look_up_lock_class(struct lockdep_map
*lock
, unsigned int subclass
)
687 struct lockdep_subclass_key
*key
;
688 struct list_head
*hash_head
;
689 struct lock_class
*class;
691 #ifdef CONFIG_DEBUG_LOCKDEP
693 * If the architecture calls into lockdep before initializing
694 * the hashes then we'll warn about it later. (we cannot printk
697 if (unlikely(!lockdep_initialized
)) {
699 lockdep_init_error
= 1;
700 save_stack_trace(&lockdep_init_trace
);
705 * Static locks do not have their class-keys yet - for them the key
706 * is the lock object itself:
708 if (unlikely(!lock
->key
))
709 lock
->key
= (void *)lock
;
712 * NOTE: the class-key must be unique. For dynamic locks, a static
713 * lock_class_key variable is passed in through the mutex_init()
714 * (or spin_lock_init()) call - which acts as the key. For static
715 * locks we use the lock object itself as the key.
717 BUILD_BUG_ON(sizeof(struct lock_class_key
) >
718 sizeof(struct lockdep_map
));
720 key
= lock
->key
->subkeys
+ subclass
;
722 hash_head
= classhashentry(key
);
725 * We can walk the hash lockfree, because the hash only
726 * grows, and we are careful when adding entries to the end:
728 list_for_each_entry(class, hash_head
, hash_entry
) {
729 if (class->key
== key
) {
730 WARN_ON_ONCE(class->name
!= lock
->name
);
739 * Register a lock's class in the hash-table, if the class is not present
740 * yet. Otherwise we look it up. We cache the result in the lock object
741 * itself, so actual lookup of the hash should be once per lock object.
743 static inline struct lock_class
*
744 register_lock_class(struct lockdep_map
*lock
, unsigned int subclass
, int force
)
746 struct lockdep_subclass_key
*key
;
747 struct list_head
*hash_head
;
748 struct lock_class
*class;
751 class = look_up_lock_class(lock
, subclass
);
756 * Debug-check: all keys must be persistent!
758 if (!static_obj(lock
->key
)) {
760 printk("INFO: trying to register non-static key.\n");
761 printk("the code is fine but needs lockdep annotation.\n");
762 printk("turning off the locking correctness validator.\n");
768 key
= lock
->key
->subkeys
+ subclass
;
769 hash_head
= classhashentry(key
);
771 raw_local_irq_save(flags
);
773 raw_local_irq_restore(flags
);
777 * We have to do the hash-walk again, to avoid races
780 list_for_each_entry(class, hash_head
, hash_entry
)
781 if (class->key
== key
)
784 * Allocate a new key from the static array, and add it to
787 if (nr_lock_classes
>= MAX_LOCKDEP_KEYS
) {
788 if (!debug_locks_off_graph_unlock()) {
789 raw_local_irq_restore(flags
);
792 raw_local_irq_restore(flags
);
794 printk("BUG: MAX_LOCKDEP_KEYS too low!\n");
795 printk("turning off the locking correctness validator.\n");
798 class = lock_classes
+ nr_lock_classes
++;
799 debug_atomic_inc(&nr_unused_locks
);
801 class->name
= lock
->name
;
802 class->subclass
= subclass
;
803 INIT_LIST_HEAD(&class->lock_entry
);
804 INIT_LIST_HEAD(&class->locks_before
);
805 INIT_LIST_HEAD(&class->locks_after
);
806 class->name_version
= count_matching_names(class);
808 * We use RCU's safe list-add method to make
809 * parallel walking of the hash-list safe:
811 list_add_tail_rcu(&class->hash_entry
, hash_head
);
813 * Add it to the global list of classes:
815 list_add_tail_rcu(&class->lock_entry
, &all_lock_classes
);
817 if (verbose(class)) {
819 raw_local_irq_restore(flags
);
821 printk("\nnew class %p: %s", class->key
, class->name
);
822 if (class->name_version
> 1)
823 printk("#%d", class->name_version
);
827 raw_local_irq_save(flags
);
829 raw_local_irq_restore(flags
);
835 raw_local_irq_restore(flags
);
837 if (!subclass
|| force
)
838 lock
->class_cache
= class;
840 if (DEBUG_LOCKS_WARN_ON(class->subclass
!= subclass
))
846 #ifdef CONFIG_PROVE_LOCKING
848 * Allocate a lockdep entry. (assumes the graph_lock held, returns
849 * with NULL on failure)
851 static struct lock_list
*alloc_list_entry(void)
853 if (nr_list_entries
>= MAX_LOCKDEP_ENTRIES
) {
854 if (!debug_locks_off_graph_unlock())
857 printk("BUG: MAX_LOCKDEP_ENTRIES too low!\n");
858 printk("turning off the locking correctness validator.\n");
861 return list_entries
+ nr_list_entries
++;
865 * Add a new dependency to the head of the list:
867 static int add_lock_to_list(struct lock_class
*class, struct lock_class
*this,
868 struct list_head
*head
, unsigned long ip
, int distance
)
870 struct lock_list
*entry
;
872 * Lock not present yet - get a new dependency struct and
873 * add it to the list:
875 entry
= alloc_list_entry();
879 if (!save_trace(&entry
->trace
))
883 entry
->distance
= distance
;
885 * Since we never remove from the dependency list, the list can
886 * be walked lockless by other CPUs, it's only allocation
887 * that must be protected by the spinlock. But this also means
888 * we must make new entries visible only once writes to the
889 * entry become visible - hence the RCU op:
891 list_add_tail_rcu(&entry
->entry
, head
);
897 * Recursive, forwards-direction lock-dependency checking, used for
898 * both noncyclic checking and for hardirq-unsafe/softirq-unsafe
901 * (to keep the stackframe of the recursive functions small we
902 * use these global variables, and we also mark various helper
903 * functions as noinline.)
905 static struct held_lock
*check_source
, *check_target
;
908 * Print a dependency chain entry (this is only done when a deadlock
909 * has been detected):
912 print_circular_bug_entry(struct lock_list
*target
, unsigned int depth
)
914 if (debug_locks_silent
)
916 printk("\n-> #%u", depth
);
917 print_lock_name(target
->class);
919 print_stack_trace(&target
->trace
, 6);
925 * When a circular dependency is detected, print the
929 print_circular_bug_header(struct lock_list
*entry
, unsigned int depth
)
931 struct task_struct
*curr
= current
;
933 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
936 printk("\n=======================================================\n");
937 printk( "[ INFO: possible circular locking dependency detected ]\n");
938 print_kernel_version();
939 printk( "-------------------------------------------------------\n");
940 printk("%s/%d is trying to acquire lock:\n",
941 curr
->comm
, task_pid_nr(curr
));
942 print_lock(check_source
);
943 printk("\nbut task is already holding lock:\n");
944 print_lock(check_target
);
945 printk("\nwhich lock already depends on the new lock.\n\n");
946 printk("\nthe existing dependency chain (in reverse order) is:\n");
948 print_circular_bug_entry(entry
, depth
);
953 static noinline
int print_circular_bug_tail(void)
955 struct task_struct
*curr
= current
;
956 struct lock_list
this;
958 if (debug_locks_silent
)
961 this.class = hlock_class(check_source
);
962 if (!save_trace(&this.trace
))
965 print_circular_bug_entry(&this, 0);
967 printk("\nother info that might help us debug this:\n\n");
968 lockdep_print_held_locks(curr
);
970 printk("\nstack backtrace:\n");
976 #define RECURSION_LIMIT 40
978 static int noinline
print_infinite_recursion_bug(void)
980 if (!debug_locks_off_graph_unlock())
988 unsigned long __lockdep_count_forward_deps(struct lock_class
*class,
991 struct lock_list
*entry
;
992 unsigned long ret
= 1;
994 if (lockdep_dependency_visit(class, depth
))
998 * Recurse this class's dependency list:
1000 list_for_each_entry(entry
, &class->locks_after
, entry
)
1001 ret
+= __lockdep_count_forward_deps(entry
->class, depth
+ 1);
1006 unsigned long lockdep_count_forward_deps(struct lock_class
*class)
1008 unsigned long ret
, flags
;
1010 local_irq_save(flags
);
1011 __raw_spin_lock(&lockdep_lock
);
1012 ret
= __lockdep_count_forward_deps(class, 0);
1013 __raw_spin_unlock(&lockdep_lock
);
1014 local_irq_restore(flags
);
1019 unsigned long __lockdep_count_backward_deps(struct lock_class
*class,
1022 struct lock_list
*entry
;
1023 unsigned long ret
= 1;
1025 if (lockdep_dependency_visit(class, depth
))
1028 * Recurse this class's dependency list:
1030 list_for_each_entry(entry
, &class->locks_before
, entry
)
1031 ret
+= __lockdep_count_backward_deps(entry
->class, depth
+ 1);
1036 unsigned long lockdep_count_backward_deps(struct lock_class
*class)
1038 unsigned long ret
, flags
;
1040 local_irq_save(flags
);
1041 __raw_spin_lock(&lockdep_lock
);
1042 ret
= __lockdep_count_backward_deps(class, 0);
1043 __raw_spin_unlock(&lockdep_lock
);
1044 local_irq_restore(flags
);
1050 * Prove that the dependency graph starting at <entry> can not
1051 * lead to <target>. Print an error and return 0 if it does.
1054 check_noncircular(struct lock_class
*source
, unsigned int depth
)
1056 struct lock_list
*entry
;
1058 if (lockdep_dependency_visit(source
, depth
))
1061 debug_atomic_inc(&nr_cyclic_check_recursions
);
1062 if (depth
> max_recursion_depth
)
1063 max_recursion_depth
= depth
;
1064 if (depth
>= RECURSION_LIMIT
)
1065 return print_infinite_recursion_bug();
1067 * Check this lock's dependency list:
1069 list_for_each_entry(entry
, &source
->locks_after
, entry
) {
1070 if (entry
->class == hlock_class(check_target
))
1071 return print_circular_bug_header(entry
, depth
+1);
1072 debug_atomic_inc(&nr_cyclic_checks
);
1073 if (!check_noncircular(entry
->class, depth
+1))
1074 return print_circular_bug_entry(entry
, depth
+1);
1079 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
1081 * Forwards and backwards subgraph searching, for the purposes of
1082 * proving that two subgraphs can be connected by a new dependency
1083 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
1085 static enum lock_usage_bit find_usage_bit
;
1086 static struct lock_class
*forwards_match
, *backwards_match
;
1089 * Find a node in the forwards-direction dependency sub-graph starting
1090 * at <source> that matches <find_usage_bit>.
1092 * Return 2 if such a node exists in the subgraph, and put that node
1093 * into <forwards_match>.
1095 * Return 1 otherwise and keep <forwards_match> unchanged.
1096 * Return 0 on error.
1099 find_usage_forwards(struct lock_class
*source
, unsigned int depth
)
1101 struct lock_list
*entry
;
1104 if (lockdep_dependency_visit(source
, depth
))
1107 if (depth
> max_recursion_depth
)
1108 max_recursion_depth
= depth
;
1109 if (depth
>= RECURSION_LIMIT
)
1110 return print_infinite_recursion_bug();
1112 debug_atomic_inc(&nr_find_usage_forwards_checks
);
1113 if (source
->usage_mask
& (1 << find_usage_bit
)) {
1114 forwards_match
= source
;
1119 * Check this lock's dependency list:
1121 list_for_each_entry(entry
, &source
->locks_after
, entry
) {
1122 debug_atomic_inc(&nr_find_usage_forwards_recursions
);
1123 ret
= find_usage_forwards(entry
->class, depth
+1);
1124 if (ret
== 2 || ret
== 0)
1131 * Find a node in the backwards-direction dependency sub-graph starting
1132 * at <source> that matches <find_usage_bit>.
1134 * Return 2 if such a node exists in the subgraph, and put that node
1135 * into <backwards_match>.
1137 * Return 1 otherwise and keep <backwards_match> unchanged.
1138 * Return 0 on error.
1141 find_usage_backwards(struct lock_class
*source
, unsigned int depth
)
1143 struct lock_list
*entry
;
1146 if (lockdep_dependency_visit(source
, depth
))
1149 if (!__raw_spin_is_locked(&lockdep_lock
))
1150 return DEBUG_LOCKS_WARN_ON(1);
1152 if (depth
> max_recursion_depth
)
1153 max_recursion_depth
= depth
;
1154 if (depth
>= RECURSION_LIMIT
)
1155 return print_infinite_recursion_bug();
1157 debug_atomic_inc(&nr_find_usage_backwards_checks
);
1158 if (source
->usage_mask
& (1 << find_usage_bit
)) {
1159 backwards_match
= source
;
1163 if (!source
&& debug_locks_off_graph_unlock()) {
1169 * Check this lock's dependency list:
1171 list_for_each_entry(entry
, &source
->locks_before
, entry
) {
1172 debug_atomic_inc(&nr_find_usage_backwards_recursions
);
1173 ret
= find_usage_backwards(entry
->class, depth
+1);
1174 if (ret
== 2 || ret
== 0)
1181 print_bad_irq_dependency(struct task_struct
*curr
,
1182 struct held_lock
*prev
,
1183 struct held_lock
*next
,
1184 enum lock_usage_bit bit1
,
1185 enum lock_usage_bit bit2
,
1186 const char *irqclass
)
1188 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1191 printk("\n======================================================\n");
1192 printk( "[ INFO: %s-safe -> %s-unsafe lock order detected ]\n",
1193 irqclass
, irqclass
);
1194 print_kernel_version();
1195 printk( "------------------------------------------------------\n");
1196 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] is trying to acquire:\n",
1197 curr
->comm
, task_pid_nr(curr
),
1198 curr
->hardirq_context
, hardirq_count() >> HARDIRQ_SHIFT
,
1199 curr
->softirq_context
, softirq_count() >> SOFTIRQ_SHIFT
,
1200 curr
->hardirqs_enabled
,
1201 curr
->softirqs_enabled
);
1204 printk("\nand this task is already holding:\n");
1206 printk("which would create a new lock dependency:\n");
1207 print_lock_name(hlock_class(prev
));
1209 print_lock_name(hlock_class(next
));
1212 printk("\nbut this new dependency connects a %s-irq-safe lock:\n",
1214 print_lock_name(backwards_match
);
1215 printk("\n... which became %s-irq-safe at:\n", irqclass
);
1217 print_stack_trace(backwards_match
->usage_traces
+ bit1
, 1);
1219 printk("\nto a %s-irq-unsafe lock:\n", irqclass
);
1220 print_lock_name(forwards_match
);
1221 printk("\n... which became %s-irq-unsafe at:\n", irqclass
);
1224 print_stack_trace(forwards_match
->usage_traces
+ bit2
, 1);
1226 printk("\nother info that might help us debug this:\n\n");
1227 lockdep_print_held_locks(curr
);
1229 printk("\nthe %s-irq-safe lock's dependencies:\n", irqclass
);
1230 print_lock_dependencies(backwards_match
, 0);
1232 printk("\nthe %s-irq-unsafe lock's dependencies:\n", irqclass
);
1233 print_lock_dependencies(forwards_match
, 0);
1235 printk("\nstack backtrace:\n");
1242 check_usage(struct task_struct
*curr
, struct held_lock
*prev
,
1243 struct held_lock
*next
, enum lock_usage_bit bit_backwards
,
1244 enum lock_usage_bit bit_forwards
, const char *irqclass
)
1248 find_usage_bit
= bit_backwards
;
1249 /* fills in <backwards_match> */
1250 ret
= find_usage_backwards(hlock_class(prev
), 0);
1251 if (!ret
|| ret
== 1)
1254 find_usage_bit
= bit_forwards
;
1255 ret
= find_usage_forwards(hlock_class(next
), 0);
1256 if (!ret
|| ret
== 1)
1259 return print_bad_irq_dependency(curr
, prev
, next
,
1260 bit_backwards
, bit_forwards
, irqclass
);
1264 check_prev_add_irq(struct task_struct
*curr
, struct held_lock
*prev
,
1265 struct held_lock
*next
)
1268 * Prove that the new dependency does not connect a hardirq-safe
1269 * lock with a hardirq-unsafe lock - to achieve this we search
1270 * the backwards-subgraph starting at <prev>, and the
1271 * forwards-subgraph starting at <next>:
1273 if (!check_usage(curr
, prev
, next
, LOCK_USED_IN_HARDIRQ
,
1274 LOCK_ENABLED_HARDIRQS
, "hard"))
1278 * Prove that the new dependency does not connect a hardirq-safe-read
1279 * lock with a hardirq-unsafe lock - to achieve this we search
1280 * the backwards-subgraph starting at <prev>, and the
1281 * forwards-subgraph starting at <next>:
1283 if (!check_usage(curr
, prev
, next
, LOCK_USED_IN_HARDIRQ_READ
,
1284 LOCK_ENABLED_HARDIRQS
, "hard-read"))
1288 * Prove that the new dependency does not connect a softirq-safe
1289 * lock with a softirq-unsafe lock - to achieve this we search
1290 * the backwards-subgraph starting at <prev>, and the
1291 * forwards-subgraph starting at <next>:
1293 if (!check_usage(curr
, prev
, next
, LOCK_USED_IN_SOFTIRQ
,
1294 LOCK_ENABLED_SOFTIRQS
, "soft"))
1297 * Prove that the new dependency does not connect a softirq-safe-read
1298 * lock with a softirq-unsafe lock - to achieve this we search
1299 * the backwards-subgraph starting at <prev>, and the
1300 * forwards-subgraph starting at <next>:
1302 if (!check_usage(curr
, prev
, next
, LOCK_USED_IN_SOFTIRQ_READ
,
1303 LOCK_ENABLED_SOFTIRQS
, "soft"))
1309 static void inc_chains(void)
1311 if (current
->hardirq_context
)
1312 nr_hardirq_chains
++;
1314 if (current
->softirq_context
)
1315 nr_softirq_chains
++;
1317 nr_process_chains
++;
1324 check_prev_add_irq(struct task_struct
*curr
, struct held_lock
*prev
,
1325 struct held_lock
*next
)
1330 static inline void inc_chains(void)
1332 nr_process_chains
++;
1338 print_deadlock_bug(struct task_struct
*curr
, struct held_lock
*prev
,
1339 struct held_lock
*next
)
1341 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1344 printk("\n=============================================\n");
1345 printk( "[ INFO: possible recursive locking detected ]\n");
1346 print_kernel_version();
1347 printk( "---------------------------------------------\n");
1348 printk("%s/%d is trying to acquire lock:\n",
1349 curr
->comm
, task_pid_nr(curr
));
1351 printk("\nbut task is already holding lock:\n");
1354 printk("\nother info that might help us debug this:\n");
1355 lockdep_print_held_locks(curr
);
1357 printk("\nstack backtrace:\n");
1364 * Check whether we are holding such a class already.
1366 * (Note that this has to be done separately, because the graph cannot
1367 * detect such classes of deadlocks.)
1369 * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read
1372 check_deadlock(struct task_struct
*curr
, struct held_lock
*next
,
1373 struct lockdep_map
*next_instance
, int read
)
1375 struct held_lock
*prev
;
1376 struct held_lock
*nest
= NULL
;
1379 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
1380 prev
= curr
->held_locks
+ i
;
1382 if (prev
->instance
== next
->nest_lock
)
1385 if (hlock_class(prev
) != hlock_class(next
))
1389 * Allow read-after-read recursion of the same
1390 * lock class (i.e. read_lock(lock)+read_lock(lock)):
1392 if ((read
== 2) && prev
->read
)
1396 * We're holding the nest_lock, which serializes this lock's
1397 * nesting behaviour.
1402 return print_deadlock_bug(curr
, prev
, next
);
1408 * There was a chain-cache miss, and we are about to add a new dependency
1409 * to a previous lock. We recursively validate the following rules:
1411 * - would the adding of the <prev> -> <next> dependency create a
1412 * circular dependency in the graph? [== circular deadlock]
1414 * - does the new prev->next dependency connect any hardirq-safe lock
1415 * (in the full backwards-subgraph starting at <prev>) with any
1416 * hardirq-unsafe lock (in the full forwards-subgraph starting at
1417 * <next>)? [== illegal lock inversion with hardirq contexts]
1419 * - does the new prev->next dependency connect any softirq-safe lock
1420 * (in the full backwards-subgraph starting at <prev>) with any
1421 * softirq-unsafe lock (in the full forwards-subgraph starting at
1422 * <next>)? [== illegal lock inversion with softirq contexts]
1424 * any of these scenarios could lead to a deadlock.
1426 * Then if all the validations pass, we add the forwards and backwards
1430 check_prev_add(struct task_struct
*curr
, struct held_lock
*prev
,
1431 struct held_lock
*next
, int distance
)
1433 struct lock_list
*entry
;
1437 * Prove that the new <prev> -> <next> dependency would not
1438 * create a circular dependency in the graph. (We do this by
1439 * forward-recursing into the graph starting at <next>, and
1440 * checking whether we can reach <prev>.)
1442 * We are using global variables to control the recursion, to
1443 * keep the stackframe size of the recursive functions low:
1445 check_source
= next
;
1446 check_target
= prev
;
1447 if (!(check_noncircular(hlock_class(next
), 0)))
1448 return print_circular_bug_tail();
1450 if (!check_prev_add_irq(curr
, prev
, next
))
1454 * For recursive read-locks we do all the dependency checks,
1455 * but we dont store read-triggered dependencies (only
1456 * write-triggered dependencies). This ensures that only the
1457 * write-side dependencies matter, and that if for example a
1458 * write-lock never takes any other locks, then the reads are
1459 * equivalent to a NOP.
1461 if (next
->read
== 2 || prev
->read
== 2)
1464 * Is the <prev> -> <next> dependency already present?
1466 * (this may occur even though this is a new chain: consider
1467 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3
1468 * chains - the second one will be new, but L1 already has
1469 * L2 added to its dependency list, due to the first chain.)
1471 list_for_each_entry(entry
, &hlock_class(prev
)->locks_after
, entry
) {
1472 if (entry
->class == hlock_class(next
)) {
1474 entry
->distance
= 1;
1480 * Ok, all validations passed, add the new lock
1481 * to the previous lock's dependency list:
1483 ret
= add_lock_to_list(hlock_class(prev
), hlock_class(next
),
1484 &hlock_class(prev
)->locks_after
,
1485 next
->acquire_ip
, distance
);
1490 ret
= add_lock_to_list(hlock_class(next
), hlock_class(prev
),
1491 &hlock_class(next
)->locks_before
,
1492 next
->acquire_ip
, distance
);
1497 * Debugging printouts:
1499 if (verbose(hlock_class(prev
)) || verbose(hlock_class(next
))) {
1501 printk("\n new dependency: ");
1502 print_lock_name(hlock_class(prev
));
1504 print_lock_name(hlock_class(next
));
1507 return graph_lock();
1513 * Add the dependency to all directly-previous locks that are 'relevant'.
1514 * The ones that are relevant are (in increasing distance from curr):
1515 * all consecutive trylock entries and the final non-trylock entry - or
1516 * the end of this context's lock-chain - whichever comes first.
1519 check_prevs_add(struct task_struct
*curr
, struct held_lock
*next
)
1521 int depth
= curr
->lockdep_depth
;
1522 struct held_lock
*hlock
;
1527 * Depth must not be zero for a non-head lock:
1532 * At least two relevant locks must exist for this
1535 if (curr
->held_locks
[depth
].irq_context
!=
1536 curr
->held_locks
[depth
-1].irq_context
)
1540 int distance
= curr
->lockdep_depth
- depth
+ 1;
1541 hlock
= curr
->held_locks
+ depth
-1;
1543 * Only non-recursive-read entries get new dependencies
1546 if (hlock
->read
!= 2) {
1547 if (!check_prev_add(curr
, hlock
, next
, distance
))
1550 * Stop after the first non-trylock entry,
1551 * as non-trylock entries have added their
1552 * own direct dependencies already, so this
1553 * lock is connected to them indirectly:
1555 if (!hlock
->trylock
)
1560 * End of lock-stack?
1565 * Stop the search if we cross into another context:
1567 if (curr
->held_locks
[depth
].irq_context
!=
1568 curr
->held_locks
[depth
-1].irq_context
)
1573 if (!debug_locks_off_graph_unlock())
1581 unsigned long nr_lock_chains
;
1582 struct lock_chain lock_chains
[MAX_LOCKDEP_CHAINS
];
1583 int nr_chain_hlocks
;
1584 static u16 chain_hlocks
[MAX_LOCKDEP_CHAIN_HLOCKS
];
1586 struct lock_class
*lock_chain_get_class(struct lock_chain
*chain
, int i
)
1588 return lock_classes
+ chain_hlocks
[chain
->base
+ i
];
1592 * Look up a dependency chain. If the key is not present yet then
1593 * add it and return 1 - in this case the new dependency chain is
1594 * validated. If the key is already hashed, return 0.
1595 * (On return with 1 graph_lock is held.)
1597 static inline int lookup_chain_cache(struct task_struct
*curr
,
1598 struct held_lock
*hlock
,
1601 struct lock_class
*class = hlock_class(hlock
);
1602 struct list_head
*hash_head
= chainhashentry(chain_key
);
1603 struct lock_chain
*chain
;
1604 struct held_lock
*hlock_curr
, *hlock_next
;
1607 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
1610 * We can walk it lock-free, because entries only get added
1613 list_for_each_entry(chain
, hash_head
, entry
) {
1614 if (chain
->chain_key
== chain_key
) {
1616 debug_atomic_inc(&chain_lookup_hits
);
1617 if (very_verbose(class))
1618 printk("\nhash chain already cached, key: "
1619 "%016Lx tail class: [%p] %s\n",
1620 (unsigned long long)chain_key
,
1621 class->key
, class->name
);
1625 if (very_verbose(class))
1626 printk("\nnew hash chain, key: %016Lx tail class: [%p] %s\n",
1627 (unsigned long long)chain_key
, class->key
, class->name
);
1629 * Allocate a new chain entry from the static array, and add
1635 * We have to walk the chain again locked - to avoid duplicates:
1637 list_for_each_entry(chain
, hash_head
, entry
) {
1638 if (chain
->chain_key
== chain_key
) {
1643 if (unlikely(nr_lock_chains
>= MAX_LOCKDEP_CHAINS
)) {
1644 if (!debug_locks_off_graph_unlock())
1647 printk("BUG: MAX_LOCKDEP_CHAINS too low!\n");
1648 printk("turning off the locking correctness validator.\n");
1651 chain
= lock_chains
+ nr_lock_chains
++;
1652 chain
->chain_key
= chain_key
;
1653 chain
->irq_context
= hlock
->irq_context
;
1654 /* Find the first held_lock of current chain */
1656 for (i
= curr
->lockdep_depth
- 1; i
>= 0; i
--) {
1657 hlock_curr
= curr
->held_locks
+ i
;
1658 if (hlock_curr
->irq_context
!= hlock_next
->irq_context
)
1663 chain
->depth
= curr
->lockdep_depth
+ 1 - i
;
1664 cn
= nr_chain_hlocks
;
1665 while (cn
+ chain
->depth
<= MAX_LOCKDEP_CHAIN_HLOCKS
) {
1666 n
= cmpxchg(&nr_chain_hlocks
, cn
, cn
+ chain
->depth
);
1671 if (likely(cn
+ chain
->depth
<= MAX_LOCKDEP_CHAIN_HLOCKS
)) {
1673 for (j
= 0; j
< chain
->depth
- 1; j
++, i
++) {
1674 int lock_id
= curr
->held_locks
[i
].class_idx
- 1;
1675 chain_hlocks
[chain
->base
+ j
] = lock_id
;
1677 chain_hlocks
[chain
->base
+ j
] = class - lock_classes
;
1679 list_add_tail_rcu(&chain
->entry
, hash_head
);
1680 debug_atomic_inc(&chain_lookup_misses
);
1686 static int validate_chain(struct task_struct
*curr
, struct lockdep_map
*lock
,
1687 struct held_lock
*hlock
, int chain_head
, u64 chain_key
)
1690 * Trylock needs to maintain the stack of held locks, but it
1691 * does not add new dependencies, because trylock can be done
1694 * We look up the chain_key and do the O(N^2) check and update of
1695 * the dependencies only if this is a new dependency chain.
1696 * (If lookup_chain_cache() returns with 1 it acquires
1697 * graph_lock for us)
1699 if (!hlock
->trylock
&& (hlock
->check
== 2) &&
1700 lookup_chain_cache(curr
, hlock
, chain_key
)) {
1702 * Check whether last held lock:
1704 * - is irq-safe, if this lock is irq-unsafe
1705 * - is softirq-safe, if this lock is hardirq-unsafe
1707 * And check whether the new lock's dependency graph
1708 * could lead back to the previous lock.
1710 * any of these scenarios could lead to a deadlock. If
1713 int ret
= check_deadlock(curr
, hlock
, lock
, hlock
->read
);
1718 * Mark recursive read, as we jump over it when
1719 * building dependencies (just like we jump over
1725 * Add dependency only if this lock is not the head
1726 * of the chain, and if it's not a secondary read-lock:
1728 if (!chain_head
&& ret
!= 2)
1729 if (!check_prevs_add(curr
, hlock
))
1733 /* after lookup_chain_cache(): */
1734 if (unlikely(!debug_locks
))
1740 static inline int validate_chain(struct task_struct
*curr
,
1741 struct lockdep_map
*lock
, struct held_lock
*hlock
,
1742 int chain_head
, u64 chain_key
)
1749 * We are building curr_chain_key incrementally, so double-check
1750 * it from scratch, to make sure that it's done correctly:
1752 static void check_chain_key(struct task_struct
*curr
)
1754 #ifdef CONFIG_DEBUG_LOCKDEP
1755 struct held_lock
*hlock
, *prev_hlock
= NULL
;
1759 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
1760 hlock
= curr
->held_locks
+ i
;
1761 if (chain_key
!= hlock
->prev_chain_key
) {
1763 WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n",
1764 curr
->lockdep_depth
, i
,
1765 (unsigned long long)chain_key
,
1766 (unsigned long long)hlock
->prev_chain_key
);
1769 id
= hlock
->class_idx
- 1;
1770 if (DEBUG_LOCKS_WARN_ON(id
>= MAX_LOCKDEP_KEYS
))
1773 if (prev_hlock
&& (prev_hlock
->irq_context
!=
1774 hlock
->irq_context
))
1776 chain_key
= iterate_chain_key(chain_key
, id
);
1779 if (chain_key
!= curr
->curr_chain_key
) {
1781 WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n",
1782 curr
->lockdep_depth
, i
,
1783 (unsigned long long)chain_key
,
1784 (unsigned long long)curr
->curr_chain_key
);
1790 print_usage_bug(struct task_struct
*curr
, struct held_lock
*this,
1791 enum lock_usage_bit prev_bit
, enum lock_usage_bit new_bit
)
1793 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1796 printk("\n=================================\n");
1797 printk( "[ INFO: inconsistent lock state ]\n");
1798 print_kernel_version();
1799 printk( "---------------------------------\n");
1801 printk("inconsistent {%s} -> {%s} usage.\n",
1802 usage_str
[prev_bit
], usage_str
[new_bit
]);
1804 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] takes:\n",
1805 curr
->comm
, task_pid_nr(curr
),
1806 trace_hardirq_context(curr
), hardirq_count() >> HARDIRQ_SHIFT
,
1807 trace_softirq_context(curr
), softirq_count() >> SOFTIRQ_SHIFT
,
1808 trace_hardirqs_enabled(curr
),
1809 trace_softirqs_enabled(curr
));
1812 printk("{%s} state was registered at:\n", usage_str
[prev_bit
]);
1813 print_stack_trace(hlock_class(this)->usage_traces
+ prev_bit
, 1);
1815 print_irqtrace_events(curr
);
1816 printk("\nother info that might help us debug this:\n");
1817 lockdep_print_held_locks(curr
);
1819 printk("\nstack backtrace:\n");
1826 * Print out an error if an invalid bit is set:
1829 valid_state(struct task_struct
*curr
, struct held_lock
*this,
1830 enum lock_usage_bit new_bit
, enum lock_usage_bit bad_bit
)
1832 if (unlikely(hlock_class(this)->usage_mask
& (1 << bad_bit
)))
1833 return print_usage_bug(curr
, this, bad_bit
, new_bit
);
1837 static int mark_lock(struct task_struct
*curr
, struct held_lock
*this,
1838 enum lock_usage_bit new_bit
);
1840 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
1843 * print irq inversion bug:
1846 print_irq_inversion_bug(struct task_struct
*curr
, struct lock_class
*other
,
1847 struct held_lock
*this, int forwards
,
1848 const char *irqclass
)
1850 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1853 printk("\n=========================================================\n");
1854 printk( "[ INFO: possible irq lock inversion dependency detected ]\n");
1855 print_kernel_version();
1856 printk( "---------------------------------------------------------\n");
1857 printk("%s/%d just changed the state of lock:\n",
1858 curr
->comm
, task_pid_nr(curr
));
1861 printk("but this lock took another, %s-irq-unsafe lock in the past:\n", irqclass
);
1863 printk("but this lock was taken by another, %s-irq-safe lock in the past:\n", irqclass
);
1864 print_lock_name(other
);
1865 printk("\n\nand interrupts could create inverse lock ordering between them.\n\n");
1867 printk("\nother info that might help us debug this:\n");
1868 lockdep_print_held_locks(curr
);
1870 printk("\nthe first lock's dependencies:\n");
1871 print_lock_dependencies(hlock_class(this), 0);
1873 printk("\nthe second lock's dependencies:\n");
1874 print_lock_dependencies(other
, 0);
1876 printk("\nstack backtrace:\n");
1883 * Prove that in the forwards-direction subgraph starting at <this>
1884 * there is no lock matching <mask>:
1887 check_usage_forwards(struct task_struct
*curr
, struct held_lock
*this,
1888 enum lock_usage_bit bit
, const char *irqclass
)
1892 find_usage_bit
= bit
;
1893 /* fills in <forwards_match> */
1894 ret
= find_usage_forwards(hlock_class(this), 0);
1895 if (!ret
|| ret
== 1)
1898 return print_irq_inversion_bug(curr
, forwards_match
, this, 1, irqclass
);
1902 * Prove that in the backwards-direction subgraph starting at <this>
1903 * there is no lock matching <mask>:
1906 check_usage_backwards(struct task_struct
*curr
, struct held_lock
*this,
1907 enum lock_usage_bit bit
, const char *irqclass
)
1911 find_usage_bit
= bit
;
1912 /* fills in <backwards_match> */
1913 ret
= find_usage_backwards(hlock_class(this), 0);
1914 if (!ret
|| ret
== 1)
1917 return print_irq_inversion_bug(curr
, backwards_match
, this, 0, irqclass
);
1920 void print_irqtrace_events(struct task_struct
*curr
)
1922 printk("irq event stamp: %u\n", curr
->irq_events
);
1923 printk("hardirqs last enabled at (%u): ", curr
->hardirq_enable_event
);
1924 print_ip_sym(curr
->hardirq_enable_ip
);
1925 printk("hardirqs last disabled at (%u): ", curr
->hardirq_disable_event
);
1926 print_ip_sym(curr
->hardirq_disable_ip
);
1927 printk("softirqs last enabled at (%u): ", curr
->softirq_enable_event
);
1928 print_ip_sym(curr
->softirq_enable_ip
);
1929 printk("softirqs last disabled at (%u): ", curr
->softirq_disable_event
);
1930 print_ip_sym(curr
->softirq_disable_ip
);
1933 static int hardirq_verbose(struct lock_class
*class)
1936 return class_filter(class);
1941 static int softirq_verbose(struct lock_class
*class)
1944 return class_filter(class);
1949 #define STRICT_READ_CHECKS 1
1951 static int mark_lock_irq(struct task_struct
*curr
, struct held_lock
*this,
1952 enum lock_usage_bit new_bit
)
1957 case LOCK_USED_IN_HARDIRQ
:
1958 if (!valid_state(curr
, this, new_bit
, LOCK_ENABLED_HARDIRQS
))
1960 if (!valid_state(curr
, this, new_bit
,
1961 LOCK_ENABLED_HARDIRQS_READ
))
1964 * just marked it hardirq-safe, check that this lock
1965 * took no hardirq-unsafe lock in the past:
1967 if (!check_usage_forwards(curr
, this,
1968 LOCK_ENABLED_HARDIRQS
, "hard"))
1970 #if STRICT_READ_CHECKS
1972 * just marked it hardirq-safe, check that this lock
1973 * took no hardirq-unsafe-read lock in the past:
1975 if (!check_usage_forwards(curr
, this,
1976 LOCK_ENABLED_HARDIRQS_READ
, "hard-read"))
1979 if (hardirq_verbose(hlock_class(this)))
1982 case LOCK_USED_IN_SOFTIRQ
:
1983 if (!valid_state(curr
, this, new_bit
, LOCK_ENABLED_SOFTIRQS
))
1985 if (!valid_state(curr
, this, new_bit
,
1986 LOCK_ENABLED_SOFTIRQS_READ
))
1989 * just marked it softirq-safe, check that this lock
1990 * took no softirq-unsafe lock in the past:
1992 if (!check_usage_forwards(curr
, this,
1993 LOCK_ENABLED_SOFTIRQS
, "soft"))
1995 #if STRICT_READ_CHECKS
1997 * just marked it softirq-safe, check that this lock
1998 * took no softirq-unsafe-read lock in the past:
2000 if (!check_usage_forwards(curr
, this,
2001 LOCK_ENABLED_SOFTIRQS_READ
, "soft-read"))
2004 if (softirq_verbose(hlock_class(this)))
2007 case LOCK_USED_IN_HARDIRQ_READ
:
2008 if (!valid_state(curr
, this, new_bit
, LOCK_ENABLED_HARDIRQS
))
2011 * just marked it hardirq-read-safe, check that this lock
2012 * took no hardirq-unsafe lock in the past:
2014 if (!check_usage_forwards(curr
, this,
2015 LOCK_ENABLED_HARDIRQS
, "hard"))
2017 if (hardirq_verbose(hlock_class(this)))
2020 case LOCK_USED_IN_SOFTIRQ_READ
:
2021 if (!valid_state(curr
, this, new_bit
, LOCK_ENABLED_SOFTIRQS
))
2024 * just marked it softirq-read-safe, check that this lock
2025 * took no softirq-unsafe lock in the past:
2027 if (!check_usage_forwards(curr
, this,
2028 LOCK_ENABLED_SOFTIRQS
, "soft"))
2030 if (softirq_verbose(hlock_class(this)))
2033 case LOCK_ENABLED_HARDIRQS
:
2034 if (!valid_state(curr
, this, new_bit
, LOCK_USED_IN_HARDIRQ
))
2036 if (!valid_state(curr
, this, new_bit
,
2037 LOCK_USED_IN_HARDIRQ_READ
))
2040 * just marked it hardirq-unsafe, check that no hardirq-safe
2041 * lock in the system ever took it in the past:
2043 if (!check_usage_backwards(curr
, this,
2044 LOCK_USED_IN_HARDIRQ
, "hard"))
2046 #if STRICT_READ_CHECKS
2048 * just marked it hardirq-unsafe, check that no
2049 * hardirq-safe-read lock in the system ever took
2052 if (!check_usage_backwards(curr
, this,
2053 LOCK_USED_IN_HARDIRQ_READ
, "hard-read"))
2056 if (hardirq_verbose(hlock_class(this)))
2059 case LOCK_ENABLED_SOFTIRQS
:
2060 if (!valid_state(curr
, this, new_bit
, LOCK_USED_IN_SOFTIRQ
))
2062 if (!valid_state(curr
, this, new_bit
,
2063 LOCK_USED_IN_SOFTIRQ_READ
))
2066 * just marked it softirq-unsafe, check that no softirq-safe
2067 * lock in the system ever took it in the past:
2069 if (!check_usage_backwards(curr
, this,
2070 LOCK_USED_IN_SOFTIRQ
, "soft"))
2072 #if STRICT_READ_CHECKS
2074 * just marked it softirq-unsafe, check that no
2075 * softirq-safe-read lock in the system ever took
2078 if (!check_usage_backwards(curr
, this,
2079 LOCK_USED_IN_SOFTIRQ_READ
, "soft-read"))
2082 if (softirq_verbose(hlock_class(this)))
2085 case LOCK_ENABLED_HARDIRQS_READ
:
2086 if (!valid_state(curr
, this, new_bit
, LOCK_USED_IN_HARDIRQ
))
2088 #if STRICT_READ_CHECKS
2090 * just marked it hardirq-read-unsafe, check that no
2091 * hardirq-safe lock in the system ever took it in the past:
2093 if (!check_usage_backwards(curr
, this,
2094 LOCK_USED_IN_HARDIRQ
, "hard"))
2097 if (hardirq_verbose(hlock_class(this)))
2100 case LOCK_ENABLED_SOFTIRQS_READ
:
2101 if (!valid_state(curr
, this, new_bit
, LOCK_USED_IN_SOFTIRQ
))
2103 #if STRICT_READ_CHECKS
2105 * just marked it softirq-read-unsafe, check that no
2106 * softirq-safe lock in the system ever took it in the past:
2108 if (!check_usage_backwards(curr
, this,
2109 LOCK_USED_IN_SOFTIRQ
, "soft"))
2112 if (softirq_verbose(hlock_class(this)))
2124 * Mark all held locks with a usage bit:
2127 mark_held_locks(struct task_struct
*curr
, int hardirq
)
2129 enum lock_usage_bit usage_bit
;
2130 struct held_lock
*hlock
;
2133 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
2134 hlock
= curr
->held_locks
+ i
;
2138 usage_bit
= LOCK_ENABLED_HARDIRQS_READ
;
2140 usage_bit
= LOCK_ENABLED_HARDIRQS
;
2143 usage_bit
= LOCK_ENABLED_SOFTIRQS_READ
;
2145 usage_bit
= LOCK_ENABLED_SOFTIRQS
;
2147 if (!mark_lock(curr
, hlock
, usage_bit
))
2155 * Debugging helper: via this flag we know that we are in
2156 * 'early bootup code', and will warn about any invalid irqs-on event:
2158 static int early_boot_irqs_enabled
;
2160 void early_boot_irqs_off(void)
2162 early_boot_irqs_enabled
= 0;
2165 void early_boot_irqs_on(void)
2167 early_boot_irqs_enabled
= 1;
2171 * Hardirqs will be enabled:
2173 void trace_hardirqs_on_caller(unsigned long ip
)
2175 struct task_struct
*curr
= current
;
2177 time_hardirqs_on(CALLER_ADDR0
, ip
);
2179 if (unlikely(!debug_locks
|| current
->lockdep_recursion
))
2182 if (DEBUG_LOCKS_WARN_ON(unlikely(!early_boot_irqs_enabled
)))
2185 if (unlikely(curr
->hardirqs_enabled
)) {
2186 debug_atomic_inc(&redundant_hardirqs_on
);
2189 /* we'll do an OFF -> ON transition: */
2190 curr
->hardirqs_enabled
= 1;
2192 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2194 if (DEBUG_LOCKS_WARN_ON(current
->hardirq_context
))
2197 * We are going to turn hardirqs on, so set the
2198 * usage bit for all held locks:
2200 if (!mark_held_locks(curr
, 1))
2203 * If we have softirqs enabled, then set the usage
2204 * bit for all held locks. (disabled hardirqs prevented
2205 * this bit from being set before)
2207 if (curr
->softirqs_enabled
)
2208 if (!mark_held_locks(curr
, 0))
2211 curr
->hardirq_enable_ip
= ip
;
2212 curr
->hardirq_enable_event
= ++curr
->irq_events
;
2213 debug_atomic_inc(&hardirqs_on_events
);
2215 EXPORT_SYMBOL(trace_hardirqs_on_caller
);
2217 void trace_hardirqs_on(void)
2219 trace_hardirqs_on_caller(CALLER_ADDR0
);
2221 EXPORT_SYMBOL(trace_hardirqs_on
);
2224 * Hardirqs were disabled:
2226 void trace_hardirqs_off_caller(unsigned long ip
)
2228 struct task_struct
*curr
= current
;
2230 time_hardirqs_off(CALLER_ADDR0
, ip
);
2232 if (unlikely(!debug_locks
|| current
->lockdep_recursion
))
2235 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2238 if (curr
->hardirqs_enabled
) {
2240 * We have done an ON -> OFF transition:
2242 curr
->hardirqs_enabled
= 0;
2243 curr
->hardirq_disable_ip
= ip
;
2244 curr
->hardirq_disable_event
= ++curr
->irq_events
;
2245 debug_atomic_inc(&hardirqs_off_events
);
2247 debug_atomic_inc(&redundant_hardirqs_off
);
2249 EXPORT_SYMBOL(trace_hardirqs_off_caller
);
2251 void trace_hardirqs_off(void)
2253 trace_hardirqs_off_caller(CALLER_ADDR0
);
2255 EXPORT_SYMBOL(trace_hardirqs_off
);
2258 * Softirqs will be enabled:
2260 void trace_softirqs_on(unsigned long ip
)
2262 struct task_struct
*curr
= current
;
2264 if (unlikely(!debug_locks
))
2267 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2270 if (curr
->softirqs_enabled
) {
2271 debug_atomic_inc(&redundant_softirqs_on
);
2276 * We'll do an OFF -> ON transition:
2278 curr
->softirqs_enabled
= 1;
2279 curr
->softirq_enable_ip
= ip
;
2280 curr
->softirq_enable_event
= ++curr
->irq_events
;
2281 debug_atomic_inc(&softirqs_on_events
);
2283 * We are going to turn softirqs on, so set the
2284 * usage bit for all held locks, if hardirqs are
2287 if (curr
->hardirqs_enabled
)
2288 mark_held_locks(curr
, 0);
2292 * Softirqs were disabled:
2294 void trace_softirqs_off(unsigned long ip
)
2296 struct task_struct
*curr
= current
;
2298 if (unlikely(!debug_locks
))
2301 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2304 if (curr
->softirqs_enabled
) {
2306 * We have done an ON -> OFF transition:
2308 curr
->softirqs_enabled
= 0;
2309 curr
->softirq_disable_ip
= ip
;
2310 curr
->softirq_disable_event
= ++curr
->irq_events
;
2311 debug_atomic_inc(&softirqs_off_events
);
2312 DEBUG_LOCKS_WARN_ON(!softirq_count());
2314 debug_atomic_inc(&redundant_softirqs_off
);
2317 static int mark_irqflags(struct task_struct
*curr
, struct held_lock
*hlock
)
2320 * If non-trylock use in a hardirq or softirq context, then
2321 * mark the lock as used in these contexts:
2323 if (!hlock
->trylock
) {
2325 if (curr
->hardirq_context
)
2326 if (!mark_lock(curr
, hlock
,
2327 LOCK_USED_IN_HARDIRQ_READ
))
2329 if (curr
->softirq_context
)
2330 if (!mark_lock(curr
, hlock
,
2331 LOCK_USED_IN_SOFTIRQ_READ
))
2334 if (curr
->hardirq_context
)
2335 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_HARDIRQ
))
2337 if (curr
->softirq_context
)
2338 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_SOFTIRQ
))
2342 if (!hlock
->hardirqs_off
) {
2344 if (!mark_lock(curr
, hlock
,
2345 LOCK_ENABLED_HARDIRQS_READ
))
2347 if (curr
->softirqs_enabled
)
2348 if (!mark_lock(curr
, hlock
,
2349 LOCK_ENABLED_SOFTIRQS_READ
))
2352 if (!mark_lock(curr
, hlock
,
2353 LOCK_ENABLED_HARDIRQS
))
2355 if (curr
->softirqs_enabled
)
2356 if (!mark_lock(curr
, hlock
,
2357 LOCK_ENABLED_SOFTIRQS
))
2365 static int separate_irq_context(struct task_struct
*curr
,
2366 struct held_lock
*hlock
)
2368 unsigned int depth
= curr
->lockdep_depth
;
2371 * Keep track of points where we cross into an interrupt context:
2373 hlock
->irq_context
= 2*(curr
->hardirq_context
? 1 : 0) +
2374 curr
->softirq_context
;
2376 struct held_lock
*prev_hlock
;
2378 prev_hlock
= curr
->held_locks
+ depth
-1;
2380 * If we cross into another context, reset the
2381 * hash key (this also prevents the checking and the
2382 * adding of the dependency to 'prev'):
2384 if (prev_hlock
->irq_context
!= hlock
->irq_context
)
2393 int mark_lock_irq(struct task_struct
*curr
, struct held_lock
*this,
2394 enum lock_usage_bit new_bit
)
2400 static inline int mark_irqflags(struct task_struct
*curr
,
2401 struct held_lock
*hlock
)
2406 static inline int separate_irq_context(struct task_struct
*curr
,
2407 struct held_lock
*hlock
)
2415 * Mark a lock with a usage bit, and validate the state transition:
2417 static int mark_lock(struct task_struct
*curr
, struct held_lock
*this,
2418 enum lock_usage_bit new_bit
)
2420 unsigned int new_mask
= 1 << new_bit
, ret
= 1;
2423 * If already set then do not dirty the cacheline,
2424 * nor do any checks:
2426 if (likely(hlock_class(this)->usage_mask
& new_mask
))
2432 * Make sure we didnt race:
2434 if (unlikely(hlock_class(this)->usage_mask
& new_mask
)) {
2439 hlock_class(this)->usage_mask
|= new_mask
;
2441 if (!save_trace(hlock_class(this)->usage_traces
+ new_bit
))
2445 case LOCK_USED_IN_HARDIRQ
:
2446 case LOCK_USED_IN_SOFTIRQ
:
2447 case LOCK_USED_IN_HARDIRQ_READ
:
2448 case LOCK_USED_IN_SOFTIRQ_READ
:
2449 case LOCK_ENABLED_HARDIRQS
:
2450 case LOCK_ENABLED_SOFTIRQS
:
2451 case LOCK_ENABLED_HARDIRQS_READ
:
2452 case LOCK_ENABLED_SOFTIRQS_READ
:
2453 ret
= mark_lock_irq(curr
, this, new_bit
);
2458 debug_atomic_dec(&nr_unused_locks
);
2461 if (!debug_locks_off_graph_unlock())
2470 * We must printk outside of the graph_lock:
2473 printk("\nmarked lock as {%s}:\n", usage_str
[new_bit
]);
2475 print_irqtrace_events(curr
);
2483 * Initialize a lock instance's lock-class mapping info:
2485 void lockdep_init_map(struct lockdep_map
*lock
, const char *name
,
2486 struct lock_class_key
*key
, int subclass
)
2488 if (unlikely(!debug_locks
))
2491 if (DEBUG_LOCKS_WARN_ON(!key
))
2493 if (DEBUG_LOCKS_WARN_ON(!name
))
2496 * Sanity check, the lock-class key must be persistent:
2498 if (!static_obj(key
)) {
2499 printk("BUG: key %p not in .data!\n", key
);
2500 DEBUG_LOCKS_WARN_ON(1);
2505 lock
->class_cache
= NULL
;
2506 #ifdef CONFIG_LOCK_STAT
2507 lock
->cpu
= raw_smp_processor_id();
2510 register_lock_class(lock
, subclass
, 1);
2513 EXPORT_SYMBOL_GPL(lockdep_init_map
);
2516 * This gets called for every mutex_lock*()/spin_lock*() operation.
2517 * We maintain the dependency maps and validate the locking attempt:
2519 static int __lock_acquire(struct lockdep_map
*lock
, unsigned int subclass
,
2520 int trylock
, int read
, int check
, int hardirqs_off
,
2521 struct lockdep_map
*nest_lock
, unsigned long ip
)
2523 struct task_struct
*curr
= current
;
2524 struct lock_class
*class = NULL
;
2525 struct held_lock
*hlock
;
2526 unsigned int depth
, id
;
2533 if (unlikely(!debug_locks
))
2536 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2539 if (unlikely(subclass
>= MAX_LOCKDEP_SUBCLASSES
)) {
2541 printk("BUG: MAX_LOCKDEP_SUBCLASSES too low!\n");
2542 printk("turning off the locking correctness validator.\n");
2547 class = lock
->class_cache
;
2549 * Not cached yet or subclass?
2551 if (unlikely(!class)) {
2552 class = register_lock_class(lock
, subclass
, 0);
2556 debug_atomic_inc((atomic_t
*)&class->ops
);
2557 if (very_verbose(class)) {
2558 printk("\nacquire class [%p] %s", class->key
, class->name
);
2559 if (class->name_version
> 1)
2560 printk("#%d", class->name_version
);
2566 * Add the lock to the list of currently held locks.
2567 * (we dont increase the depth just yet, up until the
2568 * dependency checks are done)
2570 depth
= curr
->lockdep_depth
;
2571 if (DEBUG_LOCKS_WARN_ON(depth
>= MAX_LOCK_DEPTH
))
2574 hlock
= curr
->held_locks
+ depth
;
2575 if (DEBUG_LOCKS_WARN_ON(!class))
2577 hlock
->class_idx
= class - lock_classes
+ 1;
2578 hlock
->acquire_ip
= ip
;
2579 hlock
->instance
= lock
;
2580 hlock
->nest_lock
= nest_lock
;
2581 hlock
->trylock
= trylock
;
2583 hlock
->check
= check
;
2584 hlock
->hardirqs_off
= !!hardirqs_off
;
2585 #ifdef CONFIG_LOCK_STAT
2586 hlock
->waittime_stamp
= 0;
2587 hlock
->holdtime_stamp
= sched_clock();
2590 if (check
== 2 && !mark_irqflags(curr
, hlock
))
2593 /* mark it as used: */
2594 if (!mark_lock(curr
, hlock
, LOCK_USED
))
2598 * Calculate the chain hash: it's the combined hash of all the
2599 * lock keys along the dependency chain. We save the hash value
2600 * at every step so that we can get the current hash easily
2601 * after unlock. The chain hash is then used to cache dependency
2604 * The 'key ID' is what is the most compact key value to drive
2605 * the hash, not class->key.
2607 id
= class - lock_classes
;
2608 if (DEBUG_LOCKS_WARN_ON(id
>= MAX_LOCKDEP_KEYS
))
2611 chain_key
= curr
->curr_chain_key
;
2613 if (DEBUG_LOCKS_WARN_ON(chain_key
!= 0))
2618 hlock
->prev_chain_key
= chain_key
;
2619 if (separate_irq_context(curr
, hlock
)) {
2623 chain_key
= iterate_chain_key(chain_key
, id
);
2625 if (!validate_chain(curr
, lock
, hlock
, chain_head
, chain_key
))
2628 curr
->curr_chain_key
= chain_key
;
2629 curr
->lockdep_depth
++;
2630 check_chain_key(curr
);
2631 #ifdef CONFIG_DEBUG_LOCKDEP
2632 if (unlikely(!debug_locks
))
2635 if (unlikely(curr
->lockdep_depth
>= MAX_LOCK_DEPTH
)) {
2637 printk("BUG: MAX_LOCK_DEPTH too low!\n");
2638 printk("turning off the locking correctness validator.\n");
2642 if (unlikely(curr
->lockdep_depth
> max_lockdep_depth
))
2643 max_lockdep_depth
= curr
->lockdep_depth
;
2649 print_unlock_inbalance_bug(struct task_struct
*curr
, struct lockdep_map
*lock
,
2652 if (!debug_locks_off())
2654 if (debug_locks_silent
)
2657 printk("\n=====================================\n");
2658 printk( "[ BUG: bad unlock balance detected! ]\n");
2659 printk( "-------------------------------------\n");
2660 printk("%s/%d is trying to release lock (",
2661 curr
->comm
, task_pid_nr(curr
));
2662 print_lockdep_cache(lock
);
2665 printk("but there are no more locks to release!\n");
2666 printk("\nother info that might help us debug this:\n");
2667 lockdep_print_held_locks(curr
);
2669 printk("\nstack backtrace:\n");
2676 * Common debugging checks for both nested and non-nested unlock:
2678 static int check_unlock(struct task_struct
*curr
, struct lockdep_map
*lock
,
2681 if (unlikely(!debug_locks
))
2683 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2686 if (curr
->lockdep_depth
<= 0)
2687 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2693 __lock_set_subclass(struct lockdep_map
*lock
,
2694 unsigned int subclass
, unsigned long ip
)
2696 struct task_struct
*curr
= current
;
2697 struct held_lock
*hlock
, *prev_hlock
;
2698 struct lock_class
*class;
2702 depth
= curr
->lockdep_depth
;
2703 if (DEBUG_LOCKS_WARN_ON(!depth
))
2707 for (i
= depth
-1; i
>= 0; i
--) {
2708 hlock
= curr
->held_locks
+ i
;
2710 * We must not cross into another context:
2712 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
2714 if (hlock
->instance
== lock
)
2718 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2721 class = register_lock_class(lock
, subclass
, 0);
2722 hlock
->class_idx
= class - lock_classes
+ 1;
2724 curr
->lockdep_depth
= i
;
2725 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2727 for (; i
< depth
; i
++) {
2728 hlock
= curr
->held_locks
+ i
;
2729 if (!__lock_acquire(hlock
->instance
,
2730 hlock_class(hlock
)->subclass
, hlock
->trylock
,
2731 hlock
->read
, hlock
->check
, hlock
->hardirqs_off
,
2732 hlock
->nest_lock
, hlock
->acquire_ip
))
2736 if (DEBUG_LOCKS_WARN_ON(curr
->lockdep_depth
!= depth
))
2742 * Remove the lock to the list of currently held locks in a
2743 * potentially non-nested (out of order) manner. This is a
2744 * relatively rare operation, as all the unlock APIs default
2745 * to nested mode (which uses lock_release()):
2748 lock_release_non_nested(struct task_struct
*curr
,
2749 struct lockdep_map
*lock
, unsigned long ip
)
2751 struct held_lock
*hlock
, *prev_hlock
;
2756 * Check whether the lock exists in the current stack
2759 depth
= curr
->lockdep_depth
;
2760 if (DEBUG_LOCKS_WARN_ON(!depth
))
2764 for (i
= depth
-1; i
>= 0; i
--) {
2765 hlock
= curr
->held_locks
+ i
;
2767 * We must not cross into another context:
2769 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
2771 if (hlock
->instance
== lock
)
2775 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2778 lock_release_holdtime(hlock
);
2781 * We have the right lock to unlock, 'hlock' points to it.
2782 * Now we remove it from the stack, and add back the other
2783 * entries (if any), recalculating the hash along the way:
2785 curr
->lockdep_depth
= i
;
2786 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2788 for (i
++; i
< depth
; i
++) {
2789 hlock
= curr
->held_locks
+ i
;
2790 if (!__lock_acquire(hlock
->instance
,
2791 hlock_class(hlock
)->subclass
, hlock
->trylock
,
2792 hlock
->read
, hlock
->check
, hlock
->hardirqs_off
,
2793 hlock
->nest_lock
, hlock
->acquire_ip
))
2797 if (DEBUG_LOCKS_WARN_ON(curr
->lockdep_depth
!= depth
- 1))
2803 * Remove the lock to the list of currently held locks - this gets
2804 * called on mutex_unlock()/spin_unlock*() (or on a failed
2805 * mutex_lock_interruptible()). This is done for unlocks that nest
2806 * perfectly. (i.e. the current top of the lock-stack is unlocked)
2808 static int lock_release_nested(struct task_struct
*curr
,
2809 struct lockdep_map
*lock
, unsigned long ip
)
2811 struct held_lock
*hlock
;
2815 * Pop off the top of the lock stack:
2817 depth
= curr
->lockdep_depth
- 1;
2818 hlock
= curr
->held_locks
+ depth
;
2821 * Is the unlock non-nested:
2823 if (hlock
->instance
!= lock
)
2824 return lock_release_non_nested(curr
, lock
, ip
);
2825 curr
->lockdep_depth
--;
2827 if (DEBUG_LOCKS_WARN_ON(!depth
&& (hlock
->prev_chain_key
!= 0)))
2830 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2832 lock_release_holdtime(hlock
);
2834 #ifdef CONFIG_DEBUG_LOCKDEP
2835 hlock
->prev_chain_key
= 0;
2836 hlock
->class_idx
= 0;
2837 hlock
->acquire_ip
= 0;
2838 hlock
->irq_context
= 0;
2844 * Remove the lock to the list of currently held locks - this gets
2845 * called on mutex_unlock()/spin_unlock*() (or on a failed
2846 * mutex_lock_interruptible()). This is done for unlocks that nest
2847 * perfectly. (i.e. the current top of the lock-stack is unlocked)
2850 __lock_release(struct lockdep_map
*lock
, int nested
, unsigned long ip
)
2852 struct task_struct
*curr
= current
;
2854 if (!check_unlock(curr
, lock
, ip
))
2858 if (!lock_release_nested(curr
, lock
, ip
))
2861 if (!lock_release_non_nested(curr
, lock
, ip
))
2865 check_chain_key(curr
);
2869 * Check whether we follow the irq-flags state precisely:
2871 static void check_flags(unsigned long flags
)
2873 #if defined(CONFIG_PROVE_LOCKING) && defined(CONFIG_DEBUG_LOCKDEP) && \
2874 defined(CONFIG_TRACE_IRQFLAGS)
2878 if (irqs_disabled_flags(flags
)) {
2879 if (DEBUG_LOCKS_WARN_ON(current
->hardirqs_enabled
)) {
2880 printk("possible reason: unannotated irqs-off.\n");
2883 if (DEBUG_LOCKS_WARN_ON(!current
->hardirqs_enabled
)) {
2884 printk("possible reason: unannotated irqs-on.\n");
2889 * We dont accurately track softirq state in e.g.
2890 * hardirq contexts (such as on 4KSTACKS), so only
2891 * check if not in hardirq contexts:
2893 if (!hardirq_count()) {
2894 if (softirq_count())
2895 DEBUG_LOCKS_WARN_ON(current
->softirqs_enabled
);
2897 DEBUG_LOCKS_WARN_ON(!current
->softirqs_enabled
);
2901 print_irqtrace_events(current
);
2906 lock_set_subclass(struct lockdep_map
*lock
,
2907 unsigned int subclass
, unsigned long ip
)
2909 unsigned long flags
;
2911 if (unlikely(current
->lockdep_recursion
))
2914 raw_local_irq_save(flags
);
2915 current
->lockdep_recursion
= 1;
2917 if (__lock_set_subclass(lock
, subclass
, ip
))
2918 check_chain_key(current
);
2919 current
->lockdep_recursion
= 0;
2920 raw_local_irq_restore(flags
);
2923 EXPORT_SYMBOL_GPL(lock_set_subclass
);
2926 * We are not always called with irqs disabled - do that here,
2927 * and also avoid lockdep recursion:
2929 void lock_acquire(struct lockdep_map
*lock
, unsigned int subclass
,
2930 int trylock
, int read
, int check
,
2931 struct lockdep_map
*nest_lock
, unsigned long ip
)
2933 unsigned long flags
;
2935 if (unlikely(current
->lockdep_recursion
))
2938 raw_local_irq_save(flags
);
2941 current
->lockdep_recursion
= 1;
2942 __lock_acquire(lock
, subclass
, trylock
, read
, check
,
2943 irqs_disabled_flags(flags
), nest_lock
, ip
);
2944 current
->lockdep_recursion
= 0;
2945 raw_local_irq_restore(flags
);
2948 EXPORT_SYMBOL_GPL(lock_acquire
);
2950 void lock_release(struct lockdep_map
*lock
, int nested
,
2953 unsigned long flags
;
2955 if (unlikely(current
->lockdep_recursion
))
2958 raw_local_irq_save(flags
);
2960 current
->lockdep_recursion
= 1;
2961 __lock_release(lock
, nested
, ip
);
2962 current
->lockdep_recursion
= 0;
2963 raw_local_irq_restore(flags
);
2966 EXPORT_SYMBOL_GPL(lock_release
);
2968 #ifdef CONFIG_LOCK_STAT
2970 print_lock_contention_bug(struct task_struct
*curr
, struct lockdep_map
*lock
,
2973 if (!debug_locks_off())
2975 if (debug_locks_silent
)
2978 printk("\n=================================\n");
2979 printk( "[ BUG: bad contention detected! ]\n");
2980 printk( "---------------------------------\n");
2981 printk("%s/%d is trying to contend lock (",
2982 curr
->comm
, task_pid_nr(curr
));
2983 print_lockdep_cache(lock
);
2986 printk("but there are no locks held!\n");
2987 printk("\nother info that might help us debug this:\n");
2988 lockdep_print_held_locks(curr
);
2990 printk("\nstack backtrace:\n");
2997 __lock_contended(struct lockdep_map
*lock
, unsigned long ip
)
2999 struct task_struct
*curr
= current
;
3000 struct held_lock
*hlock
, *prev_hlock
;
3001 struct lock_class_stats
*stats
;
3005 depth
= curr
->lockdep_depth
;
3006 if (DEBUG_LOCKS_WARN_ON(!depth
))
3010 for (i
= depth
-1; i
>= 0; i
--) {
3011 hlock
= curr
->held_locks
+ i
;
3013 * We must not cross into another context:
3015 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
3017 if (hlock
->instance
== lock
)
3021 print_lock_contention_bug(curr
, lock
, ip
);
3025 hlock
->waittime_stamp
= sched_clock();
3027 point
= lock_contention_point(hlock_class(hlock
), ip
);
3029 stats
= get_lock_stats(hlock_class(hlock
));
3030 if (point
< ARRAY_SIZE(stats
->contention_point
))
3031 stats
->contention_point
[point
]++;
3032 if (lock
->cpu
!= smp_processor_id())
3033 stats
->bounces
[bounce_contended
+ !!hlock
->read
]++;
3034 put_lock_stats(stats
);
3038 __lock_acquired(struct lockdep_map
*lock
)
3040 struct task_struct
*curr
= current
;
3041 struct held_lock
*hlock
, *prev_hlock
;
3042 struct lock_class_stats
*stats
;
3048 depth
= curr
->lockdep_depth
;
3049 if (DEBUG_LOCKS_WARN_ON(!depth
))
3053 for (i
= depth
-1; i
>= 0; i
--) {
3054 hlock
= curr
->held_locks
+ i
;
3056 * We must not cross into another context:
3058 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
3060 if (hlock
->instance
== lock
)
3064 print_lock_contention_bug(curr
, lock
, _RET_IP_
);
3068 cpu
= smp_processor_id();
3069 if (hlock
->waittime_stamp
) {
3070 now
= sched_clock();
3071 waittime
= now
- hlock
->waittime_stamp
;
3072 hlock
->holdtime_stamp
= now
;
3075 stats
= get_lock_stats(hlock_class(hlock
));
3078 lock_time_inc(&stats
->read_waittime
, waittime
);
3080 lock_time_inc(&stats
->write_waittime
, waittime
);
3082 if (lock
->cpu
!= cpu
)
3083 stats
->bounces
[bounce_acquired
+ !!hlock
->read
]++;
3084 put_lock_stats(stats
);
3089 void lock_contended(struct lockdep_map
*lock
, unsigned long ip
)
3091 unsigned long flags
;
3093 if (unlikely(!lock_stat
))
3096 if (unlikely(current
->lockdep_recursion
))
3099 raw_local_irq_save(flags
);
3101 current
->lockdep_recursion
= 1;
3102 __lock_contended(lock
, ip
);
3103 current
->lockdep_recursion
= 0;
3104 raw_local_irq_restore(flags
);
3106 EXPORT_SYMBOL_GPL(lock_contended
);
3108 void lock_acquired(struct lockdep_map
*lock
)
3110 unsigned long flags
;
3112 if (unlikely(!lock_stat
))
3115 if (unlikely(current
->lockdep_recursion
))
3118 raw_local_irq_save(flags
);
3120 current
->lockdep_recursion
= 1;
3121 __lock_acquired(lock
);
3122 current
->lockdep_recursion
= 0;
3123 raw_local_irq_restore(flags
);
3125 EXPORT_SYMBOL_GPL(lock_acquired
);
3129 * Used by the testsuite, sanitize the validator state
3130 * after a simulated failure:
3133 void lockdep_reset(void)
3135 unsigned long flags
;
3138 raw_local_irq_save(flags
);
3139 current
->curr_chain_key
= 0;
3140 current
->lockdep_depth
= 0;
3141 current
->lockdep_recursion
= 0;
3142 memset(current
->held_locks
, 0, MAX_LOCK_DEPTH
*sizeof(struct held_lock
));
3143 nr_hardirq_chains
= 0;
3144 nr_softirq_chains
= 0;
3145 nr_process_chains
= 0;
3147 for (i
= 0; i
< CHAINHASH_SIZE
; i
++)
3148 INIT_LIST_HEAD(chainhash_table
+ i
);
3149 raw_local_irq_restore(flags
);
3152 static void zap_class(struct lock_class
*class)
3157 * Remove all dependencies this lock is
3160 for (i
= 0; i
< nr_list_entries
; i
++) {
3161 if (list_entries
[i
].class == class)
3162 list_del_rcu(&list_entries
[i
].entry
);
3165 * Unhash the class and remove it from the all_lock_classes list:
3167 list_del_rcu(&class->hash_entry
);
3168 list_del_rcu(&class->lock_entry
);
3173 static inline int within(const void *addr
, void *start
, unsigned long size
)
3175 return addr
>= start
&& addr
< start
+ size
;
3178 void lockdep_free_key_range(void *start
, unsigned long size
)
3180 struct lock_class
*class, *next
;
3181 struct list_head
*head
;
3182 unsigned long flags
;
3186 raw_local_irq_save(flags
);
3187 locked
= graph_lock();
3190 * Unhash all classes that were created by this module:
3192 for (i
= 0; i
< CLASSHASH_SIZE
; i
++) {
3193 head
= classhash_table
+ i
;
3194 if (list_empty(head
))
3196 list_for_each_entry_safe(class, next
, head
, hash_entry
) {
3197 if (within(class->key
, start
, size
))
3199 else if (within(class->name
, start
, size
))
3206 raw_local_irq_restore(flags
);
3209 void lockdep_reset_lock(struct lockdep_map
*lock
)
3211 struct lock_class
*class, *next
;
3212 struct list_head
*head
;
3213 unsigned long flags
;
3217 raw_local_irq_save(flags
);
3220 * Remove all classes this lock might have:
3222 for (j
= 0; j
< MAX_LOCKDEP_SUBCLASSES
; j
++) {
3224 * If the class exists we look it up and zap it:
3226 class = look_up_lock_class(lock
, j
);
3231 * Debug check: in the end all mapped classes should
3234 locked
= graph_lock();
3235 for (i
= 0; i
< CLASSHASH_SIZE
; i
++) {
3236 head
= classhash_table
+ i
;
3237 if (list_empty(head
))
3239 list_for_each_entry_safe(class, next
, head
, hash_entry
) {
3240 if (unlikely(class == lock
->class_cache
)) {
3241 if (debug_locks_off_graph_unlock())
3251 raw_local_irq_restore(flags
);
3254 void lockdep_init(void)
3259 * Some architectures have their own start_kernel()
3260 * code which calls lockdep_init(), while we also
3261 * call lockdep_init() from the start_kernel() itself,
3262 * and we want to initialize the hashes only once:
3264 if (lockdep_initialized
)
3267 for (i
= 0; i
< CLASSHASH_SIZE
; i
++)
3268 INIT_LIST_HEAD(classhash_table
+ i
);
3270 for (i
= 0; i
< CHAINHASH_SIZE
; i
++)
3271 INIT_LIST_HEAD(chainhash_table
+ i
);
3273 lockdep_initialized
= 1;
3276 void __init
lockdep_info(void)
3278 printk("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n");
3280 printk("... MAX_LOCKDEP_SUBCLASSES: %lu\n", MAX_LOCKDEP_SUBCLASSES
);
3281 printk("... MAX_LOCK_DEPTH: %lu\n", MAX_LOCK_DEPTH
);
3282 printk("... MAX_LOCKDEP_KEYS: %lu\n", MAX_LOCKDEP_KEYS
);
3283 printk("... CLASSHASH_SIZE: %lu\n", CLASSHASH_SIZE
);
3284 printk("... MAX_LOCKDEP_ENTRIES: %lu\n", MAX_LOCKDEP_ENTRIES
);
3285 printk("... MAX_LOCKDEP_CHAINS: %lu\n", MAX_LOCKDEP_CHAINS
);
3286 printk("... CHAINHASH_SIZE: %lu\n", CHAINHASH_SIZE
);
3288 printk(" memory used by lock dependency info: %lu kB\n",
3289 (sizeof(struct lock_class
) * MAX_LOCKDEP_KEYS
+
3290 sizeof(struct list_head
) * CLASSHASH_SIZE
+
3291 sizeof(struct lock_list
) * MAX_LOCKDEP_ENTRIES
+
3292 sizeof(struct lock_chain
) * MAX_LOCKDEP_CHAINS
+
3293 sizeof(struct list_head
) * CHAINHASH_SIZE
) / 1024);
3295 printk(" per task-struct memory footprint: %lu bytes\n",
3296 sizeof(struct held_lock
) * MAX_LOCK_DEPTH
);
3298 #ifdef CONFIG_DEBUG_LOCKDEP
3299 if (lockdep_init_error
) {
3300 printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
3301 printk("Call stack leading to lockdep invocation was:\n");
3302 print_stack_trace(&lockdep_init_trace
, 0);
3308 print_freed_lock_bug(struct task_struct
*curr
, const void *mem_from
,
3309 const void *mem_to
, struct held_lock
*hlock
)
3311 if (!debug_locks_off())
3313 if (debug_locks_silent
)
3316 printk("\n=========================\n");
3317 printk( "[ BUG: held lock freed! ]\n");
3318 printk( "-------------------------\n");
3319 printk("%s/%d is freeing memory %p-%p, with a lock still held there!\n",
3320 curr
->comm
, task_pid_nr(curr
), mem_from
, mem_to
-1);
3322 lockdep_print_held_locks(curr
);
3324 printk("\nstack backtrace:\n");
3328 static inline int not_in_range(const void* mem_from
, unsigned long mem_len
,
3329 const void* lock_from
, unsigned long lock_len
)
3331 return lock_from
+ lock_len
<= mem_from
||
3332 mem_from
+ mem_len
<= lock_from
;
3336 * Called when kernel memory is freed (or unmapped), or if a lock
3337 * is destroyed or reinitialized - this code checks whether there is
3338 * any held lock in the memory range of <from> to <to>:
3340 void debug_check_no_locks_freed(const void *mem_from
, unsigned long mem_len
)
3342 struct task_struct
*curr
= current
;
3343 struct held_lock
*hlock
;
3344 unsigned long flags
;
3347 if (unlikely(!debug_locks
))
3350 local_irq_save(flags
);
3351 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
3352 hlock
= curr
->held_locks
+ i
;
3354 if (not_in_range(mem_from
, mem_len
, hlock
->instance
,
3355 sizeof(*hlock
->instance
)))
3358 print_freed_lock_bug(curr
, mem_from
, mem_from
+ mem_len
, hlock
);
3361 local_irq_restore(flags
);
3363 EXPORT_SYMBOL_GPL(debug_check_no_locks_freed
);
3365 static void print_held_locks_bug(struct task_struct
*curr
)
3367 if (!debug_locks_off())
3369 if (debug_locks_silent
)
3372 printk("\n=====================================\n");
3373 printk( "[ BUG: lock held at task exit time! ]\n");
3374 printk( "-------------------------------------\n");
3375 printk("%s/%d is exiting with locks still held!\n",
3376 curr
->comm
, task_pid_nr(curr
));
3377 lockdep_print_held_locks(curr
);
3379 printk("\nstack backtrace:\n");
3383 void debug_check_no_locks_held(struct task_struct
*task
)
3385 if (unlikely(task
->lockdep_depth
> 0))
3386 print_held_locks_bug(task
);
3389 void debug_show_all_locks(void)
3391 struct task_struct
*g
, *p
;
3395 if (unlikely(!debug_locks
)) {
3396 printk("INFO: lockdep is turned off.\n");
3399 printk("\nShowing all locks held in the system:\n");
3402 * Here we try to get the tasklist_lock as hard as possible,
3403 * if not successful after 2 seconds we ignore it (but keep
3404 * trying). This is to enable a debug printout even if a
3405 * tasklist_lock-holding task deadlocks or crashes.
3408 if (!read_trylock(&tasklist_lock
)) {
3410 printk("hm, tasklist_lock locked, retrying... ");
3413 printk(" #%d", 10-count
);
3417 printk(" ignoring it.\n");
3421 printk(KERN_CONT
" locked it.\n");
3424 do_each_thread(g
, p
) {
3426 * It's not reliable to print a task's held locks
3427 * if it's not sleeping (or if it's not the current
3430 if (p
->state
== TASK_RUNNING
&& p
!= current
)
3432 if (p
->lockdep_depth
)
3433 lockdep_print_held_locks(p
);
3435 if (read_trylock(&tasklist_lock
))
3437 } while_each_thread(g
, p
);
3440 printk("=============================================\n\n");
3443 read_unlock(&tasklist_lock
);
3446 EXPORT_SYMBOL_GPL(debug_show_all_locks
);
3449 * Careful: only use this function if you are sure that
3450 * the task cannot run in parallel!
3452 void __debug_show_held_locks(struct task_struct
*task
)
3454 if (unlikely(!debug_locks
)) {
3455 printk("INFO: lockdep is turned off.\n");
3458 lockdep_print_held_locks(task
);
3460 EXPORT_SYMBOL_GPL(__debug_show_held_locks
);
3462 void debug_show_held_locks(struct task_struct
*task
)
3464 __debug_show_held_locks(task
);
3467 EXPORT_SYMBOL_GPL(debug_show_held_locks
);
3469 void lockdep_sys_exit(void)
3471 struct task_struct
*curr
= current
;
3473 if (unlikely(curr
->lockdep_depth
)) {
3474 if (!debug_locks_off())
3476 printk("\n================================================\n");
3477 printk( "[ BUG: lock held when returning to user space! ]\n");
3478 printk( "------------------------------------------------\n");
3479 printk("%s/%d is leaving the kernel with locks still held!\n",
3480 curr
->comm
, curr
->pid
);
3481 lockdep_print_held_locks(curr
);