Skip to content

Commit ed4629d

Browse files
isilencegregkh
authored andcommitted
io_uring: lock overflowing for IOPOLL
commit 544d163 upstream. syzbot reports an issue with overflow filling for IOPOLL: WARNING: CPU: 0 PID: 28 at io_uring/io_uring.c:734 io_cqring_event_overflow+0x1c0/0x230 io_uring/io_uring.c:734 CPU: 0 PID: 28 Comm: kworker/u4:1 Not tainted 6.2.0-rc3-syzkaller-16369-g358a161a6a9e #0 Workqueue: events_unbound io_ring_exit_work Call trace:  io_cqring_event_overflow+0x1c0/0x230 io_uring/io_uring.c:734  io_req_cqe_overflow+0x5c/0x70 io_uring/io_uring.c:773  io_fill_cqe_req io_uring/io_uring.h:168 [inline]  io_do_iopoll+0x474/0x62c io_uring/rw.c:1065  io_iopoll_try_reap_events+0x6c/0x108 io_uring/io_uring.c:1513  io_uring_try_cancel_requests+0x13c/0x258 io_uring/io_uring.c:3056  io_ring_exit_work+0xec/0x390 io_uring/io_uring.c:2869  process_one_work+0x2d8/0x504 kernel/workqueue.c:2289  worker_thread+0x340/0x610 kernel/workqueue.c:2436  kthread+0x12c/0x158 kernel/kthread.c:376  ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:863 There is no real problem for normal IOPOLL as flush is also called with uring_lock taken, but it's getting more complicated for IOPOLL|SQPOLL, for which __io_cqring_overflow_flush() happens from the CQ waiting path. Reported-and-tested-by: syzbot+6805087452d72929404e@syzkaller.appspotmail.com Cc: stable@vger.kernel.org # 5.10+ Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fbf5015 commit ed4629d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

io_uring/io_uring.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,12 +2477,26 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
24772477

24782478
io_init_req_batch(&rb);
24792479
while (!list_empty(done)) {
2480+
struct io_uring_cqe *cqe;
2481+
unsigned cflags;
2482+
24802483
req = list_first_entry(done, struct io_kiocb, inflight_entry);
24812484
list_del(&req->inflight_entry);
2482-
2483-
io_fill_cqe_req(req, req->result, io_put_rw_kbuf(req));
2485+
cflags = io_put_rw_kbuf(req);
24842486
(*nr_events)++;
24852487

2488+
cqe = io_get_cqe(ctx);
2489+
if (cqe) {
2490+
WRITE_ONCE(cqe->user_data, req->user_data);
2491+
WRITE_ONCE(cqe->res, req->result);
2492+
WRITE_ONCE(cqe->flags, cflags);
2493+
} else {
2494+
spin_lock(&ctx->completion_lock);
2495+
io_cqring_event_overflow(ctx, req->user_data,
2496+
req->result, cflags);
2497+
spin_unlock(&ctx->completion_lock);
2498+
}
2499+
24862500
if (req_ref_put_and_test(req))
24872501
io_req_free_batch(&rb, req, &ctx->submit_state);
24882502
}

0 commit comments

Comments
 (0)