]> git.baikalelectronics.ru Git - kernel.git/commit
locking/mutex: Introduce __mutex_trylock_or_handoff()
authorPeter Zijlstra <peterz@infradead.org>
Wed, 30 Jun 2021 15:35:19 +0000 (17:35 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 7 Jul 2021 11:53:25 +0000 (13:53 +0200)
commit495a61323aa0d1985ddb696222e4feb4795f3247
tree961ea9c382b93450563bd307f960ee1616193141
parent13143124a9a0f0a7c32dcac1f95b54f17e16f295
locking/mutex: Introduce __mutex_trylock_or_handoff()

Yanfei reported that it is possible to loose HANDOFF when we race with
mutex_unlock() and end up setting HANDOFF on an unlocked mutex. At
that point anybody can steal it, losing HANDOFF in the process.

If this happens often enough, we can in fact starve the top waiter.

Solve this by folding the 'set HANDOFF' operation into the trylock
operation, such that either we acquire the lock, or it gets HANDOFF
set. This avoids having HANDOFF set on an unlocked mutex.

Reported-by: Yanfei Xu <yanfei.xu@windriver.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Waiman Long <longman@redhat.com>
Reviewed-by: Yanfei Xu <yanfei.xu@windriver.com>
Link: https://lore.kernel.org/r/20210630154114.958507900@infradead.org
kernel/locking/mutex.c