Skip to content

Commit 6231acb

Browse files
KAGA-KOKOingomolnar
authored andcommitted
futex: Simplify handle_early_requeue_pi_wakeup()
Move the futex key match out of handle_early_requeue_pi_wakeup() which allows to simplify that function. The upcoming state machine for requeue_pi() will make that go away. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210815211305.638938670@linutronix.de
1 parent d69cba5 commit 6231acb

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

‎kernel/futex.c‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,27 +3070,22 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
30703070
}
30713071

30723072
/**
3073-
* handle_early_requeue_pi_wakeup() - Detect early wakeup on the initial futex
3073+
* handle_early_requeue_pi_wakeup() - Handle early wakeup on the initial futex
30743074
* @hb: the hash_bucket futex_q was original enqueued on
30753075
* @q: the futex_q woken while waiting to be requeued
3076-
* @key2: the futex_key of the requeue target futex
30773076
* @timeout: the timeout associated with the wait (NULL if none)
30783077
*
3079-
* Detect if the task was woken on the initial futex as opposed to the requeue
3080-
* target futex. If so, determine if it was a timeout or a signal that caused
3081-
* the wakeup and return the appropriate error code to the caller. Must be
3082-
* called with the hb lock held.
3078+
* Determine the cause for the early wakeup.
30833079
*
30843080
* Return:
3085-
* - 0 = no early wakeup detected;
3086-
* - <0 = -ETIMEDOUT or -ERESTARTNOINTR
3081+
* -EWOULDBLOCK or -ETIMEDOUT or -ERESTARTNOINTR
30873082
*/
30883083
static inline
30893084
int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
3090-
struct futex_q *q, union futex_key *key2,
3085+
struct futex_q *q,
30913086
struct hrtimer_sleeper *timeout)
30923087
{
3093-
int ret = 0;
3088+
int ret;
30943089

30953090
/*
30963091
* With the hb lock held, we avoid races while we process the wakeup.
@@ -3099,22 +3094,21 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
30993094
* It can't be requeued from uaddr2 to something else since we don't
31003095
* support a PI aware source futex for requeue.
31013096
*/
3102-
if (!match_futex(&q->key, key2)) {
3103-
WARN_ON(q->lock_ptr && (&hb->lock != q->lock_ptr));
3104-
/*
3105-
* We were woken prior to requeue by a timeout or a signal.
3106-
* Unqueue the futex_q and determine which it was.
3107-
*/
3108-
plist_del(&q->list, &hb->chain);
3109-
hb_waiters_dec(hb);
3097+
WARN_ON_ONCE(&hb->lock != q->lock_ptr);
31103098

3111-
/* Handle spurious wakeups gracefully */
3112-
ret = -EWOULDBLOCK;
3113-
if (timeout && !timeout->task)
3114-
ret = -ETIMEDOUT;
3115-
else if (signal_pending(current))
3116-
ret = -ERESTARTNOINTR;
3117-
}
3099+
/*
3100+
* We were woken prior to requeue by a timeout or a signal.
3101+
* Unqueue the futex_q and determine which it was.
3102+
*/
3103+
plist_del(&q->list, &hb->chain);
3104+
hb_waiters_dec(hb);
3105+
3106+
/* Handle spurious wakeups gracefully */
3107+
ret = -EWOULDBLOCK;
3108+
if (timeout && !timeout->task)
3109+
ret = -ETIMEDOUT;
3110+
else if (signal_pending(current))
3111+
ret = -ERESTARTNOINTR;
31183112
return ret;
31193113
}
31203114

@@ -3217,7 +3211,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
32173211
futex_wait_queue_me(hb, &q, to);
32183212

32193213
spin_lock(&hb->lock);
3220-
ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
3214+
/* Is @q still queued on uaddr1? */
3215+
if (!match_futex(&q->key, key2))
3216+
ret = handle_early_requeue_pi_wakeup(hb, &q, to);
32213217
spin_unlock(&hb->lock);
32223218
if (ret)
32233219
goto out;

0 commit comments

Comments
 (0)