Skip to contentSkip to conversation

rw link fixes

PATCH Applied Pavel Begunkov 2 participants 4 messages Sep 26, 2022 – Sep 27, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

v2 cover rw link fixes

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

v2: rebase and add tested-by

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(-)
Signature · 1 line
2.37.2
#1 lore raw

PATCH v2 1/2 io_uring/rw: fix unexpected link breakage

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.

---
 io_uring/rw.c | 1 +
 1 file changed, 1 insertion(+)
io_uring/rw.c +1 -0
index 59c92a4616b8..ed14322aadb9 100644
@@ -793,6 +793,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
Signature · 1 line
2.37.2
#2 lore raw

PATCH v2 2/2 io_uring/rw: don't lose short results on io_setup_async_rw()

In reply to Pavel Begunkov

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.

---
 io_uring/rw.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
io_uring/rw.c +5 -3
index ed14322aadb9..1ae1e52ab4cb 100644
@@ -764,10 +764,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;
 	/*
Signature · 1 line
2.37.2
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 10 lines · Pavel Begunkov

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

v2: rebase and add tested-by

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: bf68b5b34311ee57ed40749a1257a30b46127556
[2/2] io_uring/rw: don't lose short results on io_setup_async_rw()
      commit: c278d9f8ac0db5590909e6d9e85b5ca2b786704f

Best regards,

Signature · 1 line
Jens Axboe