Commit 6200b0ae authored by Jens Axboe's avatar Jens Axboe

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: default avatarJens Axboe <axboe@kernel.dk>
parent 87ceb6a6
...@@ -1753,6 +1753,9 @@ static int io_req_task_work_add(struct io_kiocb *req, struct callback_head *cb, ...@@ -1753,6 +1753,9 @@ static int io_req_task_work_add(struct io_kiocb *req, struct callback_head *cb,
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
int ret, notify; int ret, notify;
if (tsk->flags & PF_EXITING)
return -ESRCH;
/* /*
* SQPOLL kernel thread doesn't need notification, just a wakeup. For * SQPOLL kernel thread doesn't need notification, just a wakeup. For
* all other cases, use TWA_SIGNAL unconditionally to ensure we're * 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) ...@@ -2012,6 +2015,12 @@ static inline unsigned int io_put_rw_kbuf(struct io_kiocb *req)
static inline bool io_run_task_work(void) static inline bool io_run_task_work(void)
{ {
/*
* Not safe to run on exiting task, and the task_work handling will
* not add work to such a task.
*/
if (unlikely(current->flags & PF_EXITING))
return false;
if (current->task_works) { if (current->task_works) {
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
task_work_run(); task_work_run();
...@@ -8184,6 +8193,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx, ...@@ -8184,6 +8193,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
/* cancel this request, or head link requests */ /* cancel this request, or head link requests */
io_attempt_cancel(ctx, cancel_req); io_attempt_cancel(ctx, cancel_req);
io_put_req(cancel_req); io_put_req(cancel_req);
/* cancellations _may_ trigger task work */
io_run_task_work();
schedule(); schedule();
finish_wait(&ctx->inflight_wait, &wait); finish_wait(&ctx->inflight_wait, &wait);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment