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.

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

+5 -10
+5 -10
kernel/locking/mutex.c
··· 909 909 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) 910 910 { 911 911 struct mutex_waiter waiter; 912 - bool first = false; 913 912 struct ww_mutex *ww; 914 913 int ret; 915 914 ··· 987 988 988 989 set_current_state(state); 989 990 for (;;) { 991 + bool first; 992 + 990 993 /* 991 994 * Once we hold wait_lock, we're serialized against 992 995 * mutex_unlock() handing the lock off to us, do a trylock ··· 1017 1016 spin_unlock(&lock->wait_lock); 1018 1017 schedule_preempt_disabled(); 1019 1018 1020 - /* 1021 - * ww_mutex needs to always recheck its position since its waiter 1022 - * list is not FIFO ordered. 1023 - */ 1024 - if (ww_ctx || !first) { 1025 - first = __mutex_waiter_is_first(lock, &waiter); 1026 - if (first) 1027 - __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); 1028 - } 1019 + first = __mutex_waiter_is_first(lock, &waiter); 1020 + if (first) 1021 + __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); 1029 1022 1030 1023 set_current_state(state); 1031 1024 /*