Skip to contentSkip to conversation

io_uring: fail negative results for multishot issue too

PATCH New Jens Axboe 1 participant 1 message Nov 14 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: fail negative results for multishot issue too

Multishot retries are issued through io_poll_issue(), which doesn't share the IOU_COMPLETE handling in io_issue_sqe(). Move failing of negative results and the restart code fixup to a helper and use it for both, and drop the open-coded versions from the accept, multishot read, and uring_cmd handlers.

---

io_uring/io_uring.c +16 -5
index be5a4f9505e0..eba8132d6823 100644
@@ -1526,6 +1526,19 @@ static inline int __io_issue_sqe(struct io_kiocb *req,
 	return ret;
 }
 
+static noinline void __io_req_fail_on_error(struct io_kiocb *req)
+{
+	req->cqe.res = io_fixup_restart_res(req->cqe.res);
+	req_set_fail(req);
+}
+
+/* Fail requests completing with an error, and fix up restart codes */
+static inline void io_req_fail_on_error(struct io_kiocb *req)
+{
+	if (unlikely(req->cqe.res < 0))
+		__io_req_fail_on_error(req);
+}
+
 static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 {
 	const struct io_issue_def *def = &io_issue_defs[req->opcode];
@@ -1537,11 +1550,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	ret = __io_issue_sqe(req, issue_flags, def);
 
 	if (ret == IOU_COMPLETE) {
-		if (unlikely(req->cqe.res < 0)) {
-			if (req->cqe.res <= -ERESTARTSYS)
-				req->cqe.res = io_fixup_restart_res(req->cqe.res);
-			req_set_fail(req);
-		}
+		io_req_fail_on_error(req);
 		if (issue_flags & IO_URING_F_COMPLETE_DEFER)
 			io_req_complete_defer(req);
 		else
@@ -1575,6 +1584,8 @@ int io_poll_issue(struct io_kiocb *req, io_tw_token_t tw)
 		return -EFAULT;
 
 	ret = __io_issue_sqe(req, issue_flags, &io_issue_defs[req->opcode]);
+	if (ret == IOU_COMPLETE)
+		io_req_fail_on_error(req);
 
 	WARN_ON_ONCE(ret == IOU_ISSUE_SKIP_COMPLETE);
 	return ret;
io_uring/net.c +0 -2
index 04927fa5d242..cca940b36759 100644
@@ -1727,8 +1727,6 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
 	}
 
 	io_req_set_res(req, ret, cflags);
-	if (ret < 0)
-		req_set_fail(req);
 	return IOU_COMPLETE;
 }
 
io_uring/rw.c +0 -4
index e3a752225dbb..f6849c5ec64a 100644
@@ -1057,10 +1057,6 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
 		return IOU_RETRY;
 	} else if (ret <= 0) {
 		io_kbuf_recycle(req, sel.buf_list, issue_flags);
-		if (ret < 0) {
-			ret = io_fixup_restart_res(ret);
-			req_set_fail(req);
-		}
 	} else if (!(req->flags & REQ_F_APOLL_MULTISHOT)) {
 		cflags = io_put_kbuf(req, ret, sel.buf_list);
 	} else {
io_uring/uring_cmd.c +0 -2
index ba2d8c9028eb..4706cf61d37e 100644
@@ -262,8 +262,6 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
 	}
 	if (ret == -EIOCBQUEUED)
 		return ret;
-	if (ret < 0)
-		req_set_fail(req);
 	io_req_uring_cleanup(req, issue_flags);
 	io_req_set_res(req, ret, 0);
 	return IOU_COMPLETE;
Signature · 1 line
Jens Axboe