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 <linux/bitops.h>
46 #include <linux/gfp.h>
48 #include <asm/sections.h>
50 #include "lockdep_internals.h"
52 #define CREATE_TRACE_POINTS
53 #include <trace/events/lock.h>
55 #ifdef CONFIG_PROVE_LOCKING
56 int prove_locking = 1;
57 module_param(prove_locking, int, 0644);
59 #define prove_locking 0
62 #ifdef CONFIG_LOCK_STAT
64 module_param(lock_stat, int, 0644);
70 * lockdep_lock: protects the lockdep graph, the hashes and the
71 * class/list/hash allocators.
73 * This is one of the rare exceptions where it's justified
74 * to use a raw spinlock - we really dont want the spinlock
75 * code to recurse back into the lockdep code...
77 static arch_spinlock_t lockdep_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
79 static int graph_lock(void)
81 arch_spin_lock(&lockdep_lock);
83 * Make sure that if another CPU detected a bug while
84 * walking the graph we dont change it (while the other
85 * CPU is busy printing out stuff with the graph lock
89 arch_spin_unlock(&lockdep_lock);
92 /* prevent any recursions within lockdep from causing deadlocks */
93 current->lockdep_recursion++;
97 static inline int graph_unlock(void)
99 if (debug_locks && !arch_spin_is_locked(&lockdep_lock))
100 return DEBUG_LOCKS_WARN_ON(1);
102 current->lockdep_recursion--;
103 arch_spin_unlock(&lockdep_lock);
108 * Turn lock debugging off and return with 0 if it was off already,
109 * and also release the graph lock:
111 static inline int debug_locks_off_graph_unlock(void)
113 int ret = debug_locks_off();
115 arch_spin_unlock(&lockdep_lock);
120 static int lockdep_initialized;
122 unsigned long nr_list_entries;
123 static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
126 * All data structures here are protected by the global debug_lock.
128 * Mutex key structs only get allocated, once during bootup, and never
129 * get freed - this significantly simplifies the debugging code.
131 unsigned long nr_lock_classes;
132 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
134 static inline struct lock_class *hlock_class(struct held_lock *hlock)
136 if (!hlock->class_idx) {
137 DEBUG_LOCKS_WARN_ON(1);
140 return lock_classes + hlock->class_idx - 1;
143 #ifdef CONFIG_LOCK_STAT
144 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS],
147 static inline u64 lockstat_clock(void)
149 return local_clock();
152 static int lock_point(unsigned long points[], unsigned long ip)
156 for (i = 0; i < LOCKSTAT_POINTS; i++) {
157 if (points[i] == 0) {
168 static void lock_time_inc(struct lock_time *lt, u64 time)
173 if (time < lt->min || !lt->nr)
180 static inline void lock_time_add(struct lock_time *src, struct lock_time *dst)
185 if (src->max > dst->max)
188 if (src->min < dst->min || !dst->nr)
191 dst->total += src->total;
195 struct lock_class_stats lock_stats(struct lock_class *class)
197 struct lock_class_stats stats;
200 memset(&stats, 0, sizeof(struct lock_class_stats));
201 for_each_possible_cpu(cpu) {
202 struct lock_class_stats *pcs =
203 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes];
205 for (i = 0; i < ARRAY_SIZE(stats.contention_point); i++)
206 stats.contention_point[i] += pcs->contention_point[i];
208 for (i = 0; i < ARRAY_SIZE(stats.contending_point); i++)
209 stats.contending_point[i] += pcs->contending_point[i];
211 lock_time_add(&pcs->read_waittime, &stats.read_waittime);
212 lock_time_add(&pcs->write_waittime, &stats.write_waittime);
214 lock_time_add(&pcs->read_holdtime, &stats.read_holdtime);
215 lock_time_add(&pcs->write_holdtime, &stats.write_holdtime);
217 for (i = 0; i < ARRAY_SIZE(stats.bounces); i++)
218 stats.bounces[i] += pcs->bounces[i];
224 void clear_lock_stats(struct lock_class *class)
228 for_each_possible_cpu(cpu) {
229 struct lock_class_stats *cpu_stats =
230 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes];
232 memset(cpu_stats, 0, sizeof(struct lock_class_stats));
234 memset(class->contention_point, 0, sizeof(class->contention_point));
235 memset(class->contending_point, 0, sizeof(class->contending_point));
238 static struct lock_class_stats *get_lock_stats(struct lock_class *class)
240 return &get_cpu_var(cpu_lock_stats)[class - lock_classes];
243 static void put_lock_stats(struct lock_class_stats *stats)
245 put_cpu_var(cpu_lock_stats);
248 static void lock_release_holdtime(struct held_lock *hlock)
250 struct lock_class_stats *stats;
256 holdtime = lockstat_clock() - hlock->holdtime_stamp;
258 stats = get_lock_stats(hlock_class(hlock));
260 lock_time_inc(&stats->read_holdtime, holdtime);
262 lock_time_inc(&stats->write_holdtime, holdtime);
263 put_lock_stats(stats);
266 static inline void lock_release_holdtime(struct held_lock *hlock)
272 * We keep a global list of all lock classes. The list only grows,
273 * never shrinks. The list is only accessed with the lockdep
274 * spinlock lock held.
276 LIST_HEAD(all_lock_classes);
279 * The lockdep classes are in a hash-table as well, for fast lookup:
281 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
282 #define CLASSHASH_SIZE (1UL << CLASSHASH_BITS)
283 #define __classhashfn(key) hash_long((unsigned long)key, CLASSHASH_BITS)
284 #define classhashentry(key) (classhash_table + __classhashfn((key)))
286 static struct list_head classhash_table[CLASSHASH_SIZE];
289 * We put the lock dependency chains into a hash-table as well, to cache
292 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
293 #define CHAINHASH_SIZE (1UL << CHAINHASH_BITS)
294 #define __chainhashfn(chain) hash_long(chain, CHAINHASH_BITS)
295 #define chainhashentry(chain) (chainhash_table + __chainhashfn((chain)))
297 static struct list_head chainhash_table[CHAINHASH_SIZE];
300 * The hash key of the lock dependency chains is a hash itself too:
301 * it's a hash of all locks taken up to that lock, including that lock.
302 * It's a 64-bit hash, because it's important for the keys to be
305 #define iterate_chain_key(key1, key2) \
306 (((key1) << MAX_LOCKDEP_KEYS_BITS) ^ \
307 ((key1) >> (64-MAX_LOCKDEP_KEYS_BITS)) ^ \
310 void lockdep_off(void)
312 current->lockdep_recursion++;
314 EXPORT_SYMBOL(lockdep_off);
316 void lockdep_on(void)
318 current->lockdep_recursion--;
320 EXPORT_SYMBOL(lockdep_on);
323 * Debugging switches:
327 #define VERY_VERBOSE 0
330 # define HARDIRQ_VERBOSE 1
331 # define SOFTIRQ_VERBOSE 1
332 # define RECLAIM_VERBOSE 1
334 # define HARDIRQ_VERBOSE 0
335 # define SOFTIRQ_VERBOSE 0
336 # define RECLAIM_VERBOSE 0
339 #if VERBOSE || HARDIRQ_VERBOSE || SOFTIRQ_VERBOSE || RECLAIM_VERBOSE
341 * Quick filtering for interesting events:
343 static int class_filter(struct lock_class *class)
347 if (class->name_version == 1 &&
348 !strcmp(class->name, "lockname"))
350 if (class->name_version == 1 &&
351 !strcmp(class->name, "&struct->lockfield"))
354 /* Filter everything else. 1 would be to allow everything else */
359 static int verbose(struct lock_class *class)
362 return class_filter(class);
368 * Stack-trace: tightly packed array of stack backtrace
369 * addresses. Protected by the graph_lock.
371 unsigned long nr_stack_trace_entries;
372 static unsigned long stack_trace[MAX_STACK_TRACE_ENTRIES];
374 static int save_trace(struct stack_trace *trace)
376 trace->nr_entries = 0;
377 trace->max_entries = MAX_STACK_TRACE_ENTRIES - nr_stack_trace_entries;
378 trace->entries = stack_trace + nr_stack_trace_entries;
382 save_stack_trace(trace);
385 * Some daft arches put -1 at the end to indicate its a full trace.
387 * <rant> this is buggy anyway, since it takes a whole extra entry so a
388 * complete trace that maxes out the entries provided will be reported
389 * as incomplete, friggin useless </rant>
391 if (trace->nr_entries != 0 &&
392 trace->entries[trace->nr_entries-1] == ULONG_MAX)
395 trace->max_entries = trace->nr_entries;
397 nr_stack_trace_entries += trace->nr_entries;
399 if (nr_stack_trace_entries >= MAX_STACK_TRACE_ENTRIES-1) {
400 if (!debug_locks_off_graph_unlock())
403 printk("BUG: MAX_STACK_TRACE_ENTRIES too low!\n");
404 printk("turning off the locking correctness validator.\n");
413 unsigned int nr_hardirq_chains;
414 unsigned int nr_softirq_chains;
415 unsigned int nr_process_chains;
416 unsigned int max_lockdep_depth;
418 #ifdef CONFIG_DEBUG_LOCKDEP
420 * We cannot printk in early bootup code. Not even early_printk()
421 * might work. So we mark any initialization errors and printk
422 * about it later on, in lockdep_info().
424 static int lockdep_init_error;
425 static unsigned long lockdep_init_trace_data[20];
426 static struct stack_trace lockdep_init_trace = {
427 .max_entries = ARRAY_SIZE(lockdep_init_trace_data),
428 .entries = lockdep_init_trace_data,
432 * Various lockdep statistics:
434 DEFINE_PER_CPU(struct lockdep_stats, lockdep_stats);
441 #define __USAGE(__STATE) \
442 [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \
443 [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \
444 [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\
445 [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R",
447 static const char *usage_str[] =
449 #define LOCKDEP_STATE(__STATE) __USAGE(__STATE)
450 #include "lockdep_states.h"
452 [LOCK_USED] = "INITIAL USE",
455 const char * __get_key_name(struct lockdep_subclass_key *key, char *str)
457 return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
460 static inline unsigned long lock_flag(enum lock_usage_bit bit)
465 static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit)
469 if (class->usage_mask & lock_flag(bit + 2))
471 if (class->usage_mask & lock_flag(bit)) {
473 if (class->usage_mask & lock_flag(bit + 2))
480 void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS])
484 #define LOCKDEP_STATE(__STATE) \
485 usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE); \
486 usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE##_READ);
487 #include "lockdep_states.h"
493 static void print_lock_name(struct lock_class *class)
495 char str[KSYM_NAME_LEN], usage[LOCK_USAGE_CHARS];
498 get_usage_chars(class, usage);
502 name = __get_key_name(class->key, str);
503 printk(" (%s", name);
505 printk(" (%s", name);
506 if (class->name_version > 1)
507 printk("#%d", class->name_version);
509 printk("/%d", class->subclass);
511 printk("){%s}", usage);
514 static void print_lockdep_cache(struct lockdep_map *lock)
517 char str[KSYM_NAME_LEN];
521 name = __get_key_name(lock->key->subkeys, str);
526 static void print_lock(struct held_lock *hlock)
528 print_lock_name(hlock_class(hlock));
530 print_ip_sym(hlock->acquire_ip);
533 static void lockdep_print_held_locks(struct task_struct *curr)
535 int i, depth = curr->lockdep_depth;
538 printk("no locks held by %s/%d.\n", curr->comm, task_pid_nr(curr));
541 printk("%d lock%s held by %s/%d:\n",
542 depth, depth > 1 ? "s" : "", curr->comm, task_pid_nr(curr));
544 for (i = 0; i < depth; i++) {
546 print_lock(curr->held_locks + i);
550 static void print_kernel_version(void)
552 printk("%s %.*s\n", init_utsname()->release,
553 (int)strcspn(init_utsname()->version, " "),
554 init_utsname()->version);
557 static int very_verbose(struct lock_class *class)
560 return class_filter(class);
566 * Is this the address of a static object:
568 static int static_obj(void *obj)
570 unsigned long start = (unsigned long) &_stext,
571 end = (unsigned long) &_end,
572 addr = (unsigned long) obj;
577 if ((addr >= start) && (addr < end))
580 if (arch_is_kernel_data(addr))
584 * in-kernel percpu var?
586 if (is_kernel_percpu_address(addr))
590 * module static or percpu var?
592 return is_module_address(addr) || is_module_percpu_address(addr);
596 * To make lock name printouts unique, we calculate a unique
597 * class->name_version generation counter:
599 static int count_matching_names(struct lock_class *new_class)
601 struct lock_class *class;
604 if (!new_class->name)
607 list_for_each_entry(class, &all_lock_classes, lock_entry) {
608 if (new_class->key - new_class->subclass == class->key)
609 return class->name_version;
610 if (class->name && !strcmp(class->name, new_class->name))
611 count = max(count, class->name_version);
618 * Register a lock's class in the hash-table, if the class is not present
619 * yet. Otherwise we look it up. We cache the result in the lock object
620 * itself, so actual lookup of the hash should be once per lock object.
622 static inline struct lock_class *
623 look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
625 struct lockdep_subclass_key *key;
626 struct list_head *hash_head;
627 struct lock_class *class;
629 #ifdef CONFIG_DEBUG_LOCKDEP
631 * If the architecture calls into lockdep before initializing
632 * the hashes then we'll warn about it later. (we cannot printk
635 if (unlikely(!lockdep_initialized)) {
637 lockdep_init_error = 1;
638 save_stack_trace(&lockdep_init_trace);
643 * Static locks do not have their class-keys yet - for them the key
644 * is the lock object itself:
646 if (unlikely(!lock->key))
647 lock->key = (void *)lock;
650 * NOTE: the class-key must be unique. For dynamic locks, a static
651 * lock_class_key variable is passed in through the mutex_init()
652 * (or spin_lock_init()) call - which acts as the key. For static
653 * locks we use the lock object itself as the key.
655 BUILD_BUG_ON(sizeof(struct lock_class_key) >
656 sizeof(struct lockdep_map));
658 key = lock->key->subkeys + subclass;
660 hash_head = classhashentry(key);
663 * We can walk the hash lockfree, because the hash only
664 * grows, and we are careful when adding entries to the end:
666 list_for_each_entry(class, hash_head, hash_entry) {
667 if (class->key == key) {
668 WARN_ON_ONCE(class->name != lock->name);
677 * Register a lock's class in the hash-table, if the class is not present
678 * yet. Otherwise we look it up. We cache the result in the lock object
679 * itself, so actual lookup of the hash should be once per lock object.
681 static inline struct lock_class *
682 register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
684 struct lockdep_subclass_key *key;
685 struct list_head *hash_head;
686 struct lock_class *class;
689 class = look_up_lock_class(lock, subclass);
694 * Debug-check: all keys must be persistent!
696 if (!static_obj(lock->key)) {
698 printk("INFO: trying to register non-static key.\n");
699 printk("the code is fine but needs lockdep annotation.\n");
700 printk("turning off the locking correctness validator.\n");
706 key = lock->key->subkeys + subclass;
707 hash_head = classhashentry(key);
709 raw_local_irq_save(flags);
711 raw_local_irq_restore(flags);
715 * We have to do the hash-walk again, to avoid races
718 list_for_each_entry(class, hash_head, hash_entry)
719 if (class->key == key)
722 * Allocate a new key from the static array, and add it to
725 if (nr_lock_classes >= MAX_LOCKDEP_KEYS) {
726 if (!debug_locks_off_graph_unlock()) {
727 raw_local_irq_restore(flags);
730 raw_local_irq_restore(flags);
732 printk("BUG: MAX_LOCKDEP_KEYS too low!\n");
733 printk("turning off the locking correctness validator.\n");
737 class = lock_classes + nr_lock_classes++;
738 debug_atomic_inc(nr_unused_locks);
740 class->name = lock->name;
741 class->subclass = subclass;
742 INIT_LIST_HEAD(&class->lock_entry);
743 INIT_LIST_HEAD(&class->locks_before);
744 INIT_LIST_HEAD(&class->locks_after);
745 class->name_version = count_matching_names(class);
747 * We use RCU's safe list-add method to make
748 * parallel walking of the hash-list safe:
750 list_add_tail_rcu(&class->hash_entry, hash_head);
752 * Add it to the global list of classes:
754 list_add_tail_rcu(&class->lock_entry, &all_lock_classes);
756 if (verbose(class)) {
758 raw_local_irq_restore(flags);
760 printk("\nnew class %p: %s", class->key, class->name);
761 if (class->name_version > 1)
762 printk("#%d", class->name_version);
766 raw_local_irq_save(flags);
768 raw_local_irq_restore(flags);
774 raw_local_irq_restore(flags);
776 if (!subclass || force)
777 lock->class_cache[0] = class;
778 else if (subclass < NR_LOCKDEP_CACHING_CLASSES)
779 lock->class_cache[subclass] = class;
781 if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass))
787 #ifdef CONFIG_PROVE_LOCKING
789 * Allocate a lockdep entry. (assumes the graph_lock held, returns
790 * with NULL on failure)
792 static struct lock_list *alloc_list_entry(void)
794 if (nr_list_entries >= MAX_LOCKDEP_ENTRIES) {
795 if (!debug_locks_off_graph_unlock())
798 printk("BUG: MAX_LOCKDEP_ENTRIES too low!\n");
799 printk("turning off the locking correctness validator.\n");
803 return list_entries + nr_list_entries++;
807 * Add a new dependency to the head of the list:
809 static int add_lock_to_list(struct lock_class *class, struct lock_class *this,
810 struct list_head *head, unsigned long ip,
811 int distance, struct stack_trace *trace)
813 struct lock_list *entry;
815 * Lock not present yet - get a new dependency struct and
816 * add it to the list:
818 entry = alloc_list_entry();
823 entry->distance = distance;
824 entry->trace = *trace;
826 * Since we never remove from the dependency list, the list can
827 * be walked lockless by other CPUs, it's only allocation
828 * that must be protected by the spinlock. But this also means
829 * we must make new entries visible only once writes to the
830 * entry become visible - hence the RCU op:
832 list_add_tail_rcu(&entry->entry, head);
838 * For good efficiency of modular, we use power of 2
840 #define MAX_CIRCULAR_QUEUE_SIZE 4096UL
841 #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1)
844 * The circular_queue and helpers is used to implement the
845 * breadth-first search(BFS)algorithem, by which we can build
846 * the shortest path from the next lock to be acquired to the
847 * previous held lock if there is a circular between them.
849 struct circular_queue {
850 unsigned long element[MAX_CIRCULAR_QUEUE_SIZE];
851 unsigned int front, rear;
854 static struct circular_queue lock_cq;
856 unsigned int max_bfs_queue_depth;
858 static unsigned int lockdep_dependency_gen_id;
860 static inline void __cq_init(struct circular_queue *cq)
862 cq->front = cq->rear = 0;
863 lockdep_dependency_gen_id++;
866 static inline int __cq_empty(struct circular_queue *cq)
868 return (cq->front == cq->rear);
871 static inline int __cq_full(struct circular_queue *cq)
873 return ((cq->rear + 1) & CQ_MASK) == cq->front;
876 static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem)
881 cq->element[cq->rear] = elem;
882 cq->rear = (cq->rear + 1) & CQ_MASK;
886 static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem)
891 *elem = cq->element[cq->front];
892 cq->front = (cq->front + 1) & CQ_MASK;
896 static inline unsigned int __cq_get_elem_count(struct circular_queue *cq)
898 return (cq->rear - cq->front) & CQ_MASK;
901 static inline void mark_lock_accessed(struct lock_list *lock,
902 struct lock_list *parent)
906 nr = lock - list_entries;
907 WARN_ON(nr >= nr_list_entries);
908 lock->parent = parent;
909 lock->class->dep_gen_id = lockdep_dependency_gen_id;
912 static inline unsigned long lock_accessed(struct lock_list *lock)
916 nr = lock - list_entries;
917 WARN_ON(nr >= nr_list_entries);
918 return lock->class->dep_gen_id == lockdep_dependency_gen_id;
921 static inline struct lock_list *get_lock_parent(struct lock_list *child)
923 return child->parent;
926 static inline int get_lock_depth(struct lock_list *child)
929 struct lock_list *parent;
931 while ((parent = get_lock_parent(child))) {
938 static int __bfs(struct lock_list *source_entry,
940 int (*match)(struct lock_list *entry, void *data),
941 struct lock_list **target_entry,
944 struct lock_list *entry;
945 struct list_head *head;
946 struct circular_queue *cq = &lock_cq;
949 if (match(source_entry, data)) {
950 *target_entry = source_entry;
956 head = &source_entry->class->locks_after;
958 head = &source_entry->class->locks_before;
960 if (list_empty(head))
964 __cq_enqueue(cq, (unsigned long)source_entry);
966 while (!__cq_empty(cq)) {
967 struct lock_list *lock;
969 __cq_dequeue(cq, (unsigned long *)&lock);
977 head = &lock->class->locks_after;
979 head = &lock->class->locks_before;
981 list_for_each_entry(entry, head, entry) {
982 if (!lock_accessed(entry)) {
983 unsigned int cq_depth;
984 mark_lock_accessed(entry, lock);
985 if (match(entry, data)) {
986 *target_entry = entry;
991 if (__cq_enqueue(cq, (unsigned long)entry)) {
995 cq_depth = __cq_get_elem_count(cq);
996 if (max_bfs_queue_depth < cq_depth)
997 max_bfs_queue_depth = cq_depth;
1005 static inline int __bfs_forwards(struct lock_list *src_entry,
1007 int (*match)(struct lock_list *entry, void *data),
1008 struct lock_list **target_entry)
1010 return __bfs(src_entry, data, match, target_entry, 1);
1014 static inline int __bfs_backwards(struct lock_list *src_entry,
1016 int (*match)(struct lock_list *entry, void *data),
1017 struct lock_list **target_entry)
1019 return __bfs(src_entry, data, match, target_entry, 0);
1024 * Recursive, forwards-direction lock-dependency checking, used for
1025 * both noncyclic checking and for hardirq-unsafe/softirq-unsafe
1030 * Print a dependency chain entry (this is only done when a deadlock
1031 * has been detected):
1034 print_circular_bug_entry(struct lock_list *target, int depth)
1036 if (debug_locks_silent)
1038 printk("\n-> #%u", depth);
1039 print_lock_name(target->class);
1041 print_stack_trace(&target->trace, 6);
1047 * When a circular dependency is detected, print the
1051 print_circular_bug_header(struct lock_list *entry, unsigned int depth,
1052 struct held_lock *check_src,
1053 struct held_lock *check_tgt)
1055 struct task_struct *curr = current;
1057 if (debug_locks_silent)
1060 printk("\n=======================================================\n");
1061 printk( "[ INFO: possible circular locking dependency detected ]\n");
1062 print_kernel_version();
1063 printk( "-------------------------------------------------------\n");
1064 printk("%s/%d is trying to acquire lock:\n",
1065 curr->comm, task_pid_nr(curr));
1066 print_lock(check_src);
1067 printk("\nbut task is already holding lock:\n");
1068 print_lock(check_tgt);
1069 printk("\nwhich lock already depends on the new lock.\n\n");
1070 printk("\nthe existing dependency chain (in reverse order) is:\n");
1072 print_circular_bug_entry(entry, depth);
1077 static inline int class_equal(struct lock_list *entry, void *data)
1079 return entry->class == data;
1082 static noinline int print_circular_bug(struct lock_list *this,
1083 struct lock_list *target,
1084 struct held_lock *check_src,
1085 struct held_lock *check_tgt)
1087 struct task_struct *curr = current;
1088 struct lock_list *parent;
1091 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
1094 if (!save_trace(&this->trace))
1097 depth = get_lock_depth(target);
1099 print_circular_bug_header(target, depth, check_src, check_tgt);
1101 parent = get_lock_parent(target);
1104 print_circular_bug_entry(parent, --depth);
1105 parent = get_lock_parent(parent);
1108 printk("\nother info that might help us debug this:\n\n");
1109 lockdep_print_held_locks(curr);
1111 printk("\nstack backtrace:\n");
1117 static noinline int print_bfs_bug(int ret)
1119 if (!debug_locks_off_graph_unlock())
1122 WARN(1, "lockdep bfs error:%d\n", ret);
1127 static int noop_count(struct lock_list *entry, void *data)
1129 (*(unsigned long *)data)++;
1133 unsigned long __lockdep_count_forward_deps(struct lock_list *this)
1135 unsigned long count = 0;
1136 struct lock_list *uninitialized_var(target_entry);
1138 __bfs_forwards(this, (void *)&count, noop_count, &target_entry);
1142 unsigned long lockdep_count_forward_deps(struct lock_class *class)
1144 unsigned long ret, flags;
1145 struct lock_list this;
1150 local_irq_save(flags);
1151 arch_spin_lock(&lockdep_lock);
1152 ret = __lockdep_count_forward_deps(&this);
1153 arch_spin_unlock(&lockdep_lock);
1154 local_irq_restore(flags);
1159 unsigned long __lockdep_count_backward_deps(struct lock_list *this)
1161 unsigned long count = 0;
1162 struct lock_list *uninitialized_var(target_entry);
1164 __bfs_backwards(this, (void *)&count, noop_count, &target_entry);
1169 unsigned long lockdep_count_backward_deps(struct lock_class *class)
1171 unsigned long ret, flags;
1172 struct lock_list this;
1177 local_irq_save(flags);
1178 arch_spin_lock(&lockdep_lock);
1179 ret = __lockdep_count_backward_deps(&this);
1180 arch_spin_unlock(&lockdep_lock);
1181 local_irq_restore(flags);
1187 * Prove that the dependency graph starting at <entry> can not
1188 * lead to <target>. Print an error and return 0 if it does.
1191 check_noncircular(struct lock_list *root, struct lock_class *target,
1192 struct lock_list **target_entry)
1196 debug_atomic_inc(nr_cyclic_checks);
1198 result = __bfs_forwards(root, target, class_equal, target_entry);
1203 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
1205 * Forwards and backwards subgraph searching, for the purposes of
1206 * proving that two subgraphs can be connected by a new dependency
1207 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
1210 static inline int usage_match(struct lock_list *entry, void *bit)
1212 return entry->class->usage_mask & (1 << (enum lock_usage_bit)bit);
1218 * Find a node in the forwards-direction dependency sub-graph starting
1219 * at @root->class that matches @bit.
1221 * Return 0 if such a node exists in the subgraph, and put that node
1222 * into *@target_entry.
1224 * Return 1 otherwise and keep *@target_entry unchanged.
1225 * Return <0 on error.
1228 find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit,
1229 struct lock_list **target_entry)
1233 debug_atomic_inc(nr_find_usage_forwards_checks);
1235 result = __bfs_forwards(root, (void *)bit, usage_match, target_entry);
1241 * Find a node in the backwards-direction dependency sub-graph starting
1242 * at @root->class that matches @bit.
1244 * Return 0 if such a node exists in the subgraph, and put that node
1245 * into *@target_entry.
1247 * Return 1 otherwise and keep *@target_entry unchanged.
1248 * Return <0 on error.
1251 find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit,
1252 struct lock_list **target_entry)
1256 debug_atomic_inc(nr_find_usage_backwards_checks);
1258 result = __bfs_backwards(root, (void *)bit, usage_match, target_entry);
1263 static void print_lock_class_header(struct lock_class *class, int depth)
1267 printk("%*s->", depth, "");
1268 print_lock_name(class);
1269 printk(" ops: %lu", class->ops);
1272 for (bit = 0; bit < LOCK_USAGE_STATES; bit++) {
1273 if (class->usage_mask & (1 << bit)) {
1276 len += printk("%*s %s", depth, "", usage_str[bit]);
1277 len += printk(" at:\n");
1278 print_stack_trace(class->usage_traces + bit, len);
1281 printk("%*s }\n", depth, "");
1283 printk("%*s ... key at: ",depth,"");
1284 print_ip_sym((unsigned long)class->key);
1288 * printk the shortest lock dependencies from @start to @end in reverse order:
1291 print_shortest_lock_dependencies(struct lock_list *leaf,
1292 struct lock_list *root)
1294 struct lock_list *entry = leaf;
1297 /*compute depth from generated tree by BFS*/
1298 depth = get_lock_depth(leaf);
1301 print_lock_class_header(entry->class, depth);
1302 printk("%*s ... acquired at:\n", depth, "");
1303 print_stack_trace(&entry->trace, 2);
1306 if (depth == 0 && (entry != root)) {
1307 printk("lockdep:%s bad BFS generated tree\n", __func__);
1311 entry = get_lock_parent(entry);
1313 } while (entry && (depth >= 0));
1319 print_bad_irq_dependency(struct task_struct *curr,
1320 struct lock_list *prev_root,
1321 struct lock_list *next_root,
1322 struct lock_list *backwards_entry,
1323 struct lock_list *forwards_entry,
1324 struct held_lock *prev,
1325 struct held_lock *next,
1326 enum lock_usage_bit bit1,
1327 enum lock_usage_bit bit2,
1328 const char *irqclass)
1330 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
1333 printk("\n======================================================\n");
1334 printk( "[ INFO: %s-safe -> %s-unsafe lock order detected ]\n",
1335 irqclass, irqclass);
1336 print_kernel_version();
1337 printk( "------------------------------------------------------\n");
1338 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] is trying to acquire:\n",
1339 curr->comm, task_pid_nr(curr),
1340 curr->hardirq_context, hardirq_count() >> HARDIRQ_SHIFT,
1341 curr->softirq_context, softirq_count() >> SOFTIRQ_SHIFT,
1342 curr->hardirqs_enabled,
1343 curr->softirqs_enabled);
1346 printk("\nand this task is already holding:\n");
1348 printk("which would create a new lock dependency:\n");
1349 print_lock_name(hlock_class(prev));
1351 print_lock_name(hlock_class(next));
1354 printk("\nbut this new dependency connects a %s-irq-safe lock:\n",
1356 print_lock_name(backwards_entry->class);
1357 printk("\n... which became %s-irq-safe at:\n", irqclass);
1359 print_stack_trace(backwards_entry->class->usage_traces + bit1, 1);
1361 printk("\nto a %s-irq-unsafe lock:\n", irqclass);
1362 print_lock_name(forwards_entry->class);
1363 printk("\n... which became %s-irq-unsafe at:\n", irqclass);
1366 print_stack_trace(forwards_entry->class->usage_traces + bit2, 1);
1368 printk("\nother info that might help us debug this:\n\n");
1369 lockdep_print_held_locks(curr);
1371 printk("\nthe dependencies between %s-irq-safe lock", irqclass);
1372 printk(" and the holding lock:\n");
1373 if (!save_trace(&prev_root->trace))
1375 print_shortest_lock_dependencies(backwards_entry, prev_root);
1377 printk("\nthe dependencies between the lock to be acquired");
1378 printk(" and %s-irq-unsafe lock:\n", irqclass);
1379 if (!save_trace(&next_root->trace))
1381 print_shortest_lock_dependencies(forwards_entry, next_root);
1383 printk("\nstack backtrace:\n");
1390 check_usage(struct task_struct *curr, struct held_lock *prev,
1391 struct held_lock *next, enum lock_usage_bit bit_backwards,
1392 enum lock_usage_bit bit_forwards, const char *irqclass)
1395 struct lock_list this, that;
1396 struct lock_list *uninitialized_var(target_entry);
1397 struct lock_list *uninitialized_var(target_entry1);
1401 this.class = hlock_class(prev);
1402 ret = find_usage_backwards(&this, bit_backwards, &target_entry);
1404 return print_bfs_bug(ret);
1409 that.class = hlock_class(next);
1410 ret = find_usage_forwards(&that, bit_forwards, &target_entry1);
1412 return print_bfs_bug(ret);
1416 return print_bad_irq_dependency(curr, &this, &that,
1417 target_entry, target_entry1,
1419 bit_backwards, bit_forwards, irqclass);
1422 static const char *state_names[] = {
1423 #define LOCKDEP_STATE(__STATE) \
1424 __stringify(__STATE),
1425 #include "lockdep_states.h"
1426 #undef LOCKDEP_STATE
1429 static const char *state_rnames[] = {
1430 #define LOCKDEP_STATE(__STATE) \
1431 __stringify(__STATE)"-READ",
1432 #include "lockdep_states.h"
1433 #undef LOCKDEP_STATE
1436 static inline const char *state_name(enum lock_usage_bit bit)
1438 return (bit & 1) ? state_rnames[bit >> 2] : state_names[bit >> 2];
1441 static int exclusive_bit(int new_bit)
1449 * bit 0 - write/read
1450 * bit 1 - used_in/enabled
1454 int state = new_bit & ~3;
1455 int dir = new_bit & 2;
1458 * keep state, bit flip the direction and strip read.
1460 return state | (dir ^ 2);
1463 static int check_irq_usage(struct task_struct *curr, struct held_lock *prev,
1464 struct held_lock *next, enum lock_usage_bit bit)
1467 * Prove that the new dependency does not connect a hardirq-safe
1468 * lock with a hardirq-unsafe lock - to achieve this we search
1469 * the backwards-subgraph starting at <prev>, and the
1470 * forwards-subgraph starting at <next>:
1472 if (!check_usage(curr, prev, next, bit,
1473 exclusive_bit(bit), state_name(bit)))
1479 * Prove that the new dependency does not connect a hardirq-safe-read
1480 * lock with a hardirq-unsafe lock - to achieve this we search
1481 * the backwards-subgraph starting at <prev>, and the
1482 * forwards-subgraph starting at <next>:
1484 if (!check_usage(curr, prev, next, bit,
1485 exclusive_bit(bit), state_name(bit)))
1492 check_prev_add_irq(struct task_struct *curr, struct held_lock *prev,
1493 struct held_lock *next)
1495 #define LOCKDEP_STATE(__STATE) \
1496 if (!check_irq_usage(curr, prev, next, LOCK_USED_IN_##__STATE)) \
1498 #include "lockdep_states.h"
1499 #undef LOCKDEP_STATE
1504 static void inc_chains(void)
1506 if (current->hardirq_context)
1507 nr_hardirq_chains++;
1509 if (current->softirq_context)
1510 nr_softirq_chains++;
1512 nr_process_chains++;
1519 check_prev_add_irq(struct task_struct *curr, struct held_lock *prev,
1520 struct held_lock *next)
1525 static inline void inc_chains(void)
1527 nr_process_chains++;
1533 print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
1534 struct held_lock *next)
1536 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
1539 printk("\n=============================================\n");
1540 printk( "[ INFO: possible recursive locking detected ]\n");
1541 print_kernel_version();
1542 printk( "---------------------------------------------\n");
1543 printk("%s/%d is trying to acquire lock:\n",
1544 curr->comm, task_pid_nr(curr));
1546 printk("\nbut task is already holding lock:\n");
1549 printk("\nother info that might help us debug this:\n");
1550 lockdep_print_held_locks(curr);
1552 printk("\nstack backtrace:\n");
1559 * Check whether we are holding such a class already.
1561 * (Note that this has to be done separately, because the graph cannot
1562 * detect such classes of deadlocks.)
1564 * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read
1567 check_deadlock(struct task_struct *curr, struct held_lock *next,
1568 struct lockdep_map *next_instance, int read)
1570 struct held_lock *prev;
1571 struct held_lock *nest = NULL;
1574 for (i = 0; i < curr->lockdep_depth; i++) {
1575 prev = curr->held_locks + i;
1577 if (prev->instance == next->nest_lock)
1580 if (hlock_class(prev) != hlock_class(next))
1584 * Allow read-after-read recursion of the same
1585 * lock class (i.e. read_lock(lock)+read_lock(lock)):
1587 if ((read == 2) && prev->read)
1591 * We're holding the nest_lock, which serializes this lock's
1592 * nesting behaviour.
1597 return print_deadlock_bug(curr, prev, next);
1603 * There was a chain-cache miss, and we are about to add a new dependency
1604 * to a previous lock. We recursively validate the following rules:
1606 * - would the adding of the <prev> -> <next> dependency create a
1607 * circular dependency in the graph? [== circular deadlock]
1609 * - does the new prev->next dependency connect any hardirq-safe lock
1610 * (in the full backwards-subgraph starting at <prev>) with any
1611 * hardirq-unsafe lock (in the full forwards-subgraph starting at
1612 * <next>)? [== illegal lock inversion with hardirq contexts]
1614 * - does the new prev->next dependency connect any softirq-safe lock
1615 * (in the full backwards-subgraph starting at <prev>) with any
1616 * softirq-unsafe lock (in the full forwards-subgraph starting at
1617 * <next>)? [== illegal lock inversion with softirq contexts]
1619 * any of these scenarios could lead to a deadlock.
1621 * Then if all the validations pass, we add the forwards and backwards
1625 check_prev_add(struct task_struct *curr, struct held_lock *prev,
1626 struct held_lock *next, int distance, int trylock_loop)
1628 struct lock_list *entry;
1630 struct lock_list this;
1631 struct lock_list *uninitialized_var(target_entry);
1633 * Static variable, serialized by the graph_lock().
1635 * We use this static variable to save the stack trace in case
1636 * we call into this function multiple times due to encountering
1637 * trylocks in the held lock stack.
1639 static struct stack_trace trace;
1642 * Prove that the new <prev> -> <next> dependency would not
1643 * create a circular dependency in the graph. (We do this by
1644 * forward-recursing into the graph starting at <next>, and
1645 * checking whether we can reach <prev>.)
1647 * We are using global variables to control the recursion, to
1648 * keep the stackframe size of the recursive functions low:
1650 this.class = hlock_class(next);
1652 ret = check_noncircular(&this, hlock_class(prev), &target_entry);
1654 return print_circular_bug(&this, target_entry, next, prev);
1655 else if (unlikely(ret < 0))
1656 return print_bfs_bug(ret);
1658 if (!check_prev_add_irq(curr, prev, next))
1662 * For recursive read-locks we do all the dependency checks,
1663 * but we dont store read-triggered dependencies (only
1664 * write-triggered dependencies). This ensures that only the
1665 * write-side dependencies matter, and that if for example a
1666 * write-lock never takes any other locks, then the reads are
1667 * equivalent to a NOP.
1669 if (next->read == 2 || prev->read == 2)
1672 * Is the <prev> -> <next> dependency already present?
1674 * (this may occur even though this is a new chain: consider
1675 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3
1676 * chains - the second one will be new, but L1 already has
1677 * L2 added to its dependency list, due to the first chain.)
1679 list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) {
1680 if (entry->class == hlock_class(next)) {
1682 entry->distance = 1;
1687 if (!trylock_loop && !save_trace(&trace))
1691 * Ok, all validations passed, add the new lock
1692 * to the previous lock's dependency list:
1694 ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
1695 &hlock_class(prev)->locks_after,
1696 next->acquire_ip, distance, &trace);
1701 ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
1702 &hlock_class(next)->locks_before,
1703 next->acquire_ip, distance, &trace);
1708 * Debugging printouts:
1710 if (verbose(hlock_class(prev)) || verbose(hlock_class(next))) {
1712 printk("\n new dependency: ");
1713 print_lock_name(hlock_class(prev));
1715 print_lock_name(hlock_class(next));
1718 return graph_lock();
1724 * Add the dependency to all directly-previous locks that are 'relevant'.
1725 * The ones that are relevant are (in increasing distance from curr):
1726 * all consecutive trylock entries and the final non-trylock entry - or
1727 * the end of this context's lock-chain - whichever comes first.
1730 check_prevs_add(struct task_struct *curr, struct held_lock *next)
1732 int depth = curr->lockdep_depth;
1733 int trylock_loop = 0;
1734 struct held_lock *hlock;
1739 * Depth must not be zero for a non-head lock:
1744 * At least two relevant locks must exist for this
1747 if (curr->held_locks[depth].irq_context !=
1748 curr->held_locks[depth-1].irq_context)
1752 int distance = curr->lockdep_depth - depth + 1;
1753 hlock = curr->held_locks + depth-1;
1755 * Only non-recursive-read entries get new dependencies
1758 if (hlock->read != 2) {
1759 if (!check_prev_add(curr, hlock, next,
1760 distance, trylock_loop))
1763 * Stop after the first non-trylock entry,
1764 * as non-trylock entries have added their
1765 * own direct dependencies already, so this
1766 * lock is connected to them indirectly:
1768 if (!hlock->trylock)
1773 * End of lock-stack?
1778 * Stop the search if we cross into another context:
1780 if (curr->held_locks[depth].irq_context !=
1781 curr->held_locks[depth-1].irq_context)
1787 if (!debug_locks_off_graph_unlock())
1795 unsigned long nr_lock_chains;
1796 struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
1797 int nr_chain_hlocks;
1798 static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
1800 struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
1802 return lock_classes + chain_hlocks[chain->base + i];
1806 * Look up a dependency chain. If the key is not present yet then
1807 * add it and return 1 - in this case the new dependency chain is
1808 * validated. If the key is already hashed, return 0.
1809 * (On return with 1 graph_lock is held.)
1811 static inline int lookup_chain_cache(struct task_struct *curr,
1812 struct held_lock *hlock,
1815 struct lock_class *class = hlock_class(hlock);
1816 struct list_head *hash_head = chainhashentry(chain_key);
1817 struct lock_chain *chain;
1818 struct held_lock *hlock_curr, *hlock_next;
1821 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
1824 * We can walk it lock-free, because entries only get added
1827 list_for_each_entry(chain, hash_head, entry) {
1828 if (chain->chain_key == chain_key) {
1830 debug_atomic_inc(chain_lookup_hits);
1831 if (very_verbose(class))
1832 printk("\nhash chain already cached, key: "
1833 "%016Lx tail class: [%p] %s\n",
1834 (unsigned long long)chain_key,
1835 class->key, class->name);
1839 if (very_verbose(class))
1840 printk("\nnew hash chain, key: %016Lx tail class: [%p] %s\n",
1841 (unsigned long long)chain_key, class->key, class->name);
1843 * Allocate a new chain entry from the static array, and add
1849 * We have to walk the chain again locked - to avoid duplicates:
1851 list_for_each_entry(chain, hash_head, entry) {
1852 if (chain->chain_key == chain_key) {
1857 if (unlikely(nr_lock_chains >= MAX_LOCKDEP_CHAINS)) {
1858 if (!debug_locks_off_graph_unlock())
1861 printk("BUG: MAX_LOCKDEP_CHAINS too low!\n");
1862 printk("turning off the locking correctness validator.\n");
1866 chain = lock_chains + nr_lock_chains++;
1867 chain->chain_key = chain_key;
1868 chain->irq_context = hlock->irq_context;
1869 /* Find the first held_lock of current chain */
1871 for (i = curr->lockdep_depth - 1; i >= 0; i--) {
1872 hlock_curr = curr->held_locks + i;
1873 if (hlock_curr->irq_context != hlock_next->irq_context)
1878 chain->depth = curr->lockdep_depth + 1 - i;
1879 cn = nr_chain_hlocks;
1880 while (cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS) {
1881 n = cmpxchg(&nr_chain_hlocks, cn, cn + chain->depth);
1886 if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
1888 for (j = 0; j < chain->depth - 1; j++, i++) {
1889 int lock_id = curr->held_locks[i].class_idx - 1;
1890 chain_hlocks[chain->base + j] = lock_id;
1892 chain_hlocks[chain->base + j] = class - lock_classes;
1894 list_add_tail_rcu(&chain->entry, hash_head);
1895 debug_atomic_inc(chain_lookup_misses);
1901 static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
1902 struct held_lock *hlock, int chain_head, u64 chain_key)
1905 * Trylock needs to maintain the stack of held locks, but it
1906 * does not add new dependencies, because trylock can be done
1909 * We look up the chain_key and do the O(N^2) check and update of
1910 * the dependencies only if this is a new dependency chain.
1911 * (If lookup_chain_cache() returns with 1 it acquires
1912 * graph_lock for us)
1914 if (!hlock->trylock && (hlock->check == 2) &&
1915 lookup_chain_cache(curr, hlock, chain_key)) {
1917 * Check whether last held lock:
1919 * - is irq-safe, if this lock is irq-unsafe
1920 * - is softirq-safe, if this lock is hardirq-unsafe
1922 * And check whether the new lock's dependency graph
1923 * could lead back to the previous lock.
1925 * any of these scenarios could lead to a deadlock. If
1928 int ret = check_deadlock(curr, hlock, lock, hlock->read);
1933 * Mark recursive read, as we jump over it when
1934 * building dependencies (just like we jump over
1940 * Add dependency only if this lock is not the head
1941 * of the chain, and if it's not a secondary read-lock:
1943 if (!chain_head && ret != 2)
1944 if (!check_prevs_add(curr, hlock))
1948 /* after lookup_chain_cache(): */
1949 if (unlikely(!debug_locks))
1955 static inline int validate_chain(struct task_struct *curr,
1956 struct lockdep_map *lock, struct held_lock *hlock,
1957 int chain_head, u64 chain_key)
1964 * We are building curr_chain_key incrementally, so double-check
1965 * it from scratch, to make sure that it's done correctly:
1967 static void check_chain_key(struct task_struct *curr)
1969 #ifdef CONFIG_DEBUG_LOCKDEP
1970 struct held_lock *hlock, *prev_hlock = NULL;
1974 for (i = 0; i < curr->lockdep_depth; i++) {
1975 hlock = curr->held_locks + i;
1976 if (chain_key != hlock->prev_chain_key) {
1978 WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n",
1979 curr->lockdep_depth, i,
1980 (unsigned long long)chain_key,
1981 (unsigned long long)hlock->prev_chain_key);
1984 id = hlock->class_idx - 1;
1985 if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
1988 if (prev_hlock && (prev_hlock->irq_context !=
1989 hlock->irq_context))
1991 chain_key = iterate_chain_key(chain_key, id);
1994 if (chain_key != curr->curr_chain_key) {
1996 WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n",
1997 curr->lockdep_depth, i,
1998 (unsigned long long)chain_key,
1999 (unsigned long long)curr->curr_chain_key);
2005 print_usage_bug(struct task_struct *curr, struct held_lock *this,
2006 enum lock_usage_bit prev_bit, enum lock_usage_bit new_bit)
2008 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
2011 printk("\n=================================\n");
2012 printk( "[ INFO: inconsistent lock state ]\n");
2013 print_kernel_version();
2014 printk( "---------------------------------\n");
2016 printk("inconsistent {%s} -> {%s} usage.\n",
2017 usage_str[prev_bit], usage_str[new_bit]);
2019 printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] takes:\n",
2020 curr->comm, task_pid_nr(curr),
2021 trace_hardirq_context(curr), hardirq_count() >> HARDIRQ_SHIFT,
2022 trace_softirq_context(curr), softirq_count() >> SOFTIRQ_SHIFT,
2023 trace_hardirqs_enabled(curr),
2024 trace_softirqs_enabled(curr));
2027 printk("{%s} state was registered at:\n", usage_str[prev_bit]);
2028 print_stack_trace(hlock_class(this)->usage_traces + prev_bit, 1);
2030 print_irqtrace_events(curr);
2031 printk("\nother info that might help us debug this:\n");
2032 lockdep_print_held_locks(curr);
2034 printk("\nstack backtrace:\n");
2041 * Print out an error if an invalid bit is set:
2044 valid_state(struct task_struct *curr, struct held_lock *this,
2045 enum lock_usage_bit new_bit, enum lock_usage_bit bad_bit)
2047 if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit)))
2048 return print_usage_bug(curr, this, bad_bit, new_bit);
2052 static int mark_lock(struct task_struct *curr, struct held_lock *this,
2053 enum lock_usage_bit new_bit);
2055 #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
2058 * print irq inversion bug:
2061 print_irq_inversion_bug(struct task_struct *curr,
2062 struct lock_list *root, struct lock_list *other,
2063 struct held_lock *this, int forwards,
2064 const char *irqclass)
2066 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
2069 printk("\n=========================================================\n");
2070 printk( "[ INFO: possible irq lock inversion dependency detected ]\n");
2071 print_kernel_version();
2072 printk( "---------------------------------------------------------\n");
2073 printk("%s/%d just changed the state of lock:\n",
2074 curr->comm, task_pid_nr(curr));
2077 printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass);
2079 printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass);
2080 print_lock_name(other->class);
2081 printk("\n\nand interrupts could create inverse lock ordering between them.\n\n");
2083 printk("\nother info that might help us debug this:\n");
2084 lockdep_print_held_locks(curr);
2086 printk("\nthe shortest dependencies between 2nd lock and 1st lock:\n");
2087 if (!save_trace(&root->trace))
2089 print_shortest_lock_dependencies(other, root);
2091 printk("\nstack backtrace:\n");
2098 * Prove that in the forwards-direction subgraph starting at <this>
2099 * there is no lock matching <mask>:
2102 check_usage_forwards(struct task_struct *curr, struct held_lock *this,
2103 enum lock_usage_bit bit, const char *irqclass)
2106 struct lock_list root;
2107 struct lock_list *uninitialized_var(target_entry);
2110 root.class = hlock_class(this);
2111 ret = find_usage_forwards(&root, bit, &target_entry);
2113 return print_bfs_bug(ret);
2117 return print_irq_inversion_bug(curr, &root, target_entry,
2122 * Prove that in the backwards-direction subgraph starting at <this>
2123 * there is no lock matching <mask>:
2126 check_usage_backwards(struct task_struct *curr, struct held_lock *this,
2127 enum lock_usage_bit bit, const char *irqclass)
2130 struct lock_list root;
2131 struct lock_list *uninitialized_var(target_entry);
2134 root.class = hlock_class(this);
2135 ret = find_usage_backwards(&root, bit, &target_entry);
2137 return print_bfs_bug(ret);
2141 return print_irq_inversion_bug(curr, &root, target_entry,
2145 void print_irqtrace_events(struct task_struct *curr)
2147 printk("irq event stamp: %u\n", curr->irq_events);
2148 printk("hardirqs last enabled at (%u): ", curr->hardirq_enable_event);
2149 print_ip_sym(curr->hardirq_enable_ip);
2150 printk("hardirqs last disabled at (%u): ", curr->hardirq_disable_event);
2151 print_ip_sym(curr->hardirq_disable_ip);
2152 printk("softirqs last enabled at (%u): ", curr->softirq_enable_event);
2153 print_ip_sym(curr->softirq_enable_ip);
2154 printk("softirqs last disabled at (%u): ", curr->softirq_disable_event);
2155 print_ip_sym(curr->softirq_disable_ip);
2158 static int HARDIRQ_verbose(struct lock_class *class)
2161 return class_filter(class);
2166 static int SOFTIRQ_verbose(struct lock_class *class)
2169 return class_filter(class);
2174 static int RECLAIM_FS_verbose(struct lock_class *class)
2177 return class_filter(class);
2182 #define STRICT_READ_CHECKS 1
2184 static int (*state_verbose_f[])(struct lock_class *class) = {
2185 #define LOCKDEP_STATE(__STATE) \
2187 #include "lockdep_states.h"
2188 #undef LOCKDEP_STATE
2191 static inline int state_verbose(enum lock_usage_bit bit,
2192 struct lock_class *class)
2194 return state_verbose_f[bit >> 2](class);
2197 typedef int (*check_usage_f)(struct task_struct *, struct held_lock *,
2198 enum lock_usage_bit bit, const char *name);
2201 mark_lock_irq(struct task_struct *curr, struct held_lock *this,
2202 enum lock_usage_bit new_bit)
2204 int excl_bit = exclusive_bit(new_bit);
2205 int read = new_bit & 1;
2206 int dir = new_bit & 2;
2209 * mark USED_IN has to look forwards -- to ensure no dependency
2210 * has ENABLED state, which would allow recursion deadlocks.
2212 * mark ENABLED has to look backwards -- to ensure no dependee
2213 * has USED_IN state, which, again, would allow recursion deadlocks.
2215 check_usage_f usage = dir ?
2216 check_usage_backwards : check_usage_forwards;
2219 * Validate that this particular lock does not have conflicting
2222 if (!valid_state(curr, this, new_bit, excl_bit))
2226 * Validate that the lock dependencies don't have conflicting usage
2229 if ((!read || !dir || STRICT_READ_CHECKS) &&
2230 !usage(curr, this, excl_bit, state_name(new_bit & ~1)))
2234 * Check for read in write conflicts
2237 if (!valid_state(curr, this, new_bit, excl_bit + 1))
2240 if (STRICT_READ_CHECKS &&
2241 !usage(curr, this, excl_bit + 1,
2242 state_name(new_bit + 1)))
2246 if (state_verbose(new_bit, hlock_class(this)))
2253 #define LOCKDEP_STATE(__STATE) __STATE,
2254 #include "lockdep_states.h"
2255 #undef LOCKDEP_STATE
2259 * Mark all held locks with a usage bit:
2262 mark_held_locks(struct task_struct *curr, enum mark_type mark)
2264 enum lock_usage_bit usage_bit;
2265 struct held_lock *hlock;
2268 for (i = 0; i < curr->lockdep_depth; i++) {
2269 hlock = curr->held_locks + i;
2271 usage_bit = 2 + (mark << 2); /* ENABLED */
2273 usage_bit += 1; /* READ */
2275 BUG_ON(usage_bit >= LOCK_USAGE_STATES);
2277 if (!mark_lock(curr, hlock, usage_bit))
2285 * Debugging helper: via this flag we know that we are in
2286 * 'early bootup code', and will warn about any invalid irqs-on event:
2288 static int early_boot_irqs_enabled;
2290 void early_boot_irqs_off(void)
2292 early_boot_irqs_enabled = 0;
2295 void early_boot_irqs_on(void)
2297 early_boot_irqs_enabled = 1;
2301 * Hardirqs will be enabled:
2303 void trace_hardirqs_on_caller(unsigned long ip)
2305 struct task_struct *curr = current;
2307 time_hardirqs_on(CALLER_ADDR0, ip);
2309 if (unlikely(!debug_locks || current->lockdep_recursion))
2312 if (DEBUG_LOCKS_WARN_ON(unlikely(!early_boot_irqs_enabled)))
2315 if (unlikely(curr->hardirqs_enabled)) {
2317 * Neither irq nor preemption are disabled here
2318 * so this is racy by nature but loosing one hit
2319 * in a stat is not a big deal.
2321 __debug_atomic_inc(redundant_hardirqs_on);
2324 /* we'll do an OFF -> ON transition: */
2325 curr->hardirqs_enabled = 1;
2327 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2329 if (DEBUG_LOCKS_WARN_ON(current->hardirq_context))
2332 * We are going to turn hardirqs on, so set the
2333 * usage bit for all held locks:
2335 if (!mark_held_locks(curr, HARDIRQ))
2338 * If we have softirqs enabled, then set the usage
2339 * bit for all held locks. (disabled hardirqs prevented
2340 * this bit from being set before)
2342 if (curr->softirqs_enabled)
2343 if (!mark_held_locks(curr, SOFTIRQ))
2346 curr->hardirq_enable_ip = ip;
2347 curr->hardirq_enable_event = ++curr->irq_events;
2348 debug_atomic_inc(hardirqs_on_events);
2350 EXPORT_SYMBOL(trace_hardirqs_on_caller);
2352 void trace_hardirqs_on(void)
2354 trace_hardirqs_on_caller(CALLER_ADDR0);
2356 EXPORT_SYMBOL(trace_hardirqs_on);
2359 * Hardirqs were disabled:
2361 void trace_hardirqs_off_caller(unsigned long ip)
2363 struct task_struct *curr = current;
2365 time_hardirqs_off(CALLER_ADDR0, ip);
2367 if (unlikely(!debug_locks || current->lockdep_recursion))
2370 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2373 if (curr->hardirqs_enabled) {
2375 * We have done an ON -> OFF transition:
2377 curr->hardirqs_enabled = 0;
2378 curr->hardirq_disable_ip = ip;
2379 curr->hardirq_disable_event = ++curr->irq_events;
2380 debug_atomic_inc(hardirqs_off_events);
2382 debug_atomic_inc(redundant_hardirqs_off);
2384 EXPORT_SYMBOL(trace_hardirqs_off_caller);
2386 void trace_hardirqs_off(void)
2388 trace_hardirqs_off_caller(CALLER_ADDR0);
2390 EXPORT_SYMBOL(trace_hardirqs_off);
2393 * Softirqs will be enabled:
2395 void trace_softirqs_on(unsigned long ip)
2397 struct task_struct *curr = current;
2399 if (unlikely(!debug_locks))
2402 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2405 if (curr->softirqs_enabled) {
2406 debug_atomic_inc(redundant_softirqs_on);
2411 * We'll do an OFF -> ON transition:
2413 curr->softirqs_enabled = 1;
2414 curr->softirq_enable_ip = ip;
2415 curr->softirq_enable_event = ++curr->irq_events;
2416 debug_atomic_inc(softirqs_on_events);
2418 * We are going to turn softirqs on, so set the
2419 * usage bit for all held locks, if hardirqs are
2422 if (curr->hardirqs_enabled)
2423 mark_held_locks(curr, SOFTIRQ);
2427 * Softirqs were disabled:
2429 void trace_softirqs_off(unsigned long ip)
2431 struct task_struct *curr = current;
2433 if (unlikely(!debug_locks))
2436 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2439 if (curr->softirqs_enabled) {
2441 * We have done an ON -> OFF transition:
2443 curr->softirqs_enabled = 0;
2444 curr->softirq_disable_ip = ip;
2445 curr->softirq_disable_event = ++curr->irq_events;
2446 debug_atomic_inc(softirqs_off_events);
2447 DEBUG_LOCKS_WARN_ON(!softirq_count());
2449 debug_atomic_inc(redundant_softirqs_off);
2452 static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags)
2454 struct task_struct *curr = current;
2456 if (unlikely(!debug_locks))
2459 /* no reclaim without waiting on it */
2460 if (!(gfp_mask & __GFP_WAIT))
2463 /* this guy won't enter reclaim */
2464 if ((curr->flags & PF_MEMALLOC) && !(gfp_mask & __GFP_NOMEMALLOC))
2467 /* We're only interested __GFP_FS allocations for now */
2468 if (!(gfp_mask & __GFP_FS))
2471 if (DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags)))
2474 mark_held_locks(curr, RECLAIM_FS);
2477 static void check_flags(unsigned long flags);
2479 void lockdep_trace_alloc(gfp_t gfp_mask)
2481 unsigned long flags;
2483 if (unlikely(current->lockdep_recursion))
2486 raw_local_irq_save(flags);
2488 current->lockdep_recursion = 1;
2489 __lockdep_trace_alloc(gfp_mask, flags);
2490 current->lockdep_recursion = 0;
2491 raw_local_irq_restore(flags);
2494 static int mark_irqflags(struct task_struct *curr, struct held_lock *hlock)
2497 * If non-trylock use in a hardirq or softirq context, then
2498 * mark the lock as used in these contexts:
2500 if (!hlock->trylock) {
2502 if (curr->hardirq_context)
2503 if (!mark_lock(curr, hlock,
2504 LOCK_USED_IN_HARDIRQ_READ))
2506 if (curr->softirq_context)
2507 if (!mark_lock(curr, hlock,
2508 LOCK_USED_IN_SOFTIRQ_READ))
2511 if (curr->hardirq_context)
2512 if (!mark_lock(curr, hlock, LOCK_USED_IN_HARDIRQ))
2514 if (curr->softirq_context)
2515 if (!mark_lock(curr, hlock, LOCK_USED_IN_SOFTIRQ))
2519 if (!hlock->hardirqs_off) {
2521 if (!mark_lock(curr, hlock,
2522 LOCK_ENABLED_HARDIRQ_READ))
2524 if (curr->softirqs_enabled)
2525 if (!mark_lock(curr, hlock,
2526 LOCK_ENABLED_SOFTIRQ_READ))
2529 if (!mark_lock(curr, hlock,
2530 LOCK_ENABLED_HARDIRQ))
2532 if (curr->softirqs_enabled)
2533 if (!mark_lock(curr, hlock,
2534 LOCK_ENABLED_SOFTIRQ))
2540 * We reuse the irq context infrastructure more broadly as a general
2541 * context checking code. This tests GFP_FS recursion (a lock taken
2542 * during reclaim for a GFP_FS allocation is held over a GFP_FS
2545 if (!hlock->trylock && (curr->lockdep_reclaim_gfp & __GFP_FS)) {
2547 if (!mark_lock(curr, hlock, LOCK_USED_IN_RECLAIM_FS_READ))
2550 if (!mark_lock(curr, hlock, LOCK_USED_IN_RECLAIM_FS))
2558 static int separate_irq_context(struct task_struct *curr,
2559 struct held_lock *hlock)
2561 unsigned int depth = curr->lockdep_depth;
2564 * Keep track of points where we cross into an interrupt context:
2566 hlock->irq_context = 2*(curr->hardirq_context ? 1 : 0) +
2567 curr->softirq_context;
2569 struct held_lock *prev_hlock;
2571 prev_hlock = curr->held_locks + depth-1;
2573 * If we cross into another context, reset the
2574 * hash key (this also prevents the checking and the
2575 * adding of the dependency to 'prev'):
2577 if (prev_hlock->irq_context != hlock->irq_context)
2586 int mark_lock_irq(struct task_struct *curr, struct held_lock *this,
2587 enum lock_usage_bit new_bit)
2593 static inline int mark_irqflags(struct task_struct *curr,
2594 struct held_lock *hlock)
2599 static inline int separate_irq_context(struct task_struct *curr,
2600 struct held_lock *hlock)
2605 void lockdep_trace_alloc(gfp_t gfp_mask)
2612 * Mark a lock with a usage bit, and validate the state transition:
2614 static int mark_lock(struct task_struct *curr, struct held_lock *this,
2615 enum lock_usage_bit new_bit)
2617 unsigned int new_mask = 1 << new_bit, ret = 1;
2620 * If already set then do not dirty the cacheline,
2621 * nor do any checks:
2623 if (likely(hlock_class(this)->usage_mask & new_mask))
2629 * Make sure we didnt race:
2631 if (unlikely(hlock_class(this)->usage_mask & new_mask)) {
2636 hlock_class(this)->usage_mask |= new_mask;
2638 if (!save_trace(hlock_class(this)->usage_traces + new_bit))
2642 #define LOCKDEP_STATE(__STATE) \
2643 case LOCK_USED_IN_##__STATE: \
2644 case LOCK_USED_IN_##__STATE##_READ: \
2645 case LOCK_ENABLED_##__STATE: \
2646 case LOCK_ENABLED_##__STATE##_READ:
2647 #include "lockdep_states.h"
2648 #undef LOCKDEP_STATE
2649 ret = mark_lock_irq(curr, this, new_bit);
2654 debug_atomic_dec(nr_unused_locks);
2657 if (!debug_locks_off_graph_unlock())
2666 * We must printk outside of the graph_lock:
2669 printk("\nmarked lock as {%s}:\n", usage_str[new_bit]);
2671 print_irqtrace_events(curr);
2679 * Initialize a lock instance's lock-class mapping info:
2681 void lockdep_init_map(struct lockdep_map *lock, const char *name,
2682 struct lock_class_key *key, int subclass)
2686 for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
2687 lock->class_cache[i] = NULL;
2689 #ifdef CONFIG_LOCK_STAT
2690 lock->cpu = raw_smp_processor_id();
2693 if (DEBUG_LOCKS_WARN_ON(!name)) {
2694 lock->name = "NULL";
2700 if (DEBUG_LOCKS_WARN_ON(!key))
2703 * Sanity check, the lock-class key must be persistent:
2705 if (!static_obj(key)) {
2706 printk("BUG: key %p not in .data!\n", key);
2707 DEBUG_LOCKS_WARN_ON(1);
2712 if (unlikely(!debug_locks))
2716 register_lock_class(lock, subclass, 1);
2718 EXPORT_SYMBOL_GPL(lockdep_init_map);
2720 struct lock_class_key __lockdep_no_validate__;
2723 * This gets called for every mutex_lock*()/spin_lock*() operation.
2724 * We maintain the dependency maps and validate the locking attempt:
2726 static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
2727 int trylock, int read, int check, int hardirqs_off,
2728 struct lockdep_map *nest_lock, unsigned long ip,
2731 struct task_struct *curr = current;
2732 struct lock_class *class = NULL;
2733 struct held_lock *hlock;
2734 unsigned int depth, id;
2742 if (unlikely(!debug_locks))
2745 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2748 if (unlikely(subclass >= MAX_LOCKDEP_SUBCLASSES)) {
2750 printk("BUG: MAX_LOCKDEP_SUBCLASSES too low!\n");
2751 printk("turning off the locking correctness validator.\n");
2756 if (lock->key == &__lockdep_no_validate__)
2759 if (subclass < NR_LOCKDEP_CACHING_CLASSES)
2760 class = lock->class_cache[subclass];
2764 if (unlikely(!class)) {
2765 class = register_lock_class(lock, subclass, 0);
2769 atomic_inc((atomic_t *)&class->ops);
2770 if (very_verbose(class)) {
2771 printk("\nacquire class [%p] %s", class->key, class->name);
2772 if (class->name_version > 1)
2773 printk("#%d", class->name_version);
2779 * Add the lock to the list of currently held locks.
2780 * (we dont increase the depth just yet, up until the
2781 * dependency checks are done)
2783 depth = curr->lockdep_depth;
2784 if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH))
2787 class_idx = class - lock_classes + 1;
2790 hlock = curr->held_locks + depth - 1;
2791 if (hlock->class_idx == class_idx && nest_lock) {
2792 if (hlock->references)
2793 hlock->references++;
2795 hlock->references = 2;
2801 hlock = curr->held_locks + depth;
2802 if (DEBUG_LOCKS_WARN_ON(!class))
2804 hlock->class_idx = class_idx;
2805 hlock->acquire_ip = ip;
2806 hlock->instance = lock;
2807 hlock->nest_lock = nest_lock;
2808 hlock->trylock = trylock;
2810 hlock->check = check;
2811 hlock->hardirqs_off = !!hardirqs_off;
2812 hlock->references = references;
2813 #ifdef CONFIG_LOCK_STAT
2814 hlock->waittime_stamp = 0;
2815 hlock->holdtime_stamp = lockstat_clock();
2818 if (check == 2 && !mark_irqflags(curr, hlock))
2821 /* mark it as used: */
2822 if (!mark_lock(curr, hlock, LOCK_USED))
2826 * Calculate the chain hash: it's the combined hash of all the
2827 * lock keys along the dependency chain. We save the hash value
2828 * at every step so that we can get the current hash easily
2829 * after unlock. The chain hash is then used to cache dependency
2832 * The 'key ID' is what is the most compact key value to drive
2833 * the hash, not class->key.
2835 id = class - lock_classes;
2836 if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
2839 chain_key = curr->curr_chain_key;
2841 if (DEBUG_LOCKS_WARN_ON(chain_key != 0))
2846 hlock->prev_chain_key = chain_key;
2847 if (separate_irq_context(curr, hlock)) {
2851 chain_key = iterate_chain_key(chain_key, id);
2853 if (!validate_chain(curr, lock, hlock, chain_head, chain_key))
2856 curr->curr_chain_key = chain_key;
2857 curr->lockdep_depth++;
2858 check_chain_key(curr);
2859 #ifdef CONFIG_DEBUG_LOCKDEP
2860 if (unlikely(!debug_locks))
2863 if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) {
2865 printk("BUG: MAX_LOCK_DEPTH too low!\n");
2866 printk("turning off the locking correctness validator.\n");
2871 if (unlikely(curr->lockdep_depth > max_lockdep_depth))
2872 max_lockdep_depth = curr->lockdep_depth;
2878 print_unlock_inbalance_bug(struct task_struct *curr, struct lockdep_map *lock,
2881 if (!debug_locks_off())
2883 if (debug_locks_silent)
2886 printk("\n=====================================\n");
2887 printk( "[ BUG: bad unlock balance detected! ]\n");
2888 printk( "-------------------------------------\n");
2889 printk("%s/%d is trying to release lock (",
2890 curr->comm, task_pid_nr(curr));
2891 print_lockdep_cache(lock);
2894 printk("but there are no more locks to release!\n");
2895 printk("\nother info that might help us debug this:\n");
2896 lockdep_print_held_locks(curr);
2898 printk("\nstack backtrace:\n");
2905 * Common debugging checks for both nested and non-nested unlock:
2907 static int check_unlock(struct task_struct *curr, struct lockdep_map *lock,
2910 if (unlikely(!debug_locks))
2912 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
2915 if (curr->lockdep_depth <= 0)
2916 return print_unlock_inbalance_bug(curr, lock, ip);
2921 static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock)
2923 if (hlock->instance == lock)
2926 if (hlock->references) {
2927 struct lock_class *class = lock->class_cache[0];
2930 class = look_up_lock_class(lock, 0);
2932 if (DEBUG_LOCKS_WARN_ON(!class))
2935 if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock))
2938 if (hlock->class_idx == class - lock_classes + 1)
2946 __lock_set_class(struct lockdep_map *lock, const char *name,
2947 struct lock_class_key *key, unsigned int subclass,
2950 struct task_struct *curr = current;
2951 struct held_lock *hlock, *prev_hlock;
2952 struct lock_class *class;
2956 depth = curr->lockdep_depth;
2957 if (DEBUG_LOCKS_WARN_ON(!depth))
2961 for (i = depth-1; i >= 0; i--) {
2962 hlock = curr->held_locks + i;
2964 * We must not cross into another context:
2966 if (prev_hlock && prev_hlock->irq_context != hlock->irq_context)
2968 if (match_held_lock(hlock, lock))
2972 return print_unlock_inbalance_bug(curr, lock, ip);
2975 lockdep_init_map(lock, name, key, 0);
2976 class = register_lock_class(lock, subclass, 0);
2977 hlock->class_idx = class - lock_classes + 1;
2979 curr->lockdep_depth = i;
2980 curr->curr_chain_key = hlock->prev_chain_key;
2982 for (; i < depth; i++) {
2983 hlock = curr->held_locks + i;
2984 if (!__lock_acquire(hlock->instance,
2985 hlock_class(hlock)->subclass, hlock->trylock,
2986 hlock->read, hlock->check, hlock->hardirqs_off,
2987 hlock->nest_lock, hlock->acquire_ip,
2992 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth))
2998 * Remove the lock to the list of currently held locks in a
2999 * potentially non-nested (out of order) manner. This is a
3000 * relatively rare operation, as all the unlock APIs default
3001 * to nested mode (which uses lock_release()):
3004 lock_release_non_nested(struct task_struct *curr,
3005 struct lockdep_map *lock, unsigned long ip)
3007 struct held_lock *hlock, *prev_hlock;
3012 * Check whether the lock exists in the current stack
3015 depth = curr->lockdep_depth;
3016 if (DEBUG_LOCKS_WARN_ON(!depth))
3020 for (i = depth-1; i >= 0; i--) {
3021 hlock = curr->held_locks + i;
3023 * We must not cross into another context:
3025 if (prev_hlock && prev_hlock->irq_context != hlock->irq_context)
3027 if (match_held_lock(hlock, lock))
3031 return print_unlock_inbalance_bug(curr, lock, ip);
3034 if (hlock->instance == lock)
3035 lock_release_holdtime(hlock);
3037 if (hlock->references) {
3038 hlock->references--;
3039 if (hlock->references) {
3041 * We had, and after removing one, still have
3042 * references, the current lock stack is still
3043 * valid. We're done!
3050 * We have the right lock to unlock, 'hlock' points to it.
3051 * Now we remove it from the stack, and add back the other
3052 * entries (if any), recalculating the hash along the way:
3055 curr->lockdep_depth = i;
3056 curr->curr_chain_key = hlock->prev_chain_key;
3058 for (i++; i < depth; i++) {
3059 hlock = curr->held_locks + i;
3060 if (!__lock_acquire(hlock->instance,
3061 hlock_class(hlock)->subclass, hlock->trylock,
3062 hlock->read, hlock->check, hlock->hardirqs_off,
3063 hlock->nest_lock, hlock->acquire_ip,
3068 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - 1))
3074 * Remove the lock to the list of currently held locks - this gets
3075 * called on mutex_unlock()/spin_unlock*() (or on a failed
3076 * mutex_lock_interruptible()). This is done for unlocks that nest
3077 * perfectly. (i.e. the current top of the lock-stack is unlocked)
3079 static int lock_release_nested(struct task_struct *curr,
3080 struct lockdep_map *lock, unsigned long ip)
3082 struct held_lock *hlock;
3086 * Pop off the top of the lock stack:
3088 depth = curr->lockdep_depth - 1;
3089 hlock = curr->held_locks + depth;
3092 * Is the unlock non-nested:
3094 if (hlock->instance != lock || hlock->references)
3095 return lock_release_non_nested(curr, lock, ip);
3096 curr->lockdep_depth--;
3098 if (DEBUG_LOCKS_WARN_ON(!depth && (hlock->prev_chain_key != 0)))
3101 curr->curr_chain_key = hlock->prev_chain_key;
3103 lock_release_holdtime(hlock);
3105 #ifdef CONFIG_DEBUG_LOCKDEP
3106 hlock->prev_chain_key = 0;
3107 hlock->class_idx = 0;
3108 hlock->acquire_ip = 0;
3109 hlock->irq_context = 0;
3115 * Remove the lock to the list of currently held locks - this gets
3116 * called on mutex_unlock()/spin_unlock*() (or on a failed
3117 * mutex_lock_interruptible()). This is done for unlocks that nest
3118 * perfectly. (i.e. the current top of the lock-stack is unlocked)
3121 __lock_release(struct lockdep_map *lock, int nested, unsigned long ip)
3123 struct task_struct *curr = current;
3125 if (!check_unlock(curr, lock, ip))
3129 if (!lock_release_nested(curr, lock, ip))
3132 if (!lock_release_non_nested(curr, lock, ip))
3136 check_chain_key(curr);
3139 static int __lock_is_held(struct lockdep_map *lock)
3141 struct task_struct *curr = current;
3144 for (i = 0; i < curr->lockdep_depth; i++) {
3145 struct held_lock *hlock = curr->held_locks + i;
3147 if (match_held_lock(hlock, lock))
3155 * Check whether we follow the irq-flags state precisely:
3157 static void check_flags(unsigned long flags)
3159 #if defined(CONFIG_PROVE_LOCKING) && defined(CONFIG_DEBUG_LOCKDEP) && \
3160 defined(CONFIG_TRACE_IRQFLAGS)
3164 if (irqs_disabled_flags(flags)) {
3165 if (DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled)) {
3166 printk("possible reason: unannotated irqs-off.\n");
3169 if (DEBUG_LOCKS_WARN_ON(!current->hardirqs_enabled)) {
3170 printk("possible reason: unannotated irqs-on.\n");
3175 * We dont accurately track softirq state in e.g.
3176 * hardirq contexts (such as on 4KSTACKS), so only
3177 * check if not in hardirq contexts:
3179 if (!hardirq_count()) {
3180 if (softirq_count())
3181 DEBUG_LOCKS_WARN_ON(current->softirqs_enabled);
3183 DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
3187 print_irqtrace_events(current);
3191 void lock_set_class(struct lockdep_map *lock, const char *name,
3192 struct lock_class_key *key, unsigned int subclass,
3195 unsigned long flags;
3197 if (unlikely(current->lockdep_recursion))
3200 raw_local_irq_save(flags);
3201 current->lockdep_recursion = 1;
3203 if (__lock_set_class(lock, name, key, subclass, ip))
3204 check_chain_key(current);
3205 current->lockdep_recursion = 0;
3206 raw_local_irq_restore(flags);
3208 EXPORT_SYMBOL_GPL(lock_set_class);
3211 * We are not always called with irqs disabled - do that here,
3212 * and also avoid lockdep recursion:
3214 void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3215 int trylock, int read, int check,
3216 struct lockdep_map *nest_lock, unsigned long ip)
3218 unsigned long flags;
3220 if (unlikely(current->lockdep_recursion))
3223 raw_local_irq_save(flags);
3226 current->lockdep_recursion = 1;
3227 trace_lock_acquire(lock, subclass, trylock, read, check, nest_lock, ip);
3228 __lock_acquire(lock, subclass, trylock, read, check,
3229 irqs_disabled_flags(flags), nest_lock, ip, 0);
3230 current->lockdep_recursion = 0;
3231 raw_local_irq_restore(flags);
3233 EXPORT_SYMBOL_GPL(lock_acquire);
3235 void lock_release(struct lockdep_map *lock, int nested,
3238 unsigned long flags;
3240 if (unlikely(current->lockdep_recursion))
3243 raw_local_irq_save(flags);
3245 current->lockdep_recursion = 1;
3246 trace_lock_release(lock, ip);
3247 __lock_release(lock, nested, ip);
3248 current->lockdep_recursion = 0;
3249 raw_local_irq_restore(flags);
3251 EXPORT_SYMBOL_GPL(lock_release);
3253 int lock_is_held(struct lockdep_map *lock)
3255 unsigned long flags;
3258 if (unlikely(current->lockdep_recursion))
3261 raw_local_irq_save(flags);
3264 current->lockdep_recursion = 1;
3265 ret = __lock_is_held(lock);
3266 current->lockdep_recursion = 0;
3267 raw_local_irq_restore(flags);
3271 EXPORT_SYMBOL_GPL(lock_is_held);
3273 void lockdep_set_current_reclaim_state(gfp_t gfp_mask)
3275 current->lockdep_reclaim_gfp = gfp_mask;
3278 void lockdep_clear_current_reclaim_state(void)
3280 current->lockdep_reclaim_gfp = 0;
3283 #ifdef CONFIG_LOCK_STAT
3285 print_lock_contention_bug(struct task_struct *curr, struct lockdep_map *lock,
3288 if (!debug_locks_off())
3290 if (debug_locks_silent)
3293 printk("\n=================================\n");
3294 printk( "[ BUG: bad contention detected! ]\n");
3295 printk( "---------------------------------\n");
3296 printk("%s/%d is trying to contend lock (",
3297 curr->comm, task_pid_nr(curr));
3298 print_lockdep_cache(lock);
3301 printk("but there are no locks held!\n");
3302 printk("\nother info that might help us debug this:\n");
3303 lockdep_print_held_locks(curr);
3305 printk("\nstack backtrace:\n");
3312 __lock_contended(struct lockdep_map *lock, unsigned long ip)
3314 struct task_struct *curr = current;
3315 struct held_lock *hlock, *prev_hlock;
3316 struct lock_class_stats *stats;
3318 int i, contention_point, contending_point;
3320 depth = curr->lockdep_depth;
3321 if (DEBUG_LOCKS_WARN_ON(!depth))
3325 for (i = depth-1; i >= 0; i--) {
3326 hlock = curr->held_locks + i;
3328 * We must not cross into another context:
3330 if (prev_hlock && prev_hlock->irq_context != hlock->irq_context)
3332 if (match_held_lock(hlock, lock))
3336 print_lock_contention_bug(curr, lock, ip);
3340 if (hlock->instance != lock)
3343 hlock->waittime_stamp = lockstat_clock();
3345 contention_point = lock_point(hlock_class(hlock)->contention_point, ip);
3346 contending_point = lock_point(hlock_class(hlock)->contending_point,
3349 stats = get_lock_stats(hlock_class(hlock));
3350 if (contention_point < LOCKSTAT_POINTS)
3351 stats->contention_point[contention_point]++;
3352 if (contending_point < LOCKSTAT_POINTS)
3353 stats->contending_point[contending_point]++;
3354 if (lock->cpu != smp_processor_id())
3355 stats->bounces[bounce_contended + !!hlock->read]++;
3356 put_lock_stats(stats);
3360 __lock_acquired(struct lockdep_map *lock, unsigned long ip)
3362 struct task_struct *curr = current;
3363 struct held_lock *hlock, *prev_hlock;
3364 struct lock_class_stats *stats;
3366 u64 now, waittime = 0;
3369 depth = curr->lockdep_depth;
3370 if (DEBUG_LOCKS_WARN_ON(!depth))
3374 for (i = depth-1; i >= 0; i--) {
3375 hlock = curr->held_locks + i;
3377 * We must not cross into another context:
3379 if (prev_hlock && prev_hlock->irq_context != hlock->irq_context)
3381 if (match_held_lock(hlock, lock))
3385 print_lock_contention_bug(curr, lock, _RET_IP_);
3389 if (hlock->instance != lock)
3392 cpu = smp_processor_id();
3393 if (hlock->waittime_stamp) {
3394 now = lockstat_clock();
3395 waittime = now - hlock->waittime_stamp;
3396 hlock->holdtime_stamp = now;
3399 trace_lock_acquired(lock, ip);
3401 stats = get_lock_stats(hlock_class(hlock));
3404 lock_time_inc(&stats->read_waittime, waittime);
3406 lock_time_inc(&stats->write_waittime, waittime);
3408 if (lock->cpu != cpu)
3409 stats->bounces[bounce_acquired + !!hlock->read]++;
3410 put_lock_stats(stats);
3416 void lock_contended(struct lockdep_map *lock, unsigned long ip)
3418 unsigned long flags;
3420 if (unlikely(!lock_stat))
3423 if (unlikely(current->lockdep_recursion))
3426 raw_local_irq_save(flags);
3428 current->lockdep_recursion = 1;
3429 trace_lock_contended(lock, ip);
3430 __lock_contended(lock, ip);
3431 current->lockdep_recursion = 0;
3432 raw_local_irq_restore(flags);
3434 EXPORT_SYMBOL_GPL(lock_contended);
3436 void lock_acquired(struct lockdep_map *lock, unsigned long ip)
3438 unsigned long flags;
3440 if (unlikely(!lock_stat))
3443 if (unlikely(current->lockdep_recursion))
3446 raw_local_irq_save(flags);
3448 current->lockdep_recursion = 1;
3449 __lock_acquired(lock, ip);
3450 current->lockdep_recursion = 0;
3451 raw_local_irq_restore(flags);
3453 EXPORT_SYMBOL_GPL(lock_acquired);
3457 * Used by the testsuite, sanitize the validator state
3458 * after a simulated failure:
3461 void lockdep_reset(void)
3463 unsigned long flags;
3466 raw_local_irq_save(flags);
3467 current->curr_chain_key = 0;
3468 current->lockdep_depth = 0;
3469 current->lockdep_recursion = 0;
3470 memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock));
3471 nr_hardirq_chains = 0;
3472 nr_softirq_chains = 0;
3473 nr_process_chains = 0;
3475 for (i = 0; i < CHAINHASH_SIZE; i++)
3476 INIT_LIST_HEAD(chainhash_table + i);
3477 raw_local_irq_restore(flags);
3480 static void zap_class(struct lock_class *class)
3485 * Remove all dependencies this lock is
3488 for (i = 0; i < nr_list_entries; i++) {
3489 if (list_entries[i].class == class)
3490 list_del_rcu(&list_entries[i].entry);
3493 * Unhash the class and remove it from the all_lock_classes list:
3495 list_del_rcu(&class->hash_entry);
3496 list_del_rcu(&class->lock_entry);
3501 static inline int within(const void *addr, void *start, unsigned long size)
3503 return addr >= start && addr < start + size;
3506 void lockdep_free_key_range(void *start, unsigned long size)
3508 struct lock_class *class, *next;
3509 struct list_head *head;
3510 unsigned long flags;
3514 raw_local_irq_save(flags);
3515 locked = graph_lock();
3518 * Unhash all classes that were created by this module:
3520 for (i = 0; i < CLASSHASH_SIZE; i++) {
3521 head = classhash_table + i;
3522 if (list_empty(head))
3524 list_for_each_entry_safe(class, next, head, hash_entry) {
3525 if (within(class->key, start, size))
3527 else if (within(class->name, start, size))
3534 raw_local_irq_restore(flags);
3537 void lockdep_reset_lock(struct lockdep_map *lock)
3539 struct lock_class *class, *next;
3540 struct list_head *head;
3541 unsigned long flags;
3545 raw_local_irq_save(flags);
3548 * Remove all classes this lock might have:
3550 for (j = 0; j < MAX_LOCKDEP_SUBCLASSES; j++) {
3552 * If the class exists we look it up and zap it:
3554 class = look_up_lock_class(lock, j);
3559 * Debug check: in the end all mapped classes should
3562 locked = graph_lock();
3563 for (i = 0; i < CLASSHASH_SIZE; i++) {
3564 head = classhash_table + i;
3565 if (list_empty(head))
3567 list_for_each_entry_safe(class, next, head, hash_entry) {
3570 for (j = 0; j < NR_LOCKDEP_CACHING_CLASSES; j++)
3571 match |= class == lock->class_cache[j];
3573 if (unlikely(match)) {
3574 if (debug_locks_off_graph_unlock())
3584 raw_local_irq_restore(flags);
3587 void lockdep_init(void)
3592 * Some architectures have their own start_kernel()
3593 * code which calls lockdep_init(), while we also
3594 * call lockdep_init() from the start_kernel() itself,
3595 * and we want to initialize the hashes only once:
3597 if (lockdep_initialized)
3600 for (i = 0; i < CLASSHASH_SIZE; i++)
3601 INIT_LIST_HEAD(classhash_table + i);
3603 for (i = 0; i < CHAINHASH_SIZE; i++)
3604 INIT_LIST_HEAD(chainhash_table + i);
3606 lockdep_initialized = 1;
3609 void __init lockdep_info(void)
3611 printk("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n");
3613 printk("... MAX_LOCKDEP_SUBCLASSES: %lu\n", MAX_LOCKDEP_SUBCLASSES);
3614 printk("... MAX_LOCK_DEPTH: %lu\n", MAX_LOCK_DEPTH);
3615 printk("... MAX_LOCKDEP_KEYS: %lu\n", MAX_LOCKDEP_KEYS);
3616 printk("... CLASSHASH_SIZE: %lu\n", CLASSHASH_SIZE);
3617 printk("... MAX_LOCKDEP_ENTRIES: %lu\n", MAX_LOCKDEP_ENTRIES);
3618 printk("... MAX_LOCKDEP_CHAINS: %lu\n", MAX_LOCKDEP_CHAINS);
3619 printk("... CHAINHASH_SIZE: %lu\n", CHAINHASH_SIZE);
3621 printk(" memory used by lock dependency info: %lu kB\n",
3622 (sizeof(struct lock_class) * MAX_LOCKDEP_KEYS +
3623 sizeof(struct list_head) * CLASSHASH_SIZE +
3624 sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES +
3625 sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS +
3626 sizeof(struct list_head) * CHAINHASH_SIZE
3627 #ifdef CONFIG_PROVE_LOCKING
3628 + sizeof(struct circular_queue)
3633 printk(" per task-struct memory footprint: %lu bytes\n",
3634 sizeof(struct held_lock) * MAX_LOCK_DEPTH);
3636 #ifdef CONFIG_DEBUG_LOCKDEP
3637 if (lockdep_init_error) {
3638 printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
3639 printk("Call stack leading to lockdep invocation was:\n");
3640 print_stack_trace(&lockdep_init_trace, 0);
3646 print_freed_lock_bug(struct task_struct *curr, const void *mem_from,
3647 const void *mem_to, struct held_lock *hlock)
3649 if (!debug_locks_off())
3651 if (debug_locks_silent)
3654 printk("\n=========================\n");
3655 printk( "[ BUG: held lock freed! ]\n");
3656 printk( "-------------------------\n");
3657 printk("%s/%d is freeing memory %p-%p, with a lock still held there!\n",
3658 curr->comm, task_pid_nr(curr), mem_from, mem_to-1);
3660 lockdep_print_held_locks(curr);
3662 printk("\nstack backtrace:\n");
3666 static inline int not_in_range(const void* mem_from, unsigned long mem_len,
3667 const void* lock_from, unsigned long lock_len)
3669 return lock_from + lock_len <= mem_from ||
3670 mem_from + mem_len <= lock_from;
3674 * Called when kernel memory is freed (or unmapped), or if a lock
3675 * is destroyed or reinitialized - this code checks whether there is
3676 * any held lock in the memory range of <from> to <to>:
3678 void debug_check_no_locks_freed(const void *mem_from, unsigned long mem_len)
3680 struct task_struct *curr = current;
3681 struct held_lock *hlock;
3682 unsigned long flags;
3685 if (unlikely(!debug_locks))
3688 local_irq_save(flags);
3689 for (i = 0; i < curr->lockdep_depth; i++) {
3690 hlock = curr->held_locks + i;
3692 if (not_in_range(mem_from, mem_len, hlock->instance,
3693 sizeof(*hlock->instance)))
3696 print_freed_lock_bug(curr, mem_from, mem_from + mem_len, hlock);
3699 local_irq_restore(flags);
3701 EXPORT_SYMBOL_GPL(debug_check_no_locks_freed);
3703 static void print_held_locks_bug(struct task_struct *curr)
3705 if (!debug_locks_off())
3707 if (debug_locks_silent)
3710 printk("\n=====================================\n");
3711 printk( "[ BUG: lock held at task exit time! ]\n");
3712 printk( "-------------------------------------\n");
3713 printk("%s/%d is exiting with locks still held!\n",
3714 curr->comm, task_pid_nr(curr));
3715 lockdep_print_held_locks(curr);
3717 printk("\nstack backtrace:\n");
3721 void debug_check_no_locks_held(struct task_struct *task)
3723 if (unlikely(task->lockdep_depth > 0))
3724 print_held_locks_bug(task);
3727 void debug_show_all_locks(void)
3729 struct task_struct *g, *p;
3733 if (unlikely(!debug_locks)) {
3734 printk("INFO: lockdep is turned off.\n");
3737 printk("\nShowing all locks held in the system:\n");
3740 * Here we try to get the tasklist_lock as hard as possible,
3741 * if not successful after 2 seconds we ignore it (but keep
3742 * trying). This is to enable a debug printout even if a
3743 * tasklist_lock-holding task deadlocks or crashes.
3746 if (!read_trylock(&tasklist_lock)) {
3748 printk("hm, tasklist_lock locked, retrying... ");
3751 printk(" #%d", 10-count);
3755 printk(" ignoring it.\n");
3759 printk(KERN_CONT " locked it.\n");
3762 do_each_thread(g, p) {
3764 * It's not reliable to print a task's held locks
3765 * if it's not sleeping (or if it's not the current
3768 if (p->state == TASK_RUNNING && p != current)
3770 if (p->lockdep_depth)
3771 lockdep_print_held_locks(p);
3773 if (read_trylock(&tasklist_lock))
3775 } while_each_thread(g, p);
3778 printk("=============================================\n\n");
3781 read_unlock(&tasklist_lock);
3783 EXPORT_SYMBOL_GPL(debug_show_all_locks);
3786 * Careful: only use this function if you are sure that
3787 * the task cannot run in parallel!
3789 void debug_show_held_locks(struct task_struct *task)
3791 if (unlikely(!debug_locks)) {
3792 printk("INFO: lockdep is turned off.\n");
3795 lockdep_print_held_locks(task);
3797 EXPORT_SYMBOL_GPL(debug_show_held_locks);
3799 void lockdep_sys_exit(void)
3801 struct task_struct *curr = current;
3803 if (unlikely(curr->lockdep_depth)) {
3804 if (!debug_locks_off())
3806 printk("\n================================================\n");
3807 printk( "[ BUG: lock held when returning to user space! ]\n");
3808 printk( "------------------------------------------------\n");
3809 printk("%s/%d is leaving the kernel with locks still held!\n",
3810 curr->comm, curr->pid);
3811 lockdep_print_held_locks(curr);
3815 void lockdep_rcu_dereference(const char *file, const int line)
3817 struct task_struct *curr = current;
3819 #ifndef CONFIG_PROVE_RCU_REPEATEDLY
3820 if (!debug_locks_off())
3822 #endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */
3823 /* Note: the following can be executed concurrently, so be careful. */
3824 printk("\n===================================================\n");
3825 printk( "[ INFO: suspicious rcu_dereference_check() usage. ]\n");
3826 printk( "---------------------------------------------------\n");
3827 printk("%s:%d invoked rcu_dereference_check() without protection!\n",
3829 printk("\nother info that might help us debug this:\n\n");
3830 printk("\nrcu_scheduler_active = %d, debug_locks = %d\n", rcu_scheduler_active, debug_locks);
3831 lockdep_print_held_locks(curr);
3832 printk("\nstack backtrace:\n");
3835 EXPORT_SYMBOL_GPL(lockdep_rcu_dereference);