public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v2] io_uring: fix leaks on IOPOLL and CQE_SKIP
@ 2022-04-17  9:10 Pavel Begunkov
  2022-04-17 12:54 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2022-04-17  9:10 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

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: 83a13a4181b0e ("io_uring: tweak iopoll CQE_SKIP event counting")
Signed-off-by: Pavel Begunkov <[email protected]>
---

v2: rebase onto 5.18

 fs/io_uring.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 4479013854d2..43f7911ee555 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2797,11 +2797,10 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
 		/* order with io_complete_rw_iopoll(), e.g. ->result updates */
 		if (!smp_load_acquire(&req->iopoll_completed))
 			break;
+		nr_events++;
 		if (unlikely(req->flags & REQ_F_CQE_SKIP))
 			continue;
-
 		__io_fill_cqe_req(req, req->result, io_put_kbuf(req, 0));
-		nr_events++;
 	}
 
 	if (unlikely(!nr_events))
-- 
2.35.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] io_uring: fix leaks on IOPOLL and CQE_SKIP
  2022-04-17  9:10 [PATCH v2] io_uring: fix leaks on IOPOLL and CQE_SKIP Pavel Begunkov
@ 2022-04-17 12:54 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-04-17 12:54 UTC (permalink / raw)
  To: io-uring, asml.silence

On Sun, 17 Apr 2022 10:10:34 +0100, Pavel Begunkov wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] io_uring: fix leaks on IOPOLL and CQE_SKIP
      commit: c0713540f6d55c53dca65baaead55a5a8b20552d

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-17 12:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-17  9:10 [PATCH v2] io_uring: fix leaks on IOPOLL and CQE_SKIP Pavel Begunkov
2022-04-17 12:54 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox