From: Jonah Palmer <jonah.palmer@oracle.com>
To: qemu-devel@nongnu.org
Cc: eduardo@habkost.net, marcel.apfelbaum@gmail.com,
philmd@linaro.org, wangyanan55@huawei.com, zhao1.liu@intel.com,
mst@redhat.com, sgarzare@redhat.com, jasowang@redhat.com,
leiyang@redhat.com, si-wei.liu@oracle.com, eperezma@redhat.com,
boris.ostrovsky@oracle.com, armbru@redhat.com,
jonah.palmer@oracle.com
Subject: [RFC v2 07/14] virtio-net: detect VirtIONet MAC table mid-migration changes
Date: Fri, 20 Mar 2026 14:20:08 +0000 [thread overview]
Message-ID: <20260320142015.3856652-8-jonah.palmer@oracle.com> (raw)
In-Reply-To: <20260320142015.3856652-1-jonah.palmer@oracle.com>
This patch saves the virtio-net device's MAC table information to
compare with later during the stop-and-copy phase.
We leave out mac_table.first_multi since it's derived post-load.
Note: we store the exact mac_table.in_use value and the MIN macro is
only used to bound copy & compare byte spans for safety.
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
hw/net/virtio-net.c | 34 ++++++++++++++++++++++++++++++++++
include/hw/virtio/virtio-net.h | 8 ++++++++
2 files changed, 42 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 4f14bba510..2dd130777e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3884,6 +3884,26 @@ static int virtio_net_early_pre_save(void *opaque)
/* VirtIONet MAC info snapshot */
memcpy(vnet_mig->mac_early, n->mac, ETH_ALEN);
+ vnet_mig->mtable_in_use_early = n->mac_table.in_use;
+ vnet_mig->mtable_uni_overflow_early = n->mac_table.uni_overflow;
+ vnet_mig->mtable_multi_overflow_early = n->mac_table.multi_overflow;
+ /*
+ * Allocate baseline buffer once. Only copy the used slice each time.
+ * This avoids repeated allocations and keeps memcmp fast
+ */
+ if (!vnet_mig->mtable_macs_early) {
+ vnet_mig->mtable_macs_early =
+ g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN);
+ }
+ /*
+ * Copy used portion only. Cap byte span with MIN for safety even if
+ * a buggy config reports more than capacity.
+ */
+ if (vnet_mig->mtable_in_use_early) {
+ uint32_t used = MIN(vnet_mig->mtable_in_use_early, (uint32_t)MAC_TABLE_ENTRIES);
+ size_t bytes = (size_t)used * ETH_ALEN;
+ memcpy(vnet_mig->mtable_macs_early, n->mac_table.macs, bytes);
+ }
return 0;
}
@@ -4171,6 +4191,8 @@ static void virtio_net_device_unrealize(DeviceState *dev)
g_free(vdev->migration);
vdev->migration = NULL;
+ g_free(n->migration->mtable_macs_early);
+ n->migration->mtable_macs_early = NULL;
g_free(n->migration);
n->migration = NULL;
@@ -4286,6 +4308,18 @@ static bool virtio_net_has_delta(VirtIONet *n, VirtIODevice *vdev)
if (memcmp(n->mac, vnet_mig->mac_early, ETH_ALEN) != 0) {
return true;
}
+ if (n->mac_table.in_use != vnet_mig->mtable_in_use_early ||
+ n->mac_table.uni_overflow != vnet_mig->mtable_uni_overflow_early ||
+ n->mac_table.multi_overflow != vnet_mig->mtable_multi_overflow_early) {
+ return true;
+ }
+ if (n->mac_table.in_use) {
+ uint32_t used = MIN(n->mac_table.in_use, (uint32_t)MAC_TABLE_ENTRIES);
+ size_t bytes = (size_t)used * ETH_ALEN;
+ if (memcmp(n->mac_table.macs, vnet_mig->mtable_macs_early, bytes) != 0) {
+ return true;
+ }
+ }
/*
* Always return true for now until we're able to detect all possible
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 280155366c..1e1f1a3995 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -170,9 +170,17 @@ typedef struct VirtIONetQueue {
/**
* struct VirtIONetMigration - VirtIONet migration structure
* @mac_early: MAC address early migration snapshot.
+ * @mtable_in_use_early: In-use MAC table entries.
+ * @mtable_uni_overflow_early: Unicast overflow MAC table entries.
+ * @mtable_multi_overflow_early: Multicast overflow MAC table entries.
+ * @mtable_macs_early: MAC table entries.
*/
typedef struct VirtIONetMigration {
uint8_t mac_early[ETH_ALEN];
+ uint32_t mtable_in_use_early;
+ uint8_t mtable_uni_overflow_early;
+ uint8_t mtable_multi_overflow_early;
+ uint8_t *mtable_macs_early;
} VirtIONetMigration;
struct VirtIONet {
--
2.51.0
next prev parent reply other threads:[~2026-03-20 14:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 14:20 [RFC v2 00/14] virtio-net: early VMStateDescription live migration support Jonah Palmer
2026-03-20 14:20 ` [RFC v2 01/14] machine,virtio-net: add early-mig property Jonah Palmer
2026-03-23 10:25 ` Eugenio Perez Martin
2026-03-24 14:07 ` Jonah Palmer
2026-03-26 8:02 ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 02/14] virtio, virtio-net: add initial early VMSD for setup-phase migration Jonah Palmer via qemu development
2026-03-24 9:27 ` [RFC v2 02/14] virtio,virtio-net: " Eugenio Perez Martin
2026-03-24 14:28 ` Jonah Palmer
2026-03-24 14:38 ` Eugenio Perez Martin
2026-03-24 17:16 ` Jonah Palmer
2026-03-20 14:20 ` [RFC v2 03/14] virtio,virtio-net: virtio-delta VMSD - VQ state Jonah Palmer
2026-03-20 14:20 ` [RFC v2 04/14] virtio-net: detect VirtIODevice status mid-migration change Jonah Palmer
2026-03-24 10:45 ` Eugenio Perez Martin
2026-03-24 15:01 ` Jonah Palmer
2026-03-26 10:08 ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 05/14] virtio-net: detect VirtIODevice config buffer " Jonah Palmer
2026-03-24 10:48 ` Eugenio Perez Martin
2026-03-24 15:25 ` Jonah Palmer
2026-03-20 14:20 ` [RFC v2 06/14] virtio-net: detect VirtIONet MAC addr " Jonah Palmer
2026-03-20 14:20 ` Jonah Palmer [this message]
2026-03-20 14:20 ` [RFC v2 08/14] virtio-net: detect VirtIONet status " Jonah Palmer
2026-03-24 11:26 ` Eugenio Perez Martin
2026-03-24 16:23 ` Jonah Palmer
2026-03-26 10:20 ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 09/14] virtio-net: detect VirtIONet Rx filter mid-migration changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 10/14] virtio-net: detect VirtIONet VLAN filter table changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 11/14] virtio-net: detect VirtIONet guest offload & MQ mid-migration changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 12/14] virtio-net: detect RSS state " Jonah Palmer
2026-03-20 14:20 ` [RFC v2 13/14] virtio-net: detect pending Tx work for VQs " Jonah Palmer
2026-03-24 11:35 ` Eugenio Perez Martin
2026-03-24 16:47 ` Jonah Palmer
2026-03-26 10:30 ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 14/14] virtio-net, vhost-net: early migration support for vhost-net Jonah Palmer via qemu development
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=20260320142015.3856652-8-jonah.palmer@oracle.com \
--to=jonah.palmer@oracle.com \
--cc=armbru@redhat.com \
--cc=boris.ostrovsky@oracle.com \
--cc=eduardo@habkost.net \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=leiyang@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=si-wei.liu@oracle.com \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox