]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
virtio: Allow to fill a whole virtqueue in order
authorEugenio Pérez <eperezma@redhat.com>
Wed, 4 Mar 2026 17:35:29 +0000 (18:35 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 3 Jun 2026 12:36:41 +0000 (08:36 -0400)
As the while steps < max_steps is already one less than the vq size, the
right maximum max_steps variable is queue length, not the maximum
possible remainder of % vq->vring.num.

Fixes: b44135daa37 ("virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER support")
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20260304173535.2702587-2-eperezma@redhat.com>

hw/virtio/virtio.c

index fb7f7f0f06120fe1263e7af182545b15492a2333..ed58c1af9f922d00ba2c78a13c0e531abeb365e1 100644 (file)
@@ -986,7 +986,7 @@ static void virtqueue_ordered_fill(VirtQueue *vq, const VirtQueueElement *elem,
      * We shouldn't need to increase 'i' by more than or equal to
      * the distance between used_idx and last_avail_idx (max_steps).
      */
-    max_steps = (vq->last_avail_idx - vq->used_idx) % vq->vring.num;
+    max_steps = MIN(vq->last_avail_idx - vq->used_idx, vq->vring.num);
 
     /* Search for element in vq->used_elems */
     while (steps < max_steps) {