Skip to content

Commit abdad70

Browse files
committed
io_uring: recycle provided before arming poll
We currently have a race where we recycle the selected buffer if poll returns IO_APOLL_OK. But that's too late, as the poll could already be triggering or have triggered. If that race happens, then we're putting a buffer that's already being used. Fix this by recycling before we arm poll. This does mean that we'll sometimes almost instantly re-select the buffer, but it's rare enough in testing that it should not pose a performance issue. Fixes: b1c6264 ("io_uring: recycle provided buffers if request goes async") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5e92936 commit abdad70

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

fs/io_uring.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6240,6 +6240,8 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
62406240
req->flags |= REQ_F_POLLED;
62416241
ipt.pt._qproc = io_async_queue_proc;
62426242

6243+
io_kbuf_recycle(req);
6244+
62436245
ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask);
62446246
if (ret || ipt.error)
62456247
return ret ? IO_APOLL_READY : IO_APOLL_ABORTED;
@@ -7491,7 +7493,6 @@ static void io_queue_sqe_arm_apoll(struct io_kiocb *req)
74917493
io_queue_async_work(req, NULL);
74927494
break;
74937495
case IO_APOLL_OK:
7494-
io_kbuf_recycle(req);
74957496
break;
74967497
}
74977498

0 commit comments

Comments
 (0)