lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 18 Oct 2021 03:02:43 -0400
From:   Noah Goldstein <goldstein.w.n@...il.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     goldstein.w.n@...il.com, axboe@...nel.dk, asml.silence@...il.com,
        io-uring@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v1] fs/io_uring: Hoist ret2 == -EAGAIN check in tail of io_write

This commit reorganizes the branches in the tail of io_write so that
the 'ret2 == -EAGAIN' check is not repeated and done first.

The previous version was duplicating the 'ret2 == -EAGAIN'. As well
'ret2 != -EAGAIN' gurantees the 'done:' path so it makes sense to
move that check to the front before the likely more expensive branches
which require memory derefences.

Signed-off-by: Noah Goldstein <goldstein.w.n@...il.com>
---
Generally I would want to rewrite this as:
```
if (ret2 != -EAGAIN
    || (req->flags & REQ_F_NOWAIT)
    || (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL)))
        kiocb_done(kiocb, ret2, issue_flags);
else {
    ...
```

But the style of the file seems to be to use gotos. If the above is
prefereable, let me know and I'll post a new version.    
 fs/io_uring.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index d1e672e7a2d1..932fc84d70d3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3648,12 +3648,15 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
 	 */
 	if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
 		ret2 = -EAGAIN;
+
+	if (ret2 != -EAGAIN)
+		goto done;
 	/* no retry on NONBLOCK nor RWF_NOWAIT */
-	if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT))
+	if (req->flags & REQ_F_NOWAIT)
 		goto done;
-	if (!force_nonblock || ret2 != -EAGAIN) {
+	if (!force_nonblock) {
 		/* IOPOLL retry should happen for io-wq threads */
-		if (ret2 == -EAGAIN && (req->ctx->flags & IORING_SETUP_IOPOLL))
+		if (req->ctx->flags & IORING_SETUP_IOPOLL)
 			goto copy_iov;
 done:
 		kiocb_done(kiocb, ret2, issue_flags);
-- 
2.29.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ