Skip to content

Commit 2bae047

Browse files
committed
io_uring: io_async_task_func() should check and honor cancelation
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 <[email protected]>
1 parent 74ce6ce commit 2bae047

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/io_uring.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4181,6 +4181,7 @@ static void io_async_task_func(struct callback_head *cb)
41814181
struct io_kiocb *req = container_of(cb, struct io_kiocb, task_work);
41824182
struct async_poll *apoll = req->apoll;
41834183
struct io_ring_ctx *ctx = req->ctx;
4184+
bool canceled;
41844185

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

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

4196+
canceled = READ_ONCE(apoll->poll.canceled);
4197+
if (canceled) {
4198+
io_cqring_fill_event(req, -ECANCELED);
4199+
io_commit_cqring(ctx);
4200+
}
4201+
41954202
spin_unlock_irq(&ctx->completion_lock);
41964203

4204+
if (canceled) {
4205+
kfree(apoll);
4206+
io_cqring_ev_posted(ctx);
4207+
req_set_fail_links(req);
4208+
io_put_req(req);
4209+
return;
4210+
}
4211+
41974212
/* restore ->work in case we need to retry again */
41984213
memcpy(&req->work, &apoll->work, sizeof(req->work));
41994214

0 commit comments

Comments
 (0)