diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-09-15 06:18:15 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-09-15 06:18:15 -0400 |
commit | dca2d6ac09d9ef59ff46820d4f0c94b08a671202 (patch) | |
tree | fdec753b842dad09e3a4151954fab3eb5c43500d /kernel/lockdep.c | |
parent | d6a65dffb30d8636b1e5d4c201564ef401a246cf (diff) | |
parent | 18240904960a39e582ced8ba8ececb10b8c22dd3 (diff) |
Merge branch 'linus' into tracing/hw-breakpoints
Conflicts:
arch/x86/kernel/process_64.c
Semantic conflict fixed in:
arch/x86/kvm/x86.c
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/lockdep.c')
-rw-r--r-- | kernel/lockdep.c | 792 |
1 files changed, 535 insertions, 257 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 8bbeef996c76..f74d2d7aa605 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/hash.h> | 42 | #include <linux/hash.h> |
43 | #include <linux/ftrace.h> | 43 | #include <linux/ftrace.h> |
44 | #include <linux/stringify.h> | 44 | #include <linux/stringify.h> |
45 | #include <linux/bitops.h> | ||
45 | 46 | ||
46 | #include <asm/sections.h> | 47 | #include <asm/sections.h> |
47 | 48 | ||
@@ -366,11 +367,21 @@ static int save_trace(struct stack_trace *trace) | |||
366 | 367 | ||
367 | save_stack_trace(trace); | 368 | save_stack_trace(trace); |
368 | 369 | ||
370 | /* | ||
371 | * Some daft arches put -1 at the end to indicate its a full trace. | ||
372 | * | ||
373 | * <rant> this is buggy anyway, since it takes a whole extra entry so a | ||
374 | * complete trace that maxes out the entries provided will be reported | ||
375 | * as incomplete, friggin useless </rant> | ||
376 | */ | ||
377 | if (trace->entries[trace->nr_entries-1] == ULONG_MAX) | ||
378 | trace->nr_entries--; | ||
379 | |||
369 | trace->max_entries = trace->nr_entries; | 380 | trace->max_entries = trace->nr_entries; |
370 | 381 | ||
371 | nr_stack_trace_entries += trace->nr_entries; | 382 | nr_stack_trace_entries += trace->nr_entries; |
372 | 383 | ||
373 | if (nr_stack_trace_entries == MAX_STACK_TRACE_ENTRIES) { | 384 | if (nr_stack_trace_entries >= MAX_STACK_TRACE_ENTRIES-1) { |
374 | if (!debug_locks_off_graph_unlock()) | 385 | if (!debug_locks_off_graph_unlock()) |
375 | return 0; | 386 | return 0; |
376 | 387 | ||
@@ -388,20 +399,6 @@ unsigned int nr_hardirq_chains; | |||
388 | unsigned int nr_softirq_chains; | 399 | unsigned int nr_softirq_chains; |
389 | unsigned int nr_process_chains; | 400 | unsigned int nr_process_chains; |
390 | unsigned int max_lockdep_depth; | 401 | unsigned int max_lockdep_depth; |
391 | unsigned int max_recursion_depth; | ||
392 | |||
393 | static unsigned int lockdep_dependency_gen_id; | ||
394 | |||
395 | static bool lockdep_dependency_visit(struct lock_class *source, | ||
396 | unsigned int depth) | ||
397 | { | ||
398 | if (!depth) | ||
399 | lockdep_dependency_gen_id++; | ||
400 | if (source->dep_gen_id == lockdep_dependency_gen_id) | ||
401 | return true; | ||
402 | source->dep_gen_id = lockdep_dependency_gen_id; | ||
403 | return false; | ||
404 | } | ||
405 | 402 | ||
406 | #ifdef CONFIG_DEBUG_LOCKDEP | 403 | #ifdef CONFIG_DEBUG_LOCKDEP |
407 | /* | 404 | /* |
@@ -431,11 +428,8 @@ atomic_t redundant_softirqs_on; | |||
431 | atomic_t redundant_softirqs_off; | 428 | atomic_t redundant_softirqs_off; |
432 | atomic_t nr_unused_locks; | 429 | atomic_t nr_unused_locks; |
433 | atomic_t nr_cyclic_checks; | 430 | atomic_t nr_cyclic_checks; |
434 | atomic_t nr_cyclic_check_recursions; | ||
435 | atomic_t nr_find_usage_forwards_checks; | 431 | atomic_t nr_find_usage_forwards_checks; |
436 | atomic_t nr_find_usage_forwards_recursions; | ||
437 | atomic_t nr_find_usage_backwards_checks; | 432 | atomic_t nr_find_usage_backwards_checks; |
438 | atomic_t nr_find_usage_backwards_recursions; | ||
439 | #endif | 433 | #endif |
440 | 434 | ||
441 | /* | 435 | /* |
@@ -551,58 +545,6 @@ static void lockdep_print_held_locks(struct task_struct *curr) | |||
551 | } | 545 | } |
552 | } | 546 | } |
553 | 547 | ||
554 | static void print_lock_class_header(struct lock_class *class, int depth) | ||
555 | { | ||
556 | int bit; | ||
557 | |||
558 | printk("%*s->", depth, ""); | ||
559 | print_lock_name(class); | ||
560 | printk(" ops: %lu", class->ops); | ||
561 | printk(" {\n"); | ||
562 | |||
563 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { | ||
564 | if (class->usage_mask & (1 << bit)) { | ||
565 | int len = depth; | ||
566 | |||
567 | len += printk("%*s %s", depth, "", usage_str[bit]); | ||
568 | len += printk(" at:\n"); | ||
569 | print_stack_trace(class->usage_traces + bit, len); | ||
570 | } | ||
571 | } | ||
572 | printk("%*s }\n", depth, ""); | ||
573 | |||
574 | printk("%*s ... key at: ",depth,""); | ||
575 | print_ip_sym((unsigned long)class->key); | ||
576 | } | ||
577 | |||
578 | /* | ||
579 | * printk all lock dependencies starting at <entry>: | ||
580 | */ | ||
581 | static void __used | ||
582 | print_lock_dependencies(struct lock_class *class, int depth) | ||
583 | { | ||
584 | struct lock_list *entry; | ||
585 | |||
586 | if (lockdep_dependency_visit(class, depth)) | ||
587 | return; | ||
588 | |||
589 | if (DEBUG_LOCKS_WARN_ON(depth >= 20)) | ||
590 | return; | ||
591 | |||
592 | print_lock_class_header(class, depth); | ||
593 | |||
594 | list_for_each_entry(entry, &class->locks_after, entry) { | ||
595 | if (DEBUG_LOCKS_WARN_ON(!entry->class)) | ||
596 | return; | ||
597 | |||
598 | print_lock_dependencies(entry->class, depth + 1); | ||
599 | |||
600 | printk("%*s ... acquired at:\n",depth,""); | ||
601 | print_stack_trace(&entry->trace, 2); | ||
602 | printk("\n"); | ||
603 | } | ||
604 | } | ||
605 | |||
606 | static void print_kernel_version(void) | 548 | static void print_kernel_version(void) |
607 | { | 549 | { |
608 | printk("%s %.*s\n", init_utsname()->release, | 550 | printk("%s %.*s\n", init_utsname()->release, |
@@ -898,22 +840,203 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
898 | } | 840 | } |
899 | 841 | ||
900 | /* | 842 | /* |
843 | * For good efficiency of modular, we use power of 2 | ||
844 | */ | ||
845 | #define MAX_CIRCULAR_QUEUE_SIZE 4096UL | ||
846 | #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) | ||
847 | |||
848 | /* | ||
849 | * The circular_queue and helpers is used to implement the | ||
850 | * breadth-first search(BFS)algorithem, by which we can build | ||
851 | * the shortest path from the next lock to be acquired to the | ||
852 | * previous held lock if there is a circular between them. | ||
853 | */ | ||
854 | struct circular_queue { | ||
855 | unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; | ||
856 | unsigned int front, rear; | ||
857 | }; | ||
858 | |||
859 | static struct circular_queue lock_cq; | ||
860 | |||
861 | unsigned int max_bfs_queue_depth; | ||
862 | |||
863 | static unsigned int lockdep_dependency_gen_id; | ||
864 | |||
865 | static inline void __cq_init(struct circular_queue *cq) | ||
866 | { | ||
867 | cq->front = cq->rear = 0; | ||
868 | lockdep_dependency_gen_id++; | ||
869 | } | ||
870 | |||
871 | static inline int __cq_empty(struct circular_queue *cq) | ||
872 | { | ||
873 | return (cq->front == cq->rear); | ||
874 | } | ||
875 | |||
876 | static inline int __cq_full(struct circular_queue *cq) | ||
877 | { | ||
878 | return ((cq->rear + 1) & CQ_MASK) == cq->front; | ||
879 | } | ||
880 | |||
881 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | ||
882 | { | ||
883 | if (__cq_full(cq)) | ||
884 | return -1; | ||
885 | |||
886 | cq->element[cq->rear] = elem; | ||
887 | cq->rear = (cq->rear + 1) & CQ_MASK; | ||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) | ||
892 | { | ||
893 | if (__cq_empty(cq)) | ||
894 | return -1; | ||
895 | |||
896 | *elem = cq->element[cq->front]; | ||
897 | cq->front = (cq->front + 1) & CQ_MASK; | ||
898 | return 0; | ||
899 | } | ||
900 | |||
901 | static inline unsigned int __cq_get_elem_count(struct circular_queue *cq) | ||
902 | { | ||
903 | return (cq->rear - cq->front) & CQ_MASK; | ||
904 | } | ||
905 | |||
906 | static inline void mark_lock_accessed(struct lock_list *lock, | ||
907 | struct lock_list *parent) | ||
908 | { | ||
909 | unsigned long nr; | ||
910 | |||
911 | nr = lock - list_entries; | ||
912 | WARN_ON(nr >= nr_list_entries); | ||
913 | lock->parent = parent; | ||
914 | lock->class->dep_gen_id = lockdep_dependency_gen_id; | ||
915 | } | ||
916 | |||
917 | static inline unsigned long lock_accessed(struct lock_list *lock) | ||
918 | { | ||
919 | unsigned long nr; | ||
920 | |||
921 | nr = lock - list_entries; | ||
922 | WARN_ON(nr >= nr_list_entries); | ||
923 | return lock->class->dep_gen_id == lockdep_dependency_gen_id; | ||
924 | } | ||
925 | |||
926 | static inline struct lock_list *get_lock_parent(struct lock_list *child) | ||
927 | { | ||
928 | return child->parent; | ||
929 | } | ||
930 | |||
931 | static inline int get_lock_depth(struct lock_list *child) | ||
932 | { | ||
933 | int depth = 0; | ||
934 | struct lock_list *parent; | ||
935 | |||
936 | while ((parent = get_lock_parent(child))) { | ||
937 | child = parent; | ||
938 | depth++; | ||
939 | } | ||
940 | return depth; | ||
941 | } | ||
942 | |||
943 | static int __bfs(struct lock_list *source_entry, | ||
944 | void *data, | ||
945 | int (*match)(struct lock_list *entry, void *data), | ||
946 | struct lock_list **target_entry, | ||
947 | int forward) | ||
948 | { | ||
949 | struct lock_list *entry; | ||
950 | struct list_head *head; | ||
951 | struct circular_queue *cq = &lock_cq; | ||
952 | int ret = 1; | ||
953 | |||
954 | if (match(source_entry, data)) { | ||
955 | *target_entry = source_entry; | ||
956 | ret = 0; | ||
957 | goto exit; | ||
958 | } | ||
959 | |||
960 | if (forward) | ||
961 | head = &source_entry->class->locks_after; | ||
962 | else | ||
963 | head = &source_entry->class->locks_before; | ||
964 | |||
965 | if (list_empty(head)) | ||
966 | goto exit; | ||
967 | |||
968 | __cq_init(cq); | ||
969 | __cq_enqueue(cq, (unsigned long)source_entry); | ||
970 | |||
971 | while (!__cq_empty(cq)) { | ||
972 | struct lock_list *lock; | ||
973 | |||
974 | __cq_dequeue(cq, (unsigned long *)&lock); | ||
975 | |||
976 | if (!lock->class) { | ||
977 | ret = -2; | ||
978 | goto exit; | ||
979 | } | ||
980 | |||
981 | if (forward) | ||
982 | head = &lock->class->locks_after; | ||
983 | else | ||
984 | head = &lock->class->locks_before; | ||
985 | |||
986 | list_for_each_entry(entry, head, entry) { | ||
987 | if (!lock_accessed(entry)) { | ||
988 | unsigned int cq_depth; | ||
989 | mark_lock_accessed(entry, lock); | ||
990 | if (match(entry, data)) { | ||
991 | *target_entry = entry; | ||
992 | ret = 0; | ||
993 | goto exit; | ||
994 | } | ||
995 | |||
996 | if (__cq_enqueue(cq, (unsigned long)entry)) { | ||
997 | ret = -1; | ||
998 | goto exit; | ||
999 | } | ||
1000 | cq_depth = __cq_get_elem_count(cq); | ||
1001 | if (max_bfs_queue_depth < cq_depth) | ||
1002 | max_bfs_queue_depth = cq_depth; | ||
1003 | } | ||
1004 | } | ||
1005 | } | ||
1006 | exit: | ||
1007 | return ret; | ||
1008 | } | ||
1009 | |||
1010 | static inline int __bfs_forwards(struct lock_list *src_entry, | ||
1011 | void *data, | ||
1012 | int (*match)(struct lock_list *entry, void *data), | ||
1013 | struct lock_list **target_entry) | ||
1014 | { | ||
1015 | return __bfs(src_entry, data, match, target_entry, 1); | ||
1016 | |||
1017 | } | ||
1018 | |||
1019 | static inline int __bfs_backwards(struct lock_list *src_entry, | ||
1020 | void *data, | ||
1021 | int (*match)(struct lock_list *entry, void *data), | ||
1022 | struct lock_list **target_entry) | ||
1023 | { | ||
1024 | return __bfs(src_entry, data, match, target_entry, 0); | ||
1025 | |||
1026 | } | ||
1027 | |||
1028 | /* | ||
901 | * Recursive, forwards-direction lock-dependency checking, used for | 1029 | * Recursive, forwards-direction lock-dependency checking, used for |
902 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe | 1030 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe |
903 | * checking. | 1031 | * checking. |
904 | * | ||
905 | * (to keep the stackframe of the recursive functions small we | ||
906 | * use these global variables, and we also mark various helper | ||
907 | * functions as noinline.) | ||
908 | */ | 1032 | */ |
909 | static struct held_lock *check_source, *check_target; | ||
910 | 1033 | ||
911 | /* | 1034 | /* |
912 | * Print a dependency chain entry (this is only done when a deadlock | 1035 | * Print a dependency chain entry (this is only done when a deadlock |
913 | * has been detected): | 1036 | * has been detected): |
914 | */ | 1037 | */ |
915 | static noinline int | 1038 | static noinline int |
916 | print_circular_bug_entry(struct lock_list *target, unsigned int depth) | 1039 | print_circular_bug_entry(struct lock_list *target, int depth) |
917 | { | 1040 | { |
918 | if (debug_locks_silent) | 1041 | if (debug_locks_silent) |
919 | return 0; | 1042 | return 0; |
@@ -930,11 +1053,13 @@ print_circular_bug_entry(struct lock_list *target, unsigned int depth) | |||
930 | * header first: | 1053 | * header first: |
931 | */ | 1054 | */ |
932 | static noinline int | 1055 | static noinline int |
933 | print_circular_bug_header(struct lock_list *entry, unsigned int depth) | 1056 | print_circular_bug_header(struct lock_list *entry, unsigned int depth, |
1057 | struct held_lock *check_src, | ||
1058 | struct held_lock *check_tgt) | ||
934 | { | 1059 | { |
935 | struct task_struct *curr = current; | 1060 | struct task_struct *curr = current; |
936 | 1061 | ||
937 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 1062 | if (debug_locks_silent) |
938 | return 0; | 1063 | return 0; |
939 | 1064 | ||
940 | printk("\n=======================================================\n"); | 1065 | printk("\n=======================================================\n"); |
@@ -943,9 +1068,9 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
943 | printk( "-------------------------------------------------------\n"); | 1068 | printk( "-------------------------------------------------------\n"); |
944 | printk("%s/%d is trying to acquire lock:\n", | 1069 | printk("%s/%d is trying to acquire lock:\n", |
945 | curr->comm, task_pid_nr(curr)); | 1070 | curr->comm, task_pid_nr(curr)); |
946 | print_lock(check_source); | 1071 | print_lock(check_src); |
947 | printk("\nbut task is already holding lock:\n"); | 1072 | printk("\nbut task is already holding lock:\n"); |
948 | print_lock(check_target); | 1073 | print_lock(check_tgt); |
949 | printk("\nwhich lock already depends on the new lock.\n\n"); | 1074 | printk("\nwhich lock already depends on the new lock.\n\n"); |
950 | printk("\nthe existing dependency chain (in reverse order) is:\n"); | 1075 | printk("\nthe existing dependency chain (in reverse order) is:\n"); |
951 | 1076 | ||
@@ -954,19 +1079,36 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
954 | return 0; | 1079 | return 0; |
955 | } | 1080 | } |
956 | 1081 | ||
957 | static noinline int print_circular_bug_tail(void) | 1082 | static inline int class_equal(struct lock_list *entry, void *data) |
1083 | { | ||
1084 | return entry->class == data; | ||
1085 | } | ||
1086 | |||
1087 | static noinline int print_circular_bug(struct lock_list *this, | ||
1088 | struct lock_list *target, | ||
1089 | struct held_lock *check_src, | ||
1090 | struct held_lock *check_tgt) | ||
958 | { | 1091 | { |
959 | struct task_struct *curr = current; | 1092 | struct task_struct *curr = current; |
960 | struct lock_list this; | 1093 | struct lock_list *parent; |
1094 | int depth; | ||
961 | 1095 | ||
962 | if (debug_locks_silent) | 1096 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
963 | return 0; | 1097 | return 0; |
964 | 1098 | ||
965 | this.class = hlock_class(check_source); | 1099 | if (!save_trace(&this->trace)) |
966 | if (!save_trace(&this.trace)) | ||
967 | return 0; | 1100 | return 0; |
968 | 1101 | ||
969 | print_circular_bug_entry(&this, 0); | 1102 | depth = get_lock_depth(target); |
1103 | |||
1104 | print_circular_bug_header(target, depth, check_src, check_tgt); | ||
1105 | |||
1106 | parent = get_lock_parent(target); | ||
1107 | |||
1108 | while (parent) { | ||
1109 | print_circular_bug_entry(parent, --depth); | ||
1110 | parent = get_lock_parent(parent); | ||
1111 | } | ||
970 | 1112 | ||
971 | printk("\nother info that might help us debug this:\n\n"); | 1113 | printk("\nother info that might help us debug this:\n\n"); |
972 | lockdep_print_held_locks(curr); | 1114 | lockdep_print_held_locks(curr); |
@@ -977,73 +1119,69 @@ static noinline int print_circular_bug_tail(void) | |||
977 | return 0; | 1119 | return 0; |
978 | } | 1120 | } |
979 | 1121 | ||
980 | #define RECURSION_LIMIT 40 | 1122 | static noinline int print_bfs_bug(int ret) |
981 | |||
982 | static int noinline print_infinite_recursion_bug(void) | ||
983 | { | 1123 | { |
984 | if (!debug_locks_off_graph_unlock()) | 1124 | if (!debug_locks_off_graph_unlock()) |
985 | return 0; | 1125 | return 0; |
986 | 1126 | ||
987 | WARN_ON(1); | 1127 | WARN(1, "lockdep bfs error:%d\n", ret); |
988 | 1128 | ||
989 | return 0; | 1129 | return 0; |
990 | } | 1130 | } |
991 | 1131 | ||
992 | unsigned long __lockdep_count_forward_deps(struct lock_class *class, | 1132 | static int noop_count(struct lock_list *entry, void *data) |
993 | unsigned int depth) | ||
994 | { | 1133 | { |
995 | struct lock_list *entry; | 1134 | (*(unsigned long *)data)++; |
996 | unsigned long ret = 1; | 1135 | return 0; |
1136 | } | ||
997 | 1137 | ||
998 | if (lockdep_dependency_visit(class, depth)) | 1138 | unsigned long __lockdep_count_forward_deps(struct lock_list *this) |
999 | return 0; | 1139 | { |
1140 | unsigned long count = 0; | ||
1141 | struct lock_list *uninitialized_var(target_entry); | ||
1000 | 1142 | ||
1001 | /* | 1143 | __bfs_forwards(this, (void *)&count, noop_count, &target_entry); |
1002 | * Recurse this class's dependency list: | ||
1003 | */ | ||
1004 | list_for_each_entry(entry, &class->locks_after, entry) | ||
1005 | ret += __lockdep_count_forward_deps(entry->class, depth + 1); | ||
1006 | 1144 | ||
1007 | return ret; | 1145 | return count; |
1008 | } | 1146 | } |
1009 | |||
1010 | unsigned long lockdep_count_forward_deps(struct lock_class *class) | 1147 | unsigned long lockdep_count_forward_deps(struct lock_class *class) |
1011 | { | 1148 | { |
1012 | unsigned long ret, flags; | 1149 | unsigned long ret, flags; |
1150 | struct lock_list this; | ||
1151 | |||
1152 | this.parent = NULL; | ||
1153 | this.class = class; | ||
1013 | 1154 | ||
1014 | local_irq_save(flags); | 1155 | local_irq_save(flags); |
1015 | __raw_spin_lock(&lockdep_lock); | 1156 | __raw_spin_lock(&lockdep_lock); |
1016 | ret = __lockdep_count_forward_deps(class, 0); | 1157 | ret = __lockdep_count_forward_deps(&this); |
1017 | __raw_spin_unlock(&lockdep_lock); | 1158 | __raw_spin_unlock(&lockdep_lock); |
1018 | local_irq_restore(flags); | 1159 | local_irq_restore(flags); |
1019 | 1160 | ||
1020 | return ret; | 1161 | return ret; |
1021 | } | 1162 | } |
1022 | 1163 | ||
1023 | unsigned long __lockdep_count_backward_deps(struct lock_class *class, | 1164 | unsigned long __lockdep_count_backward_deps(struct lock_list *this) |
1024 | unsigned int depth) | ||
1025 | { | 1165 | { |
1026 | struct lock_list *entry; | 1166 | unsigned long count = 0; |
1027 | unsigned long ret = 1; | 1167 | struct lock_list *uninitialized_var(target_entry); |
1028 | 1168 | ||
1029 | if (lockdep_dependency_visit(class, depth)) | 1169 | __bfs_backwards(this, (void *)&count, noop_count, &target_entry); |
1030 | return 0; | ||
1031 | /* | ||
1032 | * Recurse this class's dependency list: | ||
1033 | */ | ||
1034 | list_for_each_entry(entry, &class->locks_before, entry) | ||
1035 | ret += __lockdep_count_backward_deps(entry->class, depth + 1); | ||
1036 | 1170 | ||
1037 | return ret; | 1171 | return count; |
1038 | } | 1172 | } |
1039 | 1173 | ||
1040 | unsigned long lockdep_count_backward_deps(struct lock_class *class) | 1174 | unsigned long lockdep_count_backward_deps(struct lock_class *class) |
1041 | { | 1175 | { |
1042 | unsigned long ret, flags; | 1176 | unsigned long ret, flags; |
1177 | struct lock_list this; | ||
1178 | |||
1179 | this.parent = NULL; | ||
1180 | this.class = class; | ||
1043 | 1181 | ||
1044 | local_irq_save(flags); | 1182 | local_irq_save(flags); |
1045 | __raw_spin_lock(&lockdep_lock); | 1183 | __raw_spin_lock(&lockdep_lock); |
1046 | ret = __lockdep_count_backward_deps(class, 0); | 1184 | ret = __lockdep_count_backward_deps(&this); |
1047 | __raw_spin_unlock(&lockdep_lock); | 1185 | __raw_spin_unlock(&lockdep_lock); |
1048 | local_irq_restore(flags); | 1186 | local_irq_restore(flags); |
1049 | 1187 | ||
@@ -1055,29 +1193,16 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) | |||
1055 | * lead to <target>. Print an error and return 0 if it does. | 1193 | * lead to <target>. Print an error and return 0 if it does. |
1056 | */ | 1194 | */ |
1057 | static noinline int | 1195 | static noinline int |
1058 | check_noncircular(struct lock_class *source, unsigned int depth) | 1196 | check_noncircular(struct lock_list *root, struct lock_class *target, |
1197 | struct lock_list **target_entry) | ||
1059 | { | 1198 | { |
1060 | struct lock_list *entry; | 1199 | int result; |
1061 | 1200 | ||
1062 | if (lockdep_dependency_visit(source, depth)) | 1201 | debug_atomic_inc(&nr_cyclic_checks); |
1063 | return 1; | ||
1064 | 1202 | ||
1065 | debug_atomic_inc(&nr_cyclic_check_recursions); | 1203 | result = __bfs_forwards(root, target, class_equal, target_entry); |
1066 | if (depth > max_recursion_depth) | 1204 | |
1067 | max_recursion_depth = depth; | 1205 | return result; |
1068 | if (depth >= RECURSION_LIMIT) | ||
1069 | return print_infinite_recursion_bug(); | ||
1070 | /* | ||
1071 | * Check this lock's dependency list: | ||
1072 | */ | ||
1073 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
1074 | if (entry->class == hlock_class(check_target)) | ||
1075 | return print_circular_bug_header(entry, depth+1); | ||
1076 | debug_atomic_inc(&nr_cyclic_checks); | ||
1077 | if (!check_noncircular(entry->class, depth+1)) | ||
1078 | return print_circular_bug_entry(entry, depth+1); | ||
1079 | } | ||
1080 | return 1; | ||
1081 | } | 1206 | } |
1082 | 1207 | ||
1083 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) | 1208 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) |
@@ -1086,103 +1211,121 @@ check_noncircular(struct lock_class *source, unsigned int depth) | |||
1086 | * proving that two subgraphs can be connected by a new dependency | 1211 | * proving that two subgraphs can be connected by a new dependency |
1087 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. | 1212 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. |
1088 | */ | 1213 | */ |
1089 | static enum lock_usage_bit find_usage_bit; | 1214 | |
1090 | static struct lock_class *forwards_match, *backwards_match; | 1215 | static inline int usage_match(struct lock_list *entry, void *bit) |
1216 | { | ||
1217 | return entry->class->usage_mask & (1 << (enum lock_usage_bit)bit); | ||
1218 | } | ||
1219 | |||
1220 | |||
1091 | 1221 | ||
1092 | /* | 1222 | /* |
1093 | * Find a node in the forwards-direction dependency sub-graph starting | 1223 | * Find a node in the forwards-direction dependency sub-graph starting |
1094 | * at <source> that matches <find_usage_bit>. | 1224 | * at @root->class that matches @bit. |
1095 | * | 1225 | * |
1096 | * Return 2 if such a node exists in the subgraph, and put that node | 1226 | * Return 0 if such a node exists in the subgraph, and put that node |
1097 | * into <forwards_match>. | 1227 | * into *@target_entry. |
1098 | * | 1228 | * |
1099 | * Return 1 otherwise and keep <forwards_match> unchanged. | 1229 | * Return 1 otherwise and keep *@target_entry unchanged. |
1100 | * Return 0 on error. | 1230 | * Return <0 on error. |
1101 | */ | 1231 | */ |
1102 | static noinline int | 1232 | static int |
1103 | find_usage_forwards(struct lock_class *source, unsigned int depth) | 1233 | find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit, |
1234 | struct lock_list **target_entry) | ||
1104 | { | 1235 | { |
1105 | struct lock_list *entry; | 1236 | int result; |
1106 | int ret; | ||
1107 | |||
1108 | if (lockdep_dependency_visit(source, depth)) | ||
1109 | return 1; | ||
1110 | |||
1111 | if (depth > max_recursion_depth) | ||
1112 | max_recursion_depth = depth; | ||
1113 | if (depth >= RECURSION_LIMIT) | ||
1114 | return print_infinite_recursion_bug(); | ||
1115 | 1237 | ||
1116 | debug_atomic_inc(&nr_find_usage_forwards_checks); | 1238 | debug_atomic_inc(&nr_find_usage_forwards_checks); |
1117 | if (source->usage_mask & (1 << find_usage_bit)) { | ||
1118 | forwards_match = source; | ||
1119 | return 2; | ||
1120 | } | ||
1121 | 1239 | ||
1122 | /* | 1240 | result = __bfs_forwards(root, (void *)bit, usage_match, target_entry); |
1123 | * Check this lock's dependency list: | 1241 | |
1124 | */ | 1242 | return result; |
1125 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
1126 | debug_atomic_inc(&nr_find_usage_forwards_recursions); | ||
1127 | ret = find_usage_forwards(entry->class, depth+1); | ||
1128 | if (ret == 2 || ret == 0) | ||
1129 | return ret; | ||
1130 | } | ||
1131 | return 1; | ||
1132 | } | 1243 | } |
1133 | 1244 | ||
1134 | /* | 1245 | /* |
1135 | * Find a node in the backwards-direction dependency sub-graph starting | 1246 | * Find a node in the backwards-direction dependency sub-graph starting |
1136 | * at <source> that matches <find_usage_bit>. | 1247 | * at @root->class that matches @bit. |
1137 | * | 1248 | * |
1138 | * Return 2 if such a node exists in the subgraph, and put that node | 1249 | * Return 0 if such a node exists in the subgraph, and put that node |
1139 | * into <backwards_match>. | 1250 | * into *@target_entry. |
1140 | * | 1251 | * |
1141 | * Return 1 otherwise and keep <backwards_match> unchanged. | 1252 | * Return 1 otherwise and keep *@target_entry unchanged. |
1142 | * Return 0 on error. | 1253 | * Return <0 on error. |
1143 | */ | 1254 | */ |
1144 | static noinline int | 1255 | static int |
1145 | find_usage_backwards(struct lock_class *source, unsigned int depth) | 1256 | find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit, |
1257 | struct lock_list **target_entry) | ||
1146 | { | 1258 | { |
1147 | struct lock_list *entry; | 1259 | int result; |
1148 | int ret; | ||
1149 | 1260 | ||
1150 | if (lockdep_dependency_visit(source, depth)) | 1261 | debug_atomic_inc(&nr_find_usage_backwards_checks); |
1151 | return 1; | ||
1152 | 1262 | ||
1153 | if (!__raw_spin_is_locked(&lockdep_lock)) | 1263 | result = __bfs_backwards(root, (void *)bit, usage_match, target_entry); |
1154 | return DEBUG_LOCKS_WARN_ON(1); | ||
1155 | 1264 | ||
1156 | if (depth > max_recursion_depth) | 1265 | return result; |
1157 | max_recursion_depth = depth; | 1266 | } |
1158 | if (depth >= RECURSION_LIMIT) | ||
1159 | return print_infinite_recursion_bug(); | ||
1160 | 1267 | ||
1161 | debug_atomic_inc(&nr_find_usage_backwards_checks); | 1268 | static void print_lock_class_header(struct lock_class *class, int depth) |
1162 | if (source->usage_mask & (1 << find_usage_bit)) { | 1269 | { |
1163 | backwards_match = source; | 1270 | int bit; |
1164 | return 2; | ||
1165 | } | ||
1166 | 1271 | ||
1167 | if (!source && debug_locks_off_graph_unlock()) { | 1272 | printk("%*s->", depth, ""); |
1168 | WARN_ON(1); | 1273 | print_lock_name(class); |
1169 | return 0; | 1274 | printk(" ops: %lu", class->ops); |
1170 | } | 1275 | printk(" {\n"); |
1171 | 1276 | ||
1172 | /* | 1277 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { |
1173 | * Check this lock's dependency list: | 1278 | if (class->usage_mask & (1 << bit)) { |
1174 | */ | 1279 | int len = depth; |
1175 | list_for_each_entry(entry, &source->locks_before, entry) { | 1280 | |
1176 | debug_atomic_inc(&nr_find_usage_backwards_recursions); | 1281 | len += printk("%*s %s", depth, "", usage_str[bit]); |
1177 | ret = find_usage_backwards(entry->class, depth+1); | 1282 | len += printk(" at:\n"); |
1178 | if (ret == 2 || ret == 0) | 1283 | print_stack_trace(class->usage_traces + bit, len); |
1179 | return ret; | 1284 | } |
1180 | } | 1285 | } |
1181 | return 1; | 1286 | printk("%*s }\n", depth, ""); |
1287 | |||
1288 | printk("%*s ... key at: ",depth,""); | ||
1289 | print_ip_sym((unsigned long)class->key); | ||
1290 | } | ||
1291 | |||
1292 | /* | ||
1293 | * printk the shortest lock dependencies from @start to @end in reverse order: | ||
1294 | */ | ||
1295 | static void __used | ||
1296 | print_shortest_lock_dependencies(struct lock_list *leaf, | ||
1297 | struct lock_list *root) | ||
1298 | { | ||
1299 | struct lock_list *entry = leaf; | ||
1300 | int depth; | ||
1301 | |||
1302 | /*compute depth from generated tree by BFS*/ | ||
1303 | depth = get_lock_depth(leaf); | ||
1304 | |||
1305 | do { | ||
1306 | print_lock_class_header(entry->class, depth); | ||
1307 | printk("%*s ... acquired at:\n", depth, ""); | ||
1308 | print_stack_trace(&entry->trace, 2); | ||
1309 | printk("\n"); | ||
1310 | |||
1311 | if (depth == 0 && (entry != root)) { | ||
1312 | printk("lockdep:%s bad BFS generated tree\n", __func__); | ||
1313 | break; | ||
1314 | } | ||
1315 | |||
1316 | entry = get_lock_parent(entry); | ||
1317 | depth--; | ||
1318 | } while (entry && (depth >= 0)); | ||
1319 | |||
1320 | return; | ||
1182 | } | 1321 | } |
1183 | 1322 | ||
1184 | static int | 1323 | static int |
1185 | print_bad_irq_dependency(struct task_struct *curr, | 1324 | print_bad_irq_dependency(struct task_struct *curr, |
1325 | struct lock_list *prev_root, | ||
1326 | struct lock_list *next_root, | ||
1327 | struct lock_list *backwards_entry, | ||
1328 | struct lock_list *forwards_entry, | ||
1186 | struct held_lock *prev, | 1329 | struct held_lock *prev, |
1187 | struct held_lock *next, | 1330 | struct held_lock *next, |
1188 | enum lock_usage_bit bit1, | 1331 | enum lock_usage_bit bit1, |
@@ -1215,26 +1358,32 @@ print_bad_irq_dependency(struct task_struct *curr, | |||
1215 | 1358 | ||
1216 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", | 1359 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", |
1217 | irqclass); | 1360 | irqclass); |
1218 | print_lock_name(backwards_match); | 1361 | print_lock_name(backwards_entry->class); |
1219 | printk("\n... which became %s-irq-safe at:\n", irqclass); | 1362 | printk("\n... which became %s-irq-safe at:\n", irqclass); |
1220 | 1363 | ||
1221 | print_stack_trace(backwards_match->usage_traces + bit1, 1); | 1364 | print_stack_trace(backwards_entry->class->usage_traces + bit1, 1); |
1222 | 1365 | ||
1223 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); | 1366 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); |
1224 | print_lock_name(forwards_match); | 1367 | print_lock_name(forwards_entry->class); |
1225 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); | 1368 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); |
1226 | printk("..."); | 1369 | printk("..."); |
1227 | 1370 | ||
1228 | print_stack_trace(forwards_match->usage_traces + bit2, 1); | 1371 | print_stack_trace(forwards_entry->class->usage_traces + bit2, 1); |
1229 | 1372 | ||
1230 | printk("\nother info that might help us debug this:\n\n"); | 1373 | printk("\nother info that might help us debug this:\n\n"); |
1231 | lockdep_print_held_locks(curr); | 1374 | lockdep_print_held_locks(curr); |
1232 | 1375 | ||
1233 | printk("\nthe %s-irq-safe lock's dependencies:\n", irqclass); | 1376 | printk("\nthe dependencies between %s-irq-safe lock", irqclass); |
1234 | print_lock_dependencies(backwards_match, 0); | 1377 | printk(" and the holding lock:\n"); |
1378 | if (!save_trace(&prev_root->trace)) | ||
1379 | return 0; | ||
1380 | print_shortest_lock_dependencies(backwards_entry, prev_root); | ||
1235 | 1381 | ||
1236 | printk("\nthe %s-irq-unsafe lock's dependencies:\n", irqclass); | 1382 | printk("\nthe dependencies between the lock to be acquired"); |
1237 | print_lock_dependencies(forwards_match, 0); | 1383 | printk(" and %s-irq-unsafe lock:\n", irqclass); |
1384 | if (!save_trace(&next_root->trace)) | ||
1385 | return 0; | ||
1386 | print_shortest_lock_dependencies(forwards_entry, next_root); | ||
1238 | 1387 | ||
1239 | printk("\nstack backtrace:\n"); | 1388 | printk("\nstack backtrace:\n"); |
1240 | dump_stack(); | 1389 | dump_stack(); |
@@ -1248,19 +1397,30 @@ check_usage(struct task_struct *curr, struct held_lock *prev, | |||
1248 | enum lock_usage_bit bit_forwards, const char *irqclass) | 1397 | enum lock_usage_bit bit_forwards, const char *irqclass) |
1249 | { | 1398 | { |
1250 | int ret; | 1399 | int ret; |
1400 | struct lock_list this, that; | ||
1401 | struct lock_list *uninitialized_var(target_entry); | ||
1402 | struct lock_list *uninitialized_var(target_entry1); | ||
1251 | 1403 | ||
1252 | find_usage_bit = bit_backwards; | 1404 | this.parent = NULL; |
1253 | /* fills in <backwards_match> */ | 1405 | |
1254 | ret = find_usage_backwards(hlock_class(prev), 0); | 1406 | this.class = hlock_class(prev); |
1255 | if (!ret || ret == 1) | 1407 | ret = find_usage_backwards(&this, bit_backwards, &target_entry); |
1408 | if (ret < 0) | ||
1409 | return print_bfs_bug(ret); | ||
1410 | if (ret == 1) | ||
1256 | return ret; | 1411 | return ret; |
1257 | 1412 | ||
1258 | find_usage_bit = bit_forwards; | 1413 | that.parent = NULL; |
1259 | ret = find_usage_forwards(hlock_class(next), 0); | 1414 | that.class = hlock_class(next); |
1260 | if (!ret || ret == 1) | 1415 | ret = find_usage_forwards(&that, bit_forwards, &target_entry1); |
1416 | if (ret < 0) | ||
1417 | return print_bfs_bug(ret); | ||
1418 | if (ret == 1) | ||
1261 | return ret; | 1419 | return ret; |
1262 | /* ret == 2 */ | 1420 | |
1263 | return print_bad_irq_dependency(curr, prev, next, | 1421 | return print_bad_irq_dependency(curr, &this, &that, |
1422 | target_entry, target_entry1, | ||
1423 | prev, next, | ||
1264 | bit_backwards, bit_forwards, irqclass); | 1424 | bit_backwards, bit_forwards, irqclass); |
1265 | } | 1425 | } |
1266 | 1426 | ||
@@ -1472,6 +1632,8 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1472 | { | 1632 | { |
1473 | struct lock_list *entry; | 1633 | struct lock_list *entry; |
1474 | int ret; | 1634 | int ret; |
1635 | struct lock_list this; | ||
1636 | struct lock_list *uninitialized_var(target_entry); | ||
1475 | 1637 | ||
1476 | /* | 1638 | /* |
1477 | * Prove that the new <prev> -> <next> dependency would not | 1639 | * Prove that the new <prev> -> <next> dependency would not |
@@ -1482,10 +1644,13 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1482 | * We are using global variables to control the recursion, to | 1644 | * We are using global variables to control the recursion, to |
1483 | * keep the stackframe size of the recursive functions low: | 1645 | * keep the stackframe size of the recursive functions low: |
1484 | */ | 1646 | */ |
1485 | check_source = next; | 1647 | this.class = hlock_class(next); |
1486 | check_target = prev; | 1648 | this.parent = NULL; |
1487 | if (!(check_noncircular(hlock_class(next), 0))) | 1649 | ret = check_noncircular(&this, hlock_class(prev), &target_entry); |
1488 | return print_circular_bug_tail(); | 1650 | if (unlikely(!ret)) |
1651 | return print_circular_bug(&this, target_entry, next, prev); | ||
1652 | else if (unlikely(ret < 0)) | ||
1653 | return print_bfs_bug(ret); | ||
1489 | 1654 | ||
1490 | if (!check_prev_add_irq(curr, prev, next)) | 1655 | if (!check_prev_add_irq(curr, prev, next)) |
1491 | return 0; | 1656 | return 0; |
@@ -1884,7 +2049,8 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
1884 | * print irq inversion bug: | 2049 | * print irq inversion bug: |
1885 | */ | 2050 | */ |
1886 | static int | 2051 | static int |
1887 | print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | 2052 | print_irq_inversion_bug(struct task_struct *curr, |
2053 | struct lock_list *root, struct lock_list *other, | ||
1888 | struct held_lock *this, int forwards, | 2054 | struct held_lock *this, int forwards, |
1889 | const char *irqclass) | 2055 | const char *irqclass) |
1890 | { | 2056 | { |
@@ -1902,17 +2068,16 @@ print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | |||
1902 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); | 2068 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); |
1903 | else | 2069 | else |
1904 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); | 2070 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); |
1905 | print_lock_name(other); | 2071 | print_lock_name(other->class); |
1906 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); | 2072 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); |
1907 | 2073 | ||
1908 | printk("\nother info that might help us debug this:\n"); | 2074 | printk("\nother info that might help us debug this:\n"); |
1909 | lockdep_print_held_locks(curr); | 2075 | lockdep_print_held_locks(curr); |
1910 | 2076 | ||
1911 | printk("\nthe first lock's dependencies:\n"); | 2077 | printk("\nthe shortest dependencies between 2nd lock and 1st lock:\n"); |
1912 | print_lock_dependencies(hlock_class(this), 0); | 2078 | if (!save_trace(&root->trace)) |
1913 | 2079 | return 0; | |
1914 | printk("\nthe second lock's dependencies:\n"); | 2080 | print_shortest_lock_dependencies(other, root); |
1915 | print_lock_dependencies(other, 0); | ||
1916 | 2081 | ||
1917 | printk("\nstack backtrace:\n"); | 2082 | printk("\nstack backtrace:\n"); |
1918 | dump_stack(); | 2083 | dump_stack(); |
@@ -1929,14 +2094,19 @@ check_usage_forwards(struct task_struct *curr, struct held_lock *this, | |||
1929 | enum lock_usage_bit bit, const char *irqclass) | 2094 | enum lock_usage_bit bit, const char *irqclass) |
1930 | { | 2095 | { |
1931 | int ret; | 2096 | int ret; |
1932 | 2097 | struct lock_list root; | |
1933 | find_usage_bit = bit; | 2098 | struct lock_list *uninitialized_var(target_entry); |
1934 | /* fills in <forwards_match> */ | 2099 | |
1935 | ret = find_usage_forwards(hlock_class(this), 0); | 2100 | root.parent = NULL; |
1936 | if (!ret || ret == 1) | 2101 | root.class = hlock_class(this); |
2102 | ret = find_usage_forwards(&root, bit, &target_entry); | ||
2103 | if (ret < 0) | ||
2104 | return print_bfs_bug(ret); | ||
2105 | if (ret == 1) | ||
1937 | return ret; | 2106 | return ret; |
1938 | 2107 | ||
1939 | return print_irq_inversion_bug(curr, forwards_match, this, 1, irqclass); | 2108 | return print_irq_inversion_bug(curr, &root, target_entry, |
2109 | this, 1, irqclass); | ||
1940 | } | 2110 | } |
1941 | 2111 | ||
1942 | /* | 2112 | /* |
@@ -1948,14 +2118,19 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this, | |||
1948 | enum lock_usage_bit bit, const char *irqclass) | 2118 | enum lock_usage_bit bit, const char *irqclass) |
1949 | { | 2119 | { |
1950 | int ret; | 2120 | int ret; |
1951 | 2121 | struct lock_list root; | |
1952 | find_usage_bit = bit; | 2122 | struct lock_list *uninitialized_var(target_entry); |
1953 | /* fills in <backwards_match> */ | 2123 | |
1954 | ret = find_usage_backwards(hlock_class(this), 0); | 2124 | root.parent = NULL; |
1955 | if (!ret || ret == 1) | 2125 | root.class = hlock_class(this); |
2126 | ret = find_usage_backwards(&root, bit, &target_entry); | ||
2127 | if (ret < 0) | ||
2128 | return print_bfs_bug(ret); | ||
2129 | if (ret == 1) | ||
1956 | return ret; | 2130 | return ret; |
1957 | 2131 | ||
1958 | return print_irq_inversion_bug(curr, backwards_match, this, 0, irqclass); | 2132 | return print_irq_inversion_bug(curr, &root, target_entry, |
2133 | this, 1, irqclass); | ||
1959 | } | 2134 | } |
1960 | 2135 | ||
1961 | void print_irqtrace_events(struct task_struct *curr) | 2136 | void print_irqtrace_events(struct task_struct *curr) |
@@ -2530,13 +2705,15 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); | |||
2530 | */ | 2705 | */ |
2531 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 2706 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
2532 | int trylock, int read, int check, int hardirqs_off, | 2707 | int trylock, int read, int check, int hardirqs_off, |
2533 | struct lockdep_map *nest_lock, unsigned long ip) | 2708 | struct lockdep_map *nest_lock, unsigned long ip, |
2709 | int references) | ||
2534 | { | 2710 | { |
2535 | struct task_struct *curr = current; | 2711 | struct task_struct *curr = current; |
2536 | struct lock_class *class = NULL; | 2712 | struct lock_class *class = NULL; |
2537 | struct held_lock *hlock; | 2713 | struct held_lock *hlock; |
2538 | unsigned int depth, id; | 2714 | unsigned int depth, id; |
2539 | int chain_head = 0; | 2715 | int chain_head = 0; |
2716 | int class_idx; | ||
2540 | u64 chain_key; | 2717 | u64 chain_key; |
2541 | 2718 | ||
2542 | if (!prove_locking) | 2719 | if (!prove_locking) |
@@ -2584,10 +2761,24 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2584 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) | 2761 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) |
2585 | return 0; | 2762 | return 0; |
2586 | 2763 | ||
2764 | class_idx = class - lock_classes + 1; | ||
2765 | |||
2766 | if (depth) { | ||
2767 | hlock = curr->held_locks + depth - 1; | ||
2768 | if (hlock->class_idx == class_idx && nest_lock) { | ||
2769 | if (hlock->references) | ||
2770 | hlock->references++; | ||
2771 | else | ||
2772 | hlock->references = 2; | ||
2773 | |||
2774 | return 1; | ||
2775 | } | ||
2776 | } | ||
2777 | |||
2587 | hlock = curr->held_locks + depth; | 2778 | hlock = curr->held_locks + depth; |
2588 | if (DEBUG_LOCKS_WARN_ON(!class)) | 2779 | if (DEBUG_LOCKS_WARN_ON(!class)) |
2589 | return 0; | 2780 | return 0; |
2590 | hlock->class_idx = class - lock_classes + 1; | 2781 | hlock->class_idx = class_idx; |
2591 | hlock->acquire_ip = ip; | 2782 | hlock->acquire_ip = ip; |
2592 | hlock->instance = lock; | 2783 | hlock->instance = lock; |
2593 | hlock->nest_lock = nest_lock; | 2784 | hlock->nest_lock = nest_lock; |
@@ -2595,6 +2786,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2595 | hlock->read = read; | 2786 | hlock->read = read; |
2596 | hlock->check = check; | 2787 | hlock->check = check; |
2597 | hlock->hardirqs_off = !!hardirqs_off; | 2788 | hlock->hardirqs_off = !!hardirqs_off; |
2789 | hlock->references = references; | ||
2598 | #ifdef CONFIG_LOCK_STAT | 2790 | #ifdef CONFIG_LOCK_STAT |
2599 | hlock->waittime_stamp = 0; | 2791 | hlock->waittime_stamp = 0; |
2600 | hlock->holdtime_stamp = sched_clock(); | 2792 | hlock->holdtime_stamp = sched_clock(); |
@@ -2703,6 +2895,30 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock, | |||
2703 | return 1; | 2895 | return 1; |
2704 | } | 2896 | } |
2705 | 2897 | ||
2898 | static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock) | ||
2899 | { | ||
2900 | if (hlock->instance == lock) | ||
2901 | return 1; | ||
2902 | |||
2903 | if (hlock->references) { | ||
2904 | struct lock_class *class = lock->class_cache; | ||
2905 | |||
2906 | if (!class) | ||
2907 | class = look_up_lock_class(lock, 0); | ||
2908 | |||
2909 | if (DEBUG_LOCKS_WARN_ON(!class)) | ||
2910 | return 0; | ||
2911 | |||
2912 | if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) | ||
2913 | return 0; | ||
2914 | |||
2915 | if (hlock->class_idx == class - lock_classes + 1) | ||
2916 | return 1; | ||
2917 | } | ||
2918 | |||
2919 | return 0; | ||
2920 | } | ||
2921 | |||
2706 | static int | 2922 | static int |
2707 | __lock_set_class(struct lockdep_map *lock, const char *name, | 2923 | __lock_set_class(struct lockdep_map *lock, const char *name, |
2708 | struct lock_class_key *key, unsigned int subclass, | 2924 | struct lock_class_key *key, unsigned int subclass, |
@@ -2726,7 +2942,7 @@ __lock_set_class(struct lockdep_map *lock, const char *name, | |||
2726 | */ | 2942 | */ |
2727 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 2943 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
2728 | break; | 2944 | break; |
2729 | if (hlock->instance == lock) | 2945 | if (match_held_lock(hlock, lock)) |
2730 | goto found_it; | 2946 | goto found_it; |
2731 | prev_hlock = hlock; | 2947 | prev_hlock = hlock; |
2732 | } | 2948 | } |
@@ -2745,7 +2961,8 @@ found_it: | |||
2745 | if (!__lock_acquire(hlock->instance, | 2961 | if (!__lock_acquire(hlock->instance, |
2746 | hlock_class(hlock)->subclass, hlock->trylock, | 2962 | hlock_class(hlock)->subclass, hlock->trylock, |
2747 | hlock->read, hlock->check, hlock->hardirqs_off, | 2963 | hlock->read, hlock->check, hlock->hardirqs_off, |
2748 | hlock->nest_lock, hlock->acquire_ip)) | 2964 | hlock->nest_lock, hlock->acquire_ip, |
2965 | hlock->references)) | ||
2749 | return 0; | 2966 | return 0; |
2750 | } | 2967 | } |
2751 | 2968 | ||
@@ -2784,20 +3001,34 @@ lock_release_non_nested(struct task_struct *curr, | |||
2784 | */ | 3001 | */ |
2785 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3002 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
2786 | break; | 3003 | break; |
2787 | if (hlock->instance == lock) | 3004 | if (match_held_lock(hlock, lock)) |
2788 | goto found_it; | 3005 | goto found_it; |
2789 | prev_hlock = hlock; | 3006 | prev_hlock = hlock; |
2790 | } | 3007 | } |
2791 | return print_unlock_inbalance_bug(curr, lock, ip); | 3008 | return print_unlock_inbalance_bug(curr, lock, ip); |
2792 | 3009 | ||
2793 | found_it: | 3010 | found_it: |
2794 | lock_release_holdtime(hlock); | 3011 | if (hlock->instance == lock) |
3012 | lock_release_holdtime(hlock); | ||
3013 | |||
3014 | if (hlock->references) { | ||
3015 | hlock->references--; | ||
3016 | if (hlock->references) { | ||
3017 | /* | ||
3018 | * We had, and after removing one, still have | ||
3019 | * references, the current lock stack is still | ||
3020 | * valid. We're done! | ||
3021 | */ | ||
3022 | return 1; | ||
3023 | } | ||
3024 | } | ||
2795 | 3025 | ||
2796 | /* | 3026 | /* |
2797 | * We have the right lock to unlock, 'hlock' points to it. | 3027 | * We have the right lock to unlock, 'hlock' points to it. |
2798 | * Now we remove it from the stack, and add back the other | 3028 | * Now we remove it from the stack, and add back the other |
2799 | * entries (if any), recalculating the hash along the way: | 3029 | * entries (if any), recalculating the hash along the way: |
2800 | */ | 3030 | */ |
3031 | |||
2801 | curr->lockdep_depth = i; | 3032 | curr->lockdep_depth = i; |
2802 | curr->curr_chain_key = hlock->prev_chain_key; | 3033 | curr->curr_chain_key = hlock->prev_chain_key; |
2803 | 3034 | ||
@@ -2806,7 +3037,8 @@ found_it: | |||
2806 | if (!__lock_acquire(hlock->instance, | 3037 | if (!__lock_acquire(hlock->instance, |
2807 | hlock_class(hlock)->subclass, hlock->trylock, | 3038 | hlock_class(hlock)->subclass, hlock->trylock, |
2808 | hlock->read, hlock->check, hlock->hardirqs_off, | 3039 | hlock->read, hlock->check, hlock->hardirqs_off, |
2809 | hlock->nest_lock, hlock->acquire_ip)) | 3040 | hlock->nest_lock, hlock->acquire_ip, |
3041 | hlock->references)) | ||
2810 | return 0; | 3042 | return 0; |
2811 | } | 3043 | } |
2812 | 3044 | ||
@@ -2836,7 +3068,7 @@ static int lock_release_nested(struct task_struct *curr, | |||
2836 | /* | 3068 | /* |
2837 | * Is the unlock non-nested: | 3069 | * Is the unlock non-nested: |
2838 | */ | 3070 | */ |
2839 | if (hlock->instance != lock) | 3071 | if (hlock->instance != lock || hlock->references) |
2840 | return lock_release_non_nested(curr, lock, ip); | 3072 | return lock_release_non_nested(curr, lock, ip); |
2841 | curr->lockdep_depth--; | 3073 | curr->lockdep_depth--; |
2842 | 3074 | ||
@@ -2881,6 +3113,21 @@ __lock_release(struct lockdep_map *lock, int nested, unsigned long ip) | |||
2881 | check_chain_key(curr); | 3113 | check_chain_key(curr); |
2882 | } | 3114 | } |
2883 | 3115 | ||
3116 | static int __lock_is_held(struct lockdep_map *lock) | ||
3117 | { | ||
3118 | struct task_struct *curr = current; | ||
3119 | int i; | ||
3120 | |||
3121 | for (i = 0; i < curr->lockdep_depth; i++) { | ||
3122 | struct held_lock *hlock = curr->held_locks + i; | ||
3123 | |||
3124 | if (match_held_lock(hlock, lock)) | ||
3125 | return 1; | ||
3126 | } | ||
3127 | |||
3128 | return 0; | ||
3129 | } | ||
3130 | |||
2884 | /* | 3131 | /* |
2885 | * Check whether we follow the irq-flags state precisely: | 3132 | * Check whether we follow the irq-flags state precisely: |
2886 | */ | 3133 | */ |
@@ -2957,7 +3204,7 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2957 | 3204 | ||
2958 | current->lockdep_recursion = 1; | 3205 | current->lockdep_recursion = 1; |
2959 | __lock_acquire(lock, subclass, trylock, read, check, | 3206 | __lock_acquire(lock, subclass, trylock, read, check, |
2960 | irqs_disabled_flags(flags), nest_lock, ip); | 3207 | irqs_disabled_flags(flags), nest_lock, ip, 0); |
2961 | current->lockdep_recursion = 0; | 3208 | current->lockdep_recursion = 0; |
2962 | raw_local_irq_restore(flags); | 3209 | raw_local_irq_restore(flags); |
2963 | } | 3210 | } |
@@ -2982,6 +3229,26 @@ void lock_release(struct lockdep_map *lock, int nested, | |||
2982 | } | 3229 | } |
2983 | EXPORT_SYMBOL_GPL(lock_release); | 3230 | EXPORT_SYMBOL_GPL(lock_release); |
2984 | 3231 | ||
3232 | int lock_is_held(struct lockdep_map *lock) | ||
3233 | { | ||
3234 | unsigned long flags; | ||
3235 | int ret = 0; | ||
3236 | |||
3237 | if (unlikely(current->lockdep_recursion)) | ||
3238 | return ret; | ||
3239 | |||
3240 | raw_local_irq_save(flags); | ||
3241 | check_flags(flags); | ||
3242 | |||
3243 | current->lockdep_recursion = 1; | ||
3244 | ret = __lock_is_held(lock); | ||
3245 | current->lockdep_recursion = 0; | ||
3246 | raw_local_irq_restore(flags); | ||
3247 | |||
3248 | return ret; | ||
3249 | } | ||
3250 | EXPORT_SYMBOL_GPL(lock_is_held); | ||
3251 | |||
2985 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) | 3252 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) |
2986 | { | 3253 | { |
2987 | current->lockdep_reclaim_gfp = gfp_mask; | 3254 | current->lockdep_reclaim_gfp = gfp_mask; |
@@ -3041,7 +3308,7 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
3041 | */ | 3308 | */ |
3042 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3309 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
3043 | break; | 3310 | break; |
3044 | if (hlock->instance == lock) | 3311 | if (match_held_lock(hlock, lock)) |
3045 | goto found_it; | 3312 | goto found_it; |
3046 | prev_hlock = hlock; | 3313 | prev_hlock = hlock; |
3047 | } | 3314 | } |
@@ -3049,6 +3316,9 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
3049 | return; | 3316 | return; |
3050 | 3317 | ||
3051 | found_it: | 3318 | found_it: |
3319 | if (hlock->instance != lock) | ||
3320 | return; | ||
3321 | |||
3052 | hlock->waittime_stamp = sched_clock(); | 3322 | hlock->waittime_stamp = sched_clock(); |
3053 | 3323 | ||
3054 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); | 3324 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); |
@@ -3088,7 +3358,7 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
3088 | */ | 3358 | */ |
3089 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3359 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
3090 | break; | 3360 | break; |
3091 | if (hlock->instance == lock) | 3361 | if (match_held_lock(hlock, lock)) |
3092 | goto found_it; | 3362 | goto found_it; |
3093 | prev_hlock = hlock; | 3363 | prev_hlock = hlock; |
3094 | } | 3364 | } |
@@ -3096,6 +3366,9 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
3096 | return; | 3366 | return; |
3097 | 3367 | ||
3098 | found_it: | 3368 | found_it: |
3369 | if (hlock->instance != lock) | ||
3370 | return; | ||
3371 | |||
3099 | cpu = smp_processor_id(); | 3372 | cpu = smp_processor_id(); |
3100 | if (hlock->waittime_stamp) { | 3373 | if (hlock->waittime_stamp) { |
3101 | now = sched_clock(); | 3374 | now = sched_clock(); |
@@ -3326,7 +3599,12 @@ void __init lockdep_info(void) | |||
3326 | sizeof(struct list_head) * CLASSHASH_SIZE + | 3599 | sizeof(struct list_head) * CLASSHASH_SIZE + |
3327 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + | 3600 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + |
3328 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + | 3601 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + |
3329 | sizeof(struct list_head) * CHAINHASH_SIZE) / 1024); | 3602 | sizeof(struct list_head) * CHAINHASH_SIZE |
3603 | #ifdef CONFIG_PROVE_LOCKING | ||
3604 | + sizeof(struct circular_queue) | ||
3605 | #endif | ||
3606 | ) / 1024 | ||
3607 | ); | ||
3330 | 3608 | ||
3331 | printk(" per task-struct memory footprint: %lu bytes\n", | 3609 | printk(" per task-struct memory footprint: %lu bytes\n", |
3332 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); | 3610 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); |