Skip to content

Commit 6200b0a

Browse files
committed
io_uring: don't run task work on an exiting task
This isn't safe, and isn't needed either. We are guaranteed that any work we queue is on a live task (and will be run), or it goes to our backup io-wq threads if the task is exiting. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 87ceb6a commit 6200b0a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

fs/io_uring.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,9 @@ static int io_req_task_work_add(struct io_kiocb *req, struct callback_head *cb,
17531753
struct io_ring_ctx *ctx = req->ctx;
17541754
int ret, notify;
17551755

1756+
if (tsk->flags & PF_EXITING)
1757+
return -ESRCH;
1758+
17561759
/*
17571760
* SQPOLL kernel thread doesn't need notification, just a wakeup. For
17581761
* all other cases, use TWA_SIGNAL unconditionally to ensure we're
@@ -2012,6 +2015,12 @@ static inline unsigned int io_put_rw_kbuf(struct io_kiocb *req)
20122015

20132016
static inline bool io_run_task_work(void)
20142017
{
2018+
/*
2019+
* Not safe to run on exiting task, and the task_work handling will
2020+
* not add work to such a task.
2021+
*/
2022+
if (unlikely(current->flags & PF_EXITING))
2023+
return false;
20152024
if (current->task_works) {
20162025
__set_current_state(TASK_RUNNING);
20172026
task_work_run();
@@ -8184,6 +8193,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
81848193
/* cancel this request, or head link requests */
81858194
io_attempt_cancel(ctx, cancel_req);
81868195
io_put_req(cancel_req);
8196+
/* cancellations _may_ trigger task work */
8197+
io_run_task_work();
81878198
schedule();
81888199
finish_wait(&ctx->inflight_wait, &wait);
81898200
}

0 commit comments

Comments
 (0)