Skip to content

Commit 048661a

Browse files
author
Peter Zijlstra
committed
locking/mutex: Fix HANDOFF condition
Yanfei reported that setting HANDOFF should not depend on recomputing @FIRST, only on @FIRST state. Which would then give: if (ww_ctx || !first) first = __mutex_waiter_is_first(lock, &waiter); if (first) __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); But because 'ww_ctx || !first' is basically 'always' and the test for first is relatively cheap, omit that first branch entirely. 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.896786297@infradead.org
1 parent ab4e4d9 commit 048661a

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

‎kernel/locking/mutex.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
909909
struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
910910
{
911911
struct mutex_waiter waiter;
912-
bool first = false;
913912
struct ww_mutex *ww;
914913
int ret;
915914

@@ -988,6 +987,8 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
988987

989988
set_current_state(state);
990989
for (;;) {
990+
bool first;
991+
991992
/*
992993
* Once we hold wait_lock, we're serialized against
993994
* mutex_unlock() handing the lock off to us, do a trylock
@@ -1016,15 +1017,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
10161017
spin_unlock(&lock->wait_lock);
10171018
schedule_preempt_disabled();
10181019

1019-
/*
1020-
* ww_mutex needs to always recheck its position since its waiter
1021-
* list is not FIFO ordered.
1022-
*/
1023-
if (ww_ctx || !first) {
1024-
first = __mutex_waiter_is_first(lock, &waiter);
1025-
if (first)
1026-
__mutex_set_flag(lock, MUTEX_FLAG_HANDOFF);
1027-
}
1020+
first = __mutex_waiter_is_first(lock, &waiter);
1021+
if (first)
1022+
__mutex_set_flag(lock, MUTEX_FLAG_HANDOFF);
10281023

10291024
set_current_state(state);
10301025
/*

0 commit comments

Comments
 (0)