io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-next 0/2] rw link fixes
@ 2022-09-26 23:20 Pavel Begunkov
  2022-09-26 23:20 ` [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage Pavel Begunkov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pavel Begunkov @ 2022-09-26 23:20 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

1/2 fixes an unexpected link breakage issue with reads.
2/2 makes pre-retry setup fails a bit nicer.

Pavel Begunkov (2):
  io_uring/rw: fix unexpected link breakage
  io_uring/rw: don't lose short results on io_setup_async_rw()

 io_uring/rw.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

-- 
2.37.2


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

* [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage
  2022-09-26 23:20 [PATCH for-next 0/2] rw link fixes Pavel Begunkov
@ 2022-09-26 23:20 ` Pavel Begunkov
  2022-09-26 23:20 ` [PATCH for-next 2/2] io_uring/rw: don't lose short results on io_setup_async_rw() Pavel Begunkov
  2022-09-27  0:43 ` [PATCH for-next 0/2] rw link fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2022-09-26 23:20 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence, Beld Zhang

req->cqe.res is set in io_read() to the amount of bytes left to be done,
which is used to figure out whether to fail a read or not. However,
io_read() may do another without returning, and we stash the previous
value into ->bytes_done but forget to update cqe.res. Then we ask a read
to do strictly less than cqe.res but expect the return to be exactly
cqe.res.

Fix the bug by updating cqe.res for retries.

Cc: stable@vger.kernel.org
Reported-by: Beld Zhang <beldzhang@gmail.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/rw.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index 76ebcfebc9a6..c562203d7a67 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -823,6 +823,7 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags)
 			return -EAGAIN;
 		}
 
+		req->cqe.res = iov_iter_count(&s->iter);
 		/*
 		 * Now retry read with the IOCB_WAITQ parts set in the iocb. If
 		 * we get -EIOCBQUEUED, then we'll get a notification when the
-- 
2.37.2


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

* [PATCH for-next 2/2] io_uring/rw: don't lose short results on io_setup_async_rw()
  2022-09-26 23:20 [PATCH for-next 0/2] rw link fixes Pavel Begunkov
  2022-09-26 23:20 ` [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage Pavel Begunkov
@ 2022-09-26 23:20 ` Pavel Begunkov
  2022-09-27  0:43 ` [PATCH for-next 0/2] rw link fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2022-09-26 23:20 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

If a retry io_setup_async_rw() fails we lose result from the first
io_iter_do_read(), which is a problem mostly for streams/sockets.

Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/rw.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index c562203d7a67..722c06026701 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -794,10 +794,12 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags)
 	iov_iter_restore(&s->iter, &s->iter_state);
 
 	ret2 = io_setup_async_rw(req, iovec, s, true);
-	if (ret2)
-		return ret2;
-
 	iovec = NULL;
+	if (ret2) {
+		ret = ret > 0 ? ret : ret2;
+		goto done;
+	}
+
 	io = req->async_data;
 	s = &io->s;
 	/*
-- 
2.37.2


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

* Re: [PATCH for-next 0/2] rw link fixes
  2022-09-26 23:20 [PATCH for-next 0/2] rw link fixes Pavel Begunkov
  2022-09-26 23:20 ` [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage Pavel Begunkov
  2022-09-26 23:20 ` [PATCH for-next 2/2] io_uring/rw: don't lose short results on io_setup_async_rw() Pavel Begunkov
@ 2022-09-27  0:43 ` Jens Axboe
  2022-09-27  0:45   ` Jens Axboe
  2 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2022-09-27  0:43 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On Tue, 27 Sep 2022 00:20:27 +0100, Pavel Begunkov wrote:
> 1/2 fixes an unexpected link breakage issue with reads.
> 2/2 makes pre-retry setup fails a bit nicer.
> 
> Pavel Begunkov (2):
>   io_uring/rw: fix unexpected link breakage
>   io_uring/rw: don't lose short results on io_setup_async_rw()
> 
> [...]

Applied, thanks!

[1/2] io_uring/rw: fix unexpected link breakage
      commit: 99562357ddaa4ec7f62e0cf68c13cbcde41e8e8e
[2/2] io_uring/rw: don't lose short results on io_setup_async_rw()
      commit: 819c4df334438b7d47ccccb5549a8b862ef38e03

Best regards,
-- 
Jens Axboe



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

* Re: [PATCH for-next 0/2] rw link fixes
  2022-09-27  0:43 ` [PATCH for-next 0/2] rw link fixes Jens Axboe
@ 2022-09-27  0:45   ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2022-09-27  0:45 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 9/26/22 6:43 PM, Jens Axboe wrote:
> On Tue, 27 Sep 2022 00:20:27 +0100, Pavel Begunkov wrote:
>> 1/2 fixes an unexpected link breakage issue with reads.
>> 2/2 makes pre-retry setup fails a bit nicer.
>>
>> Pavel Begunkov (2):
>>   io_uring/rw: fix unexpected link breakage
>>   io_uring/rw: don't lose short results on io_setup_async_rw()
>>
>> [...]
> 
> Applied, thanks!
> 
> [1/2] io_uring/rw: fix unexpected link breakage
>       commit: 99562357ddaa4ec7f62e0cf68c13cbcde41e8e8e
> [2/2] io_uring/rw: don't lose short results on io_setup_async_rw()
>       commit: 819c4df334438b7d47ccccb5549a8b862ef38e03

Oops, saw v2 after this. Dropped this series and took v2 instead
to get the attributes.

-- 
Jens Axboe



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

end of thread, other threads:[~2022-09-27  0:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 23:20 [PATCH for-next 0/2] rw link fixes Pavel Begunkov
2022-09-26 23:20 ` [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage Pavel Begunkov
2022-09-26 23:20 ` [PATCH for-next 2/2] io_uring/rw: don't lose short results on io_setup_async_rw() Pavel Begunkov
2022-09-27  0:43 ` [PATCH for-next 0/2] rw link fixes Jens Axboe
2022-09-27  0:45   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).