From 5de747146ff02a24ebcb2f6e8a06b10734ecd422 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 5 Jul 2022 17:44:54 +0800 Subject: [PATCH] io_uring: terminate manual loop iterator loop correctly for non-vecs stable inclusion from stable-v5.10.110 commit 509565faed7e6a4d27b9df2b8f7ffeedae0067aa bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=509565faed7e6a4d27b9df2b8f7ffeedae0067aa -------------------------------- [ Upstream commit 5e929367468c8f97cd1ffb0417316cecfebef94b ] The fix for not advancing the iterator if we're using fixed buffers is broken in that it can hit a condition where we don't terminate the loop. This results in io-wq looping forever, asking to read (or write) 0 bytes for every subsequent loop. Reported-by: Joel Jaeschke Link: https://github.com/axboe/liburing/issues/549 Fixes: 16c8d2df7ec0 ("io_uring: ensure symmetry in handling iter types in loop_rw_iter()") Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Yu Liao Reviewed-by: Wei Li Signed-off-by: Zheng Zengkai --- fs/io_uring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index fa85548ac4aa..abd2513aa4cc 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3182,13 +3182,15 @@ static ssize_t loop_rw_iter(int rw, struct io_kiocb *req, struct iov_iter *iter) ret = nr; break; } + ret += nr; if (!iov_iter_is_bvec(iter)) { iov_iter_advance(iter, nr); } else { - req->rw.len -= nr; req->rw.addr += nr; + req->rw.len -= nr; + if (!req->rw.len) + break; } - ret += nr; if (nr != iovec.iov_len) break; } -- GitLab