Skip to content

Commit 687b2ba

Browse files
committed
io_uring: ensure deferred completions are flushed for multishot
Multishot normally uses io_req_post_cqe() to post completions, but when stopping it, it may finish up with a deferred completion. This is fine, except if another multishot event triggers before the deferred completions get flushed. If this occurs, then CQEs may get reordered in the CQ ring, as new multishot completions get posted before the deferred ones are flushed. This can cause confusion on the application side, if strict ordering is required for the use case. When multishot posting via io_req_post_cqe(), flush any pending deferred completions first, if any. Cc: stable@vger.kernel.org # 6.1+ Reported-by: Norman Maurer <norman_maurer@apple.com> Reported-by: Christian Mazakas <christian.mazakas@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b53e523 commit 687b2ba

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

io_uring/io_uring.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,14 @@ bool io_req_post_cqe(struct io_kiocb *req, s32 res, u32 cflags)
848848
struct io_ring_ctx *ctx = req->ctx;
849849
bool posted;
850850

851+
/*
852+
* If multishot has already posted deferred completions, ensure that
853+
* those are flushed first before posting this one. If not, CQEs
854+
* could get reordered.
855+
*/
856+
if (!wq_list_empty(&ctx->submit_state.compl_reqs))
857+
__io_submit_flush_completions(ctx);
858+
851859
lockdep_assert(!io_wq_current_is_worker());
852860
lockdep_assert_held(&ctx->uring_lock);
853861

0 commit comments

Comments
 (0)