diff mbox series

pipe: check for IOCB_NOWAIT alongside O_NONBLOCK

Message ID e5946d67-4e5e-b056-ba80-656bab12d9f6@kernel.dk (mailing list archive)
State Mainlined, archived
Headers show
Series pipe: check for IOCB_NOWAIT alongside O_NONBLOCK | expand

Commit Message

Jens Axboe May 9, 2023, 3:12 p.m. UTC
Pipe reads or writes need to enable nonblocking attempts, if either
O_NONBLOCK is set on the file, or IOCB_NOWAIT is set in the iocb being
passed in. The latter isn't currently true, ensure we check for both
before waiting on data or space.

Fixes: afed6271f5b0 ("pipe: set FMODE_NOWAIT on pipes")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

With the pipe nonblock rework, these two hunsk from one of the other
patches was inadvertently dropped. We obviously need to check both,
or files without O_NONBLOCK but IOCB_NOWAIT set in the iocb will still
block on space/data when writing/reading to/from a pipe.

I can just include this in the io_uring changes as it directly impacts
io_uring (breaking a few test cases), or you guys can queue it up on
the VFS side. Would be great to get this in -rc2 as it's stalling
the regression testing with the vanilla kernels.

Comments

Christian Brauner May 11, 2023, 6:29 p.m. UTC | #1
On Tue, 09 May 2023 09:12:24 -0600, Jens Axboe wrote:
> Pipe reads or writes need to enable nonblocking attempts, if either
> O_NONBLOCK is set on the file, or IOCB_NOWAIT is set in the iocb being
> passed in. The latter isn't currently true, ensure we check for both
> before waiting on data or space.
> 
> 

Thanks. I picked this up and pushed a tag.
I'll get this to Linus before -rc2, Jens.

tree: git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
tag: vfs/v6.4-rc1/pipe
[1/1] pipe: check for IOCB_NOWAIT alongside O_NONBLOCK
      commit: d326147107eb7152941ab3b04ed4ffba8ce93f64
diff mbox series

Patch

diff --git a/fs/pipe.c b/fs/pipe.c
index ceb17d2dfa19..c88611c612ba 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -342,7 +342,7 @@  pipe_read(struct kiocb *iocb, struct iov_iter *to)
 			break;
 		if (ret)
 			break;
-		if (filp->f_flags & O_NONBLOCK) {
+		if (filp->f_flags & O_NONBLOCK || iocb->ki_flags & IOCB_NOWAIT) {
 			ret = -EAGAIN;
 			break;
 		}
@@ -547,7 +547,7 @@  pipe_write(struct kiocb *iocb, struct iov_iter *from)
 			continue;
 
 		/* Wait for buffer space to become available. */
-		if (filp->f_flags & O_NONBLOCK) {
+		if (filp->f_flags & O_NONBLOCK || iocb->ki_flags & IOCB_NOWAIT) {
 			if (!ret)
 				ret = -EAGAIN;
 			break;