If we abort the mutex_lock() due to an interrupt, or other error from
ww_mutex, we need to relinquish the handoff flag if we applied it.
Otherwise, we may cause missed wakeups as the current owner may try to
handoff to a new thread that is not expecting the handoff and so sleep
thinking the lock is already claimed (and since the owner unlocked there
may never be a new wakeup).

Fixes: 9d659ae14b54 ("locking/mutex: Add lock handoff to avoid starvation")
Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Waiman Long <waiman.l...@hpe.com>
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Paul E. McKenney <paul...@linux.vnet.ibm.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/locking/mutex.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 9b349619f431..087bbc082ad7 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -738,6 +738,8 @@ __mutex_lock_common(struct mutex *lock, long state, 
unsigned int subclass,
 err:
        __set_task_state(task, TASK_RUNNING);
        mutex_remove_waiter(lock, &waiter, task);
+       if (first)
+               __mutex_clear_flag(lock, MUTEX_FLAG_HANDOFF);
        spin_unlock_mutex(&lock->wait_lock, flags);
        debug_mutex_free_waiter(&waiter);
        mutex_release(&lock->dep_map, 1, ip);
-- 
2.11.0

Reply via email to