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>
44 #include <linux/stringify.h>
45 #include <trace/lockdep.h>
47 #include <asm/sections.h>
49 #include "lockdep_internals.h"
51 #ifdef CONFIG_PROVE_LOCKING
52 int prove_locking
= 1;
53 module_param(prove_locking
, int, 0644);
55 #define prove_locking 0
58 #ifdef CONFIG_LOCK_STAT
60 module_param(lock_stat
, int, 0644);
66 * lockdep_lock: protects the lockdep graph, the hashes and the
67 * class/list/hash allocators.
69 * This is one of the rare exceptions where it's justified
70 * to use a raw spinlock - we really dont want the spinlock
71 * code to recurse back into the lockdep code...
73 static __raw_spinlock_t lockdep_lock
= (__raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
75 static int graph_lock(void)
77 __raw_spin_lock(&lockdep_lock
);
79 * Make sure that if another CPU detected a bug while
80 * walking the graph we dont change it (while the other
81 * CPU is busy printing out stuff with the graph lock
85 __raw_spin_unlock(&lockdep_lock
);
88 /* prevent any recursions within lockdep from causing deadlocks */
89 current
->lockdep_recursion
++;
93 static inline int graph_unlock(void)
95 if (debug_locks
&& !__raw_spin_is_locked(&lockdep_lock
))
96 return DEBUG_LOCKS_WARN_ON(1);
98 current
->lockdep_recursion
--;
99 __raw_spin_unlock(&lockdep_lock
);
104 * Turn lock debugging off and return with 0 if it was off already,
105 * and also release the graph lock:
107 static inline int debug_locks_off_graph_unlock(void)
109 int ret
= debug_locks_off();
111 __raw_spin_unlock(&lockdep_lock
);
116 static int lockdep_initialized
;
118 unsigned long nr_list_entries
;
119 static struct lock_list list_entries
[MAX_LOCKDEP_ENTRIES
];
122 * All data structures here are protected by the global debug_lock.
124 * Mutex key structs only get allocated, once during bootup, and never
125 * get freed - this significantly simplifies the debugging code.
127 unsigned long nr_lock_classes
;
128 static struct lock_class lock_classes
[MAX_LOCKDEP_KEYS
];
130 static inline struct lock_class
*hlock_class(struct held_lock
*hlock
)
132 if (!hlock
->class_idx
) {
133 DEBUG_LOCKS_WARN_ON(1);
136 return lock_classes
+ hlock
->class_idx
- 1;
139 #ifdef CONFIG_LOCK_STAT
140 static DEFINE_PER_CPU(struct lock_class_stats
[MAX_LOCKDEP_KEYS
], lock_stats
);
142 static int lock_point(unsigned long points
[], unsigned long ip
)
146 for (i
= 0; i
< LOCKSTAT_POINTS
; i
++) {
147 if (points
[i
] == 0) {
158 static void lock_time_inc(struct lock_time
*lt
, s64 time
)
163 if (time
< lt
->min
|| !lt
->min
)
170 static inline void lock_time_add(struct lock_time
*src
, struct lock_time
*dst
)
172 dst
->min
+= src
->min
;
173 dst
->max
+= src
->max
;
174 dst
->total
+= src
->total
;
178 struct lock_class_stats
lock_stats(struct lock_class
*class)
180 struct lock_class_stats stats
;
183 memset(&stats
, 0, sizeof(struct lock_class_stats
));
184 for_each_possible_cpu(cpu
) {
185 struct lock_class_stats
*pcs
=
186 &per_cpu(lock_stats
, cpu
)[class - lock_classes
];
188 for (i
= 0; i
< ARRAY_SIZE(stats
.contention_point
); i
++)
189 stats
.contention_point
[i
] += pcs
->contention_point
[i
];
191 for (i
= 0; i
< ARRAY_SIZE(stats
.contending_point
); i
++)
192 stats
.contending_point
[i
] += pcs
->contending_point
[i
];
194 lock_time_add(&pcs
->read_waittime
, &stats
.read_waittime
);
195 lock_time_add(&pcs
->write_waittime
, &stats
.write_waittime
);
197 lock_time_add(&pcs
->read_holdtime
, &stats
.read_holdtime
);
198 lock_time_add(&pcs
->write_holdtime
, &stats
.write_holdtime
);
200 for (i
= 0; i
< ARRAY_SIZE(stats
.bounces
); i
++)
201 stats
.bounces
[i
] += pcs
->bounces
[i
];
207 void clear_lock_stats(struct lock_class
*class)
211 for_each_possible_cpu(cpu
) {
212 struct lock_class_stats
*cpu_stats
=
213 &per_cpu(lock_stats
, cpu
)[class - lock_classes
];
215 memset(cpu_stats
, 0, sizeof(struct lock_class_stats
));
217 memset(class->contention_point
, 0, sizeof(class->contention_point
));
218 memset(class->contending_point
, 0, sizeof(class->contending_point
));
221 static struct lock_class_stats
*get_lock_stats(struct lock_class
*class)
223 return &get_cpu_var(lock_stats
)[class - lock_classes
];
226 static void put_lock_stats(struct lock_class_stats
*stats
)
228 put_cpu_var(lock_stats
);
231 static void lock_release_holdtime(struct held_lock
*hlock
)
233 struct lock_class_stats
*stats
;
239 holdtime
= sched_clock() - hlock
->holdtime_stamp
;
241 stats
= get_lock_stats(hlock_class(hlock
));
243 lock_time_inc(&stats
->read_holdtime
, holdtime
);
245 lock_time_inc(&stats
->write_holdtime
, holdtime
);
246 put_lock_stats(stats
);
249 static inline void lock_release_holdtime(struct held_lock
*hlock
)
255 * We keep a global list of all lock classes. The list only grows,
256 * never shrinks. The list is only accessed with the lockdep
257 * spinlock lock held.
259 LIST_HEAD(all_lock_classes
);
262 * The lockdep classes are in a hash-table as well, for fast lookup:
264 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
265 #define CLASSHASH_SIZE (1UL << CLASSHASH_BITS)
266 #define __classhashfn(key) hash_long((unsigned long)key, CLASSHASH_BITS)
267 #define classhashentry(key) (classhash_table + __classhashfn((key)))
269 static struct list_head classhash_table
[CLASSHASH_SIZE
];
272 * We put the lock dependency chains into a hash-table as well, to cache
275 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
276 #define CHAINHASH_SIZE (1UL << CHAINHASH_BITS)
277 #define __chainhashfn(chain) hash_long(chain, CHAINHASH_BITS)
278 #define chainhashentry(chain) (chainhash_table + __chainhashfn((chain)))
280 static struct list_head chainhash_table
[CHAINHASH_SIZE
];
283 * The hash key of the lock dependency chains is a hash itself too:
284 * it's a hash of all locks taken up to that lock, including that lock.
285 * It's a 64-bit hash, because it's important for the keys to be
288 #define iterate_chain_key(key1, key2) \
289 (((key1) << MAX_LOCKDEP_KEYS_BITS) ^ \
290 ((key1) >> (64-MAX_LOCKDEP_KEYS_BITS)) ^ \
293 void lockdep_off(void)
295 current
->lockdep_recursion
++;
297 EXPORT_SYMBOL(lockdep_off
);
299 void lockdep_on(void)
301 current
->lockdep_recursion
--;
303 EXPORT_SYMBOL(lockdep_on
);
306 * Debugging switches:
310 #define VERY_VERBOSE 0
313 # define HARDIRQ_VERBOSE 1
314 # define SOFTIRQ_VERBOSE 1
315 # define RECLAIM_VERBOSE 1
317 # define HARDIRQ_VERBOSE 0
318 # define SOFTIRQ_VERBOSE 0
319 # define RECLAIM_VERBOSE 0
322 #if VERBOSE || HARDIRQ_VERBOSE || SOFTIRQ_VERBOSE || RECLAIM_VERBOSE
324 * Quick filtering for interesting events:
326 static int class_filter(struct lock_class
*class)
330 if (class->name_version
== 1 &&
331 !strcmp(class->name
, "lockname"))
333 if (class->name_version
== 1 &&
334 !strcmp(class->name
, "&struct->lockfield"))
337 /* Filter everything else. 1 would be to allow everything else */
342 static int verbose(struct lock_class
*class)
345 return class_filter(class);
351 * Stack-trace: tightly packed array of stack backtrace
352 * addresses. Protected by the graph_lock.
354 unsigned long nr_stack_trace_entries
;
355 static unsigned long stack_trace
[MAX_STACK_TRACE_ENTRIES
];
357 static int save_trace(struct stack_trace
*trace
)
359 trace
->nr_entries
= 0;
360 trace
->max_entries
= MAX_STACK_TRACE_ENTRIES
- nr_stack_trace_entries
;
361 trace
->entries
= stack_trace
+ nr_stack_trace_entries
;
365 save_stack_trace(trace
);
367 trace
->max_entries
= trace
->nr_entries
;
369 nr_stack_trace_entries
+= trace
->nr_entries
;
371 if (nr_stack_trace_entries
== MAX_STACK_TRACE_ENTRIES
) {
372 if (!debug_locks_off_graph_unlock())
375 printk("BUG: MAX_STACK_TRACE_ENTRIES too low!\n");
376 printk("turning off the locking correctness validator.\n");
385 unsigned int nr_hardirq_chains
;
386 unsigned int nr_softirq_chains
;
387 unsigned int nr_process_chains
;
388 unsigned int max_lockdep_depth
;
389 unsigned int max_recursion_depth
;
391 static unsigned int lockdep_dependency_gen_id
;
393 static bool lockdep_dependency_visit(struct lock_class
*source
,
397 lockdep_dependency_gen_id
++;
398 if (source
->dep_gen_id
== lockdep_dependency_gen_id
)
400 source
->dep_gen_id
= lockdep_dependency_gen_id
;
404 #ifdef CONFIG_DEBUG_LOCKDEP
406 * We cannot printk in early bootup code. Not even early_printk()
407 * might work. So we mark any initialization errors and printk
408 * about it later on, in lockdep_info().
410 static int lockdep_init_error
;
411 static unsigned long lockdep_init_trace_data
[20];
412 static struct stack_trace lockdep_init_trace
= {
413 .max_entries
= ARRAY_SIZE(lockdep_init_trace_data
),
414 .entries
= lockdep_init_trace_data
,
418 * Various lockdep statistics:
420 atomic_t chain_lookup_hits
;
421 atomic_t chain_lookup_misses
;
422 atomic_t hardirqs_on_events
;
423 atomic_t hardirqs_off_events
;
424 atomic_t redundant_hardirqs_on
;
425 atomic_t redundant_hardirqs_off
;
426 atomic_t softirqs_on_events
;
427 atomic_t softirqs_off_events
;
428 atomic_t redundant_softirqs_on
;
429 atomic_t redundant_softirqs_off
;
430 atomic_t nr_unused_locks
;
431 atomic_t nr_cyclic_checks
;
432 atomic_t nr_cyclic_check_recursions
;
433 atomic_t nr_find_usage_forwards_checks
;
434 atomic_t nr_find_usage_forwards_recursions
;
435 atomic_t nr_find_usage_backwards_checks
;
436 atomic_t nr_find_usage_backwards_recursions
;
443 #define __USAGE(__STATE) \
444 [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \
445 [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \
446 [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\
447 [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R",
449 static const char *usage_str
[] =
451 #define LOCKDEP_STATE(__STATE) __USAGE(__STATE)
452 #include "lockdep_states.h"
454 [LOCK_USED
] = "INITIAL USE",
457 const char * __get_key_name(struct lockdep_subclass_key
*key
, char *str
)
459 return kallsyms_lookup((unsigned long)key
, NULL
, NULL
, NULL
, str
);
462 static inline unsigned long lock_flag(enum lock_usage_bit bit
)
467 static char get_usage_char(struct lock_class
*class, enum lock_usage_bit bit
)
471 if (class->usage_mask
& lock_flag(bit
+ 2))
473 if (class->usage_mask
& lock_flag(bit
)) {
475 if (class->usage_mask
& lock_flag(bit
+ 2))
482 void get_usage_chars(struct lock_class
*class, char usage
[LOCK_USAGE_CHARS
])
486 #define LOCKDEP_STATE(__STATE) \
487 usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE); \
488 usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE##_READ);
489 #include "lockdep_states.h"
495 static void print_lock_name(struct lock_class
*class)
497 char str
[KSYM_NAME_LEN
], usage
[LOCK_USAGE_CHARS
];
500 get_usage_chars(class, usage
);
504 name
= __get_key_name(class->key
, str
);
505 printk(" (%s", name
);
507 printk(" (%s", name
);
508 if (class->name_version
> 1)
509 printk("#%d", class->name_version
);
511 printk("/%d", class->subclass
);
513 printk("){%s}", usage
);
516 static void print_lockdep_cache(struct lockdep_map
*lock
)
519 char str
[KSYM_NAME_LEN
];
523 name
= __get_key_name(lock
->key
->subkeys
, str
);
528 static void print_lock(struct held_lock
*hlock
)
530 print_lock_name(hlock_class(hlock
));
532 print_ip_sym(hlock
->acquire_ip
);
535 static void lockdep_print_held_locks(struct task_struct
*curr
)
537 int i
, depth
= curr
->lockdep_depth
;
540 printk("no locks held by %s/%d.\n", curr
->comm
, task_pid_nr(curr
));
543 printk("%d lock%s held by %s/%d:\n",
544 depth
, depth
> 1 ? "s" : "", curr
->comm
, task_pid_nr(curr
));
546 for (i
= 0; i
< depth
; i
++) {
548 print_lock(curr
->held_locks
+ i
);
552 static void print_lock_class_header(struct lock_class
*class, int depth
)
556 printk("%*s->", depth
, "");
557 print_lock_name(class);
558 printk(" ops: %lu", class->ops
);
561 for (bit
= 0; bit
< LOCK_USAGE_STATES
; bit
++) {
562 if (class->usage_mask
& (1 << bit
)) {
565 len
+= printk("%*s %s", depth
, "", usage_str
[bit
]);
566 len
+= printk(" at:\n");
567 print_stack_trace(class->usage_traces
+ bit
, len
);
570 printk("%*s }\n", depth
, "");
572 printk("%*s ... key at: ",depth
,"");
573 print_ip_sym((unsigned long)class->key
);
577 * printk all lock dependencies starting at <entry>:
580 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 %p.\n", lock
->key
);
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");
799 class = lock_classes
+ nr_lock_classes
++;
800 debug_atomic_inc(&nr_unused_locks
);
802 class->name
= lock
->name
;
803 class->subclass
= subclass
;
804 INIT_LIST_HEAD(&class->lock_entry
);
805 INIT_LIST_HEAD(&class->locks_before
);
806 INIT_LIST_HEAD(&class->locks_after
);
807 class->name_version
= count_matching_names(class);
809 * We use RCU's safe list-add method to make
810 * parallel walking of the hash-list safe:
812 list_add_tail_rcu(&class->hash_entry
, hash_head
);
814 * Add it to the global list of classes:
816 list_add_tail_rcu(&class->lock_entry
, &all_lock_classes
);
818 if (verbose(class)) {
820 raw_local_irq_restore(flags
);
822 printk("\nnew class %p: %s", class->key
, class->name
);
823 if (class->name_version
> 1)
824 printk("#%d", class->name_version
);
828 raw_local_irq_save(flags
);
830 raw_local_irq_restore(flags
);
836 raw_local_irq_restore(flags
);
838 if (!subclass
|| force
)
839 lock
->class_cache
= class;
841 if (DEBUG_LOCKS_WARN_ON(class->subclass
!= subclass
))
847 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_TRACE_IRQFLAGS)
849 #define RECURSION_LIMIT 40
851 static int noinline
print_infinite_recursion_bug(void)
853 if (!debug_locks_off_graph_unlock())
860 #endif /* CONFIG_PROVE_LOCKING || CONFIG_TRACE_IRQFLAGS */
862 #ifdef CONFIG_PROVE_LOCKING
864 * Allocate a lockdep entry. (assumes the graph_lock held, returns
865 * with NULL on failure)
867 static struct lock_list
*alloc_list_entry(void)
869 if (nr_list_entries
>= MAX_LOCKDEP_ENTRIES
) {
870 if (!debug_locks_off_graph_unlock())
873 printk("BUG: MAX_LOCKDEP_ENTRIES too low!\n");
874 printk("turning off the locking correctness validator.\n");
878 return list_entries
+ nr_list_entries
++;
882 * Add a new dependency to the head of the list:
884 static int add_lock_to_list(struct lock_class
*class, struct lock_class
*this,
885 struct list_head
*head
, unsigned long ip
, int distance
)
887 struct lock_list
*entry
;
889 * Lock not present yet - get a new dependency struct and
890 * add it to the list:
892 entry
= alloc_list_entry();
896 if (!save_trace(&entry
->trace
))
900 entry
->distance
= distance
;
902 * Since we never remove from the dependency list, the list can
903 * be walked lockless by other CPUs, it's only allocation
904 * that must be protected by the spinlock. But this also means
905 * we must make new entries visible only once writes to the
906 * entry become visible - hence the RCU op:
908 list_add_tail_rcu(&entry
->entry
, head
);
914 * Recursive, forwards-direction lock-dependency checking, used for
915 * both noncyclic checking and for hardirq-unsafe/softirq-unsafe
918 * (to keep the stackframe of the recursive functions small we
919 * use these global variables, and we also mark various helper
920 * functions as noinline.)
922 static struct held_lock
*check_source
, *check_target
;
925 * Print a dependency chain entry (this is only done when a deadlock
926 * has been detected):
929 print_circular_bug_entry(struct lock_list
*target
, unsigned int depth
)
931 if (debug_locks_silent
)
933 printk("\n-> #%u", depth
);
934 print_lock_name(target
->class);
936 print_stack_trace(&target
->trace
, 6);
942 * When a circular dependency is detected, print the
946 print_circular_bug_header(struct lock_list
*entry
, unsigned int depth
)
948 struct task_struct
*curr
= current
;
950 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
953 printk("\n=======================================================\n");
954 printk( "[ INFO: possible circular locking dependency detected ]\n");
955 print_kernel_version();
956 printk( "-------------------------------------------------------\n");
957 printk("%s/%d is trying to acquire lock:\n",
958 curr
->comm
, task_pid_nr(curr
));
959 print_lock(check_source
);
960 printk("\nbut task is already holding lock:\n");
961 print_lock(check_target
);
962 printk("\nwhich lock already depends on the new lock.\n\n");
963 printk("\nthe existing dependency chain (in reverse order) is:\n");
965 print_circular_bug_entry(entry
, depth
);
970 static noinline
int print_circular_bug_tail(void)
972 struct task_struct
*curr
= current
;
973 struct lock_list
this;
975 if (debug_locks_silent
)
978 this.class = hlock_class(check_source
);
979 if (!save_trace(&this.trace
))
982 print_circular_bug_entry(&this, 0);
984 printk("\nother info that might help us debug this:\n\n");
985 lockdep_print_held_locks(curr
);
987 printk("\nstack backtrace:\n");
993 unsigned long __lockdep_count_forward_deps(struct lock_class
*class,
996 struct lock_list
*entry
;
997 unsigned long ret
= 1;
999 if (lockdep_dependency_visit(class, depth
))
1003 * Recurse this class's dependency list:
1005 list_for_each_entry(entry
, &class->locks_after
, entry
)
1006 ret
+= __lockdep_count_forward_deps(entry
->class, depth
+ 1);
1011 unsigned long lockdep_count_forward_deps(struct lock_class
*class)
1013 unsigned long ret
, flags
;
1015 local_irq_save(flags
);
1016 __raw_spin_lock(&lockdep_lock
);
1017 ret
= __lockdep_count_forward_deps(class, 0);
1018 __raw_spin_unlock(&lockdep_lock
);
1019 local_irq_restore(flags
);
1024 unsigned long __lockdep_count_backward_deps(struct lock_class
*class,
1027 struct lock_list
*entry
;
1028 unsigned long ret
= 1;
1030 if (lockdep_dependency_visit(class, depth
))
1033 * Recurse this class's dependency list:
1035 list_for_each_entry(entry
, &class->locks_before
, entry
)
1036 ret
+= __lockdep_count_backward_deps(entry
->class, depth
+ 1);
1041 unsigned long lockdep_count_backward_deps(struct lock_class
*class)
1043 unsigned long ret
, flags
;
1045 local_irq_save(flags
);
1046 __raw_spin_lock(&lockdep_lock
);
1047 ret
= __lockdep_count_backward_deps(class, 0);
1048 __raw_spin_unlock(&lockdep_lock
);
1049 local_irq_restore(flags
);
1055 * Prove that the dependency graph starting at <entry> can not
1056 * lead to <target>. Print an error and return 0 if it does.
1059 check_noncircular(struct lock_class
*source
, unsigned int depth
)
1061 struct lock_list
*entry
;
1063 if (lockdep_dependency_visit(source
, depth
))
1066 debug_atomic_inc(&nr_cyclic_check_recursions
);
1067 if (depth
> max_recursion_depth
)
1068 max_recursion_depth
= depth
;
1069 if (depth
>= RECURSION_LIMIT
)
1070 return print_infinite_recursion_bug();
1072 * Check this lock's dependency list:
1074 list_for_each_entry(entry
, &source
->locks_after
, entry
) {
1075 if (entry
->class == hlock_class(check_target
))
1076 return print_circular_bug_header(entry
, depth
+1);
1077 debug_atomic_inc(&nr_cyclic_checks
);
1078 if (!check_noncircular(entry
->class, depth
+1))
1079 return print_circular_bug_entry(entry
, depth
+1);
1084 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
1086 * Forwards and backwards subgraph searching, for the purposes of
1087 * proving that two subgraphs can be connected by a new dependency
1088 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
1090 static enum lock_usage_bit find_usage_bit
;
1091 static struct lock_class
*forwards_match
, *backwards_match
;
1094 * Find a node in the forwards-direction dependency sub-graph starting
1095 * at <source> that matches <find_usage_bit>.
1097 * Return 2 if such a node exists in the subgraph, and put that node
1098 * into <forwards_match>.
1100 * Return 1 otherwise and keep <forwards_match> unchanged.
1101 * Return 0 on error.
1104 find_usage_forwards(struct lock_class
*source
, unsigned int depth
)
1106 struct lock_list
*entry
;
1109 if (lockdep_dependency_visit(source
, depth
))
1112 if (depth
> max_recursion_depth
)
1113 max_recursion_depth
= depth
;
1114 if (depth
>= RECURSION_LIMIT
)
1115 return print_infinite_recursion_bug();
1117 debug_atomic_inc(&nr_find_usage_forwards_checks
);
1118 if (source
->usage_mask
& (1 << find_usage_bit
)) {
1119 forwards_match
= source
;
1124 * Check this lock's dependency list:
1126 list_for_each_entry(entry
, &source
->locks_after
, entry
) {
1127 debug_atomic_inc(&nr_find_usage_forwards_recursions
);
1128 ret
= find_usage_forwards(entry
->class, depth
+1);
1129 if (ret
== 2 || ret
== 0)
1136 * Find a node in the backwards-direction dependency sub-graph starting
1137 * at <source> that matches <find_usage_bit>.
1139 * Return 2 if such a node exists in the subgraph, and put that node
1140 * into <backwards_match>.
1142 * Return 1 otherwise and keep <backwards_match> unchanged.
1143 * Return 0 on error.
1146 find_usage_backwards(struct lock_class
*source
, unsigned int depth
)
1148 struct lock_list
*entry
;
1151 if (lockdep_dependency_visit(source
, depth
))
1154 if (!__raw_spin_is_locked(&lockdep_lock
))
1155 return DEBUG_LOCKS_WARN_ON(1);
1157 if (depth
> max_recursion_depth
)
1158 max_recursion_depth
= depth
;
1159 if (depth
>= RECURSION_LIMIT
)
1160 return print_infinite_recursion_bug();
1162 debug_atomic_inc(&nr_find_usage_backwards_checks
);
1163 if (source
->usage_mask
& (1 << find_usage_bit
)) {
1164 backwards_match
= source
;
1168 if (!source
&& debug_locks_off_graph_unlock()) {
1174 * Check this lock's dependency list:
1176 list_for_each_entry(entry
, &source
->locks_before
, entry
) {
1177 debug_atomic_inc(&nr_find_usage_backwards_recursions
);
1178 ret
= find_usage_backwards(entry
->class, depth
+1);
1179 if (ret
== 2 || ret
== 0)
1185 #ifdef CONFIG_PROVE_LOCKING
1187 print_bad_irq_dependency(struct task_struct
*curr
,
1188 struct held_lock
*prev
,
1189 struct held_lock
*next
,
1190 enum lock_usage_bit bit1
,
1191 enum lock_usage_bit bit2
,
1192 const char *irqclass
)
1194 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1197 printk("\n======================================================\n");
1198 printk( "[ INFO: %s-safe -> %s-unsafe lock order detected ]\n",
1199 irqclass
, irqclass
);
1200 print_kernel_version();
1201 printk( "------------------------------------------------------\n");
1202 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] is trying to acquire:\n",
1203 curr
->comm
, task_pid_nr(curr
),
1204 curr
->hardirq_context
, hardirq_count() >> HARDIRQ_SHIFT
,
1205 curr
->softirq_context
, softirq_count() >> SOFTIRQ_SHIFT
,
1206 curr
->hardirqs_enabled
,
1207 curr
->softirqs_enabled
);
1210 printk("\nand this task is already holding:\n");
1212 printk("which would create a new lock dependency:\n");
1213 print_lock_name(hlock_class(prev
));
1215 print_lock_name(hlock_class(next
));
1218 printk("\nbut this new dependency connects a %s-irq-safe lock:\n",
1220 print_lock_name(backwards_match
);
1221 printk("\n... which became %s-irq-safe at:\n", irqclass
);
1223 print_stack_trace(backwards_match
->usage_traces
+ bit1
, 1);
1225 printk("\nto a %s-irq-unsafe lock:\n", irqclass
);
1226 print_lock_name(forwards_match
);
1227 printk("\n... which became %s-irq-unsafe at:\n", irqclass
);
1230 print_stack_trace(forwards_match
->usage_traces
+ bit2
, 1);
1232 printk("\nother info that might help us debug this:\n\n");
1233 lockdep_print_held_locks(curr
);
1235 printk("\nthe %s-irq-safe lock's dependencies:\n", irqclass
);
1236 print_lock_dependencies(backwards_match
, 0);
1238 printk("\nthe %s-irq-unsafe lock's dependencies:\n", irqclass
);
1239 print_lock_dependencies(forwards_match
, 0);
1241 printk("\nstack backtrace:\n");
1246 #endif /* CONFIG_PROVE_LOCKING */
1249 check_usage(struct task_struct
*curr
, struct held_lock
*prev
,
1250 struct held_lock
*next
, enum lock_usage_bit bit_backwards
,
1251 enum lock_usage_bit bit_forwards
, const char *irqclass
)
1255 find_usage_bit
= bit_backwards
;
1256 /* fills in <backwards_match> */
1257 ret
= find_usage_backwards(hlock_class(prev
), 0);
1258 if (!ret
|| ret
== 1)
1261 find_usage_bit
= bit_forwards
;
1262 ret
= find_usage_forwards(hlock_class(next
), 0);
1263 if (!ret
|| ret
== 1)
1266 return print_bad_irq_dependency(curr
, prev
, next
,
1267 bit_backwards
, bit_forwards
, irqclass
);
1270 static const char *state_names
[] = {
1271 #define LOCKDEP_STATE(__STATE) \
1272 __stringify(__STATE),
1273 #include "lockdep_states.h"
1274 #undef LOCKDEP_STATE
1277 static const char *state_rnames
[] = {
1278 #define LOCKDEP_STATE(__STATE) \
1279 __stringify(__STATE)"-READ",
1280 #include "lockdep_states.h"
1281 #undef LOCKDEP_STATE
1284 static inline const char *state_name(enum lock_usage_bit bit
)
1286 return (bit
& 1) ? state_rnames
[bit
>> 2] : state_names
[bit
>> 2];
1289 static int exclusive_bit(int new_bit
)
1297 * bit 0 - write/read
1298 * bit 1 - used_in/enabled
1302 int state
= new_bit
& ~3;
1303 int dir
= new_bit
& 2;
1306 * keep state, bit flip the direction and strip read.
1308 return state
| (dir
^ 2);
1311 static int check_irq_usage(struct task_struct
*curr
, struct held_lock
*prev
,
1312 struct held_lock
*next
, enum lock_usage_bit bit
)
1315 * Prove that the new dependency does not connect a hardirq-safe
1316 * lock with a hardirq-unsafe lock - to achieve this we search
1317 * the backwards-subgraph starting at <prev>, and the
1318 * forwards-subgraph starting at <next>:
1320 if (!check_usage(curr
, prev
, next
, bit
,
1321 exclusive_bit(bit
), state_name(bit
)))
1327 * Prove that the new dependency does not connect a hardirq-safe-read
1328 * lock with a hardirq-unsafe lock - to achieve this we search
1329 * the backwards-subgraph starting at <prev>, and the
1330 * forwards-subgraph starting at <next>:
1332 if (!check_usage(curr
, prev
, next
, bit
,
1333 exclusive_bit(bit
), state_name(bit
)))
1340 check_prev_add_irq(struct task_struct
*curr
, struct held_lock
*prev
,
1341 struct held_lock
*next
)
1343 #define LOCKDEP_STATE(__STATE) \
1344 if (!check_irq_usage(curr, prev, next, LOCK_USED_IN_##__STATE)) \
1346 #include "lockdep_states.h"
1347 #undef LOCKDEP_STATE
1352 static void inc_chains(void)
1354 if (current
->hardirq_context
)
1355 nr_hardirq_chains
++;
1357 if (current
->softirq_context
)
1358 nr_softirq_chains
++;
1360 nr_process_chains
++;
1367 check_prev_add_irq(struct task_struct
*curr
, struct held_lock
*prev
,
1368 struct held_lock
*next
)
1373 static inline void inc_chains(void)
1375 nr_process_chains
++;
1381 print_deadlock_bug(struct task_struct
*curr
, struct held_lock
*prev
,
1382 struct held_lock
*next
)
1384 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1387 printk("\n=============================================\n");
1388 printk( "[ INFO: possible recursive locking detected ]\n");
1389 print_kernel_version();
1390 printk( "---------------------------------------------\n");
1391 printk("%s/%d is trying to acquire lock:\n",
1392 curr
->comm
, task_pid_nr(curr
));
1394 printk("\nbut task is already holding lock:\n");
1397 printk("\nother info that might help us debug this:\n");
1398 lockdep_print_held_locks(curr
);
1400 printk("\nstack backtrace:\n");
1407 * Check whether we are holding such a class already.
1409 * (Note that this has to be done separately, because the graph cannot
1410 * detect such classes of deadlocks.)
1412 * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read
1415 check_deadlock(struct task_struct
*curr
, struct held_lock
*next
,
1416 struct lockdep_map
*next_instance
, int read
)
1418 struct held_lock
*prev
;
1419 struct held_lock
*nest
= NULL
;
1422 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
1423 prev
= curr
->held_locks
+ i
;
1425 if (prev
->instance
== next
->nest_lock
)
1428 if (hlock_class(prev
) != hlock_class(next
))
1432 * Allow read-after-read recursion of the same
1433 * lock class (i.e. read_lock(lock)+read_lock(lock)):
1435 if ((read
== 2) && prev
->read
)
1439 * We're holding the nest_lock, which serializes this lock's
1440 * nesting behaviour.
1445 return print_deadlock_bug(curr
, prev
, next
);
1451 * There was a chain-cache miss, and we are about to add a new dependency
1452 * to a previous lock. We recursively validate the following rules:
1454 * - would the adding of the <prev> -> <next> dependency create a
1455 * circular dependency in the graph? [== circular deadlock]
1457 * - does the new prev->next dependency connect any hardirq-safe lock
1458 * (in the full backwards-subgraph starting at <prev>) with any
1459 * hardirq-unsafe lock (in the full forwards-subgraph starting at
1460 * <next>)? [== illegal lock inversion with hardirq contexts]
1462 * - does the new prev->next dependency connect any softirq-safe lock
1463 * (in the full backwards-subgraph starting at <prev>) with any
1464 * softirq-unsafe lock (in the full forwards-subgraph starting at
1465 * <next>)? [== illegal lock inversion with softirq contexts]
1467 * any of these scenarios could lead to a deadlock.
1469 * Then if all the validations pass, we add the forwards and backwards
1473 check_prev_add(struct task_struct
*curr
, struct held_lock
*prev
,
1474 struct held_lock
*next
, int distance
)
1476 struct lock_list
*entry
;
1480 * Prove that the new <prev> -> <next> dependency would not
1481 * create a circular dependency in the graph. (We do this by
1482 * forward-recursing into the graph starting at <next>, and
1483 * checking whether we can reach <prev>.)
1485 * We are using global variables to control the recursion, to
1486 * keep the stackframe size of the recursive functions low:
1488 check_source
= next
;
1489 check_target
= prev
;
1490 if (!(check_noncircular(hlock_class(next
), 0)))
1491 return print_circular_bug_tail();
1493 if (!check_prev_add_irq(curr
, prev
, next
))
1497 * For recursive read-locks we do all the dependency checks,
1498 * but we dont store read-triggered dependencies (only
1499 * write-triggered dependencies). This ensures that only the
1500 * write-side dependencies matter, and that if for example a
1501 * write-lock never takes any other locks, then the reads are
1502 * equivalent to a NOP.
1504 if (next
->read
== 2 || prev
->read
== 2)
1507 * Is the <prev> -> <next> dependency already present?
1509 * (this may occur even though this is a new chain: consider
1510 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3
1511 * chains - the second one will be new, but L1 already has
1512 * L2 added to its dependency list, due to the first chain.)
1514 list_for_each_entry(entry
, &hlock_class(prev
)->locks_after
, entry
) {
1515 if (entry
->class == hlock_class(next
)) {
1517 entry
->distance
= 1;
1523 * Ok, all validations passed, add the new lock
1524 * to the previous lock's dependency list:
1526 ret
= add_lock_to_list(hlock_class(prev
), hlock_class(next
),
1527 &hlock_class(prev
)->locks_after
,
1528 next
->acquire_ip
, distance
);
1533 ret
= add_lock_to_list(hlock_class(next
), hlock_class(prev
),
1534 &hlock_class(next
)->locks_before
,
1535 next
->acquire_ip
, distance
);
1540 * Debugging printouts:
1542 if (verbose(hlock_class(prev
)) || verbose(hlock_class(next
))) {
1544 printk("\n new dependency: ");
1545 print_lock_name(hlock_class(prev
));
1547 print_lock_name(hlock_class(next
));
1550 return graph_lock();
1556 * Add the dependency to all directly-previous locks that are 'relevant'.
1557 * The ones that are relevant are (in increasing distance from curr):
1558 * all consecutive trylock entries and the final non-trylock entry - or
1559 * the end of this context's lock-chain - whichever comes first.
1562 check_prevs_add(struct task_struct
*curr
, struct held_lock
*next
)
1564 int depth
= curr
->lockdep_depth
;
1565 struct held_lock
*hlock
;
1570 * Depth must not be zero for a non-head lock:
1575 * At least two relevant locks must exist for this
1578 if (curr
->held_locks
[depth
].irq_context
!=
1579 curr
->held_locks
[depth
-1].irq_context
)
1583 int distance
= curr
->lockdep_depth
- depth
+ 1;
1584 hlock
= curr
->held_locks
+ depth
-1;
1586 * Only non-recursive-read entries get new dependencies
1589 if (hlock
->read
!= 2) {
1590 if (!check_prev_add(curr
, hlock
, next
, distance
))
1593 * Stop after the first non-trylock entry,
1594 * as non-trylock entries have added their
1595 * own direct dependencies already, so this
1596 * lock is connected to them indirectly:
1598 if (!hlock
->trylock
)
1603 * End of lock-stack?
1608 * Stop the search if we cross into another context:
1610 if (curr
->held_locks
[depth
].irq_context
!=
1611 curr
->held_locks
[depth
-1].irq_context
)
1616 if (!debug_locks_off_graph_unlock())
1624 unsigned long nr_lock_chains
;
1625 struct lock_chain lock_chains
[MAX_LOCKDEP_CHAINS
];
1626 int nr_chain_hlocks
;
1627 static u16 chain_hlocks
[MAX_LOCKDEP_CHAIN_HLOCKS
];
1629 struct lock_class
*lock_chain_get_class(struct lock_chain
*chain
, int i
)
1631 return lock_classes
+ chain_hlocks
[chain
->base
+ i
];
1635 * Look up a dependency chain. If the key is not present yet then
1636 * add it and return 1 - in this case the new dependency chain is
1637 * validated. If the key is already hashed, return 0.
1638 * (On return with 1 graph_lock is held.)
1640 static inline int lookup_chain_cache(struct task_struct
*curr
,
1641 struct held_lock
*hlock
,
1644 struct lock_class
*class = hlock_class(hlock
);
1645 struct list_head
*hash_head
= chainhashentry(chain_key
);
1646 struct lock_chain
*chain
;
1647 struct held_lock
*hlock_curr
, *hlock_next
;
1650 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
1653 * We can walk it lock-free, because entries only get added
1656 list_for_each_entry(chain
, hash_head
, entry
) {
1657 if (chain
->chain_key
== chain_key
) {
1659 debug_atomic_inc(&chain_lookup_hits
);
1660 if (very_verbose(class))
1661 printk("\nhash chain already cached, key: "
1662 "%016Lx tail class: [%p] %s\n",
1663 (unsigned long long)chain_key
,
1664 class->key
, class->name
);
1668 if (very_verbose(class))
1669 printk("\nnew hash chain, key: %016Lx tail class: [%p] %s\n",
1670 (unsigned long long)chain_key
, class->key
, class->name
);
1672 * Allocate a new chain entry from the static array, and add
1678 * We have to walk the chain again locked - to avoid duplicates:
1680 list_for_each_entry(chain
, hash_head
, entry
) {
1681 if (chain
->chain_key
== chain_key
) {
1686 if (unlikely(nr_lock_chains
>= MAX_LOCKDEP_CHAINS
)) {
1687 if (!debug_locks_off_graph_unlock())
1690 printk("BUG: MAX_LOCKDEP_CHAINS too low!\n");
1691 printk("turning off the locking correctness validator.\n");
1695 chain
= lock_chains
+ nr_lock_chains
++;
1696 chain
->chain_key
= chain_key
;
1697 chain
->irq_context
= hlock
->irq_context
;
1698 /* Find the first held_lock of current chain */
1700 for (i
= curr
->lockdep_depth
- 1; i
>= 0; i
--) {
1701 hlock_curr
= curr
->held_locks
+ i
;
1702 if (hlock_curr
->irq_context
!= hlock_next
->irq_context
)
1707 chain
->depth
= curr
->lockdep_depth
+ 1 - i
;
1708 cn
= nr_chain_hlocks
;
1709 while (cn
+ chain
->depth
<= MAX_LOCKDEP_CHAIN_HLOCKS
) {
1710 n
= cmpxchg(&nr_chain_hlocks
, cn
, cn
+ chain
->depth
);
1715 if (likely(cn
+ chain
->depth
<= MAX_LOCKDEP_CHAIN_HLOCKS
)) {
1717 for (j
= 0; j
< chain
->depth
- 1; j
++, i
++) {
1718 int lock_id
= curr
->held_locks
[i
].class_idx
- 1;
1719 chain_hlocks
[chain
->base
+ j
] = lock_id
;
1721 chain_hlocks
[chain
->base
+ j
] = class - lock_classes
;
1723 list_add_tail_rcu(&chain
->entry
, hash_head
);
1724 debug_atomic_inc(&chain_lookup_misses
);
1730 static int validate_chain(struct task_struct
*curr
, struct lockdep_map
*lock
,
1731 struct held_lock
*hlock
, int chain_head
, u64 chain_key
)
1734 * Trylock needs to maintain the stack of held locks, but it
1735 * does not add new dependencies, because trylock can be done
1738 * We look up the chain_key and do the O(N^2) check and update of
1739 * the dependencies only if this is a new dependency chain.
1740 * (If lookup_chain_cache() returns with 1 it acquires
1741 * graph_lock for us)
1743 if (!hlock
->trylock
&& (hlock
->check
== 2) &&
1744 lookup_chain_cache(curr
, hlock
, chain_key
)) {
1746 * Check whether last held lock:
1748 * - is irq-safe, if this lock is irq-unsafe
1749 * - is softirq-safe, if this lock is hardirq-unsafe
1751 * And check whether the new lock's dependency graph
1752 * could lead back to the previous lock.
1754 * any of these scenarios could lead to a deadlock. If
1757 int ret
= check_deadlock(curr
, hlock
, lock
, hlock
->read
);
1762 * Mark recursive read, as we jump over it when
1763 * building dependencies (just like we jump over
1769 * Add dependency only if this lock is not the head
1770 * of the chain, and if it's not a secondary read-lock:
1772 if (!chain_head
&& ret
!= 2)
1773 if (!check_prevs_add(curr
, hlock
))
1777 /* after lookup_chain_cache(): */
1778 if (unlikely(!debug_locks
))
1784 static inline int validate_chain(struct task_struct
*curr
,
1785 struct lockdep_map
*lock
, struct held_lock
*hlock
,
1786 int chain_head
, u64 chain_key
)
1793 * We are building curr_chain_key incrementally, so double-check
1794 * it from scratch, to make sure that it's done correctly:
1796 static void check_chain_key(struct task_struct
*curr
)
1798 #ifdef CONFIG_DEBUG_LOCKDEP
1799 struct held_lock
*hlock
, *prev_hlock
= NULL
;
1803 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
1804 hlock
= curr
->held_locks
+ i
;
1805 if (chain_key
!= hlock
->prev_chain_key
) {
1807 WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n",
1808 curr
->lockdep_depth
, i
,
1809 (unsigned long long)chain_key
,
1810 (unsigned long long)hlock
->prev_chain_key
);
1813 id
= hlock
->class_idx
- 1;
1814 if (DEBUG_LOCKS_WARN_ON(id
>= MAX_LOCKDEP_KEYS
))
1817 if (prev_hlock
&& (prev_hlock
->irq_context
!=
1818 hlock
->irq_context
))
1820 chain_key
= iterate_chain_key(chain_key
, id
);
1823 if (chain_key
!= curr
->curr_chain_key
) {
1825 WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n",
1826 curr
->lockdep_depth
, i
,
1827 (unsigned long long)chain_key
,
1828 (unsigned long long)curr
->curr_chain_key
);
1834 print_usage_bug(struct task_struct
*curr
, struct held_lock
*this,
1835 enum lock_usage_bit prev_bit
, enum lock_usage_bit new_bit
)
1837 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1840 printk("\n=================================\n");
1841 printk( "[ INFO: inconsistent lock state ]\n");
1842 print_kernel_version();
1843 printk( "---------------------------------\n");
1845 printk("inconsistent {%s} -> {%s} usage.\n",
1846 usage_str
[prev_bit
], usage_str
[new_bit
]);
1848 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] takes:\n",
1849 curr
->comm
, task_pid_nr(curr
),
1850 trace_hardirq_context(curr
), hardirq_count() >> HARDIRQ_SHIFT
,
1851 trace_softirq_context(curr
), softirq_count() >> SOFTIRQ_SHIFT
,
1852 trace_hardirqs_enabled(curr
),
1853 trace_softirqs_enabled(curr
));
1856 printk("{%s} state was registered at:\n", usage_str
[prev_bit
]);
1857 print_stack_trace(hlock_class(this)->usage_traces
+ prev_bit
, 1);
1859 print_irqtrace_events(curr
);
1860 printk("\nother info that might help us debug this:\n");
1861 lockdep_print_held_locks(curr
);
1863 printk("\nstack backtrace:\n");
1870 * Print out an error if an invalid bit is set:
1873 valid_state(struct task_struct
*curr
, struct held_lock
*this,
1874 enum lock_usage_bit new_bit
, enum lock_usage_bit bad_bit
)
1876 if (unlikely(hlock_class(this)->usage_mask
& (1 << bad_bit
)))
1877 return print_usage_bug(curr
, this, bad_bit
, new_bit
);
1881 static int mark_lock(struct task_struct
*curr
, struct held_lock
*this,
1882 enum lock_usage_bit new_bit
);
1884 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
1887 * print irq inversion bug:
1890 print_irq_inversion_bug(struct task_struct
*curr
, struct lock_class
*other
,
1891 struct held_lock
*this, int forwards
,
1892 const char *irqclass
)
1894 if (!debug_locks_off_graph_unlock() || debug_locks_silent
)
1897 printk("\n=========================================================\n");
1898 printk( "[ INFO: possible irq lock inversion dependency detected ]\n");
1899 print_kernel_version();
1900 printk( "---------------------------------------------------------\n");
1901 printk("%s/%d just changed the state of lock:\n",
1902 curr
->comm
, task_pid_nr(curr
));
1905 printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass
);
1907 printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass
);
1908 print_lock_name(other
);
1909 printk("\n\nand interrupts could create inverse lock ordering between them.\n\n");
1911 printk("\nother info that might help us debug this:\n");
1912 lockdep_print_held_locks(curr
);
1914 printk("\nthe first lock's dependencies:\n");
1915 print_lock_dependencies(hlock_class(this), 0);
1917 printk("\nthe second lock's dependencies:\n");
1918 print_lock_dependencies(other
, 0);
1920 printk("\nstack backtrace:\n");
1927 * Prove that in the forwards-direction subgraph starting at <this>
1928 * there is no lock matching <mask>:
1931 check_usage_forwards(struct task_struct
*curr
, struct held_lock
*this,
1932 enum lock_usage_bit bit
, const char *irqclass
)
1936 find_usage_bit
= bit
;
1937 /* fills in <forwards_match> */
1938 ret
= find_usage_forwards(hlock_class(this), 0);
1939 if (!ret
|| ret
== 1)
1942 return print_irq_inversion_bug(curr
, forwards_match
, this, 1, irqclass
);
1946 * Prove that in the backwards-direction subgraph starting at <this>
1947 * there is no lock matching <mask>:
1950 check_usage_backwards(struct task_struct
*curr
, struct held_lock
*this,
1951 enum lock_usage_bit bit
, const char *irqclass
)
1955 find_usage_bit
= bit
;
1956 /* fills in <backwards_match> */
1957 ret
= find_usage_backwards(hlock_class(this), 0);
1958 if (!ret
|| ret
== 1)
1961 return print_irq_inversion_bug(curr
, backwards_match
, this, 0, irqclass
);
1964 void print_irqtrace_events(struct task_struct
*curr
)
1966 printk("irq event stamp: %u\n", curr
->irq_events
);
1967 printk("hardirqs last enabled at (%u): ", curr
->hardirq_enable_event
);
1968 print_ip_sym(curr
->hardirq_enable_ip
);
1969 printk("hardirqs last disabled at (%u): ", curr
->hardirq_disable_event
);
1970 print_ip_sym(curr
->hardirq_disable_ip
);
1971 printk("softirqs last enabled at (%u): ", curr
->softirq_enable_event
);
1972 print_ip_sym(curr
->softirq_enable_ip
);
1973 printk("softirqs last disabled at (%u): ", curr
->softirq_disable_event
);
1974 print_ip_sym(curr
->softirq_disable_ip
);
1977 static int HARDIRQ_verbose(struct lock_class
*class)
1980 return class_filter(class);
1985 static int SOFTIRQ_verbose(struct lock_class
*class)
1988 return class_filter(class);
1993 static int RECLAIM_FS_verbose(struct lock_class
*class)
1996 return class_filter(class);
2001 #define STRICT_READ_CHECKS 1
2003 static int (*state_verbose_f
[])(struct lock_class
*class) = {
2004 #define LOCKDEP_STATE(__STATE) \
2006 #include "lockdep_states.h"
2007 #undef LOCKDEP_STATE
2010 static inline int state_verbose(enum lock_usage_bit bit
,
2011 struct lock_class
*class)
2013 return state_verbose_f
[bit
>> 2](class);
2016 typedef int (*check_usage_f
)(struct task_struct
*, struct held_lock
*,
2017 enum lock_usage_bit bit
, const char *name
);
2020 mark_lock_irq(struct task_struct
*curr
, struct held_lock
*this,
2021 enum lock_usage_bit new_bit
)
2023 int excl_bit
= exclusive_bit(new_bit
);
2024 int read
= new_bit
& 1;
2025 int dir
= new_bit
& 2;
2028 * mark USED_IN has to look forwards -- to ensure no dependency
2029 * has ENABLED state, which would allow recursion deadlocks.
2031 * mark ENABLED has to look backwards -- to ensure no dependee
2032 * has USED_IN state, which, again, would allow recursion deadlocks.
2034 check_usage_f usage
= dir
?
2035 check_usage_backwards
: check_usage_forwards
;
2038 * Validate that this particular lock does not have conflicting
2041 if (!valid_state(curr
, this, new_bit
, excl_bit
))
2045 * Validate that the lock dependencies don't have conflicting usage
2048 if ((!read
|| !dir
|| STRICT_READ_CHECKS
) &&
2049 !usage(curr
, this, excl_bit
, state_name(new_bit
& ~1)))
2053 * Check for read in write conflicts
2056 if (!valid_state(curr
, this, new_bit
, excl_bit
+ 1))
2059 if (STRICT_READ_CHECKS
&&
2060 !usage(curr
, this, excl_bit
+ 1,
2061 state_name(new_bit
+ 1)))
2065 if (state_verbose(new_bit
, hlock_class(this)))
2072 #define LOCKDEP_STATE(__STATE) __STATE,
2073 #include "lockdep_states.h"
2074 #undef LOCKDEP_STATE
2078 * Mark all held locks with a usage bit:
2081 mark_held_locks(struct task_struct
*curr
, enum mark_type mark
)
2083 enum lock_usage_bit usage_bit
;
2084 struct held_lock
*hlock
;
2087 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
2088 hlock
= curr
->held_locks
+ i
;
2090 usage_bit
= 2 + (mark
<< 2); /* ENABLED */
2092 usage_bit
+= 1; /* READ */
2094 BUG_ON(usage_bit
>= LOCK_USAGE_STATES
);
2096 if (!mark_lock(curr
, hlock
, usage_bit
))
2104 * Debugging helper: via this flag we know that we are in
2105 * 'early bootup code', and will warn about any invalid irqs-on event:
2107 static int early_boot_irqs_enabled
;
2109 void early_boot_irqs_off(void)
2111 early_boot_irqs_enabled
= 0;
2114 void early_boot_irqs_on(void)
2116 early_boot_irqs_enabled
= 1;
2120 * Hardirqs will be enabled:
2122 void trace_hardirqs_on_caller(unsigned long ip
)
2124 struct task_struct
*curr
= current
;
2126 time_hardirqs_on(CALLER_ADDR0
, ip
);
2128 if (unlikely(!debug_locks
|| current
->lockdep_recursion
))
2131 if (DEBUG_LOCKS_WARN_ON(unlikely(!early_boot_irqs_enabled
)))
2134 if (unlikely(curr
->hardirqs_enabled
)) {
2135 debug_atomic_inc(&redundant_hardirqs_on
);
2138 /* we'll do an OFF -> ON transition: */
2139 curr
->hardirqs_enabled
= 1;
2141 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2143 if (DEBUG_LOCKS_WARN_ON(current
->hardirq_context
))
2146 * We are going to turn hardirqs on, so set the
2147 * usage bit for all held locks:
2149 if (!mark_held_locks(curr
, HARDIRQ
))
2152 * If we have softirqs enabled, then set the usage
2153 * bit for all held locks. (disabled hardirqs prevented
2154 * this bit from being set before)
2156 if (curr
->softirqs_enabled
)
2157 if (!mark_held_locks(curr
, SOFTIRQ
))
2160 curr
->hardirq_enable_ip
= ip
;
2161 curr
->hardirq_enable_event
= ++curr
->irq_events
;
2162 debug_atomic_inc(&hardirqs_on_events
);
2164 EXPORT_SYMBOL(trace_hardirqs_on_caller
);
2166 void trace_hardirqs_on(void)
2168 trace_hardirqs_on_caller(CALLER_ADDR0
);
2170 EXPORT_SYMBOL(trace_hardirqs_on
);
2173 * Hardirqs were disabled:
2175 void trace_hardirqs_off_caller(unsigned long ip
)
2177 struct task_struct
*curr
= current
;
2179 time_hardirqs_off(CALLER_ADDR0
, ip
);
2181 if (unlikely(!debug_locks
|| current
->lockdep_recursion
))
2184 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2187 if (curr
->hardirqs_enabled
) {
2189 * We have done an ON -> OFF transition:
2191 curr
->hardirqs_enabled
= 0;
2192 curr
->hardirq_disable_ip
= ip
;
2193 curr
->hardirq_disable_event
= ++curr
->irq_events
;
2194 debug_atomic_inc(&hardirqs_off_events
);
2196 debug_atomic_inc(&redundant_hardirqs_off
);
2198 EXPORT_SYMBOL(trace_hardirqs_off_caller
);
2200 void trace_hardirqs_off(void)
2202 trace_hardirqs_off_caller(CALLER_ADDR0
);
2204 EXPORT_SYMBOL(trace_hardirqs_off
);
2207 * Softirqs will be enabled:
2209 void trace_softirqs_on(unsigned long ip
)
2211 struct task_struct
*curr
= current
;
2213 if (unlikely(!debug_locks
))
2216 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2219 if (curr
->softirqs_enabled
) {
2220 debug_atomic_inc(&redundant_softirqs_on
);
2225 * We'll do an OFF -> ON transition:
2227 curr
->softirqs_enabled
= 1;
2228 curr
->softirq_enable_ip
= ip
;
2229 curr
->softirq_enable_event
= ++curr
->irq_events
;
2230 debug_atomic_inc(&softirqs_on_events
);
2232 * We are going to turn softirqs on, so set the
2233 * usage bit for all held locks, if hardirqs are
2236 if (curr
->hardirqs_enabled
)
2237 mark_held_locks(curr
, SOFTIRQ
);
2241 * Softirqs were disabled:
2243 void trace_softirqs_off(unsigned long ip
)
2245 struct task_struct
*curr
= current
;
2247 if (unlikely(!debug_locks
))
2250 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2253 if (curr
->softirqs_enabled
) {
2255 * We have done an ON -> OFF transition:
2257 curr
->softirqs_enabled
= 0;
2258 curr
->softirq_disable_ip
= ip
;
2259 curr
->softirq_disable_event
= ++curr
->irq_events
;
2260 debug_atomic_inc(&softirqs_off_events
);
2261 DEBUG_LOCKS_WARN_ON(!softirq_count());
2263 debug_atomic_inc(&redundant_softirqs_off
);
2266 static void __lockdep_trace_alloc(gfp_t gfp_mask
, unsigned long flags
)
2268 struct task_struct
*curr
= current
;
2270 if (unlikely(!debug_locks
))
2273 /* no reclaim without waiting on it */
2274 if (!(gfp_mask
& __GFP_WAIT
))
2277 /* this guy won't enter reclaim */
2278 if ((curr
->flags
& PF_MEMALLOC
) && !(gfp_mask
& __GFP_NOMEMALLOC
))
2281 /* We're only interested __GFP_FS allocations for now */
2282 if (!(gfp_mask
& __GFP_FS
))
2285 if (DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags
)))
2288 mark_held_locks(curr
, RECLAIM_FS
);
2291 static void check_flags(unsigned long flags
);
2293 void lockdep_trace_alloc(gfp_t gfp_mask
)
2295 unsigned long flags
;
2297 if (unlikely(current
->lockdep_recursion
))
2300 raw_local_irq_save(flags
);
2302 current
->lockdep_recursion
= 1;
2303 __lockdep_trace_alloc(gfp_mask
, flags
);
2304 current
->lockdep_recursion
= 0;
2305 raw_local_irq_restore(flags
);
2308 static int mark_irqflags(struct task_struct
*curr
, struct held_lock
*hlock
)
2311 * If non-trylock use in a hardirq or softirq context, then
2312 * mark the lock as used in these contexts:
2314 if (!hlock
->trylock
) {
2316 if (curr
->hardirq_context
)
2317 if (!mark_lock(curr
, hlock
,
2318 LOCK_USED_IN_HARDIRQ_READ
))
2320 if (curr
->softirq_context
)
2321 if (!mark_lock(curr
, hlock
,
2322 LOCK_USED_IN_SOFTIRQ_READ
))
2325 if (curr
->hardirq_context
)
2326 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_HARDIRQ
))
2328 if (curr
->softirq_context
)
2329 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_SOFTIRQ
))
2333 if (!hlock
->hardirqs_off
) {
2335 if (!mark_lock(curr
, hlock
,
2336 LOCK_ENABLED_HARDIRQ_READ
))
2338 if (curr
->softirqs_enabled
)
2339 if (!mark_lock(curr
, hlock
,
2340 LOCK_ENABLED_SOFTIRQ_READ
))
2343 if (!mark_lock(curr
, hlock
,
2344 LOCK_ENABLED_HARDIRQ
))
2346 if (curr
->softirqs_enabled
)
2347 if (!mark_lock(curr
, hlock
,
2348 LOCK_ENABLED_SOFTIRQ
))
2354 * We reuse the irq context infrastructure more broadly as a general
2355 * context checking code. This tests GFP_FS recursion (a lock taken
2356 * during reclaim for a GFP_FS allocation is held over a GFP_FS
2359 if (!hlock
->trylock
&& (curr
->lockdep_reclaim_gfp
& __GFP_FS
)) {
2361 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_RECLAIM_FS_READ
))
2364 if (!mark_lock(curr
, hlock
, LOCK_USED_IN_RECLAIM_FS
))
2372 static int separate_irq_context(struct task_struct
*curr
,
2373 struct held_lock
*hlock
)
2375 unsigned int depth
= curr
->lockdep_depth
;
2378 * Keep track of points where we cross into an interrupt context:
2380 hlock
->irq_context
= 2*(curr
->hardirq_context
? 1 : 0) +
2381 curr
->softirq_context
;
2383 struct held_lock
*prev_hlock
;
2385 prev_hlock
= curr
->held_locks
+ depth
-1;
2387 * If we cross into another context, reset the
2388 * hash key (this also prevents the checking and the
2389 * adding of the dependency to 'prev'):
2391 if (prev_hlock
->irq_context
!= hlock
->irq_context
)
2400 int mark_lock_irq(struct task_struct
*curr
, struct held_lock
*this,
2401 enum lock_usage_bit new_bit
)
2407 static inline int mark_irqflags(struct task_struct
*curr
,
2408 struct held_lock
*hlock
)
2413 static inline int separate_irq_context(struct task_struct
*curr
,
2414 struct held_lock
*hlock
)
2419 void lockdep_trace_alloc(gfp_t gfp_mask
)
2426 * Mark a lock with a usage bit, and validate the state transition:
2428 static int mark_lock(struct task_struct
*curr
, struct held_lock
*this,
2429 enum lock_usage_bit new_bit
)
2431 unsigned int new_mask
= 1 << new_bit
, ret
= 1;
2434 * If already set then do not dirty the cacheline,
2435 * nor do any checks:
2437 if (likely(hlock_class(this)->usage_mask
& new_mask
))
2443 * Make sure we didnt race:
2445 if (unlikely(hlock_class(this)->usage_mask
& new_mask
)) {
2450 hlock_class(this)->usage_mask
|= new_mask
;
2452 if (!save_trace(hlock_class(this)->usage_traces
+ new_bit
))
2456 #define LOCKDEP_STATE(__STATE) \
2457 case LOCK_USED_IN_##__STATE: \
2458 case LOCK_USED_IN_##__STATE##_READ: \
2459 case LOCK_ENABLED_##__STATE: \
2460 case LOCK_ENABLED_##__STATE##_READ:
2461 #include "lockdep_states.h"
2462 #undef LOCKDEP_STATE
2463 ret
= mark_lock_irq(curr
, this, new_bit
);
2468 debug_atomic_dec(&nr_unused_locks
);
2471 if (!debug_locks_off_graph_unlock())
2480 * We must printk outside of the graph_lock:
2483 printk("\nmarked lock as {%s}:\n", usage_str
[new_bit
]);
2485 print_irqtrace_events(curr
);
2493 * Initialize a lock instance's lock-class mapping info:
2495 void lockdep_init_map(struct lockdep_map
*lock
, const char *name
,
2496 struct lock_class_key
*key
, int subclass
)
2498 if (unlikely(!debug_locks
))
2501 if (DEBUG_LOCKS_WARN_ON(!key
))
2503 if (DEBUG_LOCKS_WARN_ON(!name
))
2506 * Sanity check, the lock-class key must be persistent:
2508 if (!static_obj(key
)) {
2509 printk("BUG: key %p not in .data!\n", key
);
2510 DEBUG_LOCKS_WARN_ON(1);
2515 lock
->class_cache
= NULL
;
2516 #ifdef CONFIG_LOCK_STAT
2517 lock
->cpu
= raw_smp_processor_id();
2520 register_lock_class(lock
, subclass
, 1);
2522 EXPORT_SYMBOL_GPL(lockdep_init_map
);
2525 * This gets called for every mutex_lock*()/spin_lock*() operation.
2526 * We maintain the dependency maps and validate the locking attempt:
2528 static int __lock_acquire(struct lockdep_map
*lock
, unsigned int subclass
,
2529 int trylock
, int read
, int check
, int hardirqs_off
,
2530 struct lockdep_map
*nest_lock
, unsigned long ip
)
2532 struct task_struct
*curr
= current
;
2533 struct lock_class
*class = NULL
;
2534 struct held_lock
*hlock
;
2535 unsigned int depth
, id
;
2542 if (unlikely(!debug_locks
))
2545 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2548 if (unlikely(subclass
>= MAX_LOCKDEP_SUBCLASSES
)) {
2550 printk("BUG: MAX_LOCKDEP_SUBCLASSES too low!\n");
2551 printk("turning off the locking correctness validator.\n");
2557 class = lock
->class_cache
;
2559 * Not cached yet or subclass?
2561 if (unlikely(!class)) {
2562 class = register_lock_class(lock
, subclass
, 0);
2566 debug_atomic_inc((atomic_t
*)&class->ops
);
2567 if (very_verbose(class)) {
2568 printk("\nacquire class [%p] %s", class->key
, class->name
);
2569 if (class->name_version
> 1)
2570 printk("#%d", class->name_version
);
2576 * Add the lock to the list of currently held locks.
2577 * (we dont increase the depth just yet, up until the
2578 * dependency checks are done)
2580 depth
= curr
->lockdep_depth
;
2581 if (DEBUG_LOCKS_WARN_ON(depth
>= MAX_LOCK_DEPTH
))
2584 hlock
= curr
->held_locks
+ depth
;
2585 if (DEBUG_LOCKS_WARN_ON(!class))
2587 hlock
->class_idx
= class - lock_classes
+ 1;
2588 hlock
->acquire_ip
= ip
;
2589 hlock
->instance
= lock
;
2590 hlock
->nest_lock
= nest_lock
;
2591 hlock
->trylock
= trylock
;
2593 hlock
->check
= check
;
2594 hlock
->hardirqs_off
= !!hardirqs_off
;
2595 #ifdef CONFIG_LOCK_STAT
2596 hlock
->waittime_stamp
= 0;
2597 hlock
->holdtime_stamp
= sched_clock();
2600 if (check
== 2 && !mark_irqflags(curr
, hlock
))
2603 /* mark it as used: */
2604 if (!mark_lock(curr
, hlock
, LOCK_USED
))
2608 * Calculate the chain hash: it's the combined hash of all the
2609 * lock keys along the dependency chain. We save the hash value
2610 * at every step so that we can get the current hash easily
2611 * after unlock. The chain hash is then used to cache dependency
2614 * The 'key ID' is what is the most compact key value to drive
2615 * the hash, not class->key.
2617 id
= class - lock_classes
;
2618 if (DEBUG_LOCKS_WARN_ON(id
>= MAX_LOCKDEP_KEYS
))
2621 chain_key
= curr
->curr_chain_key
;
2623 if (DEBUG_LOCKS_WARN_ON(chain_key
!= 0))
2628 hlock
->prev_chain_key
= chain_key
;
2629 if (separate_irq_context(curr
, hlock
)) {
2633 chain_key
= iterate_chain_key(chain_key
, id
);
2635 if (!validate_chain(curr
, lock
, hlock
, chain_head
, chain_key
))
2638 curr
->curr_chain_key
= chain_key
;
2639 curr
->lockdep_depth
++;
2640 check_chain_key(curr
);
2641 #ifdef CONFIG_DEBUG_LOCKDEP
2642 if (unlikely(!debug_locks
))
2645 if (unlikely(curr
->lockdep_depth
>= MAX_LOCK_DEPTH
)) {
2647 printk("BUG: MAX_LOCK_DEPTH too low!\n");
2648 printk("turning off the locking correctness validator.\n");
2653 if (unlikely(curr
->lockdep_depth
> max_lockdep_depth
))
2654 max_lockdep_depth
= curr
->lockdep_depth
;
2660 print_unlock_inbalance_bug(struct task_struct
*curr
, struct lockdep_map
*lock
,
2663 if (!debug_locks_off())
2665 if (debug_locks_silent
)
2668 printk("\n=====================================\n");
2669 printk( "[ BUG: bad unlock balance detected! ]\n");
2670 printk( "-------------------------------------\n");
2671 printk("%s/%d is trying to release lock (",
2672 curr
->comm
, task_pid_nr(curr
));
2673 print_lockdep_cache(lock
);
2676 printk("but there are no more locks to release!\n");
2677 printk("\nother info that might help us debug this:\n");
2678 lockdep_print_held_locks(curr
);
2680 printk("\nstack backtrace:\n");
2687 * Common debugging checks for both nested and non-nested unlock:
2689 static int check_unlock(struct task_struct
*curr
, struct lockdep_map
*lock
,
2692 if (unlikely(!debug_locks
))
2694 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2697 if (curr
->lockdep_depth
<= 0)
2698 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2704 __lock_set_class(struct lockdep_map
*lock
, const char *name
,
2705 struct lock_class_key
*key
, unsigned int subclass
,
2708 struct task_struct
*curr
= current
;
2709 struct held_lock
*hlock
, *prev_hlock
;
2710 struct lock_class
*class;
2714 depth
= curr
->lockdep_depth
;
2715 if (DEBUG_LOCKS_WARN_ON(!depth
))
2719 for (i
= depth
-1; i
>= 0; i
--) {
2720 hlock
= curr
->held_locks
+ i
;
2722 * We must not cross into another context:
2724 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
2726 if (hlock
->instance
== lock
)
2730 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2733 lockdep_init_map(lock
, name
, key
, 0);
2734 class = register_lock_class(lock
, subclass
, 0);
2735 hlock
->class_idx
= class - lock_classes
+ 1;
2737 curr
->lockdep_depth
= i
;
2738 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2740 for (; i
< depth
; i
++) {
2741 hlock
= curr
->held_locks
+ i
;
2742 if (!__lock_acquire(hlock
->instance
,
2743 hlock_class(hlock
)->subclass
, hlock
->trylock
,
2744 hlock
->read
, hlock
->check
, hlock
->hardirqs_off
,
2745 hlock
->nest_lock
, hlock
->acquire_ip
))
2749 if (DEBUG_LOCKS_WARN_ON(curr
->lockdep_depth
!= depth
))
2755 * Remove the lock to the list of currently held locks in a
2756 * potentially non-nested (out of order) manner. This is a
2757 * relatively rare operation, as all the unlock APIs default
2758 * to nested mode (which uses lock_release()):
2761 lock_release_non_nested(struct task_struct
*curr
,
2762 struct lockdep_map
*lock
, unsigned long ip
)
2764 struct held_lock
*hlock
, *prev_hlock
;
2769 * Check whether the lock exists in the current stack
2772 depth
= curr
->lockdep_depth
;
2773 if (DEBUG_LOCKS_WARN_ON(!depth
))
2777 for (i
= depth
-1; i
>= 0; i
--) {
2778 hlock
= curr
->held_locks
+ i
;
2780 * We must not cross into another context:
2782 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
2784 if (hlock
->instance
== lock
)
2788 return print_unlock_inbalance_bug(curr
, lock
, ip
);
2791 lock_release_holdtime(hlock
);
2794 * We have the right lock to unlock, 'hlock' points to it.
2795 * Now we remove it from the stack, and add back the other
2796 * entries (if any), recalculating the hash along the way:
2798 curr
->lockdep_depth
= i
;
2799 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2801 for (i
++; i
< depth
; i
++) {
2802 hlock
= curr
->held_locks
+ i
;
2803 if (!__lock_acquire(hlock
->instance
,
2804 hlock_class(hlock
)->subclass
, hlock
->trylock
,
2805 hlock
->read
, hlock
->check
, hlock
->hardirqs_off
,
2806 hlock
->nest_lock
, hlock
->acquire_ip
))
2810 if (DEBUG_LOCKS_WARN_ON(curr
->lockdep_depth
!= depth
- 1))
2816 * Remove the lock to the list of currently held locks - this gets
2817 * called on mutex_unlock()/spin_unlock*() (or on a failed
2818 * mutex_lock_interruptible()). This is done for unlocks that nest
2819 * perfectly. (i.e. the current top of the lock-stack is unlocked)
2821 static int lock_release_nested(struct task_struct
*curr
,
2822 struct lockdep_map
*lock
, unsigned long ip
)
2824 struct held_lock
*hlock
;
2828 * Pop off the top of the lock stack:
2830 depth
= curr
->lockdep_depth
- 1;
2831 hlock
= curr
->held_locks
+ depth
;
2834 * Is the unlock non-nested:
2836 if (hlock
->instance
!= lock
)
2837 return lock_release_non_nested(curr
, lock
, ip
);
2838 curr
->lockdep_depth
--;
2840 if (DEBUG_LOCKS_WARN_ON(!depth
&& (hlock
->prev_chain_key
!= 0)))
2843 curr
->curr_chain_key
= hlock
->prev_chain_key
;
2845 lock_release_holdtime(hlock
);
2847 #ifdef CONFIG_DEBUG_LOCKDEP
2848 hlock
->prev_chain_key
= 0;
2849 hlock
->class_idx
= 0;
2850 hlock
->acquire_ip
= 0;
2851 hlock
->irq_context
= 0;
2857 * Remove the lock to the list of currently held locks - this gets
2858 * called on mutex_unlock()/spin_unlock*() (or on a failed
2859 * mutex_lock_interruptible()). This is done for unlocks that nest
2860 * perfectly. (i.e. the current top of the lock-stack is unlocked)
2863 __lock_release(struct lockdep_map
*lock
, int nested
, unsigned long ip
)
2865 struct task_struct
*curr
= current
;
2867 if (!check_unlock(curr
, lock
, ip
))
2871 if (!lock_release_nested(curr
, lock
, ip
))
2874 if (!lock_release_non_nested(curr
, lock
, ip
))
2878 check_chain_key(curr
);
2882 * Check whether we follow the irq-flags state precisely:
2884 static void check_flags(unsigned long flags
)
2886 #if defined(CONFIG_PROVE_LOCKING) && defined(CONFIG_DEBUG_LOCKDEP) && \
2887 defined(CONFIG_TRACE_IRQFLAGS)
2891 if (irqs_disabled_flags(flags
)) {
2892 if (DEBUG_LOCKS_WARN_ON(current
->hardirqs_enabled
)) {
2893 printk("possible reason: unannotated irqs-off.\n");
2896 if (DEBUG_LOCKS_WARN_ON(!current
->hardirqs_enabled
)) {
2897 printk("possible reason: unannotated irqs-on.\n");
2902 * We dont accurately track softirq state in e.g.
2903 * hardirq contexts (such as on 4KSTACKS), so only
2904 * check if not in hardirq contexts:
2906 if (!hardirq_count()) {
2907 if (softirq_count())
2908 DEBUG_LOCKS_WARN_ON(current
->softirqs_enabled
);
2910 DEBUG_LOCKS_WARN_ON(!current
->softirqs_enabled
);
2914 print_irqtrace_events(current
);
2918 void lock_set_class(struct lockdep_map
*lock
, const char *name
,
2919 struct lock_class_key
*key
, unsigned int subclass
,
2922 unsigned long flags
;
2924 if (unlikely(current
->lockdep_recursion
))
2927 raw_local_irq_save(flags
);
2928 current
->lockdep_recursion
= 1;
2930 if (__lock_set_class(lock
, name
, key
, subclass
, ip
))
2931 check_chain_key(current
);
2932 current
->lockdep_recursion
= 0;
2933 raw_local_irq_restore(flags
);
2935 EXPORT_SYMBOL_GPL(lock_set_class
);
2937 DEFINE_TRACE(lock_acquire
);
2940 * We are not always called with irqs disabled - do that here,
2941 * and also avoid lockdep recursion:
2943 void lock_acquire(struct lockdep_map
*lock
, unsigned int subclass
,
2944 int trylock
, int read
, int check
,
2945 struct lockdep_map
*nest_lock
, unsigned long ip
)
2947 unsigned long flags
;
2949 trace_lock_acquire(lock
, subclass
, trylock
, read
, check
, nest_lock
, ip
);
2951 if (unlikely(current
->lockdep_recursion
))
2954 raw_local_irq_save(flags
);
2957 current
->lockdep_recursion
= 1;
2958 __lock_acquire(lock
, subclass
, trylock
, read
, check
,
2959 irqs_disabled_flags(flags
), nest_lock
, ip
);
2960 current
->lockdep_recursion
= 0;
2961 raw_local_irq_restore(flags
);
2963 EXPORT_SYMBOL_GPL(lock_acquire
);
2965 DEFINE_TRACE(lock_release
);
2967 void lock_release(struct lockdep_map
*lock
, int nested
,
2970 unsigned long flags
;
2972 trace_lock_release(lock
, nested
, ip
);
2974 if (unlikely(current
->lockdep_recursion
))
2977 raw_local_irq_save(flags
);
2979 current
->lockdep_recursion
= 1;
2980 __lock_release(lock
, nested
, ip
);
2981 current
->lockdep_recursion
= 0;
2982 raw_local_irq_restore(flags
);
2984 EXPORT_SYMBOL_GPL(lock_release
);
2986 void lockdep_set_current_reclaim_state(gfp_t gfp_mask
)
2988 current
->lockdep_reclaim_gfp
= gfp_mask
;
2991 void lockdep_clear_current_reclaim_state(void)
2993 current
->lockdep_reclaim_gfp
= 0;
2996 #ifdef CONFIG_LOCK_STAT
2998 print_lock_contention_bug(struct task_struct
*curr
, struct lockdep_map
*lock
,
3001 if (!debug_locks_off())
3003 if (debug_locks_silent
)
3006 printk("\n=================================\n");
3007 printk( "[ BUG: bad contention detected! ]\n");
3008 printk( "---------------------------------\n");
3009 printk("%s/%d is trying to contend lock (",
3010 curr
->comm
, task_pid_nr(curr
));
3011 print_lockdep_cache(lock
);
3014 printk("but there are no locks held!\n");
3015 printk("\nother info that might help us debug this:\n");
3016 lockdep_print_held_locks(curr
);
3018 printk("\nstack backtrace:\n");
3025 __lock_contended(struct lockdep_map
*lock
, unsigned long ip
)
3027 struct task_struct
*curr
= current
;
3028 struct held_lock
*hlock
, *prev_hlock
;
3029 struct lock_class_stats
*stats
;
3031 int i
, contention_point
, contending_point
;
3033 depth
= curr
->lockdep_depth
;
3034 if (DEBUG_LOCKS_WARN_ON(!depth
))
3038 for (i
= depth
-1; i
>= 0; i
--) {
3039 hlock
= curr
->held_locks
+ i
;
3041 * We must not cross into another context:
3043 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
3045 if (hlock
->instance
== lock
)
3049 print_lock_contention_bug(curr
, lock
, ip
);
3053 hlock
->waittime_stamp
= sched_clock();
3055 contention_point
= lock_point(hlock_class(hlock
)->contention_point
, ip
);
3056 contending_point
= lock_point(hlock_class(hlock
)->contending_point
,
3059 stats
= get_lock_stats(hlock_class(hlock
));
3060 if (contention_point
< LOCKSTAT_POINTS
)
3061 stats
->contention_point
[contention_point
]++;
3062 if (contending_point
< LOCKSTAT_POINTS
)
3063 stats
->contending_point
[contending_point
]++;
3064 if (lock
->cpu
!= smp_processor_id())
3065 stats
->bounces
[bounce_contended
+ !!hlock
->read
]++;
3066 put_lock_stats(stats
);
3070 __lock_acquired(struct lockdep_map
*lock
, unsigned long ip
)
3072 struct task_struct
*curr
= current
;
3073 struct held_lock
*hlock
, *prev_hlock
;
3074 struct lock_class_stats
*stats
;
3080 depth
= curr
->lockdep_depth
;
3081 if (DEBUG_LOCKS_WARN_ON(!depth
))
3085 for (i
= depth
-1; i
>= 0; i
--) {
3086 hlock
= curr
->held_locks
+ i
;
3088 * We must not cross into another context:
3090 if (prev_hlock
&& prev_hlock
->irq_context
!= hlock
->irq_context
)
3092 if (hlock
->instance
== lock
)
3096 print_lock_contention_bug(curr
, lock
, _RET_IP_
);
3100 cpu
= smp_processor_id();
3101 if (hlock
->waittime_stamp
) {
3102 now
= sched_clock();
3103 waittime
= now
- hlock
->waittime_stamp
;
3104 hlock
->holdtime_stamp
= now
;
3107 stats
= get_lock_stats(hlock_class(hlock
));
3110 lock_time_inc(&stats
->read_waittime
, waittime
);
3112 lock_time_inc(&stats
->write_waittime
, waittime
);
3114 if (lock
->cpu
!= cpu
)
3115 stats
->bounces
[bounce_acquired
+ !!hlock
->read
]++;
3116 put_lock_stats(stats
);
3122 DEFINE_TRACE(lock_contended
);
3124 void lock_contended(struct lockdep_map
*lock
, unsigned long ip
)
3126 unsigned long flags
;
3128 trace_lock_contended(lock
, ip
);
3130 if (unlikely(!lock_stat
))
3133 if (unlikely(current
->lockdep_recursion
))
3136 raw_local_irq_save(flags
);
3138 current
->lockdep_recursion
= 1;
3139 __lock_contended(lock
, ip
);
3140 current
->lockdep_recursion
= 0;
3141 raw_local_irq_restore(flags
);
3143 EXPORT_SYMBOL_GPL(lock_contended
);
3145 DEFINE_TRACE(lock_acquired
);
3147 void lock_acquired(struct lockdep_map
*lock
, unsigned long ip
)
3149 unsigned long flags
;
3151 trace_lock_acquired(lock
, ip
);
3153 if (unlikely(!lock_stat
))
3156 if (unlikely(current
->lockdep_recursion
))
3159 raw_local_irq_save(flags
);
3161 current
->lockdep_recursion
= 1;
3162 __lock_acquired(lock
, ip
);
3163 current
->lockdep_recursion
= 0;
3164 raw_local_irq_restore(flags
);
3166 EXPORT_SYMBOL_GPL(lock_acquired
);
3170 * Used by the testsuite, sanitize the validator state
3171 * after a simulated failure:
3174 void lockdep_reset(void)
3176 unsigned long flags
;
3179 raw_local_irq_save(flags
);
3180 current
->curr_chain_key
= 0;
3181 current
->lockdep_depth
= 0;
3182 current
->lockdep_recursion
= 0;
3183 memset(current
->held_locks
, 0, MAX_LOCK_DEPTH
*sizeof(struct held_lock
));
3184 nr_hardirq_chains
= 0;
3185 nr_softirq_chains
= 0;
3186 nr_process_chains
= 0;
3188 for (i
= 0; i
< CHAINHASH_SIZE
; i
++)
3189 INIT_LIST_HEAD(chainhash_table
+ i
);
3190 raw_local_irq_restore(flags
);
3193 static void zap_class(struct lock_class
*class)
3198 * Remove all dependencies this lock is
3201 for (i
= 0; i
< nr_list_entries
; i
++) {
3202 if (list_entries
[i
].class == class)
3203 list_del_rcu(&list_entries
[i
].entry
);
3206 * Unhash the class and remove it from the all_lock_classes list:
3208 list_del_rcu(&class->hash_entry
);
3209 list_del_rcu(&class->lock_entry
);
3214 static inline int within(const void *addr
, void *start
, unsigned long size
)
3216 return addr
>= start
&& addr
< start
+ size
;
3219 void lockdep_free_key_range(void *start
, unsigned long size
)
3221 struct lock_class
*class, *next
;
3222 struct list_head
*head
;
3223 unsigned long flags
;
3227 raw_local_irq_save(flags
);
3228 locked
= graph_lock();
3231 * Unhash all classes that were created by this module:
3233 for (i
= 0; i
< CLASSHASH_SIZE
; i
++) {
3234 head
= classhash_table
+ i
;
3235 if (list_empty(head
))
3237 list_for_each_entry_safe(class, next
, head
, hash_entry
) {
3238 if (within(class->key
, start
, size
))
3240 else if (within(class->name
, start
, size
))
3247 raw_local_irq_restore(flags
);
3250 void lockdep_reset_lock(struct lockdep_map
*lock
)
3252 struct lock_class
*class, *next
;
3253 struct list_head
*head
;
3254 unsigned long flags
;
3258 raw_local_irq_save(flags
);
3261 * Remove all classes this lock might have:
3263 for (j
= 0; j
< MAX_LOCKDEP_SUBCLASSES
; j
++) {
3265 * If the class exists we look it up and zap it:
3267 class = look_up_lock_class(lock
, j
);
3272 * Debug check: in the end all mapped classes should
3275 locked
= graph_lock();
3276 for (i
= 0; i
< CLASSHASH_SIZE
; i
++) {
3277 head
= classhash_table
+ i
;
3278 if (list_empty(head
))
3280 list_for_each_entry_safe(class, next
, head
, hash_entry
) {
3281 if (unlikely(class == lock
->class_cache
)) {
3282 if (debug_locks_off_graph_unlock())
3292 raw_local_irq_restore(flags
);
3295 void lockdep_init(void)
3300 * Some architectures have their own start_kernel()
3301 * code which calls lockdep_init(), while we also
3302 * call lockdep_init() from the start_kernel() itself,
3303 * and we want to initialize the hashes only once:
3305 if (lockdep_initialized
)
3308 for (i
= 0; i
< CLASSHASH_SIZE
; i
++)
3309 INIT_LIST_HEAD(classhash_table
+ i
);
3311 for (i
= 0; i
< CHAINHASH_SIZE
; i
++)
3312 INIT_LIST_HEAD(chainhash_table
+ i
);
3314 lockdep_initialized
= 1;
3317 void __init
lockdep_info(void)
3319 printk("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n");
3321 printk("... MAX_LOCKDEP_SUBCLASSES: %lu\n", MAX_LOCKDEP_SUBCLASSES
);
3322 printk("... MAX_LOCK_DEPTH: %lu\n", MAX_LOCK_DEPTH
);
3323 printk("... MAX_LOCKDEP_KEYS: %lu\n", MAX_LOCKDEP_KEYS
);
3324 printk("... CLASSHASH_SIZE: %lu\n", CLASSHASH_SIZE
);
3325 printk("... MAX_LOCKDEP_ENTRIES: %lu\n", MAX_LOCKDEP_ENTRIES
);
3326 printk("... MAX_LOCKDEP_CHAINS: %lu\n", MAX_LOCKDEP_CHAINS
);
3327 printk("... CHAINHASH_SIZE: %lu\n", CHAINHASH_SIZE
);
3329 printk(" memory used by lock dependency info: %lu kB\n",
3330 (sizeof(struct lock_class
) * MAX_LOCKDEP_KEYS
+
3331 sizeof(struct list_head
) * CLASSHASH_SIZE
+
3332 sizeof(struct lock_list
) * MAX_LOCKDEP_ENTRIES
+
3333 sizeof(struct lock_chain
) * MAX_LOCKDEP_CHAINS
+
3334 sizeof(struct list_head
) * CHAINHASH_SIZE
) / 1024);
3336 printk(" per task-struct memory footprint: %lu bytes\n",
3337 sizeof(struct held_lock
) * MAX_LOCK_DEPTH
);
3339 #ifdef CONFIG_DEBUG_LOCKDEP
3340 if (lockdep_init_error
) {
3341 printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
3342 printk("Call stack leading to lockdep invocation was:\n");
3343 print_stack_trace(&lockdep_init_trace
, 0);
3349 print_freed_lock_bug(struct task_struct
*curr
, const void *mem_from
,
3350 const void *mem_to
, struct held_lock
*hlock
)
3352 if (!debug_locks_off())
3354 if (debug_locks_silent
)
3357 printk("\n=========================\n");
3358 printk( "[ BUG: held lock freed! ]\n");
3359 printk( "-------------------------\n");
3360 printk("%s/%d is freeing memory %p-%p, with a lock still held there!\n",
3361 curr
->comm
, task_pid_nr(curr
), mem_from
, mem_to
-1);
3363 lockdep_print_held_locks(curr
);
3365 printk("\nstack backtrace:\n");
3369 static inline int not_in_range(const void* mem_from
, unsigned long mem_len
,
3370 const void* lock_from
, unsigned long lock_len
)
3372 return lock_from
+ lock_len
<= mem_from
||
3373 mem_from
+ mem_len
<= lock_from
;
3377 * Called when kernel memory is freed (or unmapped), or if a lock
3378 * is destroyed or reinitialized - this code checks whether there is
3379 * any held lock in the memory range of <from> to <to>:
3381 void debug_check_no_locks_freed(const void *mem_from
, unsigned long mem_len
)
3383 struct task_struct
*curr
= current
;
3384 struct held_lock
*hlock
;
3385 unsigned long flags
;
3388 if (unlikely(!debug_locks
))
3391 local_irq_save(flags
);
3392 for (i
= 0; i
< curr
->lockdep_depth
; i
++) {
3393 hlock
= curr
->held_locks
+ i
;
3395 if (not_in_range(mem_from
, mem_len
, hlock
->instance
,
3396 sizeof(*hlock
->instance
)))
3399 print_freed_lock_bug(curr
, mem_from
, mem_from
+ mem_len
, hlock
);
3402 local_irq_restore(flags
);
3404 EXPORT_SYMBOL_GPL(debug_check_no_locks_freed
);
3406 static void print_held_locks_bug(struct task_struct
*curr
)
3408 if (!debug_locks_off())
3410 if (debug_locks_silent
)
3413 printk("\n=====================================\n");
3414 printk( "[ BUG: lock held at task exit time! ]\n");
3415 printk( "-------------------------------------\n");
3416 printk("%s/%d is exiting with locks still held!\n",
3417 curr
->comm
, task_pid_nr(curr
));
3418 lockdep_print_held_locks(curr
);
3420 printk("\nstack backtrace:\n");
3424 void debug_check_no_locks_held(struct task_struct
*task
)
3426 if (unlikely(task
->lockdep_depth
> 0))
3427 print_held_locks_bug(task
);
3430 void debug_show_all_locks(void)
3432 struct task_struct
*g
, *p
;
3436 if (unlikely(!debug_locks
)) {
3437 printk("INFO: lockdep is turned off.\n");
3440 printk("\nShowing all locks held in the system:\n");
3443 * Here we try to get the tasklist_lock as hard as possible,
3444 * if not successful after 2 seconds we ignore it (but keep
3445 * trying). This is to enable a debug printout even if a
3446 * tasklist_lock-holding task deadlocks or crashes.
3449 if (!read_trylock(&tasklist_lock
)) {
3451 printk("hm, tasklist_lock locked, retrying... ");
3454 printk(" #%d", 10-count
);
3458 printk(" ignoring it.\n");
3462 printk(KERN_CONT
" locked it.\n");
3465 do_each_thread(g
, p
) {
3467 * It's not reliable to print a task's held locks
3468 * if it's not sleeping (or if it's not the current
3471 if (p
->state
== TASK_RUNNING
&& p
!= current
)
3473 if (p
->lockdep_depth
)
3474 lockdep_print_held_locks(p
);
3476 if (read_trylock(&tasklist_lock
))
3478 } while_each_thread(g
, p
);
3481 printk("=============================================\n\n");
3484 read_unlock(&tasklist_lock
);
3486 EXPORT_SYMBOL_GPL(debug_show_all_locks
);
3489 * Careful: only use this function if you are sure that
3490 * the task cannot run in parallel!
3492 void __debug_show_held_locks(struct task_struct
*task
)
3494 if (unlikely(!debug_locks
)) {
3495 printk("INFO: lockdep is turned off.\n");
3498 lockdep_print_held_locks(task
);
3500 EXPORT_SYMBOL_GPL(__debug_show_held_locks
);
3502 void debug_show_held_locks(struct task_struct
*task
)
3504 __debug_show_held_locks(task
);
3506 EXPORT_SYMBOL_GPL(debug_show_held_locks
);
3508 void lockdep_sys_exit(void)
3510 struct task_struct
*curr
= current
;
3512 if (unlikely(curr
->lockdep_depth
)) {
3513 if (!debug_locks_off())
3515 printk("\n================================================\n");
3516 printk( "[ BUG: lock held when returning to user space! ]\n");
3517 printk( "------------------------------------------------\n");
3518 printk("%s/%d is leaving the kernel with locks still held!\n",
3519 curr
->comm
, curr
->pid
);
3520 lockdep_print_held_locks(curr
);