Commit 2fb29209 authored by Peter Zijlstra's avatar Peter Zijlstra
Browse files

futex: Pull futex_hash() out of futex_q_lock()



Getting the hash bucket and queuing it are two distinct actions. In
light of wanting to add a put hash bucket function later, untangle
them.

Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250416162921.513656-5-bigeasy@linutronix.de
parent 93f1b6d7
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -502,13 +502,9 @@ void __futex_unqueue(struct futex_q *q)
}

/* The key must be already stored in q->key. */
struct futex_hash_bucket *futex_q_lock(struct futex_q *q)
void futex_q_lock(struct futex_q *q, struct futex_hash_bucket *hb)
	__acquires(&hb->lock)
{
	struct futex_hash_bucket *hb;

	hb = futex_hash(&q->key);

	/*
	 * Increment the counter before taking the lock so that
	 * a potential waker won't miss a to-be-slept task that is
@@ -522,7 +518,6 @@ struct futex_hash_bucket *futex_q_lock(struct futex_q *q)
	q->lock_ptr = &hb->lock;

	spin_lock(&hb->lock);
	return hb;
}

void futex_q_unlock(struct futex_hash_bucket *hb)
+1 −1
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ static inline int futex_hb_waiters_pending(struct futex_hash_bucket *hb)
#endif
}

extern struct futex_hash_bucket *futex_q_lock(struct futex_q *q);
extern void futex_q_lock(struct futex_q *q, struct futex_hash_bucket *hb);
extern void futex_q_unlock(struct futex_hash_bucket *hb);


+2 −1
Original line number Diff line number Diff line
@@ -939,7 +939,8 @@ int futex_lock_pi(u32 __user *uaddr, unsigned int flags, ktime_t *time, int tryl
		goto out;

retry_private:
	hb = futex_q_lock(&q);
	hb = futex_hash(&q.key);
	futex_q_lock(&q, hb);

	ret = futex_lock_pi_atomic(uaddr, hb, &q.key, &q.pi_state, current,
				   &exiting, 0);
+4 −2
Original line number Diff line number Diff line
@@ -441,7 +441,8 @@ int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *woken)
		struct futex_q *q = &vs[i].q;
		u32 val = vs[i].w.val;

		hb = futex_q_lock(q);
		hb = futex_hash(&q->key);
		futex_q_lock(q, hb);
		ret = futex_get_value_locked(&uval, uaddr);

		if (!ret && uval == val) {
@@ -611,7 +612,8 @@ int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
		return ret;

retry_private:
	hb = futex_q_lock(q);
	hb = futex_hash(&q->key);
	futex_q_lock(q, hb);

	ret = futex_get_value_locked(&uval, uaddr);