Lines Matching full:lock
17 void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name, in __raw_spin_lock_init() argument
22 * Make sure we are not reinitializing a held lock: in __raw_spin_lock_init()
24 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); in __raw_spin_lock_init()
25 lockdep_init_map_wait(&lock->dep_map, name, key, 0, inner); in __raw_spin_lock_init()
27 lock->raw_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; in __raw_spin_lock_init()
28 lock->magic = SPINLOCK_MAGIC; in __raw_spin_lock_init()
29 lock->owner = SPINLOCK_OWNER_INIT; in __raw_spin_lock_init()
30 lock->owner_cpu = -1; in __raw_spin_lock_init()
36 void __rwlock_init(rwlock_t *lock, const char *name, in __rwlock_init() argument
41 * Make sure we are not reinitializing a held lock: in __rwlock_init()
43 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); in __rwlock_init()
44 lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_CONFIG); in __rwlock_init()
46 lock->raw_lock = (arch_rwlock_t) __ARCH_RW_LOCK_UNLOCKED; in __rwlock_init()
47 lock->magic = RWLOCK_MAGIC; in __rwlock_init()
48 lock->owner = SPINLOCK_OWNER_INIT; in __rwlock_init()
49 lock->owner_cpu = -1; in __rwlock_init()
55 static void spin_dump(raw_spinlock_t *lock, const char *msg) in spin_dump() argument
57 struct task_struct *owner = READ_ONCE(lock->owner); in spin_dump()
64 printk(KERN_EMERG " lock: %pS, .magic: %08x, .owner: %s/%d, " in spin_dump()
66 lock, READ_ONCE(lock->magic), in spin_dump()
69 READ_ONCE(lock->owner_cpu)); in spin_dump()
73 static void spin_bug(raw_spinlock_t *lock, const char *msg) in spin_bug() argument
78 spin_dump(lock, msg); in spin_bug()
81 #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) argument
84 debug_spin_lock_before(raw_spinlock_t *lock) in debug_spin_lock_before() argument
86 SPIN_BUG_ON(READ_ONCE(lock->magic) != SPINLOCK_MAGIC, lock, "bad magic"); in debug_spin_lock_before()
87 SPIN_BUG_ON(READ_ONCE(lock->owner) == current, lock, "recursion"); in debug_spin_lock_before()
88 SPIN_BUG_ON(READ_ONCE(lock->owner_cpu) == raw_smp_processor_id(), in debug_spin_lock_before()
89 lock, "cpu recursion"); in debug_spin_lock_before()
92 static inline void debug_spin_lock_after(raw_spinlock_t *lock) in debug_spin_lock_after() argument
94 WRITE_ONCE(lock->owner_cpu, raw_smp_processor_id()); in debug_spin_lock_after()
95 WRITE_ONCE(lock->owner, current); in debug_spin_lock_after()
98 static inline void debug_spin_unlock(raw_spinlock_t *lock) in debug_spin_unlock() argument
100 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); in debug_spin_unlock()
101 SPIN_BUG_ON(!raw_spin_is_locked(lock), lock, "already unlocked"); in debug_spin_unlock()
102 SPIN_BUG_ON(lock->owner != current, lock, "wrong owner"); in debug_spin_unlock()
103 SPIN_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), in debug_spin_unlock()
104 lock, "wrong CPU"); in debug_spin_unlock()
105 WRITE_ONCE(lock->owner, SPINLOCK_OWNER_INIT); in debug_spin_unlock()
106 WRITE_ONCE(lock->owner_cpu, -1); in debug_spin_unlock()
111 * the detection here with an unfair lock which can cause problem of its own.
113 void do_raw_spin_lock(raw_spinlock_t *lock) in do_raw_spin_lock() argument
115 debug_spin_lock_before(lock); in do_raw_spin_lock()
116 arch_spin_lock(&lock->raw_lock); in do_raw_spin_lock()
118 debug_spin_lock_after(lock); in do_raw_spin_lock()
121 int do_raw_spin_trylock(raw_spinlock_t *lock) in do_raw_spin_trylock() argument
123 int ret = arch_spin_trylock(&lock->raw_lock); in do_raw_spin_trylock()
127 debug_spin_lock_after(lock); in do_raw_spin_trylock()
133 SPIN_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_spin_trylock()
138 void do_raw_spin_unlock(raw_spinlock_t *lock) in do_raw_spin_unlock() argument
141 debug_spin_unlock(lock); in do_raw_spin_unlock()
142 arch_spin_unlock(&lock->raw_lock); in do_raw_spin_unlock()
146 static void rwlock_bug(rwlock_t *lock, const char *msg) in rwlock_bug() argument
153 task_pid_nr(current), lock); in rwlock_bug()
157 #define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg) argument
159 void do_raw_read_lock(rwlock_t *lock) in do_raw_read_lock() argument
161 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in do_raw_read_lock()
162 arch_read_lock(&lock->raw_lock); in do_raw_read_lock()
165 int do_raw_read_trylock(rwlock_t *lock) in do_raw_read_trylock() argument
167 int ret = arch_read_trylock(&lock->raw_lock); in do_raw_read_trylock()
173 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_read_trylock()
178 void do_raw_read_unlock(rwlock_t *lock) in do_raw_read_unlock() argument
180 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in do_raw_read_unlock()
181 arch_read_unlock(&lock->raw_lock); in do_raw_read_unlock()
184 static inline void debug_write_lock_before(rwlock_t *lock) in debug_write_lock_before() argument
186 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in debug_write_lock_before()
187 RWLOCK_BUG_ON(lock->owner == current, lock, "recursion"); in debug_write_lock_before()
188 RWLOCK_BUG_ON(lock->owner_cpu == raw_smp_processor_id(), in debug_write_lock_before()
189 lock, "cpu recursion"); in debug_write_lock_before()
192 static inline void debug_write_lock_after(rwlock_t *lock) in debug_write_lock_after() argument
194 WRITE_ONCE(lock->owner_cpu, raw_smp_processor_id()); in debug_write_lock_after()
195 WRITE_ONCE(lock->owner, current); in debug_write_lock_after()
198 static inline void debug_write_unlock(rwlock_t *lock) in debug_write_unlock() argument
200 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in debug_write_unlock()
201 RWLOCK_BUG_ON(lock->owner != current, lock, "wrong owner"); in debug_write_unlock()
202 RWLOCK_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), in debug_write_unlock()
203 lock, "wrong CPU"); in debug_write_unlock()
204 WRITE_ONCE(lock->owner, SPINLOCK_OWNER_INIT); in debug_write_unlock()
205 WRITE_ONCE(lock->owner_cpu, -1); in debug_write_unlock()
208 void do_raw_write_lock(rwlock_t *lock) in do_raw_write_lock() argument
210 debug_write_lock_before(lock); in do_raw_write_lock()
211 arch_write_lock(&lock->raw_lock); in do_raw_write_lock()
212 debug_write_lock_after(lock); in do_raw_write_lock()
215 int do_raw_write_trylock(rwlock_t *lock) in do_raw_write_trylock() argument
217 int ret = arch_write_trylock(&lock->raw_lock); in do_raw_write_trylock()
220 debug_write_lock_after(lock); in do_raw_write_trylock()
225 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_write_trylock()
230 void do_raw_write_unlock(rwlock_t *lock) in do_raw_write_unlock() argument
232 debug_write_unlock(lock); in do_raw_write_unlock()
233 arch_write_unlock(&lock->raw_lock); in do_raw_write_unlock()