From 829f6a9a93f99231cf1cda088816cce013ec393c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 21 May 2019 10:45:16 -0600 Subject: io_uring_submit: fix head/tail wrap issue Use proper unsigned math to figure out how many entries we have. If we have head and tail on either side of UINT_MAX, then we currently don't submit anything as: while (head < tail) { is never true. Reported-by: Weiping Zhang Signed-off-by: Jens Axboe --- src/queue.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/queue.c b/src/queue.c index 4b4fea9..5bbb279 100644 --- a/src/queue.c +++ b/src/queue.c @@ -71,7 +71,7 @@ int io_uring_submit(struct io_uring *ring) { struct io_uring_sq *sq = &ring->sq; const unsigned mask = *sq->kring_mask; - unsigned ktail, ktail_next, submitted; + unsigned ktail, ktail_next, submitted, to_submit; int ret; /* @@ -93,7 +93,8 @@ int io_uring_submit(struct io_uring *ring) */ submitted = 0; ktail = ktail_next = *sq->ktail; - while (sq->sqe_head < sq->sqe_tail) { + to_submit = sq->sqe_tail - sq->sqe_head; + while (to_submit--) { ktail_next++; read_barrier(); -- cgit