diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2007-12-05 09:46:09 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2007-12-05 09:46:09 -0500 |
commit | 54561783ee99d73a086f3abbda3e44f87f6bf65b (patch) | |
tree | 73f836a158f9c05ece41cae6cdb80888d9d6ba07 /kernel/lockdep.c | |
parent | 856848737bd944c1db3ce0a66bbf67e56bd6f77d (diff) |
lockdep: in_range() fix
Torsten Kaiser wrote:
| static inline int in_range(const void *start, const void *addr, const void *end)
| {
| return addr >= start && addr <= end;
| }
| This will return true, if addr is in the range of start (including)
| to end (including).
|
| But debug_check_no_locks_freed() seems does:
| const void *mem_to = mem_from + mem_len
| -> mem_to is the last byte of the freed range, that fits in_range
| lock_from = (void *)hlock->instance;
| -> first byte of the lock
| lock_to = (void *)(hlock->instance + 1);
| -> first byte of the next lock, not last byte of the lock that is being checked!
|
| The test is:
| if (!in_range(mem_from, lock_from, mem_to) &&
| !in_range(mem_from, lock_to, mem_to))
| continue;
| So it tests, if the first byte of the lock is in the range that is freed ->OK
| And if the first byte of the *next* lock is in the range that is freed
| -> Not OK.
We can also simplify in_range checks, we need only 2 comparisons, not 4.
If the lock is not in memory range, it should be either at the left of range
or at the right.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Diffstat (limited to 'kernel/lockdep.c')
-rw-r--r-- | kernel/lockdep.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 7e2ca7c9d99..0f389621bb6 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -3054,11 +3054,6 @@ void __init lockdep_info(void) | |||
3054 | #endif | 3054 | #endif |
3055 | } | 3055 | } |
3056 | 3056 | ||
3057 | static inline int in_range(const void *start, const void *addr, const void *end) | ||
3058 | { | ||
3059 | return addr >= start && addr <= end; | ||
3060 | } | ||
3061 | |||
3062 | static void | 3057 | static void |
3063 | print_freed_lock_bug(struct task_struct *curr, const void *mem_from, | 3058 | print_freed_lock_bug(struct task_struct *curr, const void *mem_from, |
3064 | const void *mem_to, struct held_lock *hlock) | 3059 | const void *mem_to, struct held_lock *hlock) |
@@ -3080,6 +3075,13 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from, | |||
3080 | dump_stack(); | 3075 | dump_stack(); |
3081 | } | 3076 | } |
3082 | 3077 | ||
3078 | static inline int not_in_range(const void* mem_from, unsigned long mem_len, | ||
3079 | const void* lock_from, unsigned long lock_len) | ||
3080 | { | ||
3081 | return lock_from + lock_len <= mem_from || | ||
3082 | mem_from + mem_len <= lock_from; | ||
3083 | } | ||
3084 | |||
3083 | /* | 3085 | /* |
3084 | * Called when kernel memory is freed (or unmapped), or if a lock | 3086 | * Called when kernel memory is freed (or unmapped), or if a lock |
3085 | * is destroyed or reinitialized - this code checks whether there is | 3087 | * is destroyed or reinitialized - this code checks whether there is |
@@ -3087,7 +3089,6 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from, | |||
3087 | */ | 3089 | */ |
3088 | void debug_check_no_locks_freed(const void *mem_from, unsigned long mem_len) | 3090 | void debug_check_no_locks_freed(const void *mem_from, unsigned long mem_len) |
3089 | { | 3091 | { |
3090 | const void *mem_to = mem_from + mem_len, *lock_from, *lock_to; | ||
3091 | struct task_struct *curr = current; | 3092 | struct task_struct *curr = current; |
3092 | struct held_lock *hlock; | 3093 | struct held_lock *hlock; |
3093 | unsigned long flags; | 3094 | unsigned long flags; |
@@ -3100,14 +3101,11 @@ void debug_check_no_locks_freed(const void *mem_from, unsigned long mem_len) | |||
3100 | for (i = 0; i < curr->lockdep_depth; i++) { | 3101 | for (i = 0; i < curr->lockdep_depth; i++) { |
3101 | hlock = curr->held_locks + i; | 3102 | hlock = curr->held_locks + i; |
3102 | 3103 | ||
3103 | lock_from = (void *)hlock->instance; | 3104 | if (not_in_range(mem_from, mem_len, hlock->instance, |
3104 | lock_to = (void *)(hlock->instance + 1); | 3105 | sizeof(*hlock->instance))) |
3105 | |||
3106 | if (!in_range(mem_from, lock_from, mem_to) && | ||
3107 | !in_range(mem_from, lock_to, mem_to)) | ||
3108 | continue; | 3106 | continue; |
3109 | 3107 | ||
3110 | print_freed_lock_bug(curr, mem_from, mem_to, hlock); | 3108 | print_freed_lock_bug(curr, mem_from, mem_from + mem_len, hlock); |
3111 | break; | 3109 | break; |
3112 | } | 3110 | } |
3113 | local_irq_restore(flags); | 3111 | local_irq_restore(flags); |