From efd6b3d1768d04d5491b62ad7385f623fb12f627 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Tue, 9 Dec 2025 20:11:17 +0100 Subject: [PATCH] Revert "hw/net/virtio-net: make VirtIONet.vlans an array instead of a pointer" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Per https://lore.kernel.org/qemu-devel/7798584d-e861-47b7-af52-2c2efb67a4de@proxmox.com/: Loading a VM state taken with v10.1.2 or older doesn't work anymore, using the script [*] we get: kvm: VQ 1 size 0x100 < last_avail_idx 0x9 - used_idx 0x3e30 kvm: load of migration failed: Operation not permitted: error while loading state for instance 0x0 of device '0000:00:13.0/virtio-net': Failed to load element of type virtio for virtio: -1 qemu-system-x86_64: Missing section footer for 0000:00:13.0/virtio-net qemu-system-x86_64: Section footer error, section_id: 41 [*]: #!/bin/bash rm /tmp/disk.qcow2 args=" -netdev type=tap,id=net1,ifname=tap104i1,script=/usr/libexec/qemu-server/pve-bridge,downscript=/usr/libexec/qemu-server/pve-bridgedown,vhost=on -device virtio-net-pci,mac=BC:24:11:32:3C:69,netdev=net1,bus=pci.0,addr=0x13,id=net1 -machine type=pc-i440fx-10.1 " $1/qemu-img create -f qcow2 /tmp/disk.qcow2 1G $1/qemu-system-x86_64 --qmp stdio --blockdev qcow2,node-name=node0,file.driver=file,file.filename=/tmp/disk.qcow2 $args < Suggested-by: Fiona Ebner Signed-off-by: Philippe Mathieu-Daudé --- hw/net/virtio-net.c | 9 +++++---- include/hw/virtio/virtio-net.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f5d93eb400..ca813203d7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -986,7 +986,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, virtio_has_feature_ex(vdev->guest_features_ex, VIRTIO_NET_F_CTRL_VLAN)) { bool vlan = virtio_has_feature_ex(features, VIRTIO_NET_F_CTRL_VLAN); - memset(n->vlans, vlan ? 0 : 0xff, sizeof(n->vlans)); + memset(n->vlans, vlan ? 0 : 0xff, MAX_VLAN >> 3); } if (virtio_has_feature_ex(features, VIRTIO_NET_F_STANDBY)) { @@ -3598,8 +3598,7 @@ static const VMStateDescription vmstate_virtio_net_device = { * buffer; hold onto your endiannesses; it's actually used as a bitmap * but based on the uint. */ - VMSTATE_BUFFER_UNSAFE(vlans, VirtIONet, 0, - sizeof(typeof_field(VirtIONet, vlans))), + VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -4017,7 +4016,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); - memset(n->vlans, 0xff, sizeof(n->vlans)); + n->vlans = g_malloc0(MAX_VLAN >> 3); + memset(n->vlans, 0xff, MAX_VLAN >> 3); nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; @@ -4066,6 +4066,7 @@ static void virtio_net_device_unrealize(DeviceState *dev) n->netclient_type = NULL; g_free(n->mac_table.macs); + g_free(n->vlans); if (n->failover) { qobject_unref(n->primary_opts); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index f708355306..5b8ab7bda7 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -202,7 +202,7 @@ struct VirtIONet { uint8_t uni_overflow; uint8_t *macs; } mac_table; - uint32_t vlans[MAX_VLAN]; + uint32_t *vlans; virtio_net_conf net_conf; NICConf nic_conf; DeviceState *qdev; -- 2.47.3