Skip to contentSkip to conversation

fortify async punt preparation

PATCH In review Pavel Begunkov 2 participants 4 messages May 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fortify async punt preparation

[2] fixes FORCE_ASYNC. I don't want to go through every bit, so not sure whether this is an actual issue with [1], but it's just safer this way. Please, consider it for-5.7

IMHO, all preparation thing became a bit messy, definitely could use some rethinking in the future.

Pavel Begunkov (2):
io_uring: don't prepare DRAIN reqs twice
io_uring: fix FORCE_ASYNC req preparation

 fs/io_uring.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/2 io_uring: don't prepare DRAIN reqs twice

If req->io is not NULL, it's already prepared. Don't do it again, it's dangerous.

---
 fs/io_uring.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
fs/io_uring.c +7 -6
index 5a19120345e4..9e81781d7632 100644
@@ -5098,12 +5098,13 @@ static int io_req_defer(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (!req_need_defer(req) && list_empty_careful(&ctx->defer_list))
 		return 0;
 
-	if (!req->io && io_alloc_async_ctx(req))
-		return -EAGAIN;
-
-	ret = io_req_defer_prep(req, sqe);
-	if (ret < 0)
-		return ret;
+	if (!req->io) {
+		if (io_alloc_async_ctx(req))
+			return -EAGAIN;
+		ret = io_req_defer_prep(req, sqe);
+		if (ret < 0)
+			return ret;
+	}
 
 	spin_lock_irq(&ctx->completion_lock);
 	if (!req_need_defer(req) && list_empty(&ctx->defer_list)) {
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/2 io_uring: fix FORCE_ASYNC req preparation

In reply to Pavel Begunkov

As for other not inlined requests, alloc req->io for FORCE_ASYNC reqs, so they can be prepared properly.

---
 fs/io_uring.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
fs/io_uring.c +9 -3
index 9e81781d7632..3d0a08560689 100644
@@ -5692,9 +5692,15 @@ static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 			io_double_put_req(req);
 		}
 	} else if (req->flags & REQ_F_FORCE_ASYNC) {
-		ret = io_req_defer_prep(req, sqe);
-		if (unlikely(ret < 0))
-			goto fail_req;
+		if (!req->io) {
+			ret = -EAGAIN;
+			if (io_alloc_async_ctx(req))
+				goto fail_req;
+			ret = io_req_defer_prep(req, sqe);
+			if (unlikely(ret < 0))
+				goto fail_req;
+		}
+
 		/*
 		 * Never try inline submit of IOSQE_ASYNC is set, go straight
 		 * to async execution.
Signature · 1 line
2.24.0
maintainer
#3 lore raw
In reply to Pavel Begunkov
Quoted 3 lines · Pavel Begunkov

[2] fixes FORCE_ASYNC. I don't want to go through every bit, so not sure whether this is an actual issue with [1], but it's just safer this way. Please, consider it for-5.7

LGTM, applied.

Signature · 1 line
Jens Axboe