From: "Michael S. Tsirkin" <mst@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-stable@nongnu.org,
"Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P . Berrangé" <berrange@redhat.com>
Subject: Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
Date: Thu, 3 Dec 2026 09:02:27 -0500 [thread overview]
Message-ID: <20261203085900-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20261203131137.3127943-1-mjt@tls.msk.ru>
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
next prev parent reply other threads:[~2026-12-03 14:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203085900-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=berrange@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.