Skip to content

Commit ef9865a

Browse files
isilenceaxboe
authored andcommitted
io_uring: don't forget to task-cancel drained reqs
If there is a long-standing request of one task locking up execution of deferred requests, and the defer list contains requests of another task (all files-less), then a potential execution of __io_uring_task_cancel() by that another task will sleep until that first long-standing request completion, and that may take long. E.g. tsk1: req1/read(empty_pipe) -> tsk2: req(DRAIN) Then __io_uring_task_cancel(tsk2) waits for req1 completion. It seems we even can manufacture a complicated case with many tasks sharing many rings that can lock them forever. Cancel deferred requests for __io_uring_task_cancel() as well. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 99b3280 commit ef9865a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/io_uring.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8496,14 +8496,16 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
84968496
}
84978497

84988498
static void io_cancel_defer_files(struct io_ring_ctx *ctx,
8499+
struct task_struct *task,
84998500
struct files_struct *files)
85008501
{
85018502
struct io_defer_entry *de = NULL;
85028503
LIST_HEAD(list);
85038504

85048505
spin_lock_irq(&ctx->completion_lock);
85058506
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
8506-
if (io_match_files(de->req, files)) {
8507+
if (io_task_match(de->req, task) &&
8508+
io_match_files(de->req, files)) {
85078509
list_cut_position(&list, &ctx->defer_list, &de->list);
85088510
break;
85098511
}
@@ -8529,7 +8531,6 @@ static bool io_uring_cancel_files(struct io_ring_ctx *ctx,
85298531
if (list_empty_careful(&ctx->inflight_list))
85308532
return false;
85318533

8532-
io_cancel_defer_files(ctx, files);
85338534
/* cancel all at once, should be faster than doing it one by one*/
85348535
io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);
85358536

@@ -8621,6 +8622,11 @@ static void io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
86218622
io_sq_thread_park(ctx->sq_data);
86228623
}
86238624

8625+
if (files)
8626+
io_cancel_defer_files(ctx, NULL, files);
8627+
else
8628+
io_cancel_defer_files(ctx, task, NULL);
8629+
86248630
io_cqring_overflow_flush(ctx, true, task, files);
86258631

86268632
while (__io_uring_cancel_task_requests(ctx, task, files)) {

0 commit comments

Comments
 (0)