add printk.time option, deprecate 'time'
[safe/jmp/linux-2.6] / kernel / lockdep.c
index 69e92c6..1a5ff22 100644 (file)
 #include "lockdep_internals.h"
 
 /*
- * hash_lock: protects the lockdep hashes and class/list/hash allocators.
+ * lockdep_lock: protects the lockdep graph, the hashes and the
+ *               class/list/hash allocators.
  *
  * This is one of the rare exceptions where it's justified
  * to use a raw spinlock - we really dont want the spinlock
- * code to recurse back into the lockdep code.
+ * code to recurse back into the lockdep code...
  */
-static raw_spinlock_t hash_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+static raw_spinlock_t lockdep_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+
+static int graph_lock(void)
+{
+       __raw_spin_lock(&lockdep_lock);
+       /*
+        * Make sure that if another CPU detected a bug while
+        * walking the graph we dont change it (while the other
+        * CPU is busy printing out stuff with the graph lock
+        * dropped already)
+        */
+       if (!debug_locks) {
+               __raw_spin_unlock(&lockdep_lock);
+               return 0;
+       }
+       return 1;
+}
+
+static inline int graph_unlock(void)
+{
+       if (debug_locks && !__raw_spin_is_locked(&lockdep_lock))
+               return DEBUG_LOCKS_WARN_ON(1);
+
+       __raw_spin_unlock(&lockdep_lock);
+       return 0;
+}
+
+/*
+ * Turn lock debugging off and return with 0 if it was off already,
+ * and also release the graph lock:
+ */
+static inline int debug_locks_off_graph_unlock(void)
+{
+       int ret = debug_locks_off();
+
+       __raw_spin_unlock(&lockdep_lock);
+
+       return ret;
+}
 
 static int lockdep_initialized;
 
@@ -57,14 +96,15 @@ unsigned long nr_list_entries;
 static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
 
 /*
- * Allocate a lockdep entry. (assumes hash_lock held, returns
+ * Allocate a lockdep entry. (assumes the graph_lock held, returns
  * with NULL on failure)
  */
 static struct lock_list *alloc_list_entry(void)
 {
        if (nr_list_entries >= MAX_LOCKDEP_ENTRIES) {
-               __raw_spin_unlock(&hash_lock);
-               debug_locks_off();
+               if (!debug_locks_off_graph_unlock())
+                       return NULL;
+
                printk("BUG: MAX_LOCKDEP_ENTRIES too low!\n");
                printk("turning off the locking correctness validator.\n");
                return NULL;
@@ -205,7 +245,7 @@ static int softirq_verbose(struct lock_class *class)
 
 /*
  * Stack-trace: tightly packed array of stack backtrace
- * addresses. Protected by the hash_lock.
+ * addresses. Protected by the graph_lock.
  */
 unsigned long nr_stack_trace_entries;
 static unsigned long stack_trace[MAX_STACK_TRACE_ENTRIES];
@@ -217,25 +257,21 @@ static int save_trace(struct stack_trace *trace)
        trace->entries = stack_trace + nr_stack_trace_entries;
 
        trace->skip = 3;
-       trace->all_contexts = 0;
 
-       save_stack_trace(trace, NULL);
+       save_stack_trace(trace);
 
        trace->max_entries = trace->nr_entries;
 
        nr_stack_trace_entries += trace->nr_entries;
-       if (DEBUG_LOCKS_WARN_ON(nr_stack_trace_entries > MAX_STACK_TRACE_ENTRIES)) {
-               __raw_spin_unlock(&hash_lock);
-               return 0;
-       }
 
        if (nr_stack_trace_entries == MAX_STACK_TRACE_ENTRIES) {
-               __raw_spin_unlock(&hash_lock);
-               if (debug_locks_off()) {
-                       printk("BUG: MAX_STACK_TRACE_ENTRIES too low!\n");
-                       printk("turning off the locking correctness validator.\n");
-                       dump_stack();
-               }
+               if (!debug_locks_off_graph_unlock())
+                       return 0;
+
+               printk("BUG: MAX_STACK_TRACE_ENTRIES too low!\n");
+               printk("turning off the locking correctness validator.\n");
+               dump_stack();
+
                return 0;
        }
 
@@ -304,10 +340,7 @@ static const char *usage_str[] =
 
 const char * __get_key_name(struct lockdep_subclass_key *key, char *str)
 {
-       unsigned long offs, size;
-       char *modname;
-
-       return kallsyms_lookup((unsigned long)key, &size, &offs, &modname, str);
+       return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
 }
 
 void
@@ -453,7 +486,7 @@ static void print_lock_dependencies(struct lock_class *class, int depth)
  * Add a new dependency to the head of the list:
  */
 static int add_lock_to_list(struct lock_class *class, struct lock_class *this,
-                           struct list_head *head, unsigned long ip)
+                           struct list_head *head, unsigned long ip, int distance)
 {
        struct lock_list *entry;
        /*
@@ -465,6 +498,7 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this,
                return 0;
 
        entry->class = this;
+       entry->distance = distance;
        if (!save_trace(&entry->trace))
                return 0;
 
@@ -524,9 +558,7 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth)
 {
        struct task_struct *curr = current;
 
-       __raw_spin_unlock(&hash_lock);
-       debug_locks_off();
-       if (debug_locks_silent)
+       if (!debug_locks_off_graph_unlock() || debug_locks_silent)
                return 0;
 
        printk("\n=======================================================\n");
@@ -554,12 +586,10 @@ static noinline int print_circular_bug_tail(void)
        if (debug_locks_silent)
                return 0;
 
-       /* hash_lock unlocked by the header */
-       __raw_spin_lock(&hash_lock);
        this.class = check_source->class;
        if (!save_trace(&this.trace))
                return 0;
-       __raw_spin_unlock(&hash_lock);
+
        print_circular_bug_entry(&this, 0);
 
        printk("\nother info that might help us debug this:\n\n");
@@ -575,8 +605,10 @@ static noinline int print_circular_bug_tail(void)
 
 static int noinline print_infinite_recursion_bug(void)
 {
-       __raw_spin_unlock(&hash_lock);
-       DEBUG_LOCKS_WARN_ON(1);
+       if (!debug_locks_off_graph_unlock())
+               return 0;
+
+       WARN_ON(1);
 
        return 0;
 }
@@ -680,6 +712,9 @@ find_usage_backwards(struct lock_class *source, unsigned int depth)
        struct lock_list *entry;
        int ret;
 
+       if (!__raw_spin_is_locked(&lockdep_lock))
+               return DEBUG_LOCKS_WARN_ON(1);
+
        if (depth > max_recursion_depth)
                max_recursion_depth = depth;
        if (depth >= RECURSION_LIMIT)
@@ -711,9 +746,7 @@ print_bad_irq_dependency(struct task_struct *curr,
                         enum lock_usage_bit bit2,
                         const char *irqclass)
 {
-       __raw_spin_unlock(&hash_lock);
-       debug_locks_off();
-       if (debug_locks_silent)
+       if (!debug_locks_off_graph_unlock() || debug_locks_silent)
                return 0;
 
        printk("\n======================================================\n");
@@ -794,9 +827,7 @@ static int
 print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
                   struct held_lock *next)
 {
-       debug_locks_off();
-       __raw_spin_unlock(&hash_lock);
-       if (debug_locks_silent)
+       if (!debug_locks_off_graph_unlock() || debug_locks_silent)
                return 0;
 
        printk("\n=============================================\n");
@@ -872,7 +903,7 @@ check_deadlock(struct task_struct *curr, struct held_lock *next,
  */
 static int
 check_prev_add(struct task_struct *curr, struct held_lock *prev,
-              struct held_lock *next)
+              struct held_lock *next, int distance)
 {
        struct lock_list *entry;
        int ret;
@@ -950,8 +981,11 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
         *  L2 added to its dependency list, due to the first chain.)
         */
        list_for_each_entry(entry, &prev->class->locks_after, entry) {
-               if (entry->class == next->class)
+               if (entry->class == next->class) {
+                       if (distance == 1)
+                               entry->distance = 1;
                        return 2;
+               }
        }
 
        /*
@@ -959,12 +993,13 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
         * to the previous lock's dependency list:
         */
        ret = add_lock_to_list(prev->class, next->class,
-                              &prev->class->locks_after, next->acquire_ip);
+                              &prev->class->locks_after, next->acquire_ip, distance);
+
        if (!ret)
                return 0;
 
        ret = add_lock_to_list(next->class, prev->class,
-                              &next->class->locks_before, next->acquire_ip);
+                              &next->class->locks_before, next->acquire_ip, distance);
        if (!ret)
                return 0;
 
@@ -972,14 +1007,14 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
         * Debugging printouts:
         */
        if (verbose(prev->class) || verbose(next->class)) {
-               __raw_spin_unlock(&hash_lock);
+               graph_unlock();
                printk("\n new dependency: ");
                print_lock_name(prev->class);
                printk(" => ");
                print_lock_name(next->class);
                printk("\n");
                dump_stack();
-               __raw_spin_lock(&hash_lock);
+               return graph_lock();
        }
        return 1;
 }
@@ -1012,13 +1047,14 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
                goto out_bug;
 
        for (;;) {
+               int distance = curr->lockdep_depth - depth + 1;
                hlock = curr->held_locks + depth-1;
                /*
                 * Only non-recursive-read entries get new dependencies
                 * added:
                 */
                if (hlock->read != 2) {
-                       if (!check_prev_add(curr, hlock, next))
+                       if (!check_prev_add(curr, hlock, next, distance))
                                return 0;
                        /*
                         * Stop after the first non-trylock entry,
@@ -1044,8 +1080,10 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
        }
        return 1;
 out_bug:
-       __raw_spin_unlock(&hash_lock);
-       DEBUG_LOCKS_WARN_ON(1);
+       if (!debug_locks_off_graph_unlock())
+               return 0;
+
+       WARN_ON(1);
 
        return 0;
 }
@@ -1199,7 +1237,10 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
        hash_head = classhashentry(key);
 
        raw_local_irq_save(flags);
-       __raw_spin_lock(&hash_lock);
+       if (!graph_lock()) {
+               raw_local_irq_restore(flags);
+               return NULL;
+       }
        /*
         * We have to do the hash-walk again, to avoid races
         * with another CPU:
@@ -1212,9 +1253,12 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
         * the hash:
         */
        if (nr_lock_classes >= MAX_LOCKDEP_KEYS) {
-               __raw_spin_unlock(&hash_lock);
+               if (!debug_locks_off_graph_unlock()) {
+                       raw_local_irq_restore(flags);
+                       return NULL;
+               }
                raw_local_irq_restore(flags);
-               debug_locks_off();
+
                printk("BUG: MAX_LOCKDEP_KEYS too low!\n");
                printk("turning off the locking correctness validator.\n");
                return NULL;
@@ -1235,39 +1279,47 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
        list_add_tail_rcu(&class->hash_entry, hash_head);
 
        if (verbose(class)) {
-               __raw_spin_unlock(&hash_lock);
+               graph_unlock();
                raw_local_irq_restore(flags);
+
                printk("\nnew class %p: %s", class->key, class->name);
                if (class->name_version > 1)
                        printk("#%d", class->name_version);
                printk("\n");
                dump_stack();
+
                raw_local_irq_save(flags);
-               __raw_spin_lock(&hash_lock);
+               if (!graph_lock()) {
+                       raw_local_irq_restore(flags);
+                       return NULL;
+               }
        }
 out_unlock_set:
-       __raw_spin_unlock(&hash_lock);
+       graph_unlock();
        raw_local_irq_restore(flags);
 
        if (!subclass || force)
                lock->class_cache = class;
 
-       DEBUG_LOCKS_WARN_ON(class->subclass != subclass);
+       if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass))
+               return NULL;
 
        return class;
 }
 
 /*
  * Look up a dependency chain. If the key is not present yet then
- * add it and return 0 - in this case the new dependency chain is
- * validated. If the key is already hashed, return 1.
+ * add it and return 1 - in this case the new dependency chain is
+ * validated. If the key is already hashed, return 0.
+ * (On return with 1 graph_lock is held.)
  */
 static inline int lookup_chain_cache(u64 chain_key, struct lock_class *class)
 {
        struct list_head *hash_head = chainhashentry(chain_key);
        struct lock_chain *chain;
 
-       DEBUG_LOCKS_WARN_ON(!irqs_disabled());
+       if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
+               return 0;
        /*
         * We can walk it lock-free, because entries only get added
         * to the hash:
@@ -1277,29 +1329,35 @@ static inline int lookup_chain_cache(u64 chain_key, struct lock_class *class)
 cache_hit:
                        debug_atomic_inc(&chain_lookup_hits);
                        if (very_verbose(class))
-                               printk("\nhash chain already cached, key: %016Lx tail class: [%p] %s\n", chain_key, class->key, class->name);
+                               printk("\nhash chain already cached, key: "
+                                       "%016Lx tail class: [%p] %s\n",
+                                       (unsigned long long)chain_key,
+                                       class->key, class->name);
                        return 0;
                }
        }
        if (very_verbose(class))
-               printk("\nnew hash chain, key: %016Lx tail class: [%p] %s\n", chain_key, class->key, class->name);
+               printk("\nnew hash chain, key: %016Lx tail class: [%p] %s\n",
+                       (unsigned long long)chain_key, class->key, class->name);
        /*
         * Allocate a new chain entry from the static array, and add
         * it to the hash:
         */
-       __raw_spin_lock(&hash_lock);
+       if (!graph_lock())
+               return 0;
        /*
         * We have to walk the chain again locked - to avoid duplicates:
         */
        list_for_each_entry(chain, hash_head, entry) {
                if (chain->chain_key == chain_key) {
-                       __raw_spin_unlock(&hash_lock);
+                       graph_unlock();
                        goto cache_hit;
                }
        }
        if (unlikely(nr_lock_chains >= MAX_LOCKDEP_CHAINS)) {
-               __raw_spin_unlock(&hash_lock);
-               debug_locks_off();
+               if (!debug_locks_off_graph_unlock())
+                       return 0;
+
                printk("BUG: MAX_LOCKDEP_CHAINS too low!\n");
                printk("turning off the locking correctness validator.\n");
                return 0;
@@ -1347,7 +1405,9 @@ static void check_chain_key(struct task_struct *curr)
                        return;
                }
                id = hlock->class - lock_classes;
-               DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS);
+               if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
+                       return;
+
                if (prev_hlock && (prev_hlock->irq_context !=
                                                        hlock->irq_context))
                        chain_key = 0;
@@ -1375,9 +1435,7 @@ print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other,
                        struct held_lock *this, int forwards,
                        const char *irqclass)
 {
-       __raw_spin_unlock(&hash_lock);
-       debug_locks_off();
-       if (debug_locks_silent)
+       if (!debug_locks_off_graph_unlock() || debug_locks_silent)
                return 0;
 
        printk("\n=========================================================\n");
@@ -1447,7 +1505,7 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this,
        return print_irq_inversion_bug(curr, backwards_match, this, 0, irqclass);
 }
 
-static inline void print_irqtrace_events(struct task_struct *curr)
+void print_irqtrace_events(struct task_struct *curr)
 {
        printk("irq event stamp: %u\n", curr->irq_events);
        printk("hardirqs last  enabled at (%u): ", curr->hardirq_enable_event);
@@ -1460,19 +1518,13 @@ static inline void print_irqtrace_events(struct task_struct *curr)
        print_ip_sym(curr->softirq_disable_ip);
 }
 
-#else
-static inline void print_irqtrace_events(struct task_struct *curr)
-{
-}
 #endif
 
 static int
 print_usage_bug(struct task_struct *curr, struct held_lock *this,
                enum lock_usage_bit prev_bit, enum lock_usage_bit new_bit)
 {
-       __raw_spin_unlock(&hash_lock);
-       debug_locks_off();
-       if (debug_locks_silent)
+       if (!debug_locks_off_graph_unlock() || debug_locks_silent)
                return 0;
 
        printk("\n=================================\n");
@@ -1522,7 +1574,7 @@ valid_state(struct task_struct *curr, struct held_lock *this,
  * Mark a lock with a usage bit, and validate the state transition:
  */
 static int mark_lock(struct task_struct *curr, struct held_lock *this,
-                    enum lock_usage_bit new_bit, unsigned long ip)
+                    enum lock_usage_bit new_bit)
 {
        unsigned int new_mask = 1 << new_bit, ret = 1;
 
@@ -1533,25 +1585,18 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
        if (likely(this->class->usage_mask & new_mask))
                return 1;
 
-       __raw_spin_lock(&hash_lock);
+       if (!graph_lock())
+               return 0;
        /*
         * Make sure we didnt race:
         */
        if (unlikely(this->class->usage_mask & new_mask)) {
-               __raw_spin_unlock(&hash_lock);
+               graph_unlock();
                return 1;
        }
 
        this->class->usage_mask |= new_mask;
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-       if (new_bit == LOCK_ENABLED_HARDIRQS ||
-                       new_bit == LOCK_ENABLED_HARDIRQS_READ)
-               ip = curr->hardirq_enable_ip;
-       else if (new_bit == LOCK_ENABLED_SOFTIRQS ||
-                       new_bit == LOCK_ENABLED_SOFTIRQS_READ)
-               ip = curr->softirq_enable_ip;
-#endif
        if (!save_trace(this->class->usage_traces + new_bit))
                return 0;
 
@@ -1724,16 +1769,16 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
                debug_atomic_dec(&nr_unused_locks);
                break;
        default:
-               __raw_spin_unlock(&hash_lock);
-               debug_locks_off();
+               if (!debug_locks_off_graph_unlock())
+                       return 0;
                WARN_ON(1);
                return 0;
        }
 
-       __raw_spin_unlock(&hash_lock);
+       graph_unlock();
 
        /*
-        * We must printk outside of the hash_lock:
+        * We must printk outside of the graph_lock:
         */
        if (ret == 2) {
                printk("\nmarked lock as {%s}:\n", usage_str[new_bit]);
@@ -1750,7 +1795,7 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
  * Mark all held locks with a usage bit:
  */
 static int
-mark_held_locks(struct task_struct *curr, int hardirq, unsigned long ip)
+mark_held_locks(struct task_struct *curr, int hardirq)
 {
        enum lock_usage_bit usage_bit;
        struct held_lock *hlock;
@@ -1770,7 +1815,7 @@ mark_held_locks(struct task_struct *curr, int hardirq, unsigned long ip)
                        else
                                usage_bit = LOCK_ENABLED_SOFTIRQS;
                }
-               if (!mark_lock(curr, hlock, usage_bit, ip))
+               if (!mark_lock(curr, hlock, usage_bit))
                        return 0;
        }
 
@@ -1823,7 +1868,7 @@ void trace_hardirqs_on(void)
         * We are going to turn hardirqs on, so set the
         * usage bit for all held locks:
         */
-       if (!mark_held_locks(curr, 1, ip))
+       if (!mark_held_locks(curr, 1))
                return;
        /*
         * If we have softirqs enabled, then set the usage
@@ -1831,7 +1876,7 @@ void trace_hardirqs_on(void)
         * this bit from being set before)
         */
        if (curr->softirqs_enabled)
-               if (!mark_held_locks(curr, 0, ip))
+               if (!mark_held_locks(curr, 0))
                        return;
 
        curr->hardirq_enable_ip = ip;
@@ -1899,7 +1944,7 @@ void trace_softirqs_on(unsigned long ip)
         * enabled too:
         */
        if (curr->hardirqs_enabled)
-               mark_held_locks(curr, 0, ip);
+               mark_held_locks(curr, 0);
 }
 
 /*
@@ -2037,43 +2082,43 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
                if (read) {
                        if (curr->hardirq_context)
                                if (!mark_lock(curr, hlock,
-                                               LOCK_USED_IN_HARDIRQ_READ, ip))
+                                               LOCK_USED_IN_HARDIRQ_READ))
                                        return 0;
                        if (curr->softirq_context)
                                if (!mark_lock(curr, hlock,
-                                               LOCK_USED_IN_SOFTIRQ_READ, ip))
+                                               LOCK_USED_IN_SOFTIRQ_READ))
                                        return 0;
                } else {
                        if (curr->hardirq_context)
-                               if (!mark_lock(curr, hlock, LOCK_USED_IN_HARDIRQ, ip))
+                               if (!mark_lock(curr, hlock, LOCK_USED_IN_HARDIRQ))
                                        return 0;
                        if (curr->softirq_context)
-                               if (!mark_lock(curr, hlock, LOCK_USED_IN_SOFTIRQ, ip))
+                               if (!mark_lock(curr, hlock, LOCK_USED_IN_SOFTIRQ))
                                        return 0;
                }
        }
        if (!hardirqs_off) {
                if (read) {
                        if (!mark_lock(curr, hlock,
-                                       LOCK_ENABLED_HARDIRQS_READ, ip))
+                                       LOCK_ENABLED_HARDIRQS_READ))
                                return 0;
                        if (curr->softirqs_enabled)
                                if (!mark_lock(curr, hlock,
-                                               LOCK_ENABLED_SOFTIRQS_READ, ip))
+                                               LOCK_ENABLED_SOFTIRQS_READ))
                                        return 0;
                } else {
                        if (!mark_lock(curr, hlock,
-                                       LOCK_ENABLED_HARDIRQS, ip))
+                                       LOCK_ENABLED_HARDIRQS))
                                return 0;
                        if (curr->softirqs_enabled)
                                if (!mark_lock(curr, hlock,
-                                               LOCK_ENABLED_SOFTIRQS, ip))
+                                               LOCK_ENABLED_SOFTIRQS))
                                        return 0;
                }
        }
 #endif
        /* mark it as used: */
-       if (!mark_lock(curr, hlock, LOCK_USED, ip))
+       if (!mark_lock(curr, hlock, LOCK_USED))
                return 0;
 out_calc_hash:
        /*
@@ -2131,7 +2176,7 @@ out_calc_hash:
         * We look up the chain_key and do the O(N^2) check and update of
         * the dependencies only if this is a new dependency chain.
         * (If lookup_chain_cache() returns with 1 it acquires
-        * hash_lock for us)
+        * graph_lock for us)
         */
        if (!trylock && (check == 2) && lookup_chain_cache(chain_key, class)) {
                /*
@@ -2164,16 +2209,25 @@ out_calc_hash:
                if (!chain_head && ret != 2)
                        if (!check_prevs_add(curr, hlock))
                                return 0;
-               __raw_spin_unlock(&hash_lock);
-       }
+               graph_unlock();
+       } else
+               /* after lookup_chain_cache(): */
+               if (unlikely(!debug_locks))
+                       return 0;
+
        curr->lockdep_depth++;
        check_chain_key(curr);
+#ifdef CONFIG_DEBUG_LOCKDEP
+       if (unlikely(!debug_locks))
+               return 0;
+#endif
        if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) {
                debug_locks_off();
                printk("BUG: MAX_LOCK_DEPTH too low!\n");
                printk("turning off the locking correctness validator.\n");
                return 0;
        }
+
        if (unlikely(curr->lockdep_depth > max_lockdep_depth))
                max_lockdep_depth = curr->lockdep_depth;
 
@@ -2476,7 +2530,7 @@ void lockdep_free_key_range(void *start, unsigned long size)
        int i;
 
        raw_local_irq_save(flags);
-       __raw_spin_lock(&hash_lock);
+       graph_lock();
 
        /*
         * Unhash all classes that were created by this module:
@@ -2490,7 +2544,7 @@ void lockdep_free_key_range(void *start, unsigned long size)
                                zap_class(class);
        }
 
-       __raw_spin_unlock(&hash_lock);
+       graph_unlock();
        raw_local_irq_restore(flags);
 }
 
@@ -2518,26 +2572,26 @@ void lockdep_reset_lock(struct lockdep_map *lock)
         * Debug check: in the end all mapped classes should
         * be gone.
         */
-       __raw_spin_lock(&hash_lock);
+       graph_lock();
        for (i = 0; i < CLASSHASH_SIZE; i++) {
                head = classhash_table + i;
                if (list_empty(head))
                        continue;
                list_for_each_entry_safe(class, next, head, hash_entry) {
                        if (unlikely(class == lock->class_cache)) {
-                               __raw_spin_unlock(&hash_lock);
-                               DEBUG_LOCKS_WARN_ON(1);
+                               if (debug_locks_off_graph_unlock())
+                                       WARN_ON(1);
                                goto out_restore;
                        }
                }
        }
-       __raw_spin_unlock(&hash_lock);
+       graph_unlock();
 
 out_restore:
        raw_local_irq_restore(flags);
 }
 
-void __init lockdep_init(void)
+void lockdep_init(void)
 {
        int i;
 
@@ -2677,6 +2731,10 @@ void debug_show_all_locks(void)
        int count = 10;
        int unlock = 1;
 
+       if (unlikely(!debug_locks)) {
+               printk("INFO: lockdep is turned off.\n");
+               return;
+       }
        printk("\nShowing all locks held in the system:\n");
 
        /*
@@ -2720,8 +2778,11 @@ EXPORT_SYMBOL_GPL(debug_show_all_locks);
 
 void debug_show_held_locks(struct task_struct *task)
 {
+       if (unlikely(!debug_locks)) {
+               printk("INFO: lockdep is turned off.\n");
+               return;
+       }
        lockdep_print_held_locks(task);
 }
 
 EXPORT_SYMBOL_GPL(debug_show_held_locks);
-