|
39 | 39 | * |
40 | 40 | * It is not allowed to initialize an already locked mutex. |
41 | 41 | */ |
42 | | -__always_inline void fastcall __mutex_init(struct mutex *lock, const char *name) |
| 42 | +void |
| 43 | +__mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) |
43 | 44 | { |
44 | 45 | atomic_set(&lock->count, 1); |
45 | 46 | spin_lock_init(&lock->wait_lock); |
46 | 47 | INIT_LIST_HEAD(&lock->wait_list); |
47 | 48 |
|
48 | | - debug_mutex_init(lock, name); |
| 49 | + debug_mutex_init(lock, name, key); |
49 | 50 | } |
50 | 51 |
|
51 | 52 | EXPORT_SYMBOL(__mutex_init); |
@@ -131,6 +132,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass) |
131 | 132 | spin_lock_mutex(&lock->wait_lock, flags); |
132 | 133 |
|
133 | 134 | debug_mutex_lock_common(lock, &waiter); |
| 135 | + mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
134 | 136 | debug_mutex_add_waiter(lock, &waiter, task->thread_info); |
135 | 137 |
|
136 | 138 | /* add waiting tasks to the end of the waitqueue (FIFO): */ |
@@ -158,6 +160,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass) |
158 | 160 | if (unlikely(state == TASK_INTERRUPTIBLE && |
159 | 161 | signal_pending(task))) { |
160 | 162 | mutex_remove_waiter(lock, &waiter, task->thread_info); |
| 163 | + mutex_release(&lock->dep_map, 1, _RET_IP_); |
161 | 164 | spin_unlock_mutex(&lock->wait_lock, flags); |
162 | 165 |
|
163 | 166 | debug_mutex_free_waiter(&waiter); |
@@ -194,16 +197,28 @@ __mutex_lock_slowpath(atomic_t *lock_count) |
194 | 197 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0); |
195 | 198 | } |
196 | 199 |
|
| 200 | +#ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 201 | +void __sched |
| 202 | +mutex_lock_nested(struct mutex *lock, unsigned int subclass) |
| 203 | +{ |
| 204 | + might_sleep(); |
| 205 | + __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass); |
| 206 | +} |
| 207 | + |
| 208 | +EXPORT_SYMBOL_GPL(mutex_lock_nested); |
| 209 | +#endif |
| 210 | + |
197 | 211 | /* |
198 | 212 | * Release the lock, slowpath: |
199 | 213 | */ |
200 | 214 | static fastcall inline void |
201 | | -__mutex_unlock_common_slowpath(atomic_t *lock_count) |
| 215 | +__mutex_unlock_common_slowpath(atomic_t *lock_count, int nested) |
202 | 216 | { |
203 | 217 | struct mutex *lock = container_of(lock_count, struct mutex, count); |
204 | 218 | unsigned long flags; |
205 | 219 |
|
206 | 220 | spin_lock_mutex(&lock->wait_lock, flags); |
| 221 | + mutex_release(&lock->dep_map, nested, _RET_IP_); |
207 | 222 | debug_mutex_unlock(lock); |
208 | 223 |
|
209 | 224 | /* |
@@ -236,7 +251,7 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count) |
236 | 251 | static fastcall noinline void |
237 | 252 | __mutex_unlock_slowpath(atomic_t *lock_count) |
238 | 253 | { |
239 | | - __mutex_unlock_common_slowpath(lock_count); |
| 254 | + __mutex_unlock_common_slowpath(lock_count, 1); |
240 | 255 | } |
241 | 256 |
|
242 | 257 | /* |
@@ -287,9 +302,10 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count) |
287 | 302 | spin_lock_mutex(&lock->wait_lock, flags); |
288 | 303 |
|
289 | 304 | prev = atomic_xchg(&lock->count, -1); |
290 | | - if (likely(prev == 1)) |
| 305 | + if (likely(prev == 1)) { |
291 | 306 | debug_mutex_set_owner(lock, current_thread_info()); |
292 | | - |
| 307 | + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
| 308 | + } |
293 | 309 | /* Set it back to 0 if there are no waiters: */ |
294 | 310 | if (likely(list_empty(&lock->wait_list))) |
295 | 311 | atomic_set(&lock->count, 0); |
|
0 commit comments