Skip to content

Commit 7788c3f

Browse files
Mikhail Sennikovskyjasowang
Mikhail Sennikovsky
authored andcommitted
virtio-net: prevent offloads reset on migration
Currently offloads disabled by guest via the VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET command are not preserved on VM migration. Instead all offloads reported by guest features (via VIRTIO_PCI_GUEST_FEATURES) get enabled. What happens is: first the VirtIONet::curr_guest_offloads gets restored and offloads are getting set correctly: #0 qemu_set_offload (nc=0x555556a11400, csum=1, tso4=0, tso6=0, ecn=0, ufo=0) at net/net.c:474 qemu#1 virtio_net_apply_guest_offloads (n=0x555557701ca0) at hw/net/virtio-net.c:720 qemu#2 virtio_net_post_load_device (opaque=0x555557701ca0, version_id=11) at hw/net/virtio-net.c:2334 qemu#3 vmstate_load_state (f=0x5555569dc010, vmsd=0x555556577c80 <vmstate_virtio_net_device>, opaque=0x555557701ca0, version_id=11) at migration/vmstate.c:168 qemu#4 virtio_load (vdev=0x555557701ca0, f=0x5555569dc010, version_id=11) at hw/virtio/virtio.c:2197 qemu#5 virtio_device_get (f=0x5555569dc010, opaque=0x555557701ca0, size=0, field=0x55555668cd00 <__compound_literal.5>) at hw/virtio/virtio.c:2036 qemu#6 vmstate_load_state (f=0x5555569dc010, vmsd=0x555556577ce0 <vmstate_virtio_net>, opaque=0x555557701ca0, version_id=11) at migration/vmstate.c:143 qemu#7 vmstate_load (f=0x5555569dc010, se=0x5555578189e0) at migration/savevm.c:829 qemu#8 qemu_loadvm_section_start_full (f=0x5555569dc010, mis=0x5555569eee20) at migration/savevm.c:2211 qemu#9 qemu_loadvm_state_main (f=0x5555569dc010, mis=0x5555569eee20) at migration/savevm.c:2395 qemu#10 qemu_loadvm_state (f=0x5555569dc010) at migration/savevm.c:2467 qemu#11 process_incoming_migration_co (opaque=0x0) at migration/migration.c:449 However later on the features are getting restored, and offloads get reset to everything supported by features: #0 qemu_set_offload (nc=0x555556a11400, csum=1, tso4=1, tso6=1, ecn=0, ufo=0) at net/net.c:474 qemu#1 virtio_net_apply_guest_offloads (n=0x555557701ca0) at hw/net/virtio-net.c:720 qemu#2 virtio_net_set_features (vdev=0x555557701ca0, features=5104441767) at hw/net/virtio-net.c:773 qemu#3 virtio_set_features_nocheck (vdev=0x555557701ca0, val=5104441767) at hw/virtio/virtio.c:2052 qemu#4 virtio_load (vdev=0x555557701ca0, f=0x5555569dc010, version_id=11) at hw/virtio/virtio.c:2220 qemu#5 virtio_device_get (f=0x5555569dc010, opaque=0x555557701ca0, size=0, field=0x55555668cd00 <__compound_literal.5>) at hw/virtio/virtio.c:2036 qemu#6 vmstate_load_state (f=0x5555569dc010, vmsd=0x555556577ce0 <vmstate_virtio_net>, opaque=0x555557701ca0, version_id=11) at migration/vmstate.c:143 qemu#7 vmstate_load (f=0x5555569dc010, se=0x5555578189e0) at migration/savevm.c:829 qemu#8 qemu_loadvm_section_start_full (f=0x5555569dc010, mis=0x5555569eee20) at migration/savevm.c:2211 qemu#9 qemu_loadvm_state_main (f=0x5555569dc010, mis=0x5555569eee20) at migration/savevm.c:2395 qemu#10 qemu_loadvm_state (f=0x5555569dc010) at migration/savevm.c:2467 qemu#11 process_incoming_migration_co (opaque=0x0) at migration/migration.c:449 Fix this by preserving the state in saved_guest_offloads field and pushing out offload initialization to the new post load hook. Cc: [email protected] Signed-off-by: Mikhail Sennikovsky <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 1dd7138 commit 7788c3f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

hw/net/virtio-net.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -2333,9 +2333,13 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
23332333
n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
23342334
}
23352335

2336-
if (peer_has_vnet_hdr(n)) {
2337-
virtio_net_apply_guest_offloads(n);
2338-
}
2336+
/*
2337+
* curr_guest_offloads will be later overwritten by the
2338+
* virtio_set_features_nocheck call done from the virtio_load.
2339+
* Here we make sure it is preserved and restored accordingly
2340+
* in the virtio_net_post_load_virtio callback.
2341+
*/
2342+
n->saved_guest_offloads = n->curr_guest_offloads;
23392343

23402344
virtio_net_set_queues(n);
23412345

@@ -2370,6 +2374,22 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
23702374
return 0;
23712375
}
23722376

2377+
static int virtio_net_post_load_virtio(VirtIODevice *vdev)
2378+
{
2379+
VirtIONet *n = VIRTIO_NET(vdev);
2380+
/*
2381+
* The actual needed state is now in saved_guest_offloads,
2382+
* see virtio_net_post_load_device for detail.
2383+
* Restore it back and apply the desired offloads.
2384+
*/
2385+
n->curr_guest_offloads = n->saved_guest_offloads;
2386+
if (peer_has_vnet_hdr(n)) {
2387+
virtio_net_apply_guest_offloads(n);
2388+
}
2389+
2390+
return 0;
2391+
}
2392+
23732393
/* tx_waiting field of a VirtIONetQueue */
23742394
static const VMStateDescription vmstate_virtio_net_queue_tx_waiting = {
23752395
.name = "virtio-net-queue-tx_waiting",
@@ -2912,6 +2932,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
29122932
vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;
29132933
vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
29142934
vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
2935+
vdc->post_load = virtio_net_post_load_virtio;
29152936
vdc->vmsd = &vmstate_virtio_net_device;
29162937
}
29172938

include/hw/virtio/virtio-net.h

+2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ struct VirtIONet {
182182
char *netclient_name;
183183
char *netclient_type;
184184
uint64_t curr_guest_offloads;
185+
/* used on saved state restore phase to preserve the curr_guest_offloads */
186+
uint64_t saved_guest_offloads;
185187
AnnounceTimer announce_timer;
186188
bool needs_vnet_hdr_swap;
187189
bool mtu_bypass_backend;

0 commit comments

Comments
 (0)