Skip to content

Commit c9d952b

Browse files
committed
io_uring/rw: fix cflags posting for single issue multishot read
If multishot gets disabled, and hence the request will get terminated rather than persist for more iterations, then posting the CQE with the right cflags is still important. Most notably, the buffer reference needs to be included. Refactor the return of __io_read() a bit, so that the provided buffer is always put correctly, and hence returned to the application. Reported-by: Sharon Rosner <Sharon Rosner> Link: axboe/liburing#1257 Cc: [email protected] Fixes: 2a975d4 ("io_uring/rw: don't allow multishot reads without NOWAIT support") Signed-off-by: Jens Axboe <[email protected]>
1 parent c314094 commit c9d952b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

io_uring/rw.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -972,17 +972,21 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
972972
if (issue_flags & IO_URING_F_MULTISHOT)
973973
return IOU_ISSUE_SKIP_COMPLETE;
974974
return -EAGAIN;
975-
}
976-
977-
/*
978-
* Any successful return value will keep the multishot read armed.
979-
*/
980-
if (ret > 0 && req->flags & REQ_F_APOLL_MULTISHOT) {
975+
} else if (ret <= 0) {
976+
io_kbuf_recycle(req, issue_flags);
977+
if (ret < 0)
978+
req_set_fail(req);
979+
} else {
981980
/*
982-
* Put our buffer and post a CQE. If we fail to post a CQE, then
981+
* Any successful return value will keep the multishot read
982+
* armed, if it's still set. Put our buffer and post a CQE. If
983+
* we fail to post a CQE, or multishot is no longer set, then
983984
* jump to the termination path. This request is then done.
984985
*/
985986
cflags = io_put_kbuf(req, ret, issue_flags);
987+
if (!(req->flags & REQ_F_APOLL_MULTISHOT))
988+
goto done;
989+
986990
rw->len = 0; /* similarly to above, reset len to 0 */
987991

988992
if (io_req_post_cqe(req, ret, cflags | IORING_CQE_F_MORE)) {
@@ -1003,6 +1007,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
10031007
* Either an error, or we've hit overflow posting the CQE. For any
10041008
* multishot request, hitting overflow will terminate it.
10051009
*/
1010+
done:
10061011
io_req_set_res(req, ret, cflags);
10071012
io_req_rw_cleanup(req, issue_flags);
10081013
if (issue_flags & IO_URING_F_MULTISHOT)

0 commit comments

Comments
 (0)