pipe: set FMODE_NOWAIT on pipes
authorJens Axboe <axboe@kernel.dk>
Wed, 8 Mar 2023 00:56:28 +0000 (17:56 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 25 Apr 2023 20:08:59 +0000 (14:08 -0600)
Pipes themselves do not hold the the pipe lock across IO, and hence are
safe for RWF_NOWAIT/IOCB_NOWAIT usage. The "contract" for NOWAIT is
really "should not do IO under this lock", not strictly that we cannot
block or that the below code is in any way atomic. Pipes fulfil that
criteria.

Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/pipe.c

index 42c7ff41c2dba2904cf6c8f2d10ea6984a402823..ceb17d2dfa195a077d0f0014866b3bfc33f5aeac 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -976,6 +976,9 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags)
        audit_fd_pair(fdr, fdw);
        fd[0] = fdr;
        fd[1] = fdw;
+       /* pipe groks IOCB_NOWAIT */
+       files[0]->f_mode |= FMODE_NOWAIT;
+       files[1]->f_mode |= FMODE_NOWAIT;
        return 0;
 
  err_fdr: