All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree
@ 2021-09-18 12:34 gregkh
  2021-09-18 12:44 ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: gregkh @ 2021-09-18 12:34 UTC (permalink / raw)
  To: axboe, dmm; +Cc: stable


The patch below does not apply to the 5.14-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 5d329e1286b0a040264e239b80257c937f6e685f Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Tue, 14 Sep 2021 11:08:37 -0600
Subject: [PATCH] io_uring: allow retry for O_NONBLOCK if async is supported

A common complaint is that using O_NONBLOCK files with io_uring can be a
bit of a pain. Be a bit nicer and allow normal retry IFF the file does
support async behavior. This makes it possible to use io_uring more
reliably with O_NONBLOCK files, for use cases where it either isn't
possible or feasible to modify the file flags.

Cc: stable@vger.kernel.org
Reported-and-tested-by: Dan Melnic <dmm@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ae489ab275dd..3077f85a2638 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2843,7 +2843,8 @@ static bool io_file_supports_nowait(struct io_kiocb *req, int rw)
 	return __io_file_supports_nowait(req->file, rw);
 }
 
-static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
+		      int rw)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 	struct kiocb *kiocb = &req->rw.kiocb;
@@ -2865,8 +2866,13 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (unlikely(ret))
 		return ret;
 
-	/* don't allow async punt for O_NONBLOCK or RWF_NOWAIT */
-	if ((kiocb->ki_flags & IOCB_NOWAIT) || (file->f_flags & O_NONBLOCK))
+	/*
+	 * If the file is marked O_NONBLOCK, still allow retry for it if it
+	 * supports async. Otherwise it's impossible to use O_NONBLOCK files
+	 * reliably. If not, or it IOCB_NOWAIT is set, don't retry.
+	 */
+	if ((kiocb->ki_flags & IOCB_NOWAIT) ||
+	    ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req, rw)))
 		req->flags |= REQ_F_NOWAIT;
 
 	ioprio = READ_ONCE(sqe->ioprio);
@@ -3349,7 +3355,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_READ)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, READ);
 }
 
 /*
@@ -3542,7 +3548,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_WRITE)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, WRITE);
 }
 
 static int io_write(struct io_kiocb *req, unsigned int issue_flags)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree
  2021-09-18 12:34 FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree gregkh
@ 2021-09-18 12:44 ` Jens Axboe
  2021-09-18 12:47   ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2021-09-18 12:44 UTC (permalink / raw)
  To: gregkh, dmm; +Cc: stable

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

On 9/18/21 6:34 AM, gregkh@linuxfoundation.org wrote:
> 
> The patch below does not apply to the 5.14-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

Just a trivial fuzz, here's a fixed version.

-- 
Jens Axboe


[-- Attachment #2: 0001-io_uring-allow-retry-for-O_NONBLOCK-if-async-is-supp.patch --]
[-- Type: text/x-patch, Size: 2581 bytes --]

From 5d329e1286b0a040264e239b80257c937f6e685f Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Tue, 14 Sep 2021 11:08:37 -0600
Subject: [PATCH] io_uring: allow retry for O_NONBLOCK if async is supported

commit 5d329e1286b0a040264e239b80257c937f6e685f upstream.

A common complaint is that using O_NONBLOCK files with io_uring can be a
bit of a pain. Be a bit nicer and allow normal retry IFF the file does
support async behavior. This makes it possible to use io_uring more
reliably with O_NONBLOCK files, for use cases where it either isn't
possible or feasible to modify the file flags.

Cc: stable@vger.kernel.org
Reported-and-tested-by: Dan Melnic <dmm@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ae489ab275dd..3077f85a2638 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2843,7 +2843,8 @@ static bool io_file_supports_nowait(struct io_kiocb *req, int rw)
 	return __io_file_supports_async(req->file, rw);
 }
 
-static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
+		      int rw)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 	struct kiocb *kiocb = &req->rw.kiocb;
@@ -2865,8 +2866,13 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (unlikely(ret))
 		return ret;
 
-	/* don't allow async punt for O_NONBLOCK or RWF_NOWAIT */
-	if ((kiocb->ki_flags & IOCB_NOWAIT) || (file->f_flags & O_NONBLOCK))
+	/*
+	 * If the file is marked O_NONBLOCK, still allow retry for it if it
+	 * supports async. Otherwise it's impossible to use O_NONBLOCK files
+	 * reliably. If not, or it IOCB_NOWAIT is set, don't retry.
+	 */
+	if ((kiocb->ki_flags & IOCB_NOWAIT) ||
+	    ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req, rw)))
 		req->flags |= REQ_F_NOWAIT;
 
 	ioprio = READ_ONCE(sqe->ioprio);
@@ -3349,7 +3355,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_READ)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, READ);
 }
 
 /*
@@ -3542,7 +3548,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_WRITE)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, WRITE);
 }
 
 static int io_write(struct io_kiocb *req, unsigned int issue_flags)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree
  2021-09-18 12:44 ` Jens Axboe
@ 2021-09-18 12:47   ` Greg KH
  2021-09-18 12:49     ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2021-09-18 12:47 UTC (permalink / raw)
  To: Jens Axboe; +Cc: dmm, stable

On Sat, Sep 18, 2021 at 06:44:16AM -0600, Jens Axboe wrote:
> On 9/18/21 6:34 AM, gregkh@linuxfoundation.org wrote:
> > 
> > The patch below does not apply to the 5.14-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
> 
> Just a trivial fuzz, here's a fixed version.

Sorry, no, the fuzz was easy, this breaks the build:

fs/io_uring.c: In function ‘io_prep_rw’:
fs/io_uring.c:2715:47: error: implicit declaration of function ‘io_file_supports_nowait’; did you mean ‘io_file_supports_async’? [-Werror=implicit-function-declaration]
 2715 |             ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req, rw)))
      |                                               ^~~~~~~~~~~~~~~~~~~~~~~
      |                                               io_file_supports_async
  CHK     kernel/kheaders_data.tar.xz
cc1: some warnings being treated as errors


Any hint as to what that function would be in 5.14.y?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree
  2021-09-18 12:47   ` Greg KH
@ 2021-09-18 12:49     ` Jens Axboe
  2021-09-18 12:59       ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2021-09-18 12:49 UTC (permalink / raw)
  To: Greg KH; +Cc: dmm, stable

[-- Attachment #1: Type: text/plain, Size: 1263 bytes --]

On 9/18/21 6:47 AM, Greg KH wrote:
> On Sat, Sep 18, 2021 at 06:44:16AM -0600, Jens Axboe wrote:
>> On 9/18/21 6:34 AM, gregkh@linuxfoundation.org wrote:
>>>
>>> The patch below does not apply to the 5.14-stable tree.
>>> If someone wants it applied there, or to any other stable or longterm
>>> tree, then please email the backport, including the original git commit
>>> id to <stable@vger.kernel.org>.
>>
>> Just a trivial fuzz, here's a fixed version.
> 
> Sorry, no, the fuzz was easy, this breaks the build:
> 
> fs/io_uring.c: In function ‘io_prep_rw’:
> fs/io_uring.c:2715:47: error: implicit declaration of function ‘io_file_supports_nowait’; did you mean ‘io_file_supports_async’? [-Werror=implicit-function-declaration]
>  2715 |             ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req, rw)))
>       |                                               ^~~~~~~~~~~~~~~~~~~~~~~
>       |                                               io_file_supports_async
>   CHK     kernel/kheaders_data.tar.xz
> cc1: some warnings being treated as errors
> 
> 
> Any hint as to what that function would be in 5.14.y?

Ah sorry I'm an idiot, it should be that io_file_supports_nowait() that
also caused the fuzz in applying.

-- 
Jens Axboe


[-- Attachment #2: 0001-io_uring-allow-retry-for-O_NONBLOCK-if-async-is-supp.patch --]
[-- Type: text/x-patch, Size: 2579 bytes --]

From 71e536f57c2f4309de4c2d5ae352eb830cdf776c Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Tue, 14 Sep 2021 11:08:37 -0600
Subject: [PATCH] io_uring: allow retry for O_NONBLOCK if async is supported

commit 5d329e1286b0a040264e239b80257c937f6e685f upstream.

A common complaint is that using O_NONBLOCK files with io_uring can be a
bit of a pain. Be a bit nicer and allow normal retry IFF the file does
support async behavior. This makes it possible to use io_uring more
reliably with O_NONBLOCK files, for use cases where it either isn't
possible or feasible to modify the file flags.

Cc: stable@vger.kernel.org
Reported-and-tested-by: Dan Melnic <dmm@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index c5d4638f6d7f..483cc024a40f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2683,7 +2683,8 @@ static bool io_file_supports_async(struct io_kiocb *req, int rw)
 	return __io_file_supports_async(req->file, rw);
 }
 
-static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
+		      int rw)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 	struct kiocb *kiocb = &req->rw.kiocb;
@@ -2705,8 +2706,13 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (unlikely(ret))
 		return ret;
 
-	/* don't allow async punt for O_NONBLOCK or RWF_NOWAIT */
-	if ((kiocb->ki_flags & IOCB_NOWAIT) || (file->f_flags & O_NONBLOCK))
+	/*
+	 * If the file is marked O_NONBLOCK, still allow retry for it if it
+	 * supports async. Otherwise it's impossible to use O_NONBLOCK files
+	 * reliably. If not, or it IOCB_NOWAIT is set, don't retry.
+	 */
+	if ((kiocb->ki_flags & IOCB_NOWAIT) ||
+	    ((file->f_flags & O_NONBLOCK) && !io_file_supports_async(req, rw)))
 		req->flags |= REQ_F_NOWAIT;
 
 	ioprio = READ_ONCE(sqe->ioprio);
@@ -3190,7 +3196,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_READ)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, READ);
 }
 
 /*
@@ -3379,7 +3385,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	if (unlikely(!(req->file->f_mode & FMODE_WRITE)))
 		return -EBADF;
-	return io_prep_rw(req, sqe);
+	return io_prep_rw(req, sqe, WRITE);
 }
 
 static int io_write(struct io_kiocb *req, unsigned int issue_flags)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree
  2021-09-18 12:49     ` Jens Axboe
@ 2021-09-18 12:59       ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-09-18 12:59 UTC (permalink / raw)
  To: Jens Axboe; +Cc: dmm, stable

On Sat, Sep 18, 2021 at 06:49:35AM -0600, Jens Axboe wrote:
> On 9/18/21 6:47 AM, Greg KH wrote:
> > On Sat, Sep 18, 2021 at 06:44:16AM -0600, Jens Axboe wrote:
> >> On 9/18/21 6:34 AM, gregkh@linuxfoundation.org wrote:
> >>>
> >>> The patch below does not apply to the 5.14-stable tree.
> >>> If someone wants it applied there, or to any other stable or longterm
> >>> tree, then please email the backport, including the original git commit
> >>> id to <stable@vger.kernel.org>.
> >>
> >> Just a trivial fuzz, here's a fixed version.
> > 
> > Sorry, no, the fuzz was easy, this breaks the build:
> > 
> > fs/io_uring.c: In function ‘io_prep_rw’:
> > fs/io_uring.c:2715:47: error: implicit declaration of function ‘io_file_supports_nowait’; did you mean ‘io_file_supports_async’? [-Werror=implicit-function-declaration]
> >  2715 |             ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req, rw)))
> >       |                                               ^~~~~~~~~~~~~~~~~~~~~~~
> >       |                                               io_file_supports_async
> >   CHK     kernel/kheaders_data.tar.xz
> > cc1: some warnings being treated as errors
> > 
> > 
> > Any hint as to what that function would be in 5.14.y?
> 
> Ah sorry I'm an idiot, it should be that io_file_supports_nowait() that
> also caused the fuzz in applying.

This version worked, thanks!

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-18 12:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 12:34 FAILED: patch "[PATCH] io_uring: allow retry for O_NONBLOCK if async is supported" failed to apply to 5.14-stable tree gregkh
2021-09-18 12:44 ` Jens Axboe
2021-09-18 12:47   ` Greg KH
2021-09-18 12:49     ` Jens Axboe
2021-09-18 12:59       ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.