io_uring: ensure IOSQE_ASYNC file table grabbing works with SQPOLL
authorJens Axboe <axboe@kernel.dk>
Tue, 8 Sep 2020 14:59:04 +0000 (08:59 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 9 Sep 2020 16:58:04 +0000 (10:58 -0600)
commit67b08c1c9ffb003fa0a71541b3cb28e4d19231c0
tree7f04992d53d7220f307a4f2620f9b1e9b62153fe
parent6ad2da5f67c3a4e3fd21e37836fdb55dbb3a7ef2
io_uring: ensure IOSQE_ASYNC file table grabbing works with SQPOLL

Fd instantiating commands like IORING_OP_ACCEPT now work with SQPOLL, but
we have an error in grabbing that if IOSQE_ASYNC is set. Ensure we assign
the ring fd/file appropriately so we can defer grab them.

Hook off fops->flush() for managing the ring fd/file. If the original
ring fd is closed, then clear the existing entry and mark us as needing
a new assignment. This process works just like any other need the SQPOLL
thread has for needing the application to enter the kernel, using the
NEED_WAKEUP flag. In the interim, this ctx isn't processing new
submissions. Once the application enters the kernel and sees the need
to assign new ring fd/file values, it'll do so and submission
processing can resume.

If an application wishes to use SQPOLL without registered files, and it
dups/receives/whatever a new descriptor for the ring without closing
the other one, it must ensure that io_uring_enter() is called to update
the ring fd. This is done automatically, the application just has to
ensure that the call is made (eg through manual io_uring_enter() call,
or forcing IORING_ENTER_SQ_WAKEUP if using liburing).

Reported-by: Josef Grieb <josef.grieb@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c