summary refs log tree commit diff
path: root/io_uring/rw.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2022-11-23 11:33:36 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-12-31 13:33:11 +0100
commit16225abb3cbc0d810c589541f5b9ca88003f5128 (patch)
tree5a8abbb0b767df569b27864176052f051fa53c14 /io_uring/rw.c
parent3a6ee45e3ceb60818c5fa4acd3c258bb124452a8 (diff)
downloadlinux-16225abb3cbc0d810c589541f5b9ca88003f5128.tar.gz
io_uring: add completion locking for iopoll
commit 2ccc92f4effcfa1c51c4fcf1e34d769099d3cad4 upstream.

There are pieces of code that may allow iopoll to race filling cqes,
temporarily add spinlocking around posting events.

Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/84d86b5c117feda075471c5c9e65208e0dccf5d0.1669203009.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring/rw.c')
-rw-r--r--io_uring/rw.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/io_uring/rw.c b/io_uring/rw.c
index bb47cc4da713..98dfd8fdc9dc 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -1043,6 +1043,7 @@ int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
 	else if (!pos)
 		return 0;
 
+	spin_lock(&ctx->completion_lock);
 	prev = start;
 	wq_list_for_each_resume(pos, prev) {
 		struct io_kiocb *req = container_of(pos, struct io_kiocb, comp_list);
@@ -1057,11 +1058,11 @@ int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
 		req->cqe.flags = io_put_kbuf(req, 0);
 		__io_fill_cqe_req(req->ctx, req);
 	}
-
+	io_commit_cqring(ctx);
+	spin_unlock(&ctx->completion_lock);
 	if (unlikely(!nr_events))
 		return 0;
 
-	io_commit_cqring(ctx);
 	io_cqring_ev_posted_iopoll(ctx);
 	pos = start ? start->next : ctx->iopoll_list.first;
 	wq_list_cut(&ctx->iopoll_list, prev, start);