io_uring: add support for futex wake and wait
authorJens Axboe <axboe@kernel.dk>
Thu, 8 Jun 2023 17:57:40 +0000 (11:57 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Sep 2023 15:41:32 +0000 (09:41 -0600)
commit224618a96b286af8e831b008daf916222f64e08e
treea4916a2d69b643c5d6989df04cd6a96973adcf52
parente5c7f5eee9c808404f2936935a3a69fea0907010
io_uring: add support for futex wake and wait

Add support for FUTEX_WAKE/WAIT primitives.

IORING_OP_FUTEX_WAKE is mix of FUTEX_WAKE and FUTEX_WAKE_BITSET, as
it does support passing in a bitset.

Similary, IORING_OP_FUTEX_WAIT is a mix of FUTEX_WAIT and
FUTEX_WAIT_BITSET.

FUTEX_WAKE is straight forward, as those can always be done directly from
the io_uring submission without needing async handling. For FUTEX_WAIT,
things are a bit more complicated. If the futex isn't ready, then we
rely on a callback via futex_queue->wake() when someone wakes up the
futex. From that calback, we queue up task_work with the original task,
which will post a CQE and wake it, if necessary.

Cancelations are supported, both from the application point-of-view,
but also to be able to cancel pending waits if the ring exits before
all events have occurred. The return value of futex_unqueue() is used
to gate who wins the potential race between cancelation and futex
wakeups. Whomever gets a 'ret == 1' return from that claims ownership
of the io_uring futex request.

This is just the barebones wait/wake support. PI or REQUEUE support is
not added at this point, unclear if we might look into that later.

Likewise, explicit timeouts are not supported either. It is expected
that users that need timeouts would do so via the usual io_uring
mechanism to do that using linked timeouts.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
include/uapi/linux/io_uring.h
io_uring/Makefile
io_uring/cancel.c
io_uring/cancel.h
io_uring/futex.c [new file with mode: 0644]
io_uring/futex.h [new file with mode: 0644]
io_uring/io_uring.c
io_uring/opdef.c