Commit e244725e86be ("vhost: fix used ring index wrap in vhost_add_used_n_in_order") made the loop that writes the used ring entries wrap start with a mask, because start + nheads[i] can reach 2 * vq->num, e.g. on the vhost-net TX path where done_idx can reach VHOST_NET_BATCH (64) with a 32-entry ring. The loop that logs those entries for dirty tracking, added just before by commit bfcde6b64769 ("vhost: fix dirty logging for in-order used ring entries"), walks the same sequence of positions but still wraps with a single subtraction: next = start + nheads[i]; if (next >= vq->num) next -= vq->num; so with the same inputs next stays at or above vq->num. The following run is then logged at vq->used->ring + log_start with log_start past the end of the ring, and the entries that were actually written after the wrap are not logged. With migration in progress that leaves stale used ring entries on the destination, and log_used() can set bits for guest memory beyond the used ring. Use the same mask as the write loop. VHOST_SET_VRING_NUM guarantees vq->num is a power of two. Fixes: bfcde6b64769 ("vhost: fix dirty logging for in-order used ring entries") Signed-off-by: Peng Hao --- drivers/vhost/vhost.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index dc97328756..80b887e151 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -3206,9 +3206,7 @@ static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq, log_start = start; log_count++; - next = start + nheads[i]; - if (next >= vq->num) - next -= vq->num; + next = (start + nheads[i]) & (vq->num - 1); if (i + 1 == count || next != start + 1) { used = vq->used->ring + log_start; log_used(vq, -- 2.43.7