diff mbox series

[5.10,21/63] kernel/io_uring: cancel io_uring before task works

Message ID 20210104155709.846535201@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg Kroah-Hartman Jan. 4, 2021, 3:57 p.m. UTC
From: Pavel Begunkov <asml.silence@gmail.com>

commit b1b6b5a30dce872f500dc43f067cba8e7f86fc7d upstream.

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: stable@vger.kernel.org # 5.5+
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/file.c     |    2 --
 kernel/exit.c |    2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Pavel Begunkov Jan. 4, 2021, 4:06 p.m. UTC | #1
On 04/01/2021 15:57, Greg Kroah-Hartman wrote:
> From: Pavel Begunkov <asml.silence@gmail.com>
> 
> commit b1b6b5a30dce872f500dc43f067cba8e7f86fc7d upstream.
> 
> 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.

Greg, can you drop it from stable for now? I'll backport it later when
related problems are sorted.

> 
> 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: stable@vger.kernel.org # 5.5+
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> ---
>  fs/file.c     |    2 --
>  kernel/exit.c |    2 ++
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> --- a/fs/file.c
> +++ b/fs/file.c
> @@ -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;
> @@ -453,7 +452,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);
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -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>
> @@ -762,6 +763,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 */
> 
>
Sasha Levin Jan. 4, 2021, 5:43 p.m. UTC | #2
On Mon, Jan 04, 2021 at 04:06:39PM +0000, Pavel Begunkov wrote:
>On 04/01/2021 15:57, Greg Kroah-Hartman wrote:
>> From: Pavel Begunkov <asml.silence@gmail.com>
>>
>> commit b1b6b5a30dce872f500dc43f067cba8e7f86fc7d upstream.
>>
>> 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.
>
>Greg, can you drop it from stable for now? I'll backport it later when
>related problems are sorted.

I've dropped it, let us know when it's good to go back in.
diff mbox series

Patch

--- a/fs/file.c
+++ b/fs/file.c
@@ -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;
@@ -453,7 +452,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);
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -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>
@@ -762,6 +763,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 */