* [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
* Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
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
0 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2026-12-03 14:02 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-devel, qemu-stable, Peter Maydell, Daniel P . Berrangé
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
2026-12-03 14:02 ` Michael S. Tsirkin
@ 2026-12-03 14:08 ` Michael Tokarev
2026-12-03 14:18 ` Michael S. Tsirkin
0 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2026-12-03 14:08 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: qemu-devel, qemu-stable, Peter Maydell, Daniel P. Berrangé
On 12/3/26 17:02, Michael S. Tsirkin wrote:
> 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.
This is exactly why I put a check for initially empty queue.
In 10.0.13 and 11.0.4, *all* virtio queues are allocated with
1024 entries at qemu startup already. And this is why I asked
for the amount of damage - how much is that, currently?
But yes, it was my first thought too, to limit this to some
machine versions (11.1 and 10.0), or at least to <11.1. The
only prob is that I dunno how to do this properly :) I have
your example though, and can try to go from there.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
2026-12-03 14:08 ` Michael Tokarev
@ 2026-12-03 14:18 ` Michael S. Tsirkin
2026-12-03 14:40 ` Michael Tokarev
0 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2026-12-03 14:18 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-devel, qemu-stable, Peter Maydell, Daniel P. Berrangé
On Thu, Dec 03, 2026 at 05:08:29PM +0300, Michael Tokarev wrote:
> On 12/3/26 17:02, Michael S. Tsirkin wrote:
> > 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.
>
> This is exactly why I put a check for initially empty queue.
> In 10.0.13 and 11.0.4, *all* virtio queues are allocated with
> 1024 entries at qemu startup already. And this is why I asked
> for the amount of damage - how much is that, currently?
>
> But yes, it was my first thought too, to limit this to some
> machine versions (11.1 and 10.0), or at least to <11.1. The
> only prob is that I dunno how to do this properly :)
> I have
> your example though, and can try to go from there.
>
> Thanks,
>
> /mjt
Compat property, as usual.
--
MST
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
2026-12-03 14:18 ` Michael S. Tsirkin
@ 2026-12-03 14:40 ` Michael Tokarev
2026-12-04 19:10 ` Michael Tokarev
0 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2026-12-03 14:40 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: qemu-devel, qemu-stable, Peter Maydell, Daniel P. Berrangé
On 12/3/26 17:18, Michael S. Tsirkin wrote:
> On Thu, Dec 03, 2026 at 05:08:29PM +0300, Michael Tokarev wrote:
>> But yes, it was my first thought too, to limit this to some
>> machine versions (11.1 and 10.0), or at least to <11.1. The
>> only prob is that I dunno how to do this properly :)
>> I have your example though, and can try to go from there.
> Compat property, as usual.
One compat propery for *every* possible virtio device?
Which ones would it be? The ones who calls virtio_add_queue()?
That's why I'm asking for some help/assistance here, as I know
almost nothing about the whole thing. I learned how compat
properties work - the basic principles - just yesterday :)
But anyway, I'll try to go from virtio_add_queue calls in 11.0,
for now, to see how it all will look like.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] virtio: compensate for incoming migration of virtio queues from broken stable series
2026-12-03 14:40 ` Michael Tokarev
@ 2026-12-04 19:10 ` Michael Tokarev
0 siblings, 0 replies; 6+ messages in thread
From: Michael Tokarev @ 2026-12-04 19:10 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: qemu-devel, qemu-stable, Peter Maydell, Daniel P. Berrangé
On 12/3/26 17:40, Michael Tokarev wrote:
> On 12/3/26 17:18, Michael S. Tsirkin wrote:
>> On Thu, Dec 03, 2026 at 05:08:29PM +0300, Michael Tokarev wrote:
>
>>> But yes, it was my first thought too, to limit this to some
>>> machine versions (11.1 and 10.0), or at least to <11.1. The
>>> only prob is that I dunno how to do this properly :)
>>> I have your example though, and can try to go from there.
>
>> Compat property, as usual.
> One compat propery for *every* possible virtio device?
> Which ones would it be? The ones who calls virtio_add_queue()?
>
> That's why I'm asking for some help/assistance here, as I know
> almost nothing about the whole thing. I learned how compat
> properties work - the basic principles - just yesterday :)
>
> But anyway, I'll try to go from virtio_add_queue calls in 11.0,
> for now, to see how it all will look like.
Ok. I wont able to learn principles of qemu migration and qdev
stuff in time for 11.2 release. This small change requires learning
much more than it is about to fix. Unfortunately it turns out I don't
know even the very basics of qemu. Apparently I shouldn't be doing
any stable releases with this lack of knowledge.
I'm sorry for the mess I caused. Let's not repeat it or make it bigger,
until I can do proper maintenance (if at all).
If someone can step in to maintain the stable series, please do now.
I'll write a separate email about this.
Thanks,
/mjt
^ permalink raw reply [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.