virtio-devices, vmm: Always restore virtio devices in paused state

Following the new restore design, it is not appropriate to set every
virtio device threads into a paused state after they've been started.

This is why we remove the line of code pausing the devices only after
they've been restored, and replace it with a small patch in every virtio
device implementation. When a virtio device is created as part of a
restored VM, the associated "paused" boolean is set to true. This
ensures the corresponding thread will be directly parked when being
started, avoiding the thread to be in a different state than the one it
was on the source VM during the snapshot.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-11-30 17:10:04 +01:00
parent 8f1e03fcf4
commit b62a40efae
15 changed files with 400 additions and 332 deletions

View File

@@ -451,57 +451,65 @@ impl Net {
let mtu = taps[0].mtu().map_err(Error::TapError)? as u16;
let (avail_features, acked_features, config, queue_sizes) = if let Some(state) = state {
info!("Restoring virtio-net {}", id);
(
state.avail_features,
state.acked_features,
state.config,
state.queue_size,
)
} else {
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
| 1 << VIRTIO_NET_F_GUEST_CSUM
| 1 << VIRTIO_NET_F_GUEST_ECN
| 1 << VIRTIO_NET_F_GUEST_TSO4
| 1 << VIRTIO_NET_F_GUEST_TSO6
| 1 << VIRTIO_NET_F_GUEST_UFO
| 1 << VIRTIO_NET_F_HOST_ECN
| 1 << VIRTIO_NET_F_HOST_TSO4
| 1 << VIRTIO_NET_F_HOST_TSO6
| 1 << VIRTIO_NET_F_HOST_UFO
| 1 << VIRTIO_NET_F_MTU
| 1 << VIRTIO_RING_F_EVENT_IDX
| 1 << VIRTIO_F_VERSION_1;
if iommu {
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
}
avail_features |= 1 << VIRTIO_NET_F_CTRL_VQ;
let queue_num = num_queues + 1;
let mut config = VirtioNetConfig::default();
if let Some(mac) = guest_mac {
build_net_config_space(
&mut config,
mac,
num_queues,
Some(mtu),
&mut avail_features,
);
let (avail_features, acked_features, config, queue_sizes, paused) =
if let Some(state) = state {
info!("Restoring virtio-net {}", id);
(
state.avail_features,
state.acked_features,
state.config,
state.queue_size,
true,
)
} else {
build_net_config_space_with_mq(
&mut config,
num_queues,
Some(mtu),
&mut avail_features,
);
}
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
| 1 << VIRTIO_NET_F_GUEST_CSUM
| 1 << VIRTIO_NET_F_GUEST_ECN
| 1 << VIRTIO_NET_F_GUEST_TSO4
| 1 << VIRTIO_NET_F_GUEST_TSO6
| 1 << VIRTIO_NET_F_GUEST_UFO
| 1 << VIRTIO_NET_F_HOST_ECN
| 1 << VIRTIO_NET_F_HOST_TSO4
| 1 << VIRTIO_NET_F_HOST_TSO6
| 1 << VIRTIO_NET_F_HOST_UFO
| 1 << VIRTIO_NET_F_MTU
| 1 << VIRTIO_RING_F_EVENT_IDX
| 1 << VIRTIO_F_VERSION_1;
(avail_features, 0, config, vec![queue_size; queue_num])
};
if iommu {
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
}
avail_features |= 1 << VIRTIO_NET_F_CTRL_VQ;
let queue_num = num_queues + 1;
let mut config = VirtioNetConfig::default();
if let Some(mac) = guest_mac {
build_net_config_space(
&mut config,
mac,
num_queues,
Some(mtu),
&mut avail_features,
);
} else {
build_net_config_space_with_mq(
&mut config,
num_queues,
Some(mtu),
&mut avail_features,
);
}
(
avail_features,
0,
config,
vec![queue_size; queue_num],
false,
)
};
Ok(Net {
common: VirtioCommon {
@@ -511,6 +519,7 @@ impl Net {
queue_sizes,
paused_sync: Some(Arc::new(Barrier::new((num_queues / 2) + 1))),
min_queues: 2,
paused: Arc::new(AtomicBool::new(paused)),
..Default::default()
},
id,