diff options
author | Ingo Molnar <mingo@elte.hu> | 2006-07-03 03:24:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-07-03 18:27:01 -0400 |
commit | 9a11b49a805665e13a56aa067afaf81d43ec1514 (patch) | |
tree | bf499956e3f67d1211d68ab1e2eb76645f453dfb /include/linux | |
parent | fb7e42413a098cc45b3adf858da290033af62bae (diff) |
[PATCH] lockdep: better lock debugging
Generic lock debugging:
- generalized lock debugging framework. For example, a bug in one lock
subsystem turns off debugging in all lock subsystems.
- got rid of the caller address passing (__IP__/__IP_DECL__/etc.) from
the mutex/rtmutex debugging code: it caused way too much prototype
hackery, and lockdep will give the same information anyway.
- ability to do silent tests
- check lock freeing in vfree too.
- more finegrained debugging options, to allow distributions to
turn off more expensive debugging features.
There's no separate 'held mutexes' list anymore - but there's a 'held locks'
stack within lockdep, which unifies deadlock detection across all lock
classes. (this is independent of the lockdep validation stuff - lockdep first
checks whether we are holding a lock already)
Here are the current debugging options:
CONFIG_DEBUG_MUTEXES=y
CONFIG_DEBUG_LOCK_ALLOC=y
which do:
config DEBUG_MUTEXES
bool "Mutex debugging, basic checks"
config DEBUG_LOCK_ALLOC
bool "Detect incorrect freeing of live mutexes"
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/debug_locks.h | 69 | ||||
-rw-r--r-- | include/linux/init_task.h | 1 | ||||
-rw-r--r-- | include/linux/mm.h | 8 | ||||
-rw-r--r-- | include/linux/mutex-debug.h | 12 | ||||
-rw-r--r-- | include/linux/mutex.h | 6 | ||||
-rw-r--r-- | include/linux/rtmutex.h | 10 | ||||
-rw-r--r-- | include/linux/sched.h | 4 |
7 files changed, 73 insertions, 37 deletions
diff --git a/include/linux/debug_locks.h b/include/linux/debug_locks.h new file mode 100644 index 000000000000..6a7047851e48 --- /dev/null +++ b/include/linux/debug_locks.h | |||
@@ -0,0 +1,69 @@ | |||
1 | #ifndef __LINUX_DEBUG_LOCKING_H | ||
2 | #define __LINUX_DEBUG_LOCKING_H | ||
3 | |||
4 | extern int debug_locks; | ||
5 | extern int debug_locks_silent; | ||
6 | |||
7 | /* | ||
8 | * Generic 'turn off all lock debugging' function: | ||
9 | */ | ||
10 | extern int debug_locks_off(void); | ||
11 | |||
12 | /* | ||
13 | * In the debug case we carry the caller's instruction pointer into | ||
14 | * other functions, but we dont want the function argument overhead | ||
15 | * in the nondebug case - hence these macros: | ||
16 | */ | ||
17 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) | ||
18 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) | ||
19 | |||
20 | #define DEBUG_LOCKS_WARN_ON(c) \ | ||
21 | ({ \ | ||
22 | int __ret = 0; \ | ||
23 | \ | ||
24 | if (unlikely(c)) { \ | ||
25 | if (debug_locks_off()) \ | ||
26 | WARN_ON(1); \ | ||
27 | __ret = 1; \ | ||
28 | } \ | ||
29 | __ret; \ | ||
30 | }) | ||
31 | |||
32 | #ifdef CONFIG_SMP | ||
33 | # define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c) | ||
34 | #else | ||
35 | # define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0) | ||
36 | #endif | ||
37 | |||
38 | #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS | ||
39 | extern void locking_selftest(void); | ||
40 | #else | ||
41 | # define locking_selftest() do { } while (0) | ||
42 | #endif | ||
43 | |||
44 | #ifdef CONFIG_LOCKDEP | ||
45 | extern void debug_show_all_locks(void); | ||
46 | extern void debug_show_held_locks(struct task_struct *task); | ||
47 | extern void debug_check_no_locks_freed(const void *from, unsigned long len); | ||
48 | extern void debug_check_no_locks_held(struct task_struct *task); | ||
49 | #else | ||
50 | static inline void debug_show_all_locks(void) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | static inline void debug_show_held_locks(struct task_struct *task) | ||
55 | { | ||
56 | } | ||
57 | |||
58 | static inline void | ||
59 | debug_check_no_locks_freed(const void *from, unsigned long len) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | static inline void | ||
64 | debug_check_no_locks_held(struct task_struct *task) | ||
65 | { | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | #endif | ||
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index 3a256957fb56..678c1a90380d 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
@@ -124,7 +124,6 @@ extern struct group_info init_groups; | |||
124 | .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ | 124 | .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ |
125 | .fs_excl = ATOMIC_INIT(0), \ | 125 | .fs_excl = ATOMIC_INIT(0), \ |
126 | .pi_lock = SPIN_LOCK_UNLOCKED, \ | 126 | .pi_lock = SPIN_LOCK_UNLOCKED, \ |
127 | INIT_RT_MUTEXES(tsk) \ | ||
128 | } | 127 | } |
129 | 128 | ||
130 | 129 | ||
diff --git a/include/linux/mm.h b/include/linux/mm.h index 75179529e399..990957e0929f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/prio_tree.h> | 14 | #include <linux/prio_tree.h> |
15 | #include <linux/fs.h> | 15 | #include <linux/fs.h> |
16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
17 | #include <linux/debug_locks.h> | ||
17 | 18 | ||
18 | struct mempolicy; | 19 | struct mempolicy; |
19 | struct anon_vma; | 20 | struct anon_vma; |
@@ -1034,13 +1035,6 @@ static inline void vm_stat_account(struct mm_struct *mm, | |||
1034 | } | 1035 | } |
1035 | #endif /* CONFIG_PROC_FS */ | 1036 | #endif /* CONFIG_PROC_FS */ |
1036 | 1037 | ||
1037 | static inline void | ||
1038 | debug_check_no_locks_freed(const void *from, unsigned long len) | ||
1039 | { | ||
1040 | mutex_debug_check_no_locks_freed(from, len); | ||
1041 | rt_mutex_debug_check_no_locks_freed(from, len); | ||
1042 | } | ||
1043 | |||
1044 | #ifndef CONFIG_DEBUG_PAGEALLOC | 1038 | #ifndef CONFIG_DEBUG_PAGEALLOC |
1045 | static inline void | 1039 | static inline void |
1046 | kernel_map_pages(struct page *page, int numpages, int enable) | 1040 | kernel_map_pages(struct page *page, int numpages, int enable) |
diff --git a/include/linux/mutex-debug.h b/include/linux/mutex-debug.h index 8b5769f00467..70a26091fc73 100644 --- a/include/linux/mutex-debug.h +++ b/include/linux/mutex-debug.h | |||
@@ -7,17 +7,11 @@ | |||
7 | * Mutexes - debugging helpers: | 7 | * Mutexes - debugging helpers: |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #define __DEBUG_MUTEX_INITIALIZER(lockname) \ | 10 | #define __DEBUG_MUTEX_INITIALIZER(lockname) \ |
11 | , .held_list = LIST_HEAD_INIT(lockname.held_list), \ | 11 | , .magic = &lockname |
12 | .name = #lockname , .magic = &lockname | ||
13 | 12 | ||
14 | #define mutex_init(sem) __mutex_init(sem, __FUNCTION__) | 13 | #define mutex_init(sem) __mutex_init(sem, __FILE__":"#sem) |
15 | 14 | ||
16 | extern void FASTCALL(mutex_destroy(struct mutex *lock)); | 15 | extern void FASTCALL(mutex_destroy(struct mutex *lock)); |
17 | 16 | ||
18 | extern void mutex_debug_show_all_locks(void); | ||
19 | extern void mutex_debug_show_held_locks(struct task_struct *filter); | ||
20 | extern void mutex_debug_check_no_locks_held(struct task_struct *task); | ||
21 | extern void mutex_debug_check_no_locks_freed(const void *from, unsigned long len); | ||
22 | |||
23 | #endif | 17 | #endif |
diff --git a/include/linux/mutex.h b/include/linux/mutex.h index f1ac507fa20d..caafecd5e366 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h | |||
@@ -50,8 +50,6 @@ struct mutex { | |||
50 | struct list_head wait_list; | 50 | struct list_head wait_list; |
51 | #ifdef CONFIG_DEBUG_MUTEXES | 51 | #ifdef CONFIG_DEBUG_MUTEXES |
52 | struct thread_info *owner; | 52 | struct thread_info *owner; |
53 | struct list_head held_list; | ||
54 | unsigned long acquire_ip; | ||
55 | const char *name; | 53 | const char *name; |
56 | void *magic; | 54 | void *magic; |
57 | #endif | 55 | #endif |
@@ -76,10 +74,6 @@ struct mutex_waiter { | |||
76 | # define __DEBUG_MUTEX_INITIALIZER(lockname) | 74 | # define __DEBUG_MUTEX_INITIALIZER(lockname) |
77 | # define mutex_init(mutex) __mutex_init(mutex, NULL) | 75 | # define mutex_init(mutex) __mutex_init(mutex, NULL) |
78 | # define mutex_destroy(mutex) do { } while (0) | 76 | # define mutex_destroy(mutex) do { } while (0) |
79 | # define mutex_debug_show_all_locks() do { } while (0) | ||
80 | # define mutex_debug_show_held_locks(p) do { } while (0) | ||
81 | # define mutex_debug_check_no_locks_held(task) do { } while (0) | ||
82 | # define mutex_debug_check_no_locks_freed(from, len) do { } while (0) | ||
83 | #endif | 77 | #endif |
84 | 78 | ||
85 | #define __MUTEX_INITIALIZER(lockname) \ | 79 | #define __MUTEX_INITIALIZER(lockname) \ |
diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index fa4a3b82ba70..5d41dee82f80 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h | |||
@@ -29,8 +29,6 @@ struct rt_mutex { | |||
29 | struct task_struct *owner; | 29 | struct task_struct *owner; |
30 | #ifdef CONFIG_DEBUG_RT_MUTEXES | 30 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
31 | int save_state; | 31 | int save_state; |
32 | struct list_head held_list_entry; | ||
33 | unsigned long acquire_ip; | ||
34 | const char *name, *file; | 32 | const char *name, *file; |
35 | int line; | 33 | int line; |
36 | void *magic; | 34 | void *magic; |
@@ -98,14 +96,6 @@ extern int rt_mutex_trylock(struct rt_mutex *lock); | |||
98 | 96 | ||
99 | extern void rt_mutex_unlock(struct rt_mutex *lock); | 97 | extern void rt_mutex_unlock(struct rt_mutex *lock); |
100 | 98 | ||
101 | #ifdef CONFIG_DEBUG_RT_MUTEXES | ||
102 | # define INIT_RT_MUTEX_DEBUG(tsk) \ | ||
103 | .held_list_head = LIST_HEAD_INIT(tsk.held_list_head), \ | ||
104 | .held_list_lock = SPIN_LOCK_UNLOCKED | ||
105 | #else | ||
106 | # define INIT_RT_MUTEX_DEBUG(tsk) | ||
107 | #endif | ||
108 | |||
109 | #ifdef CONFIG_RT_MUTEXES | 99 | #ifdef CONFIG_RT_MUTEXES |
110 | # define INIT_RT_MUTEXES(tsk) \ | 100 | # define INIT_RT_MUTEXES(tsk) \ |
111 | .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \ | 101 | .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index aaf723308ed4..bdabeee10a78 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -865,10 +865,6 @@ struct task_struct { | |||
865 | struct plist_head pi_waiters; | 865 | struct plist_head pi_waiters; |
866 | /* Deadlock detection and priority inheritance handling */ | 866 | /* Deadlock detection and priority inheritance handling */ |
867 | struct rt_mutex_waiter *pi_blocked_on; | 867 | struct rt_mutex_waiter *pi_blocked_on; |
868 | # ifdef CONFIG_DEBUG_RT_MUTEXES | ||
869 | spinlock_t held_list_lock; | ||
870 | struct list_head held_list_head; | ||
871 | # endif | ||
872 | #endif | 868 | #endif |
873 | 869 | ||
874 | #ifdef CONFIG_DEBUG_MUTEXES | 870 | #ifdef CONFIG_DEBUG_MUTEXES |