Skip to contentSkip to conversation

io_uring: flush deferred completions in io_req_post_cqe32()

PATCH New Josh Law 1 participant 1 message Mar 19 io_uring

lore
Share & tools
lore

Josh Law

author
#0 lore raw

PATCH 1/1 io_uring: flush deferred completions in io_req_post_cqe32()

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.

---
 io_uring/io_uring.c | 8 ++++++++
 1 file changed, 8 insertions(+)
io_uring/io_uring.c +8 -0
index 9a37035e76c0..43d2f2b0830d 100644
@@ -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);
 
Signature · 1 line
2.34.1