Skip to content

Commit de7f1d9

Browse files
isilenceaxboe
authored andcommitted
io_uring: drop file refs after task cancel
io_uring fds marked O_CLOEXEC and we explicitly cancel all requests before going through exec, so we don't want to leave task's file references to not our anymore io_uring instances. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6c50315 commit de7f1d9

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

fs/io_uring.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8958,6 +8958,15 @@ static void io_uring_attempt_task_drop(struct file *file)
89588958
io_uring_del_task_file(file);
89598959
}
89608960

8961+
static void io_uring_remove_task_files(struct io_uring_task *tctx)
8962+
{
8963+
struct file *file;
8964+
unsigned long index;
8965+
8966+
xa_for_each(&tctx->xa, index, file)
8967+
io_uring_del_task_file(file);
8968+
}
8969+
89618970
void __io_uring_files_cancel(struct files_struct *files)
89628971
{
89638972
struct io_uring_task *tctx = current->io_uring;
@@ -8966,16 +8975,12 @@ void __io_uring_files_cancel(struct files_struct *files)
89668975

89678976
/* make sure overflow events are dropped */
89688977
atomic_inc(&tctx->in_idle);
8969-
8970-
xa_for_each(&tctx->xa, index, file) {
8971-
struct io_ring_ctx *ctx = file->private_data;
8972-
8973-
io_uring_cancel_task_requests(ctx, files);
8974-
if (files)
8975-
io_uring_del_task_file(file);
8976-
}
8977-
8978+
xa_for_each(&tctx->xa, index, file)
8979+
io_uring_cancel_task_requests(file->private_data, files);
89788980
atomic_dec(&tctx->in_idle);
8981+
8982+
if (files)
8983+
io_uring_remove_task_files(tctx);
89798984
}
89808985

89818986
static s64 tctx_inflight(struct io_uring_task *tctx)
@@ -9038,6 +9043,8 @@ void __io_uring_task_cancel(void)
90389043
} while (1);
90399044

90409045
atomic_dec(&tctx->in_idle);
9046+
9047+
io_uring_remove_task_files(tctx);
90419048
}
90429049

90439050
static int io_uring_flush(struct file *file, void *data)

0 commit comments

Comments
 (0)