For indirect descriptors the elelm->ndescs was one, For direct descriptors the elele->ndesc was the numbe of entries. elem->ndescs = (desc_cache == &indirect_desc_cache) ? 1 : elem_entries;
When flushing multiple elemes, the used_idx should be added to all the privious numeric entry value. Signed-off-by: Wafer <wa...@jaguarmicro.com> --- hw/virtio/virtio.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d229755eae..44f1d2fcfc 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -957,12 +957,17 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count) return; } + /* + * When the descriptor's flag was 'INDIRECT', the value of 'ndescs' is one. + * When the descriptor's flag was 'chain', the value of 'ndescs' + * is the number of entries. + */ + ndescs += vq->used_elems[0].ndescs; for (i = 1; i < count; i++) { - virtqueue_packed_fill_desc(vq, &vq->used_elems[i], i, false); + virtqueue_packed_fill_desc(vq, &vq->used_elems[i], ndescs, false); ndescs += vq->used_elems[i].ndescs; } virtqueue_packed_fill_desc(vq, &vq->used_elems[0], 0, true); - ndescs += vq->used_elems[0].ndescs; vq->inuse -= ndescs; vq->used_idx += ndescs; -- 2.27.0