This patch saves the virtio-net device's Rx filter flags as a bit-packed
uint8_t to compare with later during the stop-and-copy phase.
A local enum VirtIONetRxFlags and static inline virtio_net_rx_flags_pack
function is introduced to bit-pack VirtIONet's promisc, allmulti,
alluni, nomulti, nouni, and nobcast into a single byte for easier
comparison.
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
hw/net/virtio-net.c | 28 ++++++++++++++++++++++++++++
include/hw/virtio/virtio-net.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 88ce33b1d2..42c585142d 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3864,6 +3864,26 @@ static bool failover_hide_primary_device(DeviceListener *listener,
return qatomic_read(&n->failover_primary_hidden);
}
+enum VirtIONetRxFlags {
+ VNET_RX_F_PROMISC = 1u << 0,
+ VNET_RX_F_ALLMULTI = 1u << 1,
+ VNET_RX_F_ALLUNI = 1u << 2,
+ VNET_RX_F_NOMULTI = 1u << 3,
+ VNET_RX_F_NOUNI = 1u << 4,
+ VNET_RX_F_NOBCAST = 1u << 5,
+};
+
+/* Pack current Rx filter flags into a single uint8_t for comparison */
+static inline uint8_t virtio_net_rx_flags_pack(const VirtIONet *n)
+{
+ return (n->promisc ? VNET_RX_F_PROMISC : 0) |
+ (n->allmulti ? VNET_RX_F_ALLMULTI : 0) |
+ (n->alluni ? VNET_RX_F_ALLUNI : 0) |
+ (n->nomulti ? VNET_RX_F_NOMULTI : 0) |
+ (n->nouni ? VNET_RX_F_NOUNI : 0) |
+ (n->nobcast ? VNET_RX_F_NOBCAST : 0);
+}
+
static int virtio_net_early_pre_save(void *opaque)
{
VirtIONet *n = opaque;
@@ -3906,6 +3926,9 @@ static int virtio_net_early_pre_save(void *opaque)
memcpy(vnet_mig->mtable_macs_early, n->mac_table.macs, bytes);
}
+ /* Rx filter flags snapshot */
+ vnet_mig->rx_flags_early = virtio_net_rx_flags_pack(n);
+
return 0;
}
@@ -4327,6 +4350,11 @@ static bool virtio_net_has_delta(VirtIONet *n, VirtIODevice *vdev)
}
}
+ /* Has the VirtIONet's Rx filter flags changed? */
+ if (virtio_net_rx_flags_pack(n) != vnet_mig->rx_flags_early) {
+ return true;
+ }
+
/*
* Always return true for now until we're able to detect all possible
* changes to a VirtIONet device.
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 59345f1811..9135d277ff 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -175,6 +175,7 @@ typedef struct VirtIONetQueue {
* @mtable_uni_overflow_early: Unicast overflow MAC table entries.
* @mtable_multi_overflow_early: Multicast overflow MAC table entries.
* @mtable_macs_early: MAC table entries.
+ * @rx_flags_early: Bit-packed RX filters (promisc, allmulti, alluni, etc.).
*/
typedef struct VirtIONetMigration {
uint16_t status_early;
@@ -183,6 +184,7 @@ typedef struct VirtIONetMigration {
uint8_t mtable_uni_overflow_early;
uint8_t mtable_multi_overflow_early;
uint8_t *mtable_macs_early;
+ uint8_t rx_flags_early;
} VirtIONetMigration;
struct VirtIONet {
--
2.51.0