On 11/4/26 05:00, lirongqing wrote:
From: Li RongQing <[email protected]>
free_head tracks the index of the next free descriptor in the SVQ
descriptor ring. It is used by vhost_svq_vring_write_descs() to
choose where to place new descriptors, and is updated as descriptors
are allocated and recycled.
free_head is zero-initialized when the SVQ is created through
vhost_svq_new() (g_new0), but it is not reset in vhost_svq_start().
The start function already resets the rest of the ring state
(shadow_avail_idx, shadow_used_idx, last_used, last_used_idx and
num_free), yet free_head is left untouched.
Since an SVQ can be stopped and restarted on the same object, for
example across vDPA device migration or control virtqueue processing,
a stale free_head from the previous run survives into the new one.
This causes new descriptors to be written at the wrong position of
the SVQ descriptor ring, corrupting it.
Reset free_head to 0 in vhost_svq_start() so that descriptor
allocation always begins from the head of a fresh ring.
Fixes: 100890f7cad5 ("vhost: Shadow virtqueue buffers forwarding")
Signed-off-by: Li RongQing <[email protected]>
---
hw/virtio/vhost-shadow-virtqueue.c | 1 +
1 file changed, 1 insertion(+)
That smells like a qemu-stable material, is it not?
Thanks,
/mjt
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index c97bd9f..462c86d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -857,6 +857,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq,
VirtIODevice *vdev,
svq->shadow_used_idx = 0;
memset(&svq->batch_last, 0, sizeof(svq->batch_last));
svq->last_used = 0;
+ svq->free_head = 0;
svq->last_used_idx = 0;
svq->vdev = vdev;
svq->vq = vq;