io_uring: wake SQPOLL task when task_work is added to an empty queue
authorJens Axboe <axboe@kernel.dk>
Wed, 14 Feb 2024 20:56:08 +0000 (13:56 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 14 Feb 2024 20:56:08 +0000 (13:56 -0700)
If there's no current work on the list, we still need to potentially
wake the SQPOLL task if it is sleeping. This is ordered with the
wait queue addition in sqpoll, which adds to the wait queue before
checking for pending work items.

Fixes: af5d68f8892f ("io_uring/sqpoll: manage task_work privately")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c

index 844a7524ed916c86080aaa4018cb0a24acd42267..45a2f8f3a77c7664cdc0720f48180d2f6f1ba356 100644 (file)
@@ -1370,8 +1370,13 @@ static void io_req_normal_work_add(struct io_kiocb *req)
                atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags);
 
        /* SQPOLL doesn't need the task_work added, it'll run it itself */
-       if (ctx->flags & IORING_SETUP_SQPOLL)
+       if (ctx->flags & IORING_SETUP_SQPOLL) {
+               struct io_sq_data *sqd = ctx->sq_data;
+
+               if (wq_has_sleeper(&sqd->wait))
+                       wake_up(&sqd->wait);
                return;
+       }
 
        if (likely(!task_work_add(req->task, &tctx->task_work, ctx->notify_method)))
                return;