hw/virtio/virtio.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
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
On Thu, Dec 03, 2026 at 04:11:37PM +0300, Michael Tokarev wrote:
> 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>
Fun times. And then people will complain that incoming
migration can cause dos by drinking up unlimited memory.
If we really have to, let's put this behind a machine
compat flag that will just trigger for the broken
machines.
> ---
>
> 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
© 2016 - 2026 Red Hat, Inc.