All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
@ 2026-12-03 13:11 Michael Tokarev
  2026-12-03 14:02 ` Michael S. Tsirkin
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2026-12-03 13:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-stable, Michael S . Tsirkin, Peter Maydell,
	Daniel P . Berrangé, Michael Tokarev

Commit fbb87b0d358a "virtio-mmio: fix QUEUE_NUM_MAX" (v11.1.0)
increased queue sizes for virtio-mmio device for older machine
types to 1024.  This commit were back-ported to older stable
series (v10.0.13 and v11.0.5) incorrectly, increasing queue
sizes not just for virtio-mmio but for all virtio devices.
The result is that for non-mmio virtio devices with queues,
migration from these broken versions to curren fails, since
the destination expects smaller queue than 1024.

Instead of making queue size tied to type of device and
machine version, we can reallocate the queue at the load
time to match the source.  This way, there's no need to
have fbb87b0d358a to compensate for the original bug either,
as the queues will be adjusted on load.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/5042
Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---

Compile-tested only, I haven't actually tried to perform migration.
Also, this is my first change in this part of the code, so it might
be completely out of sanity.

 hw/virtio/virtio.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index c9f9e5b5116..d2583637cf0 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3590,10 +3590,23 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
     for (i = 0; i < num; i++) {
         vdev->vq[i].vring.num = qemu_get_be32(f);
         if (vdev->vq[i].vring.num > vdev->vq[i].vring.num_default) {
-            error_report("VQ %d vring.num %u exceeds allocated max %u",
-                         i, vdev->vq[i].vring.num,
-                         vdev->vq[i].vring.num_default);
-            return -1;
+            /*
+             * Some older stable releases (10.0.13+, 11.0.5+) always allocated
+             * queue of size 1024 for all virtio devices, due to incorrect
+             * back-port of v11.1.0-rc1-50-ga5cff318f06c "virtio-mmio: fix
+             * QUEUE_NUM_MAX". Compensate for this by reallocating queue on
+             * load, but only for initially non-empty destination queues and
+             * only for queue of source size 1024 as used by these versions.
+             */
+            if (!vdev->vq[i].vring.num_default || vdev->vq[i].vring.num != 1024) {
+                error_report("VQ %d vring.num %u exceeds allocated max %u",
+                             i, vdev->vq[i].vring.num,
+                             vdev->vq[i].vring.num_default);
+                return -1;
+            }
+            g_free(vdev->vq[i].used_elems);
+            vdev->vq[i].used_elems = g_new0(VirtQueueElement, vdev->vq[i].vring.num);
+            vdev->vq[i].vring.num_default = vdev->vq[i].vring.num;
         }
         if (k->has_variable_vring_alignment) {
             vdev->vq[i].vring.align = qemu_get_be32(f);
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-04 19:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 13:11 [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series Michael Tokarev
2026-12-03 14:02 ` Michael S. Tsirkin
2026-12-03 14:08   ` Michael Tokarev
2026-12-03 14:18     ` Michael S. Tsirkin
2026-12-03 14:40       ` Michael Tokarev
2026-12-04 19:10         ` Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.