[PATCH] io_uring: flush deferred completions in io_req_post_cqe32()

Josh Law posted 1 patch 2 weeks, 1 day ago
io_uring/io_uring.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] io_uring: flush deferred completions in io_req_post_cqe32()
Posted by Josh Law 2 weeks, 1 day ago
io_req_post_cqe32() is missing the deferred completion flush that its
sibling io_req_post_cqe() has. Without flushing pending deferred
completions before posting a 32-byte CQE, multishot CQEs can be
delivered to userspace out of order.

Add the same flush check that io_req_post_cqe() performs.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 io_uring/io_uring.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 9a37035e76c0..43d2f2b0830d 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -881,6 +881,14 @@ bool io_req_post_cqe32(struct io_kiocb *req, struct io_uring_cqe cqe[2])
 	struct io_ring_ctx *ctx = req->ctx;
 	bool posted;
 
+	/*
+	 * If multishot has already posted deferred completions, ensure that
+	 * those are flushed first before posting this one. If not, CQEs
+	 * could get reordered.
+	 */
+	if (!wq_list_empty(&ctx->submit_state.compl_reqs))
+		__io_submit_flush_completions(ctx);
+
 	lockdep_assert(!io_wq_current_is_worker());
 	lockdep_assert_held(&ctx->uring_lock);
 
-- 
2.34.1