locking/mutex: Fix HANDOFF condition
authorPeter Zijlstra <peterz@infradead.org>
Wed, 30 Jun 2021 15:35:18 +0000 (17:35 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 7 Jul 2021 11:53:24 +0000 (13:53 +0200)
commit048661a1f963e9517630f080687d48af79ed784c
treeb5850f9221b6f8ff66f79b19645c82a2f02d1124
parentab4e4d9f79b2c95ef268985d2a9625a03a73c49a
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
kernel/locking/mutex.c