public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 10/11] io_uring: hide iter revert in resubmit_prep
Date: Mon, 22 Mar 2021 01:58:33 +0000	[thread overview]
Message-ID: <2795b82e6f2b1c94872d42f9b4556548b87cb89d.1616378197.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Move iov_iter_revert() resetting iterator in case of -EIOCBQUEUED into
io_resubmit_prep(), so we don't do heavy revert in hot path, also saves
a couple of checks.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index cccd5fd582f2..775139e9d00f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2475,8 +2475,13 @@ static void kiocb_end_write(struct io_kiocb *req)
 #ifdef CONFIG_BLOCK
 static bool io_resubmit_prep(struct io_kiocb *req)
 {
-	/* either already prepared or successfully done */
-	return req->async_data || !io_req_prep_async(req);
+	struct io_async_rw *rw = req->async_data;
+
+	if (!rw)
+		return !io_req_prep_async(req);
+	/* may have left rw->iter inconsistent on -EIOCBQUEUED */
+	iov_iter_revert(&rw->iter, req->result - iov_iter_count(&rw->iter));
+	return true;
 }
 
 static bool io_rw_should_reissue(struct io_kiocb *req)
@@ -2546,14 +2551,8 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
 	struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
 
 #ifdef CONFIG_BLOCK
-	/* Rewind iter, if we have one. iopoll path resubmits as usual */
 	if (res == -EAGAIN && io_rw_should_reissue(req)) {
-		struct io_async_rw *rw = req->async_data;
-
-		if (rw)
-			iov_iter_revert(&rw->iter,
-					req->result - iov_iter_count(&rw->iter));
-		else if (!io_resubmit_prep(req))
+		if (!io_resubmit_prep(req))
 			req->flags |= REQ_F_DONT_REISSUE;
 	}
 #endif
@@ -3310,8 +3309,6 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
 	ret = io_iter_do_read(req, iter);
 
 	if (ret == -EIOCBQUEUED) {
-		if (req->async_data)
-			iov_iter_revert(iter, io_size - iov_iter_count(iter));
 		goto out_free;
 	} else if (ret == -EAGAIN) {
 		/* IOPOLL retry should happen for io-wq threads */
@@ -3444,8 +3441,6 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
 	/* no retry on NONBLOCK nor RWF_NOWAIT */
 	if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT))
 		goto done;
-	if (ret2 == -EIOCBQUEUED && req->async_data)
-		iov_iter_revert(iter, io_size - iov_iter_count(iter));
 	if (!force_nonblock || ret2 != -EAGAIN) {
 		/* IOPOLL retry should happen for io-wq threads */
 		if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN)
-- 
2.24.0


  parent reply	other threads:[~2021-03-22  2:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22  1:58 [PATCH 5.13 00/11] yet another series of random 5.13 patches Pavel Begunkov
2021-03-22  1:58 ` [PATCH 01/11] io_uring: don't clear REQ_F_LINK_TIMEOUT Pavel Begunkov
2021-03-22  1:58 ` [PATCH 02/11] io_uring: don't do extra EXITING cancellations Pavel Begunkov
2021-03-22  1:58 ` [PATCH 03/11] io_uring: optimise out task_work checks on enter Pavel Begunkov
2021-03-22 13:45   ` Jens Axboe
2021-03-22 14:53     ` Pavel Begunkov
2021-03-22 14:58       ` Jens Axboe
2021-03-22  1:58 ` [PATCH 04/11] io_uring: remove tctx->sqpoll Pavel Begunkov
2021-03-22  1:58 ` [PATCH 05/11] io-wq: refactor *_get_acct() Pavel Begunkov
2021-03-22  1:58 ` [PATCH 06/11] io_uring: don't init req->work fully in advance Pavel Begunkov
2021-03-22  1:58 ` [PATCH 07/11] io_uring: kill unused REQ_F_NO_FILE_TABLE Pavel Begunkov
2021-03-22  1:58 ` [PATCH 08/11] io_uring: optimise kiocb_end_write for !ISREG Pavel Begunkov
2021-03-22  1:58 ` [PATCH 09/11] io_uring: don't alter iopoll reissue fail ret code Pavel Begunkov
2021-03-22  1:58 ` Pavel Begunkov [this message]
2021-03-22  1:58 ` [PATCH 11/11] io_uring: optimise rw complete error handling Pavel Begunkov
2021-03-22  2:00 ` [PATCH 5.13 00/11] yet another series of random 5.13 patches Pavel Begunkov
2021-03-22 13:49 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2795b82e6f2b1c94872d42f9b4556548b87cb89d.1616378197.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox