Save the current RSS state at early migration time to compare with later during the stop-and-copy phase.
Only the RSS state that can change mid-migration is tracked. RSS fields derived from backend capability/feature negotiation (for example software-RSS capability flags and supported/peer hash capability metadata) are intentionally excluded from delta checks. Signed-off-by: Jonah Palmer <[email protected]> --- hw/net/virtio-net.c | 50 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-net.h | 16 +++++++++++ 2 files changed, 66 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 2c0b42debb..3ee49a043a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3943,6 +3943,27 @@ static int virtio_net_early_pre_save(void *opaque) vnet_mig->mq_early = n->multiqueue; vnet_mig->queue_pairs_early = n->curr_queue_pairs; + /* RSS state snapshot */ + vnet_mig->rss_enabled_early = n->rss_data.enabled; + vnet_mig->rss_redirect_early = n->rss_data.redirect; + vnet_mig->rss_populate_hash_early = n->rss_data.populate_hash; + vnet_mig->rss_runtime_hash_types_early = n->rss_data.runtime_hash_types; + vnet_mig->rss_indirections_len_early = n->rss_data.indirections_len; + vnet_mig->rss_default_queue_early = n->rss_data.default_queue; + memcpy(vnet_mig->rss_key_early, n->rss_data.key, VIRTIO_NET_RSS_MAX_KEY_SIZE); + + /* Snapshot RSS indirections table if present */ + g_free(vnet_mig->rss_indirections_table_early); + vnet_mig->rss_indirections_table_early = NULL; + + if (n->rss_data.indirections_len && n->rss_data.indirections_table) { + /* Casting to size_t avoids implicit narrow/widen arithmetic */ + size_t bytes = (size_t)n->rss_data.indirections_len * sizeof(uint16_t); + + vnet_mig->rss_indirections_table_early = + g_memdup2(n->rss_data.indirections_table, bytes); + } + return 0; } @@ -4233,6 +4254,8 @@ static void virtio_net_device_unrealize(DeviceState *dev) n->migration->mtable_macs_early = NULL; g_free(n->migration->vlans_early); n->migration->vlans_early = NULL; + g_free(n->migration->rss_indirections_table_early); + n->migration->rss_indirections_table_early = NULL; g_free(n->migration); n->migration = NULL; @@ -4389,6 +4412,33 @@ static bool virtio_net_has_delta(VirtIONet *n, VirtIODevice *vdev) return true; } + /* Has the VirtIONet's RSS state changed? */ + if (n->rss_data.enabled != vnet_mig->rss_enabled_early || + n->rss_data.redirect != vnet_mig->rss_redirect_early || + n->rss_data.populate_hash != vnet_mig->rss_populate_hash_early || + n->rss_data.runtime_hash_types != vnet_mig->rss_runtime_hash_types_early || + n->rss_data.indirections_len != vnet_mig->rss_indirections_len_early || + n->rss_data.default_queue != vnet_mig->rss_default_queue_early) { + return true; + } + if (memcmp(n->rss_data.key, vnet_mig->rss_key_early, + VIRTIO_NET_RSS_MAX_KEY_SIZE) != 0) { + return true; + } + if (n->rss_data.indirections_len) { + size_t bytes = (size_t)n->rss_data.indirections_len * sizeof(uint16_t); + + /* If either side lacks a buffer when len > 0, treat as changed */ + if (!n->rss_data.indirections_table || + !vnet_mig->rss_indirections_table_early) { + return true; + } + if (memcmp(n->rss_data.indirections_table, + vnet_mig->rss_indirections_table_early, bytes) != 0) { + 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 5d6179fa19..88074a0976 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -180,6 +180,14 @@ typedef struct VirtIONetQueue { * @guest_offloads_early: Guest offloads snapshot. * @mq_early: Multiqueue state snapshot. * @queue_pairs_early: Queue pairs snapshot. + * @rss_enabled_early: RSS enabled flag. + * @rss_redirect_early: RSS redirect flag. + * @rss_populate_hash_early: RSS populate hash flag. + * @rss_runtime_hash_types_early: RSS runtime hash types. + * @rss_indirections_len_early: RSS indirections length. + * @rss_default_queue_early: RSS default queue. + * @rss_key_early: RSS key. + * @rss_indirections_table_early: RSS indirections table. */ typedef struct VirtIONetMigration { uint16_t status_early; @@ -193,6 +201,14 @@ typedef struct VirtIONetMigration { uint64_t guest_offloads_early; int mq_early; uint16_t queue_pairs_early; + bool rss_enabled_early; + bool rss_redirect_early; + bool rss_populate_hash_early; + uint32_t rss_runtime_hash_types_early; + uint16_t rss_indirections_len_early; + uint16_t rss_default_queue_early; + uint8_t rss_key_early[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + uint16_t *rss_indirections_table_early; } VirtIONetMigration; struct VirtIONet { -- 2.51.0
