Skip to content

Commit

Permalink
io_uring: make ctx cancel on exit targeted to actual ctx
Browse files Browse the repository at this point in the history
Before IORING_SETUP_ATTACH_WQ, we could just cancel everything on the
io-wq when exiting. But that's not the case if they are shared, so
cancel for the specific ctx instead.

Cc: stable@vger.kernel.org
Fixes: 24369c2 ("io_uring: add io-wq workqueue sharing")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Dec 20, 2020
1 parent dd20166 commit 00c1864
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8637,6 +8637,13 @@ static void io_ring_exit_work(struct work_struct *work)
io_ring_ctx_free(ctx);
}

static bool io_cancel_ctx_cb(struct io_wq_work *work, void *data)
{
struct io_kiocb *req = container_of(work, struct io_kiocb, work);

return req->ctx == data;
}

static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
{
mutex_lock(&ctx->uring_lock);
Expand All @@ -8651,7 +8658,7 @@ static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
io_poll_remove_all(ctx, NULL, NULL);

if (ctx->io_wq)
io_wq_cancel_all(ctx->io_wq);
io_wq_cancel_cb(ctx->io_wq, io_cancel_ctx_cb, ctx, true);

/* if we failed setting up the ctx, we might not have any rings */
io_iopoll_try_reap_events(ctx);
Expand Down

0 comments on commit 00c1864

Please sign in to comment.