Skip to content

Commit c071354

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix leaks on IOPOLL and CQE_SKIP
If all completed requests in io_do_iopoll() were marked with REQ_F_CQE_SKIP, we'll not only skip CQE posting but also io_free_batch_list() leaking memory and resources. Move @nr_events increment before REQ_F_CQE_SKIP check. We'll potentially return the value greater than the real one, but iopolling will deal with it and the userspace will re-iopoll if needed. In anyway, I don't think there are many use cases for REQ_F_CQE_SKIP + IOPOLL. Fixes: 83a13a4 ("io_uring: tweak iopoll CQE_SKIP event counting") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/5072fc8693fbfd595f89e5d4305bfcfd5d2f0a64.1650186611.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 323b190 commit c071354

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

fs/io_uring.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,11 +2797,10 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
27972797
/* order with io_complete_rw_iopoll(), e.g. ->result updates */
27982798
if (!smp_load_acquire(&req->iopoll_completed))
27992799
break;
2800+
nr_events++;
28002801
if (unlikely(req->flags & REQ_F_CQE_SKIP))
28012802
continue;
2802-
28032803
__io_fill_cqe_req(req, req->result, io_put_kbuf(req, 0));
2804-
nr_events++;
28052804
}
28062805

28072806
if (unlikely(!nr_events))

0 commit comments

Comments
 (0)