]> Git Repo - linux.git/commit
locking/mutex: Fix mutex handoff
authorPeter Zijlstra <[email protected]>
Wed, 11 Jan 2017 13:17:48 +0000 (14:17 +0100)
committerIngo Molnar <[email protected]>
Sat, 14 Jan 2017 10:14:38 +0000 (11:14 +0100)
commite274795ea7b7caa0fd74ef651594382a69e2a951
tree345b942f86040c9361e1a2b0bc45f58f7b48bb19
parent52b94129f274937e4c25dd17b76697664a3c43c9
locking/mutex: Fix mutex handoff

While reviewing the ww_mutex patches, I noticed that it was still
possible to (incorrectly) succeed for (incorrect) code like:

mutex_lock(&a);
mutex_lock(&a);

This was possible if the second mutex_lock() would block (as expected)
but then receive a spurious wakeup. At that point it would find itself
at the front of the queue, request a handoff and instantly claim
ownership and continue, since owner would point to itself.

Avoid this scenario and simplify the code by introducing a third low
bit to signal handoff pickup. So once we request handoff, unlock
clears the handoff bit and sets the pickup bit along with the new
owner.

This also removes the need for the .handoff argument to
__mutex_trylock(), since that becomes superfluous with PICKUP.

In order to guarantee enough low bits, ensure task_struct alignment is
at least L1_CACHE_BYTES (which seems a good ideal regardless).

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Fixes: 9d659ae14b54 ("locking/mutex: Add lock handoff to avoid starvation")
Signed-off-by: Ingo Molnar <[email protected]>
include/linux/mutex.h
kernel/fork.c
kernel/locking/mutex.c
This page took 0.053423 seconds and 4 git commands to generate.