Skip to content

Commit

Permalink
io_uring/rw: fix cflags posting for single issue multishot read
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
axboe authored and gregkh committed Oct 17, 2024
1 parent a61c55f commit 84876a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions io_uring/rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,17 +973,21 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
if (issue_flags & IO_URING_F_MULTISHOT)
return IOU_ISSUE_SKIP_COMPLETE;
return -EAGAIN;
}

/*
* Any successful return value will keep the multishot read armed.
*/
if (ret > 0 && req->flags & REQ_F_APOLL_MULTISHOT) {
} else if (ret <= 0) {
io_kbuf_recycle(req, issue_flags);
if (ret < 0)
req_set_fail(req);
} else {
/*
* Put our buffer and post a CQE. If we fail to post a CQE, then
* Any successful return value will keep the multishot read
* armed, if it's still set. Put our buffer and post a CQE. If
* we fail to post a CQE, or multishot is no longer set, then
* jump to the termination path. This request is then done.
*/
cflags = io_put_kbuf(req, issue_flags);
if (!(req->flags & REQ_F_APOLL_MULTISHOT))
goto done;

rw->len = 0; /* similarly to above, reset len to 0 */

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

0 comments on commit 84876a5

Please sign in to comment.