Skip to content

Commit

Permalink
io_uring: add warn_once for io_uring_flush()
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
isilence authored and axboe committed Jan 9, 2021
1 parent 4f793dc commit 6b5733e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -9055,17 +9055,23 @@ void __io_uring_task_cancel(void)

static int io_uring_flush(struct file *file, void *data)
{
if (!current->io_uring)
struct io_uring_task *tctx = current->io_uring;

if (!tctx)
return 0;

/* we should have cancelled and erased it before PF_EXITING */
WARN_ON_ONCE((current->flags & PF_EXITING) &&
xa_load(&tctx->xa, (unsigned long)file));

/*
* fput() is pending, will be 2 if the only other ref is our potential
* task file note. If the task is exiting, drop regardless of count.
*/
if (fatal_signal_pending(current) || (current->flags & PF_EXITING) ||
atomic_long_read(&file->f_count) == 2)
io_uring_del_task_file(file);
if (atomic_long_read(&file->f_count) != 2)
return 0;

io_uring_del_task_file(file);
return 0;
}

Expand Down

0 comments on commit 6b5733e

Please sign in to comment.