Skip to content

Commit 67b0025

Browse files
isilenceaxboe
authored andcommitted
io_uring/rw: forbid multishot async reads
At the moment we can't sanely handle queuing an async request from a multishot context, so disable them. It shouldn't matter as pollable files / socekts don't normally do async. Patching it in __io_read() is not the cleanest way, but it's simpler than other options, so let's fix it there and clean up on top. Cc: stable@vger.kernel.org Reported-by: chase xd <sl1589472800@gmail.com> Fixes: fc68fcd ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/7d51732c125159d17db4fe16f51ec41b936973f8.1739919038.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fb3331f commit 67b0025

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

io_uring/rw.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,15 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
880880
if (unlikely(ret))
881881
return ret;
882882

883-
ret = io_iter_do_read(rw, &io->iter);
883+
if (unlikely(req->opcode == IORING_OP_READ_MULTISHOT)) {
884+
void *cb_copy = rw->kiocb.ki_complete;
885+
886+
rw->kiocb.ki_complete = NULL;
887+
ret = io_iter_do_read(rw, &io->iter);
888+
rw->kiocb.ki_complete = cb_copy;
889+
} else {
890+
ret = io_iter_do_read(rw, &io->iter);
891+
}
884892

885893
/*
886894
* Some file systems like to return -EOPNOTSUPP for an IOCB_NOWAIT
@@ -904,7 +912,8 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
904912
} else if (ret == -EIOCBQUEUED) {
905913
return IOU_ISSUE_SKIP_COMPLETE;
906914
} else if (ret == req->cqe.res || ret <= 0 || !force_nonblock ||
907-
(req->flags & REQ_F_NOWAIT) || !need_complete_io(req)) {
915+
(req->flags & REQ_F_NOWAIT) || !need_complete_io(req) ||
916+
(issue_flags & IO_URING_F_MULTISHOT)) {
908917
/* read all, failed, already did sync or don't want to retry */
909918
goto done;
910919
}

0 commit comments

Comments
 (0)