Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 84876a5

Browse files
axboegregkh
authored andcommitted
io_uring/rw: fix cflags posting for single issue multishot read
Commit c9d952b upstream. 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: stable@vger.kernel.org Fixes: 2a975d4 ("io_uring/rw: don't allow multishot reads without NOWAIT support") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a61c55f commit 84876a5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

io_uring/rw.c

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

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

0 commit comments

Comments
 (0)