diff options
author | Maarten Lankhorst <maarten.lankhorst@canonical.com> | 2012-09-13 05:39:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-09-13 11:00:44 -0400 |
commit | d094595078d00b63839d0c5ccb8b184ef242cb45 (patch) | |
tree | 31929a5e414de13c0c4df46f3e1b3f276f0c58bf | |
parent | 0bd1189e239c76eb3a50e458548fbe7e4a5dfff1 (diff) |
lockdep: Check if nested lock is actually held
It is considered good form to lock the lock you claim to be nested in.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
[ removed nest_lock arg to print_lock_nested_lock_not_held in favour
of hlock->nest_lock, also renamed the lock arg to hlock since its
a held_lock type ]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/5051A9E7.5040501@canonical.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/lockdep.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index ea9ee4518c35..7981e5b2350d 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -2998,6 +2998,42 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); | |||
2998 | 2998 | ||
2999 | struct lock_class_key __lockdep_no_validate__; | 2999 | struct lock_class_key __lockdep_no_validate__; |
3000 | 3000 | ||
3001 | static int | ||
3002 | print_lock_nested_lock_not_held(struct task_struct *curr, | ||
3003 | struct held_lock *hlock, | ||
3004 | unsigned long ip) | ||
3005 | { | ||
3006 | if (!debug_locks_off()) | ||
3007 | return 0; | ||
3008 | if (debug_locks_silent) | ||
3009 | return 0; | ||
3010 | |||
3011 | printk("\n"); | ||
3012 | printk("==================================\n"); | ||
3013 | printk("[ BUG: Nested lock was not taken ]\n"); | ||
3014 | print_kernel_ident(); | ||
3015 | printk("----------------------------------\n"); | ||
3016 | |||
3017 | printk("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); | ||
3018 | print_lock(hlock); | ||
3019 | |||
3020 | printk("\nbut this task is not holding:\n"); | ||
3021 | printk("%s\n", hlock->nest_lock->name); | ||
3022 | |||
3023 | printk("\nstack backtrace:\n"); | ||
3024 | dump_stack(); | ||
3025 | |||
3026 | printk("\nother info that might help us debug this:\n"); | ||
3027 | lockdep_print_held_locks(curr); | ||
3028 | |||
3029 | printk("\nstack backtrace:\n"); | ||
3030 | dump_stack(); | ||
3031 | |||
3032 | return 0; | ||
3033 | } | ||
3034 | |||
3035 | static int __lock_is_held(struct lockdep_map *lock); | ||
3036 | |||
3001 | /* | 3037 | /* |
3002 | * This gets called for every mutex_lock*()/spin_lock*() operation. | 3038 | * This gets called for every mutex_lock*()/spin_lock*() operation. |
3003 | * We maintain the dependency maps and validate the locking attempt: | 3039 | * We maintain the dependency maps and validate the locking attempt: |
@@ -3139,6 +3175,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
3139 | } | 3175 | } |
3140 | chain_key = iterate_chain_key(chain_key, id); | 3176 | chain_key = iterate_chain_key(chain_key, id); |
3141 | 3177 | ||
3178 | if (nest_lock && !__lock_is_held(nest_lock)) | ||
3179 | return print_lock_nested_lock_not_held(curr, hlock, ip); | ||
3180 | |||
3142 | if (!validate_chain(curr, lock, hlock, chain_head, chain_key)) | 3181 | if (!validate_chain(curr, lock, hlock, chain_head, chain_key)) |
3143 | return 0; | 3182 | return 0; |
3144 | 3183 | ||