Whenever possible we don't want to fallback a request. task_work_add() will be fine if the task is exiting, so don't check for PF_EXITING, there is anyway only a relatively small gap between setting the flag and doing the final task_work_run(). Also add likely for the hot path. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- fs/io_uring.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5fab427305e3..1893a4229dbb 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1990,9 +1990,6 @@ static int io_req_task_work_add(struct io_kiocb *req) unsigned long flags; int ret = 0; - if (unlikely(tsk->flags & PF_EXITING)) - return -ESRCH; - WARN_ON_ONCE(!tctx); spin_lock_irqsave(&tctx->task_lock, flags); @@ -2000,7 +1997,7 @@ static int io_req_task_work_add(struct io_kiocb *req) spin_unlock_irqrestore(&tctx->task_lock, flags); /* task_work already pending, we're done */ - if (test_bit(0, &tctx->task_state) || + if (likely(test_bit(0, &tctx->task_state)) || test_and_set_bit(0, &tctx->task_state)) return 0; @@ -2011,8 +2008,7 @@ static int io_req_task_work_add(struct io_kiocb *req) * will do the job. */ notify = (req->ctx->flags & IORING_SETUP_SQPOLL) ? TWA_NONE : TWA_SIGNAL; - - if (!task_work_add(tsk, &tctx->task_work, notify)) { + if (likely(!task_work_add(tsk, &tctx->task_work, notify))) { wake_up_process(tsk); return 0; } -- 2.32.0