hw/virtio/virtio: Rebuild vring caches when packed ring changes
PATCH 1/1 hw/virtio/virtio: Rebuild vring caches when packed ring changes
A guest can enable a virtqueue before feature negotiation completes, so virtio_queue_set_rings() creates caches before VIRTIO_F_RING_PACKED is loaded into guest_features.
Packed rings need a writable descriptor cache because used descriptors are written back into the descriptor ring. If the cache was created as a split ring cache, this can later trigger an assertion.
Rebuild existing vring caches when VIRTIO_F_RING_PACKED changes, as already done for VIRTIO_RING_F_EVENT_IDX.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3466
--- hw/virtio/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +2 -1
@@ -3223,8 +3223,9 @@ int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features) } ret =virtio_set_features_nocheck (vdev, features); -if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ) ||virtio_vdev_has_feature (vdev,VIRTIO_F_RING_PACKED )) {/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ +/* VIRTIO_F_RING_PACKED changes the cache->is_write value. */ int i;for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) {if (vdev->vq[i].vring.num !=0 ) {
Signature · 1 line
2.50.1 (Apple Git-155)
Hi,
Just a gentle ping on this patch.
It fixes a virtio-sound assertion with packed=on by rebuilding existing vring caches when VIRTIO_F_RING_PACKED changes. The issue is tracked here:
https://gitlab.com/qemu-project/qemu/-/work_items/3466
Please let me know if any changes are needed.
Thanks,
Munkhbaatar
Quoted 36 lines · Munkhbaatar Enkhbaatar
A guest can enable a virtqueue before feature negotiation completes, so
virtio_queue_set_rings()creates caches beforeVIRTIO_F_RING_PACKEDis loaded intoguest_features.
Packed rings need a writable descriptor cache because used descriptors are written back into the descriptor ring. If the cache was created as a split ring cache, this can later trigger an assertion.
Rebuild existing vring caches whenVIRTIO_F_RING_PACKEDchanges, as already done forVIRTIO_RING_F_EVENT_IDX.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3466
Signed-off-by Munkhbaatar Enkhbaatar <[email protected]>---
hw/virtio/virtio.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/virtio/virtio.c +2
-1@@ -3223,8 +3223,9 @@ int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features) } ret =virtio_set_features_nocheck (vdev, features); -if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX ) ||virtio_vdev_has_feature (vdev,VIRTIO_F_RING_PACKED )) {/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ +/* VIRTIO_F_RING_PACKED changes the cache->is_write value. */ int i;for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) {if (vdev->vq[i].vring.num !=0 ) {Signature · 1 line
2.50.1 (Apple Git-155)
Hi,
Gentle ping on patch
Quoted 58 lines · Munkhbaatar Enkhbaatar
Hi,
Just a gentle ping on this patch.
It fixes a virtio-sound assertion with packed=on by rebuilding existing vring caches when
VIRTIO_F_RING_PACKEDchanges. The issue is tracked here:https://gitlab.com/qemu-project/qemu/-/work_items/3466
Please let me know if any changes are needed.
Thanks,
MunkhbaatarQuoted 1 line
On 7 May 2026, at 22:51, Munkhbaatar Enkhbaatar <[email protected]>
Quoted 5 lines · wrote:
A guest can enable a virtqueue before feature negotiation completes, so
virtio_queue_set_rings()creates caches beforeVIRTIO_F_RING_PACKEDis loaded intoguest_features.
Packed rings need a writable descriptor cache because used descriptorsare
Quoted 1 line
written back into the descriptor ring. If the cache was created as a
split
Quoted 2 lines
ring cache, this can later trigger an assertion.
Rebuild existing vring caches whenVIRTIO_F_RING_PACKEDchanges, asalready
hw/virtio/virtio.c int virtio_set_features_ex(VirtIODevice *vdev,
Quoted 14 lines
done for
VIRTIO_RING_F_EVENT_IDX.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3466
Signed-off-by Munkhbaatar Enkhbaatar <[email protected]>---
hw/virtio/virtio.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/virtio/virtio.c +0
-0@@ -3223,8 +3223,9 @@ int virtio_set_features_ex(VirtIODevice *vdev,const
uint64_t*features)hw/virtio/virtio.c int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features)
Quoted 5 lines
hw/virtio/virtio.c +1
-1} ret =virtio_set_features_nocheck (vdev, features); -if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { + if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ||
virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
hw/virtio/virtio.c +1
-1/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ +/* VIRTIO_F_RING_PACKED changes the cache->is_write value. */ int i;for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) {if (vdev->vq[i].vring.num !=0 ) { --2.50.1 (Apple Git-155)