Skip to content

Commit b7ddce3

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix cancel of deferred reqs with ->files
While trying to cancel requests with ->files, it also should look for requests in ->defer_list, otherwise it might end up hanging a thread. Cancel all requests in ->defer_list up to the last request there with matching ->files, that's needed to follow drain ordering semantics. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c183edf commit b7ddce3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

fs/io_uring.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8098,12 +8098,39 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
80988098
io_timeout_remove_link(ctx, req);
80998099
}
81008100

8101+
static void io_cancel_defer_files(struct io_ring_ctx *ctx,
8102+
struct files_struct *files)
8103+
{
8104+
struct io_defer_entry *de = NULL;
8105+
LIST_HEAD(list);
8106+
8107+
spin_lock_irq(&ctx->completion_lock);
8108+
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
8109+
if ((de->req->flags & REQ_F_WORK_INITIALIZED)
8110+
&& de->req->work.files == files) {
8111+
list_cut_position(&list, &ctx->defer_list, &de->list);
8112+
break;
8113+
}
8114+
}
8115+
spin_unlock_irq(&ctx->completion_lock);
8116+
8117+
while (!list_empty(&list)) {
8118+
de = list_first_entry(&list, struct io_defer_entry, list);
8119+
list_del_init(&de->list);
8120+
req_set_fail_links(de->req);
8121+
io_put_req(de->req);
8122+
io_req_complete(de->req, -ECANCELED);
8123+
kfree(de);
8124+
}
8125+
}
8126+
81018127
static void io_uring_cancel_files(struct io_ring_ctx *ctx,
81028128
struct files_struct *files)
81038129
{
81048130
if (list_empty_careful(&ctx->inflight_list))
81058131
return;
81068132

8133+
io_cancel_defer_files(ctx, files);
81078134
/* cancel all at once, should be faster than doing it one by one*/
81088135
io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);
81098136

0 commit comments

Comments
 (0)