Skip to content

Commit da67631

Browse files
isilencegregkh
authored andcommitted
io_uring: add warn_once for io_uring_flush()
[ Upstream commit 6b5733e] files_cancel() should cancel all relevant requests and drop file notes, so we should never have file notes after that, including on-exit fput and flush. Add a WARN_ONCE to be sure. 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>
1 parent 18f3159 commit da67631

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fs/io_uring.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8926,17 +8926,23 @@ void __io_uring_task_cancel(void)
89268926

89278927
static int io_uring_flush(struct file *file, void *data)
89288928
{
8929-
if (!current->io_uring)
8929+
struct io_uring_task *tctx = current->io_uring;
8930+
8931+
if (!tctx)
89308932
return 0;
89318933

8934+
/* we should have cancelled and erased it before PF_EXITING */
8935+
WARN_ON_ONCE((current->flags & PF_EXITING) &&
8936+
xa_load(&tctx->xa, (unsigned long)file));
8937+
89328938
/*
89338939
* fput() is pending, will be 2 if the only other ref is our potential
89348940
* task file note. If the task is exiting, drop regardless of count.
89358941
*/
8936-
if (fatal_signal_pending(current) || (current->flags & PF_EXITING) ||
8937-
atomic_long_read(&file->f_count) == 2)
8938-
io_uring_del_task_file(file);
8942+
if (atomic_long_read(&file->f_count) != 2)
8943+
return 0;
89398944

8945+
io_uring_del_task_file(file);
89408946
return 0;
89418947
}
89428948

0 commit comments

Comments
 (0)