Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'locking-urgent-2026-04-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull locking fixes from Ingo Molnar:

- Fix ww_mutex regression, which caused hangs/pauses in some DRM drivers

- Fix rtmutex proxy-rollback bug

* tag 'locking-urgent-2026-04-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
locking/mutex: Fix ww_mutex wait_list operations
rtmutex: Use waiter::task instead of current in remove_waiter()

+67 -20
+27 -13
kernel/locking/mutex.c
··· 198 198 } 199 199 200 200 /* 201 - * Add @waiter to a given location in the lock wait_list and set the 202 - * FLAG_WAITERS flag if it's the first waiter. 201 + * Add @waiter to the @lock wait_list and set the FLAG_WAITERS flag if it's 202 + * the first waiter. 203 + * 204 + * When @pos, @waiter is added before the waiter indicated by @pos. Otherwise 205 + * @waiter will be added to the tail of the list. 203 206 */ 204 207 static void 205 208 __mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter, 206 - struct mutex_waiter *first) 209 + struct mutex_waiter *pos) 207 210 __must_hold(&lock->wait_lock) 208 211 { 212 + struct mutex_waiter *first = lock->first_waiter; 213 + 209 214 hung_task_set_blocker(lock, BLOCKER_TYPE_MUTEX); 210 215 debug_mutex_add_waiter(lock, waiter, current); 211 216 212 - if (!first) 213 - first = lock->first_waiter; 217 + if (pos) { 218 + /* 219 + * Insert @waiter before @pos. 220 + */ 221 + list_add_tail(&waiter->list, &pos->list); 222 + /* 223 + * If @pos == @first, then @waiter will be the new first. 224 + */ 225 + if (pos == first) 226 + lock->first_waiter = waiter; 227 + return; 228 + } 214 229 215 230 if (first) { 216 231 list_add_tail(&waiter->list, &first->list); 217 - } else { 218 - INIT_LIST_HEAD(&waiter->list); 219 - lock->first_waiter = waiter; 220 - __mutex_set_flag(lock, MUTEX_FLAG_WAITERS); 232 + return; 221 233 } 234 + 235 + INIT_LIST_HEAD(&waiter->list); 236 + lock->first_waiter = waiter; 237 + __mutex_set_flag(lock, MUTEX_FLAG_WAITERS); 222 238 } 223 239 224 240 static void ··· 245 229 __mutex_clear_flag(lock, MUTEX_FLAGS); 246 230 lock->first_waiter = NULL; 247 231 } else { 248 - if (lock->first_waiter == waiter) { 249 - lock->first_waiter = list_first_entry(&waiter->list, 250 - struct mutex_waiter, list); 251 - } 232 + if (lock->first_waiter == waiter) 233 + lock->first_waiter = list_next_entry(waiter, list); 252 234 list_del(&waiter->list); 253 235 } 254 236
+8 -5
kernel/locking/rtmutex.c
··· 1544 1544 * 1545 1545 * Must be called with lock->wait_lock held and interrupts disabled. It must 1546 1546 * have just failed to try_to_take_rt_mutex(). 1547 + * 1548 + * When invoked from rt_mutex_start_proxy_lock() waiter::task != current ! 1547 1549 */ 1548 1550 static void __sched remove_waiter(struct rt_mutex_base *lock, 1549 1551 struct rt_mutex_waiter *waiter) ··· 1553 1551 { 1554 1552 bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock)); 1555 1553 struct task_struct *owner = rt_mutex_owner(lock); 1554 + struct task_struct *waiter_task = waiter->task; 1556 1555 struct rt_mutex_base *next_lock; 1557 1556 1558 1557 lockdep_assert_held(&lock->wait_lock); 1559 1558 1560 - raw_spin_lock(&current->pi_lock); 1561 - rt_mutex_dequeue(lock, waiter); 1562 - current->pi_blocked_on = NULL; 1563 - raw_spin_unlock(&current->pi_lock); 1559 + scoped_guard(raw_spinlock, &waiter_task->pi_lock) { 1560 + rt_mutex_dequeue(lock, waiter); 1561 + waiter_task->pi_blocked_on = NULL; 1562 + } 1564 1563 1565 1564 /* 1566 1565 * Only update priority if the waiter was the highest priority ··· 1597 1594 raw_spin_unlock_irq(&lock->wait_lock); 1598 1595 1599 1596 rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock, 1600 - next_lock, NULL, current); 1597 + next_lock, NULL, waiter_task); 1601 1598 1602 1599 raw_spin_lock_irq(&lock->wait_lock); 1603 1600 }
+32 -2
kernel/locking/ww_mutex.h
··· 6 6 #define MUTEX_WAITER mutex_waiter 7 7 #define WAIT_LOCK wait_lock 8 8 9 + /* 10 + * +--------+ 11 + * | first | 12 + * +--------+ 13 + * | 14 + * v 15 + * +----+ +----+ +----+ 16 + * | W3 | <-> | W1 | <-> | W2 | 17 + * +----+ +----+ +----+ 18 + * ^ ^ 19 + * +---------------------+ 20 + */ 21 + 9 22 static inline struct mutex_waiter * 10 23 __ww_waiter_first(struct mutex *lock) 11 24 __must_hold(&lock->wait_lock) ··· 26 13 return lock->first_waiter; 27 14 } 28 15 16 + /* 17 + * for (cur = __ww_waiter_first(); cur; cur = __ww_waiter_next()) 18 + * 19 + * Should iterate like: W1, W2, W3 20 + */ 29 21 static inline struct mutex_waiter * 30 22 __ww_waiter_next(struct mutex *lock, struct mutex_waiter *w) 31 23 __must_hold(&lock->wait_lock) 32 24 { 33 25 w = list_next_entry(w, list); 26 + /* 27 + * Terminate if the next entry is the first again, that has already 28 + * been observed. 29 + */ 34 30 if (lock->first_waiter == w) 35 31 return NULL; 36 32 37 33 return w; 38 34 } 39 35 36 + /* 37 + * for (cur = __ww_waiter_last(); cur; cur = __ww_waiter_prev()) 38 + * 39 + * Should iterate like: W3, W2, W1 40 + */ 40 41 static inline struct mutex_waiter * 41 42 __ww_waiter_prev(struct mutex *lock, struct mutex_waiter *w) 42 43 __must_hold(&lock->wait_lock) 43 44 { 44 - w = list_prev_entry(w, list); 45 + /* 46 + * Terminate at the first entry, the previous entry of first is the 47 + * last and that has already been observed. 48 + */ 45 49 if (lock->first_waiter == w) 46 50 return NULL; 47 51 48 - return w; 52 + return list_prev_entry(w, list); 49 53 } 50 54 51 55 static inline struct mutex_waiter *