Re: [PATCH 2/7] futex: factor out the futex wake handling

From: Peter Zijlstra
Date: Wed Jul 12 2023 - 04:59:59 EST


On Tue, Jul 11, 2023 at 06:47:00PM -0600, Jens Axboe wrote:
> In preparation for having another waker that isn't futex_wake_mark(),
> add a wake handler in futex_q. No extra data is associated with the
> handler outside of struct futex_q itself. futex_wake_mark() is defined as
> the standard wakeup helper, now set through futex_q_init like other
> defaults.

Urgh... so if I understand things right, you're going to replace this
with a custom wake function that does *NOT* put the task on the wake_q.

The wake_q will thus be empty and the task does not get woken up. I'm
presuming someone gets a notification instead somewhere somehow.

I might've been nice to mention some of this somewhere ...

> Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
> ---
> kernel/futex/futex.h | 4 ++++
> kernel/futex/requeue.c | 3 ++-
> kernel/futex/waitwake.c | 6 +++---
> 3 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
> index d2949fca37d1..8eaf1a5ce967 100644
> --- a/kernel/futex/futex.h
> +++ b/kernel/futex/futex.h
> @@ -69,6 +69,9 @@ struct futex_pi_state {
> union futex_key key;
> } __randomize_layout;
>
> +struct futex_q;
> +typedef void (futex_wake_fn)(struct wake_q_head *wake_q, struct futex_q *q);
> +
> /**
> * struct futex_q - The hashed futex queue entry, one per waiting task
> * @list: priority-sorted list of tasks waiting on this futex
> @@ -98,6 +101,7 @@ struct futex_q {
>
> struct task_struct *task;
> spinlock_t *lock_ptr;
> + futex_wake_fn *wake;
> union futex_key key;
> struct futex_pi_state *pi_state;
> struct rt_mutex_waiter *rt_waiter;