Skip to content

Commit 8452d4a

Browse files
isilenceaxboe
authored andcommitted
io_uring: destroy io-wq on exec
Destroy current's io-wq backend and tctx on __io_uring_task_cancel(), aka exec(). Looks it's not strictly necessary, because it will be done at some point when the task dies and changes of creds/files/etc. are handled, but better to do that earlier to free io-wq and not potentially lock previous mm and other resources for the time being. It's safe to do because we wait for all requests of the current task to complete, so no request will use tctx afterwards. Note, that io_uring_files_cancel() may leave some requests for later reaping, so it leaves tctx intact, that's ok as the task is dying anyway. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ef8eaa4 commit 8452d4a

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

fs/io_uring.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8835,13 +8835,17 @@ static void io_uring_del_task_file(struct file *file)
88358835
fput(file);
88368836
}
88378837

8838-
static void io_uring_remove_task_files(struct io_uring_task *tctx)
8838+
static void io_uring_clean_tctx(struct io_uring_task *tctx)
88398839
{
88408840
struct file *file;
88418841
unsigned long index;
88428842

88438843
xa_for_each(&tctx->xa, index, file)
88448844
io_uring_del_task_file(file);
8845+
if (tctx->io_wq) {
8846+
io_wq_put_and_exit(tctx->io_wq);
8847+
tctx->io_wq = NULL;
8848+
}
88458849
}
88468850

88478851
void __io_uring_files_cancel(struct files_struct *files)
@@ -8856,13 +8860,8 @@ void __io_uring_files_cancel(struct files_struct *files)
88568860
io_uring_cancel_task_requests(file->private_data, files);
88578861
atomic_dec(&tctx->in_idle);
88588862

8859-
if (files) {
8860-
io_uring_remove_task_files(tctx);
8861-
if (tctx->io_wq) {
8862-
io_wq_put_and_exit(tctx->io_wq);
8863-
tctx->io_wq = NULL;
8864-
}
8865-
}
8863+
if (files)
8864+
io_uring_clean_tctx(tctx);
88668865
}
88678866

88688867
static s64 tctx_inflight(struct io_uring_task *tctx)
@@ -8954,7 +8953,9 @@ void __io_uring_task_cancel(void)
89548953

89558954
atomic_dec(&tctx->in_idle);
89568955

8957-
io_uring_remove_task_files(tctx);
8956+
io_uring_clean_tctx(tctx);
8957+
/* all current's requests should be gone, we can kill tctx */
8958+
__io_uring_free(current);
89588959
}
89598960

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

include/linux/io_uring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void __io_uring_free(struct task_struct *tsk);
3838

3939
static inline void io_uring_task_cancel(void)
4040
{
41-
if (current->io_uring && !xa_empty(&current->io_uring->xa))
41+
if (current->io_uring)
4242
__io_uring_task_cancel();
4343
}
4444
static inline void io_uring_files_cancel(struct files_struct *files)

0 commit comments

Comments
 (0)