Skip to contentSkip to conversation

io_uring: terminate manual loop iterator loop correctly for non-vecs

PATCH New Jens Axboe 1 participant 1 message Mar 18, 2022

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: terminate manual loop iterator loop correctly for non-vecs

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.

Fixes 16c8d2df7ec0 ("io_uring: ensure symmetry in handling iter types in loop_rw_iter()")

---

fs/io_uring.c +4 -2
index 2d6ab732f940..5fa736344b67 100644
@@ -3612,13 +3612,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;
 	}
Signature · 1 line
Jens Axboe