diff options
Diffstat (limited to 'kernel/lockdep.c')
| -rw-r--r-- | kernel/lockdep.c | 240 |
1 files changed, 194 insertions, 46 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 91d67ce3a8d5..e69434b070da 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
| @@ -96,8 +96,13 @@ static int graph_lock(void) | |||
| 96 | 96 | ||
| 97 | static inline int graph_unlock(void) | 97 | static inline int graph_unlock(void) |
| 98 | { | 98 | { |
| 99 | if (debug_locks && !arch_spin_is_locked(&lockdep_lock)) | 99 | if (debug_locks && !arch_spin_is_locked(&lockdep_lock)) { |
| 100 | /* | ||
| 101 | * The lockdep graph lock isn't locked while we expect it to | ||
| 102 | * be, we're confused now, bye! | ||
| 103 | */ | ||
| 100 | return DEBUG_LOCKS_WARN_ON(1); | 104 | return DEBUG_LOCKS_WARN_ON(1); |
| 105 | } | ||
| 101 | 106 | ||
| 102 | current->lockdep_recursion--; | 107 | current->lockdep_recursion--; |
| 103 | arch_spin_unlock(&lockdep_lock); | 108 | arch_spin_unlock(&lockdep_lock); |
| @@ -134,6 +139,9 @@ static struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; | |||
| 134 | static inline struct lock_class *hlock_class(struct held_lock *hlock) | 139 | static inline struct lock_class *hlock_class(struct held_lock *hlock) |
| 135 | { | 140 | { |
| 136 | if (!hlock->class_idx) { | 141 | if (!hlock->class_idx) { |
| 142 | /* | ||
| 143 | * Someone passed in garbage, we give up. | ||
| 144 | */ | ||
| 137 | DEBUG_LOCKS_WARN_ON(1); | 145 | DEBUG_LOCKS_WARN_ON(1); |
| 138 | return NULL; | 146 | return NULL; |
| 139 | } | 147 | } |
| @@ -687,6 +695,10 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass) | |||
| 687 | */ | 695 | */ |
| 688 | list_for_each_entry(class, hash_head, hash_entry) { | 696 | list_for_each_entry(class, hash_head, hash_entry) { |
| 689 | if (class->key == key) { | 697 | if (class->key == key) { |
| 698 | /* | ||
| 699 | * Huh! same key, different name? Did someone trample | ||
| 700 | * on some memory? We're most confused. | ||
| 701 | */ | ||
| 690 | WARN_ON_ONCE(class->name != lock->name); | 702 | WARN_ON_ONCE(class->name != lock->name); |
| 691 | return class; | 703 | return class; |
| 692 | } | 704 | } |
| @@ -800,6 +812,10 @@ out_unlock_set: | |||
| 800 | else if (subclass < NR_LOCKDEP_CACHING_CLASSES) | 812 | else if (subclass < NR_LOCKDEP_CACHING_CLASSES) |
| 801 | lock->class_cache[subclass] = class; | 813 | lock->class_cache[subclass] = class; |
| 802 | 814 | ||
| 815 | /* | ||
| 816 | * Hash collision, did we smoke some? We found a class with a matching | ||
| 817 | * hash but the subclass -- which is hashed in -- didn't match. | ||
| 818 | */ | ||
| 803 | if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass)) | 819 | if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass)) |
| 804 | return NULL; | 820 | return NULL; |
| 805 | 821 | ||
| @@ -926,7 +942,7 @@ static inline void mark_lock_accessed(struct lock_list *lock, | |||
| 926 | unsigned long nr; | 942 | unsigned long nr; |
| 927 | 943 | ||
| 928 | nr = lock - list_entries; | 944 | nr = lock - list_entries; |
| 929 | WARN_ON(nr >= nr_list_entries); | 945 | WARN_ON(nr >= nr_list_entries); /* Out-of-bounds, input fail */ |
| 930 | lock->parent = parent; | 946 | lock->parent = parent; |
| 931 | lock->class->dep_gen_id = lockdep_dependency_gen_id; | 947 | lock->class->dep_gen_id = lockdep_dependency_gen_id; |
| 932 | } | 948 | } |
| @@ -936,7 +952,7 @@ static inline unsigned long lock_accessed(struct lock_list *lock) | |||
| 936 | unsigned long nr; | 952 | unsigned long nr; |
| 937 | 953 | ||
| 938 | nr = lock - list_entries; | 954 | nr = lock - list_entries; |
| 939 | WARN_ON(nr >= nr_list_entries); | 955 | WARN_ON(nr >= nr_list_entries); /* Out-of-bounds, input fail */ |
| 940 | return lock->class->dep_gen_id == lockdep_dependency_gen_id; | 956 | return lock->class->dep_gen_id == lockdep_dependency_gen_id; |
| 941 | } | 957 | } |
| 942 | 958 | ||
| @@ -1129,10 +1145,11 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth, | |||
| 1129 | if (debug_locks_silent) | 1145 | if (debug_locks_silent) |
| 1130 | return 0; | 1146 | return 0; |
| 1131 | 1147 | ||
| 1132 | printk("\n=======================================================\n"); | 1148 | printk("\n"); |
| 1133 | printk( "[ INFO: possible circular locking dependency detected ]\n"); | 1149 | printk("======================================================\n"); |
| 1150 | printk("[ INFO: possible circular locking dependency detected ]\n"); | ||
| 1134 | print_kernel_version(); | 1151 | print_kernel_version(); |
| 1135 | printk( "-------------------------------------------------------\n"); | 1152 | printk("-------------------------------------------------------\n"); |
| 1136 | printk("%s/%d is trying to acquire lock:\n", | 1153 | printk("%s/%d is trying to acquire lock:\n", |
| 1137 | curr->comm, task_pid_nr(curr)); | 1154 | curr->comm, task_pid_nr(curr)); |
| 1138 | print_lock(check_src); | 1155 | print_lock(check_src); |
| @@ -1196,6 +1213,9 @@ static noinline int print_bfs_bug(int ret) | |||
| 1196 | if (!debug_locks_off_graph_unlock()) | 1213 | if (!debug_locks_off_graph_unlock()) |
| 1197 | return 0; | 1214 | return 0; |
| 1198 | 1215 | ||
| 1216 | /* | ||
| 1217 | * Breadth-first-search failed, graph got corrupted? | ||
| 1218 | */ | ||
| 1199 | WARN(1, "lockdep bfs error:%d\n", ret); | 1219 | WARN(1, "lockdep bfs error:%d\n", ret); |
| 1200 | 1220 | ||
| 1201 | return 0; | 1221 | return 0; |
| @@ -1463,11 +1483,12 @@ print_bad_irq_dependency(struct task_struct *curr, | |||
| 1463 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 1483 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 1464 | return 0; | 1484 | return 0; |
| 1465 | 1485 | ||
| 1466 | printk("\n======================================================\n"); | 1486 | printk("\n"); |
| 1467 | printk( "[ INFO: %s-safe -> %s-unsafe lock order detected ]\n", | 1487 | printk("======================================================\n"); |
| 1488 | printk("[ INFO: %s-safe -> %s-unsafe lock order detected ]\n", | ||
| 1468 | irqclass, irqclass); | 1489 | irqclass, irqclass); |
| 1469 | print_kernel_version(); | 1490 | print_kernel_version(); |
| 1470 | printk( "------------------------------------------------------\n"); | 1491 | printk("------------------------------------------------------\n"); |
| 1471 | printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] is trying to acquire:\n", | 1492 | printk("%s/%d [HC%u[%lu]:SC%u[%lu]:HE%u:SE%u] is trying to acquire:\n", |
| 1472 | curr->comm, task_pid_nr(curr), | 1493 | curr->comm, task_pid_nr(curr), |
| 1473 | curr->hardirq_context, hardirq_count() >> HARDIRQ_SHIFT, | 1494 | curr->hardirq_context, hardirq_count() >> HARDIRQ_SHIFT, |
| @@ -1692,10 +1713,11 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, | |||
| 1692 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 1713 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 1693 | return 0; | 1714 | return 0; |
| 1694 | 1715 | ||
| 1695 | printk("\n=============================================\n"); | 1716 | printk("\n"); |
| 1696 | printk( "[ INFO: possible recursive locking detected ]\n"); | 1717 | printk("=============================================\n"); |
| 1718 | printk("[ INFO: possible recursive locking detected ]\n"); | ||
| 1697 | print_kernel_version(); | 1719 | print_kernel_version(); |
| 1698 | printk( "---------------------------------------------\n"); | 1720 | printk("---------------------------------------------\n"); |
| 1699 | printk("%s/%d is trying to acquire lock:\n", | 1721 | printk("%s/%d is trying to acquire lock:\n", |
| 1700 | curr->comm, task_pid_nr(curr)); | 1722 | curr->comm, task_pid_nr(curr)); |
| 1701 | print_lock(next); | 1723 | print_lock(next); |
| @@ -1944,6 +1966,11 @@ out_bug: | |||
| 1944 | if (!debug_locks_off_graph_unlock()) | 1966 | if (!debug_locks_off_graph_unlock()) |
| 1945 | return 0; | 1967 | return 0; |
| 1946 | 1968 | ||
| 1969 | /* | ||
| 1970 | * Clearly we all shouldn't be here, but since we made it we | ||
| 1971 | * can reliable say we messed up our state. See the above two | ||
| 1972 | * gotos for reasons why we could possibly end up here. | ||
| 1973 | */ | ||
| 1947 | WARN_ON(1); | 1974 | WARN_ON(1); |
| 1948 | 1975 | ||
| 1949 | return 0; | 1976 | return 0; |
| @@ -1975,6 +2002,11 @@ static inline int lookup_chain_cache(struct task_struct *curr, | |||
| 1975 | struct held_lock *hlock_curr, *hlock_next; | 2002 | struct held_lock *hlock_curr, *hlock_next; |
| 1976 | int i, j; | 2003 | int i, j; |
| 1977 | 2004 | ||
| 2005 | /* | ||
| 2006 | * We might need to take the graph lock, ensure we've got IRQs | ||
| 2007 | * disabled to make this an IRQ-safe lock.. for recursion reasons | ||
| 2008 | * lockdep won't complain about its own locking errors. | ||
| 2009 | */ | ||
| 1978 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 2010 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 1979 | return 0; | 2011 | return 0; |
| 1980 | /* | 2012 | /* |
| @@ -2126,6 +2158,10 @@ static void check_chain_key(struct task_struct *curr) | |||
| 2126 | hlock = curr->held_locks + i; | 2158 | hlock = curr->held_locks + i; |
| 2127 | if (chain_key != hlock->prev_chain_key) { | 2159 | if (chain_key != hlock->prev_chain_key) { |
| 2128 | debug_locks_off(); | 2160 | debug_locks_off(); |
| 2161 | /* | ||
| 2162 | * We got mighty confused, our chain keys don't match | ||
| 2163 | * with what we expect, someone trample on our task state? | ||
| 2164 | */ | ||
| 2129 | WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n", | 2165 | WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n", |
| 2130 | curr->lockdep_depth, i, | 2166 | curr->lockdep_depth, i, |
| 2131 | (unsigned long long)chain_key, | 2167 | (unsigned long long)chain_key, |
| @@ -2133,6 +2169,9 @@ static void check_chain_key(struct task_struct *curr) | |||
| 2133 | return; | 2169 | return; |
| 2134 | } | 2170 | } |
| 2135 | id = hlock->class_idx - 1; | 2171 | id = hlock->class_idx - 1; |
| 2172 | /* | ||
| 2173 | * Whoops ran out of static storage again? | ||
| 2174 | */ | ||
| 2136 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) | 2175 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) |
| 2137 | return; | 2176 | return; |
| 2138 | 2177 | ||
| @@ -2144,6 +2183,10 @@ static void check_chain_key(struct task_struct *curr) | |||
| 2144 | } | 2183 | } |
| 2145 | if (chain_key != curr->curr_chain_key) { | 2184 | if (chain_key != curr->curr_chain_key) { |
| 2146 | debug_locks_off(); | 2185 | debug_locks_off(); |
| 2186 | /* | ||
| 2187 | * More smoking hash instead of calculating it, damn see these | ||
| 2188 | * numbers float.. I bet that a pink elephant stepped on my memory. | ||
| 2189 | */ | ||
| 2147 | WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n", | 2190 | WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n", |
| 2148 | curr->lockdep_depth, i, | 2191 | curr->lockdep_depth, i, |
| 2149 | (unsigned long long)chain_key, | 2192 | (unsigned long long)chain_key, |
| @@ -2177,10 +2220,11 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, | |||
| 2177 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 2220 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 2178 | return 0; | 2221 | return 0; |
| 2179 | 2222 | ||
| 2180 | printk("\n=================================\n"); | 2223 | printk("\n"); |
| 2181 | printk( "[ INFO: inconsistent lock state ]\n"); | 2224 | printk("=================================\n"); |
| 2225 | printk("[ INFO: inconsistent lock state ]\n"); | ||
| 2182 | print_kernel_version(); | 2226 | print_kernel_version(); |
| 2183 | printk( "---------------------------------\n"); | 2227 | printk("---------------------------------\n"); |
| 2184 | 2228 | ||
| 2185 | printk("inconsistent {%s} -> {%s} usage.\n", | 2229 | printk("inconsistent {%s} -> {%s} usage.\n", |
| 2186 | usage_str[prev_bit], usage_str[new_bit]); | 2230 | usage_str[prev_bit], usage_str[new_bit]); |
| @@ -2241,10 +2285,11 @@ print_irq_inversion_bug(struct task_struct *curr, | |||
| 2241 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 2285 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 2242 | return 0; | 2286 | return 0; |
| 2243 | 2287 | ||
| 2244 | printk("\n=========================================================\n"); | 2288 | printk("\n"); |
| 2245 | printk( "[ INFO: possible irq lock inversion dependency detected ]\n"); | 2289 | printk("=========================================================\n"); |
| 2290 | printk("[ INFO: possible irq lock inversion dependency detected ]\n"); | ||
| 2246 | print_kernel_version(); | 2291 | print_kernel_version(); |
| 2247 | printk( "---------------------------------------------------------\n"); | 2292 | printk("---------------------------------------------------------\n"); |
| 2248 | printk("%s/%d just changed the state of lock:\n", | 2293 | printk("%s/%d just changed the state of lock:\n", |
| 2249 | curr->comm, task_pid_nr(curr)); | 2294 | curr->comm, task_pid_nr(curr)); |
| 2250 | print_lock(this); | 2295 | print_lock(this); |
| @@ -2525,12 +2570,24 @@ void trace_hardirqs_on_caller(unsigned long ip) | |||
| 2525 | return; | 2570 | return; |
| 2526 | } | 2571 | } |
| 2527 | 2572 | ||
| 2573 | /* | ||
| 2574 | * We're enabling irqs and according to our state above irqs weren't | ||
| 2575 | * already enabled, yet we find the hardware thinks they are in fact | ||
| 2576 | * enabled.. someone messed up their IRQ state tracing. | ||
| 2577 | */ | ||
| 2528 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 2578 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 2529 | return; | 2579 | return; |
| 2530 | 2580 | ||
| 2581 | /* | ||
| 2582 | * See the fine text that goes along with this variable definition. | ||
| 2583 | */ | ||
| 2531 | if (DEBUG_LOCKS_WARN_ON(unlikely(early_boot_irqs_disabled))) | 2584 | if (DEBUG_LOCKS_WARN_ON(unlikely(early_boot_irqs_disabled))) |
| 2532 | return; | 2585 | return; |
| 2533 | 2586 | ||
| 2587 | /* | ||
| 2588 | * Can't allow enabling interrupts while in an interrupt handler, | ||
| 2589 | * that's general bad form and such. Recursion, limited stack etc.. | ||
| 2590 | */ | ||
| 2534 | if (DEBUG_LOCKS_WARN_ON(current->hardirq_context)) | 2591 | if (DEBUG_LOCKS_WARN_ON(current->hardirq_context)) |
| 2535 | return; | 2592 | return; |
| 2536 | 2593 | ||
| @@ -2558,6 +2615,10 @@ void trace_hardirqs_off_caller(unsigned long ip) | |||
| 2558 | if (unlikely(!debug_locks || current->lockdep_recursion)) | 2615 | if (unlikely(!debug_locks || current->lockdep_recursion)) |
| 2559 | return; | 2616 | return; |
| 2560 | 2617 | ||
| 2618 | /* | ||
| 2619 | * So we're supposed to get called after you mask local IRQs, but for | ||
| 2620 | * some reason the hardware doesn't quite think you did a proper job. | ||
| 2621 | */ | ||
| 2561 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 2622 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 2562 | return; | 2623 | return; |
| 2563 | 2624 | ||
| @@ -2590,6 +2651,10 @@ void trace_softirqs_on(unsigned long ip) | |||
| 2590 | if (unlikely(!debug_locks || current->lockdep_recursion)) | 2651 | if (unlikely(!debug_locks || current->lockdep_recursion)) |
| 2591 | return; | 2652 | return; |
| 2592 | 2653 | ||
| 2654 | /* | ||
| 2655 | * We fancy IRQs being disabled here, see softirq.c, avoids | ||
| 2656 | * funny state and nesting things. | ||
| 2657 | */ | ||
| 2593 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 2658 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 2594 | return; | 2659 | return; |
| 2595 | 2660 | ||
| @@ -2626,6 +2691,9 @@ void trace_softirqs_off(unsigned long ip) | |||
| 2626 | if (unlikely(!debug_locks || current->lockdep_recursion)) | 2691 | if (unlikely(!debug_locks || current->lockdep_recursion)) |
| 2627 | return; | 2692 | return; |
| 2628 | 2693 | ||
| 2694 | /* | ||
| 2695 | * We fancy IRQs being disabled here, see softirq.c | ||
| 2696 | */ | ||
| 2629 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 2697 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 2630 | return; | 2698 | return; |
| 2631 | 2699 | ||
| @@ -2637,6 +2705,9 @@ void trace_softirqs_off(unsigned long ip) | |||
| 2637 | curr->softirq_disable_ip = ip; | 2705 | curr->softirq_disable_ip = ip; |
| 2638 | curr->softirq_disable_event = ++curr->irq_events; | 2706 | curr->softirq_disable_event = ++curr->irq_events; |
| 2639 | debug_atomic_inc(softirqs_off_events); | 2707 | debug_atomic_inc(softirqs_off_events); |
| 2708 | /* | ||
| 2709 | * Whoops, we wanted softirqs off, so why aren't they? | ||
| 2710 | */ | ||
| 2640 | DEBUG_LOCKS_WARN_ON(!softirq_count()); | 2711 | DEBUG_LOCKS_WARN_ON(!softirq_count()); |
| 2641 | } else | 2712 | } else |
| 2642 | debug_atomic_inc(redundant_softirqs_off); | 2713 | debug_atomic_inc(redundant_softirqs_off); |
| @@ -2661,6 +2732,9 @@ static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags) | |||
| 2661 | if (!(gfp_mask & __GFP_FS)) | 2732 | if (!(gfp_mask & __GFP_FS)) |
| 2662 | return; | 2733 | return; |
| 2663 | 2734 | ||
| 2735 | /* | ||
| 2736 | * Oi! Can't be having __GFP_FS allocations with IRQs disabled. | ||
| 2737 | */ | ||
| 2664 | if (DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))) | 2738 | if (DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))) |
| 2665 | return; | 2739 | return; |
| 2666 | 2740 | ||
| @@ -2773,13 +2847,13 @@ static int separate_irq_context(struct task_struct *curr, | |||
| 2773 | return 0; | 2847 | return 0; |
| 2774 | } | 2848 | } |
| 2775 | 2849 | ||
| 2776 | #else | 2850 | #else /* defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) */ |
| 2777 | 2851 | ||
| 2778 | static inline | 2852 | static inline |
| 2779 | int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | 2853 | int mark_lock_irq(struct task_struct *curr, struct held_lock *this, |
| 2780 | enum lock_usage_bit new_bit) | 2854 | enum lock_usage_bit new_bit) |
| 2781 | { | 2855 | { |
| 2782 | WARN_ON(1); | 2856 | WARN_ON(1); /* Impossible innit? when we don't have TRACE_IRQFLAG */ |
| 2783 | return 1; | 2857 | return 1; |
| 2784 | } | 2858 | } |
| 2785 | 2859 | ||
| @@ -2799,7 +2873,7 @@ void lockdep_trace_alloc(gfp_t gfp_mask) | |||
| 2799 | { | 2873 | { |
| 2800 | } | 2874 | } |
| 2801 | 2875 | ||
| 2802 | #endif | 2876 | #endif /* defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) */ |
| 2803 | 2877 | ||
| 2804 | /* | 2878 | /* |
| 2805 | * Mark a lock with a usage bit, and validate the state transition: | 2879 | * Mark a lock with a usage bit, and validate the state transition: |
| @@ -2880,6 +2954,9 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name, | |||
| 2880 | lock->cpu = raw_smp_processor_id(); | 2954 | lock->cpu = raw_smp_processor_id(); |
| 2881 | #endif | 2955 | #endif |
| 2882 | 2956 | ||
| 2957 | /* | ||
| 2958 | * Can't be having no nameless bastards around this place! | ||
| 2959 | */ | ||
| 2883 | if (DEBUG_LOCKS_WARN_ON(!name)) { | 2960 | if (DEBUG_LOCKS_WARN_ON(!name)) { |
| 2884 | lock->name = "NULL"; | 2961 | lock->name = "NULL"; |
| 2885 | return; | 2962 | return; |
| @@ -2887,6 +2964,9 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name, | |||
| 2887 | 2964 | ||
| 2888 | lock->name = name; | 2965 | lock->name = name; |
| 2889 | 2966 | ||
| 2967 | /* | ||
| 2968 | * No key, no joy, we need to hash something. | ||
| 2969 | */ | ||
| 2890 | if (DEBUG_LOCKS_WARN_ON(!key)) | 2970 | if (DEBUG_LOCKS_WARN_ON(!key)) |
| 2891 | return; | 2971 | return; |
| 2892 | /* | 2972 | /* |
| @@ -2894,6 +2974,9 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name, | |||
| 2894 | */ | 2974 | */ |
| 2895 | if (!static_obj(key)) { | 2975 | if (!static_obj(key)) { |
| 2896 | printk("BUG: key %p not in .data!\n", key); | 2976 | printk("BUG: key %p not in .data!\n", key); |
| 2977 | /* | ||
| 2978 | * What it says above ^^^^^, I suggest you read it. | ||
| 2979 | */ | ||
| 2897 | DEBUG_LOCKS_WARN_ON(1); | 2980 | DEBUG_LOCKS_WARN_ON(1); |
| 2898 | return; | 2981 | return; |
| 2899 | } | 2982 | } |
| @@ -2932,6 +3015,11 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2932 | if (unlikely(!debug_locks)) | 3015 | if (unlikely(!debug_locks)) |
| 2933 | return 0; | 3016 | return 0; |
| 2934 | 3017 | ||
| 3018 | /* | ||
| 3019 | * Lockdep should run with IRQs disabled, otherwise we could | ||
| 3020 | * get an interrupt which would want to take locks, which would | ||
| 3021 | * end up in lockdep and have you got a head-ache already? | ||
| 3022 | */ | ||
| 2935 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 3023 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 2936 | return 0; | 3024 | return 0; |
| 2937 | 3025 | ||
| @@ -2963,6 +3051,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2963 | * dependency checks are done) | 3051 | * dependency checks are done) |
| 2964 | */ | 3052 | */ |
| 2965 | depth = curr->lockdep_depth; | 3053 | depth = curr->lockdep_depth; |
| 3054 | /* | ||
| 3055 | * Ran out of static storage for our per-task lock stack again have we? | ||
| 3056 | */ | ||
| 2966 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) | 3057 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) |
| 2967 | return 0; | 3058 | return 0; |
| 2968 | 3059 | ||
| @@ -2981,6 +3072,10 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2981 | } | 3072 | } |
| 2982 | 3073 | ||
| 2983 | hlock = curr->held_locks + depth; | 3074 | hlock = curr->held_locks + depth; |
| 3075 | /* | ||
| 3076 | * Plain impossible, we just registered it and checked it weren't no | ||
| 3077 | * NULL like.. I bet this mushroom I ate was good! | ||
| 3078 | */ | ||
| 2984 | if (DEBUG_LOCKS_WARN_ON(!class)) | 3079 | if (DEBUG_LOCKS_WARN_ON(!class)) |
| 2985 | return 0; | 3080 | return 0; |
| 2986 | hlock->class_idx = class_idx; | 3081 | hlock->class_idx = class_idx; |
| @@ -3015,11 +3110,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 3015 | * the hash, not class->key. | 3110 | * the hash, not class->key. |
| 3016 | */ | 3111 | */ |
| 3017 | id = class - lock_classes; | 3112 | id = class - lock_classes; |
| 3113 | /* | ||
| 3114 | * Whoops, we did it again.. ran straight out of our static allocation. | ||
| 3115 | */ | ||
| 3018 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) | 3116 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) |
| 3019 | return 0; | 3117 | return 0; |
| 3020 | 3118 | ||
| 3021 | chain_key = curr->curr_chain_key; | 3119 | chain_key = curr->curr_chain_key; |
| 3022 | if (!depth) { | 3120 | if (!depth) { |
| 3121 | /* | ||
| 3122 | * How can we have a chain hash when we ain't got no keys?! | ||
| 3123 | */ | ||
| 3023 | if (DEBUG_LOCKS_WARN_ON(chain_key != 0)) | 3124 | if (DEBUG_LOCKS_WARN_ON(chain_key != 0)) |
| 3024 | return 0; | 3125 | return 0; |
| 3025 | chain_head = 1; | 3126 | chain_head = 1; |
| @@ -3065,9 +3166,10 @@ print_unlock_inbalance_bug(struct task_struct *curr, struct lockdep_map *lock, | |||
| 3065 | if (debug_locks_silent) | 3166 | if (debug_locks_silent) |
| 3066 | return 0; | 3167 | return 0; |
| 3067 | 3168 | ||
| 3068 | printk("\n=====================================\n"); | 3169 | printk("\n"); |
| 3069 | printk( "[ BUG: bad unlock balance detected! ]\n"); | 3170 | printk("=====================================\n"); |
| 3070 | printk( "-------------------------------------\n"); | 3171 | printk("[ BUG: bad unlock balance detected! ]\n"); |
| 3172 | printk("-------------------------------------\n"); | ||
| 3071 | printk("%s/%d is trying to release lock (", | 3173 | printk("%s/%d is trying to release lock (", |
| 3072 | curr->comm, task_pid_nr(curr)); | 3174 | curr->comm, task_pid_nr(curr)); |
| 3073 | print_lockdep_cache(lock); | 3175 | print_lockdep_cache(lock); |
| @@ -3091,6 +3193,9 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock, | |||
| 3091 | { | 3193 | { |
| 3092 | if (unlikely(!debug_locks)) | 3194 | if (unlikely(!debug_locks)) |
| 3093 | return 0; | 3195 | return 0; |
| 3196 | /* | ||
| 3197 | * Lockdep should run with IRQs disabled, recursion, head-ache, etc.. | ||
| 3198 | */ | ||
| 3094 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 3199 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 3095 | return 0; | 3200 | return 0; |
| 3096 | 3201 | ||
| @@ -3120,6 +3225,11 @@ static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock) | |||
| 3120 | if (!class) | 3225 | if (!class) |
| 3121 | return 0; | 3226 | return 0; |
| 3122 | 3227 | ||
| 3228 | /* | ||
| 3229 | * References, but not a lock we're actually ref-counting? | ||
| 3230 | * State got messed up, follow the sites that change ->references | ||
| 3231 | * and try to make sense of it. | ||
| 3232 | */ | ||
| 3123 | if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) | 3233 | if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) |
| 3124 | return 0; | 3234 | return 0; |
| 3125 | 3235 | ||
| @@ -3142,6 +3252,10 @@ __lock_set_class(struct lockdep_map *lock, const char *name, | |||
| 3142 | int i; | 3252 | int i; |
| 3143 | 3253 | ||
| 3144 | depth = curr->lockdep_depth; | 3254 | depth = curr->lockdep_depth; |
| 3255 | /* | ||
| 3256 | * This function is about (re)setting the class of a held lock, | ||
| 3257 | * yet we're not actually holding any locks. Naughty user! | ||
| 3258 | */ | ||
| 3145 | if (DEBUG_LOCKS_WARN_ON(!depth)) | 3259 | if (DEBUG_LOCKS_WARN_ON(!depth)) |
| 3146 | return 0; | 3260 | return 0; |
| 3147 | 3261 | ||
| @@ -3177,6 +3291,10 @@ found_it: | |||
| 3177 | return 0; | 3291 | return 0; |
| 3178 | } | 3292 | } |
| 3179 | 3293 | ||
| 3294 | /* | ||
| 3295 | * I took it apart and put it back together again, except now I have | ||
| 3296 | * these 'spare' parts.. where shall I put them. | ||
| 3297 | */ | ||
| 3180 | if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) | 3298 | if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) |
| 3181 | return 0; | 3299 | return 0; |
| 3182 | return 1; | 3300 | return 1; |
| @@ -3201,6 +3319,10 @@ lock_release_non_nested(struct task_struct *curr, | |||
| 3201 | * of held locks: | 3319 | * of held locks: |
| 3202 | */ | 3320 | */ |
| 3203 | depth = curr->lockdep_depth; | 3321 | depth = curr->lockdep_depth; |
| 3322 | /* | ||
| 3323 | * So we're all set to release this lock.. wait what lock? We don't | ||
| 3324 | * own any locks, you've been drinking again? | ||
| 3325 | */ | ||
| 3204 | if (DEBUG_LOCKS_WARN_ON(!depth)) | 3326 | if (DEBUG_LOCKS_WARN_ON(!depth)) |
| 3205 | return 0; | 3327 | return 0; |
| 3206 | 3328 | ||
| @@ -3253,6 +3375,10 @@ found_it: | |||
| 3253 | return 0; | 3375 | return 0; |
| 3254 | } | 3376 | } |
| 3255 | 3377 | ||
| 3378 | /* | ||
| 3379 | * We had N bottles of beer on the wall, we drank one, but now | ||
| 3380 | * there's not N-1 bottles of beer left on the wall... | ||
| 3381 | */ | ||
| 3256 | if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - 1)) | 3382 | if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - 1)) |
| 3257 | return 0; | 3383 | return 0; |
| 3258 | return 1; | 3384 | return 1; |
| @@ -3283,6 +3409,9 @@ static int lock_release_nested(struct task_struct *curr, | |||
| 3283 | return lock_release_non_nested(curr, lock, ip); | 3409 | return lock_release_non_nested(curr, lock, ip); |
| 3284 | curr->lockdep_depth--; | 3410 | curr->lockdep_depth--; |
| 3285 | 3411 | ||
| 3412 | /* | ||
| 3413 | * No more locks, but somehow we've got hash left over, who left it? | ||
| 3414 | */ | ||
| 3286 | if (DEBUG_LOCKS_WARN_ON(!depth && (hlock->prev_chain_key != 0))) | 3415 | if (DEBUG_LOCKS_WARN_ON(!depth && (hlock->prev_chain_key != 0))) |
| 3287 | return 0; | 3416 | return 0; |
| 3288 | 3417 | ||
| @@ -3365,10 +3494,13 @@ static void check_flags(unsigned long flags) | |||
| 3365 | * check if not in hardirq contexts: | 3494 | * check if not in hardirq contexts: |
| 3366 | */ | 3495 | */ |
| 3367 | if (!hardirq_count()) { | 3496 | if (!hardirq_count()) { |
| 3368 | if (softirq_count()) | 3497 | if (softirq_count()) { |
| 3498 | /* like the above, but with softirqs */ | ||
| 3369 | DEBUG_LOCKS_WARN_ON(current->softirqs_enabled); | 3499 | DEBUG_LOCKS_WARN_ON(current->softirqs_enabled); |
| 3370 | else | 3500 | } else { |
| 3501 | /* lick the above, does it taste good? */ | ||
| 3371 | DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled); | 3502 | DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled); |
| 3503 | } | ||
| 3372 | } | 3504 | } |
| 3373 | 3505 | ||
| 3374 | if (!debug_locks) | 3506 | if (!debug_locks) |
| @@ -3478,9 +3610,10 @@ print_lock_contention_bug(struct task_struct *curr, struct lockdep_map *lock, | |||
| 3478 | if (debug_locks_silent) | 3610 | if (debug_locks_silent) |
| 3479 | return 0; | 3611 | return 0; |
| 3480 | 3612 | ||
| 3481 | printk("\n=================================\n"); | 3613 | printk("\n"); |
| 3482 | printk( "[ BUG: bad contention detected! ]\n"); | 3614 | printk("=================================\n"); |
| 3483 | printk( "---------------------------------\n"); | 3615 | printk("[ BUG: bad contention detected! ]\n"); |
| 3616 | printk("---------------------------------\n"); | ||
| 3484 | printk("%s/%d is trying to contend lock (", | 3617 | printk("%s/%d is trying to contend lock (", |
| 3485 | curr->comm, task_pid_nr(curr)); | 3618 | curr->comm, task_pid_nr(curr)); |
| 3486 | print_lockdep_cache(lock); | 3619 | print_lockdep_cache(lock); |
| @@ -3506,6 +3639,10 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
| 3506 | int i, contention_point, contending_point; | 3639 | int i, contention_point, contending_point; |
| 3507 | 3640 | ||
| 3508 | depth = curr->lockdep_depth; | 3641 | depth = curr->lockdep_depth; |
| 3642 | /* | ||
| 3643 | * Whee, we contended on this lock, except it seems we're not | ||
| 3644 | * actually trying to acquire anything much at all.. | ||
| 3645 | */ | ||
| 3509 | if (DEBUG_LOCKS_WARN_ON(!depth)) | 3646 | if (DEBUG_LOCKS_WARN_ON(!depth)) |
| 3510 | return; | 3647 | return; |
| 3511 | 3648 | ||
| @@ -3555,6 +3692,10 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
| 3555 | int i, cpu; | 3692 | int i, cpu; |
| 3556 | 3693 | ||
| 3557 | depth = curr->lockdep_depth; | 3694 | depth = curr->lockdep_depth; |
| 3695 | /* | ||
| 3696 | * Yay, we acquired ownership of this lock we didn't try to | ||
| 3697 | * acquire, how the heck did that happen? | ||
| 3698 | */ | ||
| 3558 | if (DEBUG_LOCKS_WARN_ON(!depth)) | 3699 | if (DEBUG_LOCKS_WARN_ON(!depth)) |
| 3559 | return; | 3700 | return; |
| 3560 | 3701 | ||
| @@ -3759,8 +3900,12 @@ void lockdep_reset_lock(struct lockdep_map *lock) | |||
| 3759 | match |= class == lock->class_cache[j]; | 3900 | match |= class == lock->class_cache[j]; |
| 3760 | 3901 | ||
| 3761 | if (unlikely(match)) { | 3902 | if (unlikely(match)) { |
| 3762 | if (debug_locks_off_graph_unlock()) | 3903 | if (debug_locks_off_graph_unlock()) { |
| 3904 | /* | ||
| 3905 | * We all just reset everything, how did it match? | ||
| 3906 | */ | ||
| 3763 | WARN_ON(1); | 3907 | WARN_ON(1); |
| 3908 | } | ||
| 3764 | goto out_restore; | 3909 | goto out_restore; |
| 3765 | } | 3910 | } |
| 3766 | } | 3911 | } |
| @@ -3839,9 +3984,10 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from, | |||
| 3839 | if (debug_locks_silent) | 3984 | if (debug_locks_silent) |
| 3840 | return; | 3985 | return; |
| 3841 | 3986 | ||
| 3842 | printk("\n=========================\n"); | 3987 | printk("\n"); |
| 3843 | printk( "[ BUG: held lock freed! ]\n"); | 3988 | printk("=========================\n"); |
| 3844 | printk( "-------------------------\n"); | 3989 | printk("[ BUG: held lock freed! ]\n"); |
| 3990 | printk("-------------------------\n"); | ||
| 3845 | printk("%s/%d is freeing memory %p-%p, with a lock still held there!\n", | 3991 | printk("%s/%d is freeing memory %p-%p, with a lock still held there!\n", |
| 3846 | curr->comm, task_pid_nr(curr), mem_from, mem_to-1); | 3992 | curr->comm, task_pid_nr(curr), mem_from, mem_to-1); |
| 3847 | print_lock(hlock); | 3993 | print_lock(hlock); |
| @@ -3895,9 +4041,10 @@ static void print_held_locks_bug(struct task_struct *curr) | |||
| 3895 | if (debug_locks_silent) | 4041 | if (debug_locks_silent) |
| 3896 | return; | 4042 | return; |
| 3897 | 4043 | ||
| 3898 | printk("\n=====================================\n"); | 4044 | printk("\n"); |
| 3899 | printk( "[ BUG: lock held at task exit time! ]\n"); | 4045 | printk("=====================================\n"); |
| 3900 | printk( "-------------------------------------\n"); | 4046 | printk("[ BUG: lock held at task exit time! ]\n"); |
| 4047 | printk("-------------------------------------\n"); | ||
| 3901 | printk("%s/%d is exiting with locks still held!\n", | 4048 | printk("%s/%d is exiting with locks still held!\n", |
| 3902 | curr->comm, task_pid_nr(curr)); | 4049 | curr->comm, task_pid_nr(curr)); |
| 3903 | lockdep_print_held_locks(curr); | 4050 | lockdep_print_held_locks(curr); |
| @@ -3991,16 +4138,17 @@ void lockdep_sys_exit(void) | |||
| 3991 | if (unlikely(curr->lockdep_depth)) { | 4138 | if (unlikely(curr->lockdep_depth)) { |
| 3992 | if (!debug_locks_off()) | 4139 | if (!debug_locks_off()) |
| 3993 | return; | 4140 | return; |
| 3994 | printk("\n================================================\n"); | 4141 | printk("\n"); |
| 3995 | printk( "[ BUG: lock held when returning to user space! ]\n"); | 4142 | printk("================================================\n"); |
| 3996 | printk( "------------------------------------------------\n"); | 4143 | printk("[ BUG: lock held when returning to user space! ]\n"); |
| 4144 | printk("------------------------------------------------\n"); | ||
| 3997 | printk("%s/%d is leaving the kernel with locks still held!\n", | 4145 | printk("%s/%d is leaving the kernel with locks still held!\n", |
| 3998 | curr->comm, curr->pid); | 4146 | curr->comm, curr->pid); |
| 3999 | lockdep_print_held_locks(curr); | 4147 | lockdep_print_held_locks(curr); |
| 4000 | } | 4148 | } |
| 4001 | } | 4149 | } |
| 4002 | 4150 | ||
| 4003 | void lockdep_rcu_dereference(const char *file, const int line) | 4151 | void lockdep_rcu_suspicious(const char *file, const int line, const char *s) |
| 4004 | { | 4152 | { |
| 4005 | struct task_struct *curr = current; | 4153 | struct task_struct *curr = current; |
| 4006 | 4154 | ||
| @@ -4009,15 +4157,15 @@ void lockdep_rcu_dereference(const char *file, const int line) | |||
| 4009 | return; | 4157 | return; |
| 4010 | #endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */ | 4158 | #endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */ |
| 4011 | /* Note: the following can be executed concurrently, so be careful. */ | 4159 | /* Note: the following can be executed concurrently, so be careful. */ |
| 4012 | printk("\n===================================================\n"); | 4160 | printk("\n"); |
| 4013 | printk( "[ INFO: suspicious rcu_dereference_check() usage. ]\n"); | 4161 | printk("===============================\n"); |
| 4014 | printk( "---------------------------------------------------\n"); | 4162 | printk("[ INFO: suspicious RCU usage. ]\n"); |
| 4015 | printk("%s:%d invoked rcu_dereference_check() without protection!\n", | 4163 | printk("-------------------------------\n"); |
| 4016 | file, line); | 4164 | printk("%s:%d %s!\n", file, line, s); |
| 4017 | printk("\nother info that might help us debug this:\n\n"); | 4165 | printk("\nother info that might help us debug this:\n\n"); |
| 4018 | printk("\nrcu_scheduler_active = %d, debug_locks = %d\n", rcu_scheduler_active, debug_locks); | 4166 | printk("\nrcu_scheduler_active = %d, debug_locks = %d\n", rcu_scheduler_active, debug_locks); |
| 4019 | lockdep_print_held_locks(curr); | 4167 | lockdep_print_held_locks(curr); |
| 4020 | printk("\nstack backtrace:\n"); | 4168 | printk("\nstack backtrace:\n"); |
| 4021 | dump_stack(); | 4169 | dump_stack(); |
| 4022 | } | 4170 | } |
| 4023 | EXPORT_SYMBOL_GPL(lockdep_rcu_dereference); | 4171 | EXPORT_SYMBOL_GPL(lockdep_rcu_suspicious); |
