Skip to content

Commit

Permalink
kernel/io_uring: cancel io_uring before task works
Browse files Browse the repository at this point in the history
For cancelling io_uring requests it needs either to be able to run
currently enqueued task_works or having it shut down by that moment.
Otherwise io_uring_cancel_files() may be waiting for requests that won't
ever complete.

Go with the first way and do cancellations before setting PF_EXITING and
so before putting the task_work infrastructure into a transition state
where task_work_run() would better not be called.

Cc: [email protected] # 5.5+
Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
isilence authored and axboe committed Dec 31, 2020
1 parent 1ffc542 commit b1b6b5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 0 additions & 2 deletions fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <linux/rcupdate.h>
#include <linux/close_range.h>
#include <net/sock.h>
#include <linux/io_uring.h>

unsigned int sysctl_nr_open __read_mostly = 1024*1024;
unsigned int sysctl_nr_open_min = BITS_PER_LONG;
Expand Down Expand Up @@ -428,7 +427,6 @@ void exit_files(struct task_struct *tsk)
struct files_struct * files = tsk->files;

if (files) {
io_uring_files_cancel(files);
task_lock(tsk);
tsk->files = NULL;
task_unlock(tsk);
Expand Down
2 changes: 2 additions & 0 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <linux/random.h>
#include <linux/rcuwait.h>
#include <linux/compat.h>
#include <linux/io_uring.h>

#include <linux/uaccess.h>
#include <asm/unistd.h>
Expand Down Expand Up @@ -776,6 +777,7 @@ void __noreturn do_exit(long code)
schedule();
}

io_uring_files_cancel(tsk->files);
exit_signals(tsk); /* sets PF_EXITING */

/* sync mm's RSS info before statistics gathering */
Expand Down

0 comments on commit b1b6b5a

Please sign in to comment.