Skip to content

Commit

Permalink
io_uring: io_async_task_func() should check and honor cancelation
Browse files Browse the repository at this point in the history
to #28170604

commit 2bae047 upstream

If the request has been marked as canceled, don't try and issue it.
Instead just fill a canceled event and finish the request.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
  • Loading branch information
axboe authored and Xiaoguang Wang committed Jun 4, 2020
1 parent 2e7787a commit 2cfc484
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -4181,6 +4181,7 @@ static void io_async_task_func(struct callback_head *cb)
struct io_kiocb *req = container_of(cb, struct io_kiocb, task_work);
struct async_poll *apoll = req->apoll;
struct io_ring_ctx *ctx = req->ctx;
bool canceled;

trace_io_uring_task_run(req->ctx, req->opcode, req->user_data);

Expand All @@ -4192,8 +4193,22 @@ static void io_async_task_func(struct callback_head *cb)
if (hash_hashed(&req->hash_node))
hash_del(&req->hash_node);

canceled = READ_ONCE(apoll->poll.canceled);
if (canceled) {
io_cqring_fill_event(req, -ECANCELED);
io_commit_cqring(ctx);
}

spin_unlock_irq(&ctx->completion_lock);

if (canceled) {
kfree(apoll);
io_cqring_ev_posted(ctx);
req_set_fail_links(req);
io_put_req(req);
return;
}

/* restore ->work in case we need to retry again */
memcpy(&req->work, &apoll->work, sizeof(req->work));

Expand Down

0 comments on commit 2cfc484

Please sign in to comment.