aboutsummaryrefslogtreecommitdiffstats
path: root/lib/spinlock_debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spinlock_debug.c')
-rw-r--r--lib/spinlock_debug.c99
1 files changed, 62 insertions, 37 deletions
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index d8b6bb419d49..3d9c4dc965ed 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -6,41 +6,73 @@
6 * DEBUG_SPINLOCK. 6 * DEBUG_SPINLOCK.
7 */ 7 */
8 8
9#include <linux/config.h>
10#include <linux/spinlock.h> 9#include <linux/spinlock.h>
11#include <linux/interrupt.h> 10#include <linux/interrupt.h>
11#include <linux/debug_locks.h>
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/module.h>
14
15void __spin_lock_init(spinlock_t *lock, const char *name,
16 struct lock_class_key *key)
17{
18#ifdef CONFIG_DEBUG_LOCK_ALLOC
19 /*
20 * Make sure we are not reinitializing a held lock:
21 */
22 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
23 lockdep_init_map(&lock->dep_map, name, key);
24#endif
25 lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
26 lock->magic = SPINLOCK_MAGIC;
27 lock->owner = SPINLOCK_OWNER_INIT;
28 lock->owner_cpu = -1;
29}
30
31EXPORT_SYMBOL(__spin_lock_init);
32
33void __rwlock_init(rwlock_t *lock, const char *name,
34 struct lock_class_key *key)
35{
36#ifdef CONFIG_DEBUG_LOCK_ALLOC
37 /*
38 * Make sure we are not reinitializing a held lock:
39 */
40 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
41 lockdep_init_map(&lock->dep_map, name, key);
42#endif
43 lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED;
44 lock->magic = RWLOCK_MAGIC;
45 lock->owner = SPINLOCK_OWNER_INIT;
46 lock->owner_cpu = -1;
47}
48
49EXPORT_SYMBOL(__rwlock_init);
13 50
14static void spin_bug(spinlock_t *lock, const char *msg) 51static void spin_bug(spinlock_t *lock, const char *msg)
15{ 52{
16 static long print_once = 1;
17 struct task_struct *owner = NULL; 53 struct task_struct *owner = NULL;
18 54
19 if (xchg(&print_once, 0)) { 55 if (!debug_locks_off())
20 if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT) 56 return;
21 owner = lock->owner; 57
22 printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", 58 if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT)
23 msg, raw_smp_processor_id(), 59 owner = lock->owner;
24 current->comm, current->pid); 60 printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n",
25 printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " 61 msg, raw_smp_processor_id(),
26 ".owner_cpu: %d\n", 62 current->comm, current->pid);
27 lock, lock->magic, 63 printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, "
28 owner ? owner->comm : "<none>", 64 ".owner_cpu: %d\n",
29 owner ? owner->pid : -1, 65 lock, lock->magic,
30 lock->owner_cpu); 66 owner ? owner->comm : "<none>",
31 dump_stack(); 67 owner ? owner->pid : -1,
32#ifdef CONFIG_SMP 68 lock->owner_cpu);
33 /* 69 dump_stack();
34 * We cannot continue on SMP:
35 */
36// panic("bad locking");
37#endif
38 }
39} 70}
40 71
41#define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) 72#define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg)
42 73
43static inline void debug_spin_lock_before(spinlock_t *lock) 74static inline void
75debug_spin_lock_before(spinlock_t *lock)
44{ 76{
45 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); 77 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic");
46 SPIN_BUG_ON(lock->owner == current, lock, "recursion"); 78 SPIN_BUG_ON(lock->owner == current, lock, "recursion");
@@ -119,20 +151,13 @@ void _raw_spin_unlock(spinlock_t *lock)
119 151
120static void rwlock_bug(rwlock_t *lock, const char *msg) 152static void rwlock_bug(rwlock_t *lock, const char *msg)
121{ 153{
122 static long print_once = 1; 154 if (!debug_locks_off())
123 155 return;
124 if (xchg(&print_once, 0)) { 156
125 printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n", 157 printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n",
126 msg, raw_smp_processor_id(), current->comm, 158 msg, raw_smp_processor_id(), current->comm,
127 current->pid, lock); 159 current->pid, lock);
128 dump_stack(); 160 dump_stack();
129#ifdef CONFIG_SMP
130 /*
131 * We cannot continue on SMP:
132 */
133 panic("bad locking");
134#endif
135 }
136} 161}
137 162
138#define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg) 163#define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg)