Skip to content

Commit e3aabf9

Browse files
committed
io_uring: cancel work if task_work_add() fails
We currently move it to the io_wqe_manager for execution, but we cannot safely do so as we may lack some of the state to execute it out of context. As we cancel work anyway when the ring/task exits, just mark this request as canceled and io_async_task_func() will do the right thing. Fixes: aa96bf8 ("io_uring: use io-wq manager as backup task if task is exiting") Signed-off-by: Jens Axboe <[email protected]>
1 parent 948a774 commit e3aabf9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/io_uring.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,12 +4135,14 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,
41354135
req->result = mask;
41364136
init_task_work(&req->task_work, func);
41374137
/*
4138-
* If this fails, then the task is exiting. Punt to one of the io-wq
4139-
* threads to ensure the work gets run, we can't always rely on exit
4140-
* cancelation taking care of this.
4138+
* If this fails, then the task is exiting. When a task exits, the
4139+
* work gets canceled, so just cancel this request as well instead
4140+
* of executing it. We can't safely execute it anyway, as we may not
4141+
* have the needed state needed for it anyway.
41414142
*/
41424143
ret = task_work_add(tsk, &req->task_work, true);
41434144
if (unlikely(ret)) {
4145+
WRITE_ONCE(poll->canceled, true);
41444146
tsk = io_wq_get_task(req->ctx->io_wq);
41454147
task_work_add(tsk, &req->task_work, true);
41464148
}

0 commit comments

Comments
 (0)