mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-22 07:51:16 +00:00
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:
parent
8f1e03fcf4
commit
b62a40efae
@ -365,9 +365,14 @@ impl Balloon {
|
|||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let mut queue_sizes = vec![QUEUE_SIZE; MIN_NUM_QUEUES];
|
let mut queue_sizes = vec![QUEUE_SIZE; MIN_NUM_QUEUES];
|
||||||
|
|
||||||
let (avail_features, acked_features, config) = if let Some(state) = state {
|
let (avail_features, acked_features, config, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-balloon {}", id);
|
info!("Restoring virtio-balloon {}", id);
|
||||||
(state.avail_features, state.acked_features, state.config)
|
(
|
||||||
|
state.avail_features,
|
||||||
|
state.acked_features,
|
||||||
|
state.config,
|
||||||
|
true,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
||||||
if deflate_on_oom {
|
if deflate_on_oom {
|
||||||
@ -382,7 +387,7 @@ impl Balloon {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
(avail_features, 0, config)
|
(avail_features, 0, config, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
if free_page_reporting {
|
if free_page_reporting {
|
||||||
@ -397,6 +402,7 @@ impl Balloon {
|
|||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
queue_sizes,
|
queue_sizes,
|
||||||
min_queues: MIN_NUM_QUEUES as u16,
|
min_queues: MIN_NUM_QUEUES as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -442,79 +442,81 @@ impl Block {
|
|||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
state: Option<BlockState>,
|
state: Option<BlockState>,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let (disk_nsectors, avail_features, acked_features, config) = if let Some(state) = state {
|
let (disk_nsectors, avail_features, acked_features, config, paused) =
|
||||||
info!("Restoring virtio-block {}", id);
|
if let Some(state) = state {
|
||||||
(
|
info!("Restoring virtio-block {}", id);
|
||||||
state.disk_nsectors,
|
(
|
||||||
state.avail_features,
|
state.disk_nsectors,
|
||||||
state.acked_features,
|
state.avail_features,
|
||||||
state.config,
|
state.acked_features,
|
||||||
)
|
state.config,
|
||||||
} else {
|
true,
|
||||||
let disk_size = disk_image.size().map_err(|e| {
|
|
||||||
io::Error::new(
|
|
||||||
io::ErrorKind::Other,
|
|
||||||
format!("Failed getting disk size: {}", e),
|
|
||||||
)
|
)
|
||||||
})?;
|
|
||||||
if disk_size % SECTOR_SIZE != 0 {
|
|
||||||
warn!(
|
|
||||||
"Disk size {} is not a multiple of sector size {}; \
|
|
||||||
the remainder will not be visible to the guest.",
|
|
||||||
disk_size, SECTOR_SIZE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1)
|
|
||||||
| (1u64 << VIRTIO_BLK_F_FLUSH)
|
|
||||||
| (1u64 << VIRTIO_BLK_F_CONFIG_WCE)
|
|
||||||
| (1u64 << VIRTIO_BLK_F_BLK_SIZE)
|
|
||||||
| (1u64 << VIRTIO_BLK_F_TOPOLOGY);
|
|
||||||
|
|
||||||
if iommu {
|
|
||||||
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if read_only {
|
|
||||||
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
|
|
||||||
}
|
|
||||||
|
|
||||||
let topology = disk_image.topology();
|
|
||||||
info!("Disk topology: {:?}", topology);
|
|
||||||
|
|
||||||
let logical_block_size = if topology.logical_block_size > 512 {
|
|
||||||
topology.logical_block_size
|
|
||||||
} else {
|
} else {
|
||||||
512
|
let disk_size = disk_image.size().map_err(|e| {
|
||||||
|
io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("Failed getting disk size: {}", e),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
if disk_size % SECTOR_SIZE != 0 {
|
||||||
|
warn!(
|
||||||
|
"Disk size {} is not a multiple of sector size {}; \
|
||||||
|
the remainder will not be visible to the guest.",
|
||||||
|
disk_size, SECTOR_SIZE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1)
|
||||||
|
| (1u64 << VIRTIO_BLK_F_FLUSH)
|
||||||
|
| (1u64 << VIRTIO_BLK_F_CONFIG_WCE)
|
||||||
|
| (1u64 << VIRTIO_BLK_F_BLK_SIZE)
|
||||||
|
| (1u64 << VIRTIO_BLK_F_TOPOLOGY);
|
||||||
|
|
||||||
|
if iommu {
|
||||||
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if read_only {
|
||||||
|
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
|
||||||
|
}
|
||||||
|
|
||||||
|
let topology = disk_image.topology();
|
||||||
|
info!("Disk topology: {:?}", topology);
|
||||||
|
|
||||||
|
let logical_block_size = if topology.logical_block_size > 512 {
|
||||||
|
topology.logical_block_size
|
||||||
|
} else {
|
||||||
|
512
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate the exponent that maps physical block to logical block
|
||||||
|
let mut physical_block_exp = 0;
|
||||||
|
let mut size = logical_block_size;
|
||||||
|
while size < topology.physical_block_size {
|
||||||
|
physical_block_exp += 1;
|
||||||
|
size <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let disk_nsectors = disk_size / SECTOR_SIZE;
|
||||||
|
let mut config = VirtioBlockConfig {
|
||||||
|
capacity: disk_nsectors,
|
||||||
|
writeback: 1,
|
||||||
|
blk_size: topology.logical_block_size as u32,
|
||||||
|
physical_block_exp,
|
||||||
|
min_io_size: (topology.minimum_io_size / logical_block_size) as u16,
|
||||||
|
opt_io_size: (topology.optimal_io_size / logical_block_size) as u32,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
if num_queues > 1 {
|
||||||
|
avail_features |= 1u64 << VIRTIO_BLK_F_MQ;
|
||||||
|
config.num_queues = num_queues as u16;
|
||||||
|
}
|
||||||
|
|
||||||
|
(disk_nsectors, avail_features, 0, config, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate the exponent that maps physical block to logical block
|
|
||||||
let mut physical_block_exp = 0;
|
|
||||||
let mut size = logical_block_size;
|
|
||||||
while size < topology.physical_block_size {
|
|
||||||
physical_block_exp += 1;
|
|
||||||
size <<= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let disk_nsectors = disk_size / SECTOR_SIZE;
|
|
||||||
let mut config = VirtioBlockConfig {
|
|
||||||
capacity: disk_nsectors,
|
|
||||||
writeback: 1,
|
|
||||||
blk_size: topology.logical_block_size as u32,
|
|
||||||
physical_block_exp,
|
|
||||||
min_io_size: (topology.minimum_io_size / logical_block_size) as u16,
|
|
||||||
opt_io_size: (topology.optimal_io_size / logical_block_size) as u32,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
if num_queues > 1 {
|
|
||||||
avail_features |= 1u64 << VIRTIO_BLK_F_MQ;
|
|
||||||
config.num_queues = num_queues as u16;
|
|
||||||
}
|
|
||||||
|
|
||||||
(disk_nsectors, avail_features, 0, config)
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Block {
|
Ok(Block {
|
||||||
common: VirtioCommon {
|
common: VirtioCommon {
|
||||||
device_type: VirtioDeviceType::Block as u32,
|
device_type: VirtioDeviceType::Block as u32,
|
||||||
@ -523,6 +525,7 @@ impl Block {
|
|||||||
paused_sync: Some(Arc::new(Barrier::new(num_queues + 1))),
|
paused_sync: Some(Arc::new(Barrier::new(num_queues + 1))),
|
||||||
queue_sizes: vec![queue_size; num_queues],
|
queue_sizes: vec![queue_size; num_queues],
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -628,13 +628,15 @@ impl Console {
|
|||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
state: Option<ConsoleState>,
|
state: Option<ConsoleState>,
|
||||||
) -> io::Result<(Console, Arc<ConsoleResizer>)> {
|
) -> io::Result<(Console, Arc<ConsoleResizer>)> {
|
||||||
let (avail_features, acked_features, config, in_buffer) = if let Some(state) = state {
|
let (avail_features, acked_features, config, in_buffer, paused) = if let Some(state) = state
|
||||||
|
{
|
||||||
info!("Restoring virtio-console {}", id);
|
info!("Restoring virtio-console {}", id);
|
||||||
(
|
(
|
||||||
state.avail_features,
|
state.avail_features,
|
||||||
state.acked_features,
|
state.acked_features,
|
||||||
state.config,
|
state.config,
|
||||||
state.in_buffer.into(),
|
state.in_buffer.into(),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_CONSOLE_F_SIZE;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_CONSOLE_F_SIZE;
|
||||||
@ -647,6 +649,7 @@ impl Console {
|
|||||||
0,
|
0,
|
||||||
VirtioConsoleConfig::default(),
|
VirtioConsoleConfig::default(),
|
||||||
VecDeque::new(),
|
VecDeque::new(),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -670,6 +673,7 @@ impl Console {
|
|||||||
acked_features,
|
acked_features,
|
||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
min_queues: NUM_QUEUES as u16,
|
min_queues: NUM_QUEUES as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -879,34 +879,36 @@ impl Iommu {
|
|||||||
msi_iova_space: (u64, u64),
|
msi_iova_space: (u64, u64),
|
||||||
state: Option<IommuState>,
|
state: Option<IommuState>,
|
||||||
) -> io::Result<(Self, Arc<IommuMapping>)> {
|
) -> io::Result<(Self, Arc<IommuMapping>)> {
|
||||||
let (avail_features, acked_features, endpoints, domains) = if let Some(state) = state {
|
let (avail_features, acked_features, endpoints, domains, paused) =
|
||||||
info!("Restoring virtio-iommu {}", id);
|
if let Some(state) = state {
|
||||||
(
|
info!("Restoring virtio-iommu {}", id);
|
||||||
state.avail_features,
|
(
|
||||||
state.acked_features,
|
state.avail_features,
|
||||||
state.endpoints.into_iter().collect(),
|
state.acked_features,
|
||||||
state
|
state.endpoints.into_iter().collect(),
|
||||||
.domains
|
state
|
||||||
.into_iter()
|
.domains
|
||||||
.map(|(k, v)| {
|
.into_iter()
|
||||||
(
|
.map(|(k, v)| {
|
||||||
k,
|
(
|
||||||
Domain {
|
k,
|
||||||
mappings: v.0.into_iter().collect(),
|
Domain {
|
||||||
bypass: v.1,
|
mappings: v.0.into_iter().collect(),
|
||||||
},
|
bypass: v.1,
|
||||||
)
|
},
|
||||||
})
|
)
|
||||||
.collect(),
|
})
|
||||||
)
|
.collect(),
|
||||||
} else {
|
true,
|
||||||
let avail_features = 1u64 << VIRTIO_F_VERSION_1
|
)
|
||||||
| 1u64 << VIRTIO_IOMMU_F_MAP_UNMAP
|
} else {
|
||||||
| 1u64 << VIRTIO_IOMMU_F_PROBE
|
let avail_features = 1u64 << VIRTIO_F_VERSION_1
|
||||||
| 1u64 << VIRTIO_IOMMU_F_BYPASS_CONFIG;
|
| 1u64 << VIRTIO_IOMMU_F_MAP_UNMAP
|
||||||
|
| 1u64 << VIRTIO_IOMMU_F_PROBE
|
||||||
|
| 1u64 << VIRTIO_IOMMU_F_BYPASS_CONFIG;
|
||||||
|
|
||||||
(avail_features, 0, BTreeMap::new(), BTreeMap::new())
|
(avail_features, 0, BTreeMap::new(), BTreeMap::new(), false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = VirtioIommuConfig {
|
let config = VirtioIommuConfig {
|
||||||
page_size_mask: VIRTIO_IOMMU_PAGE_SIZE_MASK,
|
page_size_mask: VIRTIO_IOMMU_PAGE_SIZE_MASK,
|
||||||
@ -930,6 +932,7 @@ impl Iommu {
|
|||||||
acked_features,
|
acked_features,
|
||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
min_queues: NUM_QUEUES as u16,
|
min_queues: NUM_QUEUES as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
|
@ -736,10 +736,15 @@ impl Mem {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (avail_features, acked_features, config) = if let Some(state) = state {
|
let (avail_features, acked_features, config, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-mem {}", id);
|
info!("Restoring virtio-mem {}", id);
|
||||||
*(blocks_state.lock().unwrap()) = state.blocks_state.clone();
|
*(blocks_state.lock().unwrap()) = state.blocks_state.clone();
|
||||||
(state.avail_features, state.acked_features, state.config)
|
(
|
||||||
|
state.avail_features,
|
||||||
|
state.acked_features,
|
||||||
|
state.config,
|
||||||
|
true,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
||||||
|
|
||||||
@ -779,7 +784,7 @@ impl Mem {
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
(avail_features, 0, config)
|
(avail_features, 0, config, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let host_fd = region
|
let host_fd = region
|
||||||
@ -794,6 +799,7 @@ impl Mem {
|
|||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
queue_sizes: QUEUE_SIZES.to_vec(),
|
queue_sizes: QUEUE_SIZES.to_vec(),
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -451,57 +451,65 @@ impl Net {
|
|||||||
|
|
||||||
let mtu = taps[0].mtu().map_err(Error::TapError)? as u16;
|
let mtu = taps[0].mtu().map_err(Error::TapError)? as u16;
|
||||||
|
|
||||||
let (avail_features, acked_features, config, queue_sizes) = if let Some(state) = state {
|
let (avail_features, acked_features, config, queue_sizes, paused) =
|
||||||
info!("Restoring virtio-net {}", id);
|
if let Some(state) = state {
|
||||||
(
|
info!("Restoring virtio-net {}", id);
|
||||||
state.avail_features,
|
(
|
||||||
state.acked_features,
|
state.avail_features,
|
||||||
state.config,
|
state.acked_features,
|
||||||
state.queue_size,
|
state.config,
|
||||||
)
|
state.queue_size,
|
||||||
} else {
|
true,
|
||||||
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,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
build_net_config_space_with_mq(
|
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
||||||
&mut config,
|
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
|
||||||
num_queues,
|
| 1 << VIRTIO_NET_F_GUEST_CSUM
|
||||||
Some(mtu),
|
| 1 << VIRTIO_NET_F_GUEST_ECN
|
||||||
&mut avail_features,
|
| 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 {
|
Ok(Net {
|
||||||
common: VirtioCommon {
|
common: VirtioCommon {
|
||||||
@ -511,6 +519,7 @@ impl Net {
|
|||||||
queue_sizes,
|
queue_sizes,
|
||||||
paused_sync: Some(Arc::new(Barrier::new((num_queues / 2) + 1))),
|
paused_sync: Some(Arc::new(Barrier::new((num_queues / 2) + 1))),
|
||||||
min_queues: 2,
|
min_queues: 2,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -301,9 +301,14 @@ impl Pmem {
|
|||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
state: Option<PmemState>,
|
state: Option<PmemState>,
|
||||||
) -> io::Result<Pmem> {
|
) -> io::Result<Pmem> {
|
||||||
let (avail_features, acked_features, config) = if let Some(state) = state {
|
let (avail_features, acked_features, config, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-pmem {}", id);
|
info!("Restoring virtio-pmem {}", id);
|
||||||
(state.avail_features, state.acked_features, state.config)
|
(
|
||||||
|
state.avail_features,
|
||||||
|
state.acked_features,
|
||||||
|
state.config,
|
||||||
|
true,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let config = VirtioPmemConfig {
|
let config = VirtioPmemConfig {
|
||||||
start: addr.raw_value().to_le(),
|
start: addr.raw_value().to_le(),
|
||||||
@ -315,7 +320,7 @@ impl Pmem {
|
|||||||
if iommu {
|
if iommu {
|
||||||
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
}
|
}
|
||||||
(avail_features, 0, config)
|
(avail_features, 0, config, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Pmem {
|
Ok(Pmem {
|
||||||
@ -326,6 +331,7 @@ impl Pmem {
|
|||||||
avail_features,
|
avail_features,
|
||||||
acked_features,
|
acked_features,
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -178,9 +178,9 @@ impl Rng {
|
|||||||
) -> io::Result<Rng> {
|
) -> io::Result<Rng> {
|
||||||
let random_file = File::open(path)?;
|
let random_file = File::open(path)?;
|
||||||
|
|
||||||
let (avail_features, acked_features) = if let Some(state) = state {
|
let (avail_features, acked_features, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-rng {}", id);
|
info!("Restoring virtio-rng {}", id);
|
||||||
(state.avail_features, state.acked_features)
|
(state.avail_features, state.acked_features, true)
|
||||||
} else {
|
} else {
|
||||||
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ impl Rng {
|
|||||||
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
(avail_features, 0)
|
(avail_features, 0, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Rng {
|
Ok(Rng {
|
||||||
@ -199,6 +199,7 @@ impl Rng {
|
|||||||
avail_features,
|
avail_features,
|
||||||
acked_features,
|
acked_features,
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -12,7 +12,10 @@ use anyhow::anyhow;
|
|||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
io, result,
|
io, result,
|
||||||
sync::{atomic::Ordering, Arc, Mutex},
|
sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc, Mutex,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use versionize::{VersionMap, Versionize, VersionizeResult};
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
@ -134,6 +137,7 @@ impl Vdpa {
|
|||||||
queue_sizes,
|
queue_sizes,
|
||||||
iova_range,
|
iova_range,
|
||||||
backend_features,
|
backend_features,
|
||||||
|
paused,
|
||||||
) = if let Some(state) = state {
|
) = if let Some(state) = state {
|
||||||
info!("Restoring vDPA {}", id);
|
info!("Restoring vDPA {}", id);
|
||||||
|
|
||||||
@ -152,6 +156,7 @@ impl Vdpa {
|
|||||||
last: state.iova_range_last,
|
last: state.iova_range_last,
|
||||||
},
|
},
|
||||||
state.backend_features,
|
state.backend_features,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let device_type = vhost.get_device_id().map_err(Error::GetDeviceId)?;
|
let device_type = vhost.get_device_id().map_err(Error::GetDeviceId)?;
|
||||||
@ -175,6 +180,7 @@ impl Vdpa {
|
|||||||
vec![queue_size; num_queues as usize],
|
vec![queue_size; num_queues as usize],
|
||||||
iova_range,
|
iova_range,
|
||||||
backend_features,
|
backend_features,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -185,6 +191,7 @@ impl Vdpa {
|
|||||||
avail_features,
|
avail_features,
|
||||||
acked_features,
|
acked_features,
|
||||||
min_queues: num_queues,
|
min_queues: num_queues,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -13,6 +13,7 @@ use block_util::VirtioBlockConfig;
|
|||||||
use seccompiler::SeccompAction;
|
use seccompiler::SeccompAction;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::result;
|
use std::result;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
@ -79,96 +80,102 @@ impl Blk {
|
|||||||
let mut vu =
|
let mut vu =
|
||||||
VhostUserHandle::connect_vhost_user(false, &vu_cfg.socket, num_queues as u64, false)?;
|
VhostUserHandle::connect_vhost_user(false, &vu_cfg.socket, num_queues as u64, false)?;
|
||||||
|
|
||||||
let (avail_features, acked_features, acked_protocol_features, vu_num_queues, config) =
|
let (
|
||||||
if let Some(state) = state {
|
avail_features,
|
||||||
info!("Restoring vhost-user-block {}", id);
|
acked_features,
|
||||||
|
acked_protocol_features,
|
||||||
|
vu_num_queues,
|
||||||
|
config,
|
||||||
|
paused,
|
||||||
|
) = if let Some(state) = state {
|
||||||
|
info!("Restoring vhost-user-block {}", id);
|
||||||
|
|
||||||
vu.set_protocol_features_vhost_user(
|
vu.set_protocol_features_vhost_user(
|
||||||
state.acked_features,
|
state.acked_features,
|
||||||
state.acked_protocol_features,
|
state.acked_protocol_features,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
(
|
(
|
||||||
state.avail_features,
|
state.avail_features,
|
||||||
state.acked_features,
|
state.acked_features,
|
||||||
state.acked_protocol_features,
|
state.acked_protocol_features,
|
||||||
state.vu_num_queues,
|
state.vu_num_queues,
|
||||||
state.config,
|
state.config,
|
||||||
)
|
true,
|
||||||
} else {
|
)
|
||||||
// Filling device and vring features VMM supports.
|
} else {
|
||||||
let mut avail_features = 1 << VIRTIO_BLK_F_SIZE_MAX
|
// Filling device and vring features VMM supports.
|
||||||
| 1 << VIRTIO_BLK_F_SEG_MAX
|
let mut avail_features = 1 << VIRTIO_BLK_F_SIZE_MAX
|
||||||
| 1 << VIRTIO_BLK_F_GEOMETRY
|
| 1 << VIRTIO_BLK_F_SEG_MAX
|
||||||
| 1 << VIRTIO_BLK_F_RO
|
| 1 << VIRTIO_BLK_F_GEOMETRY
|
||||||
| 1 << VIRTIO_BLK_F_BLK_SIZE
|
| 1 << VIRTIO_BLK_F_RO
|
||||||
| 1 << VIRTIO_BLK_F_FLUSH
|
| 1 << VIRTIO_BLK_F_BLK_SIZE
|
||||||
| 1 << VIRTIO_BLK_F_TOPOLOGY
|
| 1 << VIRTIO_BLK_F_FLUSH
|
||||||
| 1 << VIRTIO_BLK_F_CONFIG_WCE
|
| 1 << VIRTIO_BLK_F_TOPOLOGY
|
||||||
| 1 << VIRTIO_BLK_F_DISCARD
|
| 1 << VIRTIO_BLK_F_CONFIG_WCE
|
||||||
| 1 << VIRTIO_BLK_F_WRITE_ZEROES
|
| 1 << VIRTIO_BLK_F_DISCARD
|
||||||
| DEFAULT_VIRTIO_FEATURES;
|
| 1 << VIRTIO_BLK_F_WRITE_ZEROES
|
||||||
|
| DEFAULT_VIRTIO_FEATURES;
|
||||||
|
|
||||||
if num_queues > 1 {
|
if num_queues > 1 {
|
||||||
avail_features |= 1 << VIRTIO_BLK_F_MQ;
|
avail_features |= 1 << VIRTIO_BLK_F_MQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let avail_protocol_features = VhostUserProtocolFeatures::CONFIG
|
let avail_protocol_features = VhostUserProtocolFeatures::CONFIG
|
||||||
| VhostUserProtocolFeatures::MQ
|
| VhostUserProtocolFeatures::MQ
|
||||||
| VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS
|
| VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS
|
||||||
| VhostUserProtocolFeatures::REPLY_ACK
|
| VhostUserProtocolFeatures::REPLY_ACK
|
||||||
| VhostUserProtocolFeatures::INFLIGHT_SHMFD
|
| VhostUserProtocolFeatures::INFLIGHT_SHMFD
|
||||||
| VhostUserProtocolFeatures::LOG_SHMFD;
|
| VhostUserProtocolFeatures::LOG_SHMFD;
|
||||||
|
|
||||||
let (acked_features, acked_protocol_features) =
|
let (acked_features, acked_protocol_features) =
|
||||||
vu.negotiate_features_vhost_user(avail_features, avail_protocol_features)?;
|
vu.negotiate_features_vhost_user(avail_features, avail_protocol_features)?;
|
||||||
|
|
||||||
let backend_num_queues =
|
let backend_num_queues =
|
||||||
if acked_protocol_features & VhostUserProtocolFeatures::MQ.bits() != 0 {
|
if acked_protocol_features & VhostUserProtocolFeatures::MQ.bits() != 0 {
|
||||||
vu.socket_handle()
|
vu.socket_handle()
|
||||||
.get_queue_num()
|
.get_queue_num()
|
||||||
.map_err(Error::VhostUserGetQueueMaxNum)?
|
.map_err(Error::VhostUserGetQueueMaxNum)? as usize
|
||||||
as usize
|
} else {
|
||||||
} else {
|
DEFAULT_QUEUE_NUMBER
|
||||||
DEFAULT_QUEUE_NUMBER
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if num_queues > backend_num_queues {
|
if num_queues > backend_num_queues {
|
||||||
error!("vhost-user-blk requested too many queues ({}) since the backend only supports {}\n",
|
error!("vhost-user-blk requested too many queues ({}) since the backend only supports {}\n",
|
||||||
num_queues, backend_num_queues);
|
num_queues, backend_num_queues);
|
||||||
return Err(Error::BadQueueNum);
|
return Err(Error::BadQueueNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_len = mem::size_of::<VirtioBlockConfig>();
|
let config_len = mem::size_of::<VirtioBlockConfig>();
|
||||||
let config_space: Vec<u8> = vec![0u8; config_len];
|
let config_space: Vec<u8> = vec![0u8; config_len];
|
||||||
let (_, config_space) = vu
|
let (_, config_space) = vu
|
||||||
.socket_handle()
|
.socket_handle()
|
||||||
.get_config(
|
.get_config(
|
||||||
VHOST_USER_CONFIG_OFFSET,
|
VHOST_USER_CONFIG_OFFSET,
|
||||||
config_len as u32,
|
config_len as u32,
|
||||||
VhostUserConfigFlags::WRITABLE,
|
VhostUserConfigFlags::WRITABLE,
|
||||||
config_space.as_slice(),
|
config_space.as_slice(),
|
||||||
)
|
|
||||||
.map_err(Error::VhostUserGetConfig)?;
|
|
||||||
let mut config = VirtioBlockConfig::default();
|
|
||||||
if let Some(backend_config) = VirtioBlockConfig::from_slice(config_space.as_slice())
|
|
||||||
{
|
|
||||||
config = *backend_config;
|
|
||||||
config.num_queues = num_queues as u16;
|
|
||||||
}
|
|
||||||
|
|
||||||
(
|
|
||||||
acked_features,
|
|
||||||
// If part of the available features that have been acked,
|
|
||||||
// the PROTOCOL_FEATURES bit must be already set through
|
|
||||||
// the VIRTIO acked features as we know the guest would
|
|
||||||
// never ack it, thus the feature would be lost.
|
|
||||||
acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
|
|
||||||
acked_protocol_features,
|
|
||||||
num_queues,
|
|
||||||
config,
|
|
||||||
)
|
)
|
||||||
};
|
.map_err(Error::VhostUserGetConfig)?;
|
||||||
|
let mut config = VirtioBlockConfig::default();
|
||||||
|
if let Some(backend_config) = VirtioBlockConfig::from_slice(config_space.as_slice()) {
|
||||||
|
config = *backend_config;
|
||||||
|
config.num_queues = num_queues as u16;
|
||||||
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
acked_features,
|
||||||
|
// If part of the available features that have been acked,
|
||||||
|
// the PROTOCOL_FEATURES bit must be already set through
|
||||||
|
// the VIRTIO acked features as we know the guest would
|
||||||
|
// never ack it, thus the feature would be lost.
|
||||||
|
acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
|
||||||
|
acked_protocol_features,
|
||||||
|
num_queues,
|
||||||
|
config,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Blk {
|
Ok(Blk {
|
||||||
common: VirtioCommon {
|
common: VirtioCommon {
|
||||||
@ -178,6 +185,7 @@ impl Blk {
|
|||||||
acked_features,
|
acked_features,
|
||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
min_queues: DEFAULT_QUEUE_NUMBER as u16,
|
min_queues: DEFAULT_QUEUE_NUMBER as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
vu_common: VhostUserCommon {
|
vu_common: VhostUserCommon {
|
||||||
|
@ -16,6 +16,7 @@ use seccompiler::SeccompAction;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::result;
|
use std::result;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use versionize::{VersionMap, Versionize, VersionizeResult};
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
@ -333,6 +334,7 @@ impl Fs {
|
|||||||
vu_num_queues,
|
vu_num_queues,
|
||||||
config,
|
config,
|
||||||
slave_req_support,
|
slave_req_support,
|
||||||
|
paused,
|
||||||
) = if let Some(state) = state {
|
) = if let Some(state) = state {
|
||||||
info!("Restoring vhost-user-fs {}", id);
|
info!("Restoring vhost-user-fs {}", id);
|
||||||
|
|
||||||
@ -348,6 +350,7 @@ impl Fs {
|
|||||||
state.vu_num_queues,
|
state.vu_num_queues,
|
||||||
state.config,
|
state.config,
|
||||||
state.slave_req_support,
|
state.slave_req_support,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Filling device and vring features VMM supports.
|
// Filling device and vring features VMM supports.
|
||||||
@ -407,6 +410,7 @@ impl Fs {
|
|||||||
num_queues,
|
num_queues,
|
||||||
config,
|
config,
|
||||||
slave_req_support,
|
slave_req_support,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -418,6 +422,7 @@ impl Fs {
|
|||||||
queue_sizes: vec![queue_size; num_queues],
|
queue_sizes: vec![queue_size; num_queues],
|
||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
vu_common: VhostUserCommon {
|
vu_common: VhostUserCommon {
|
||||||
|
@ -13,6 +13,7 @@ use crate::{GuestMemoryMmap, GuestRegionMmap};
|
|||||||
use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig};
|
use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig};
|
||||||
use seccompiler::SeccompAction;
|
use seccompiler::SeccompAction;
|
||||||
use std::result;
|
use std::result;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
@ -83,106 +84,113 @@ impl Net {
|
|||||||
let mut vu =
|
let mut vu =
|
||||||
VhostUserHandle::connect_vhost_user(server, &vu_cfg.socket, num_queues as u64, false)?;
|
VhostUserHandle::connect_vhost_user(server, &vu_cfg.socket, num_queues as u64, false)?;
|
||||||
|
|
||||||
let (avail_features, acked_features, acked_protocol_features, vu_num_queues, config) =
|
let (
|
||||||
if let Some(state) = state {
|
avail_features,
|
||||||
info!("Restoring vhost-user-net {}", id);
|
acked_features,
|
||||||
|
acked_protocol_features,
|
||||||
|
vu_num_queues,
|
||||||
|
config,
|
||||||
|
paused,
|
||||||
|
) = if let Some(state) = state {
|
||||||
|
info!("Restoring vhost-user-net {}", id);
|
||||||
|
|
||||||
// The backend acknowledged features must not contain
|
// The backend acknowledged features must not contain
|
||||||
// VIRTIO_NET_F_MAC since we don't expect the backend
|
// VIRTIO_NET_F_MAC since we don't expect the backend
|
||||||
// to handle it.
|
// to handle it.
|
||||||
let backend_acked_features = state.acked_features & !(1 << VIRTIO_NET_F_MAC);
|
let backend_acked_features = state.acked_features & !(1 << VIRTIO_NET_F_MAC);
|
||||||
|
|
||||||
vu.set_protocol_features_vhost_user(
|
vu.set_protocol_features_vhost_user(
|
||||||
backend_acked_features,
|
backend_acked_features,
|
||||||
state.acked_protocol_features,
|
state.acked_protocol_features,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// If the control queue feature has been negotiated, let's
|
// If the control queue feature has been negotiated, let's
|
||||||
// increase the number of queues.
|
// increase the number of queues.
|
||||||
if state.acked_features & (1 << VIRTIO_NET_F_CTRL_VQ) != 0 {
|
if state.acked_features & (1 << VIRTIO_NET_F_CTRL_VQ) != 0 {
|
||||||
num_queues += 1;
|
num_queues += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
state.avail_features,
|
state.avail_features,
|
||||||
state.acked_features,
|
state.acked_features,
|
||||||
state.acked_protocol_features,
|
state.acked_protocol_features,
|
||||||
state.vu_num_queues,
|
state.vu_num_queues,
|
||||||
state.config,
|
state.config,
|
||||||
)
|
true,
|
||||||
} else {
|
)
|
||||||
// Filling device and vring features VMM supports.
|
} else {
|
||||||
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
// Filling device and vring features VMM supports.
|
||||||
| 1 << VIRTIO_NET_F_GUEST_CSUM
|
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
||||||
| 1 << VIRTIO_NET_F_GUEST_TSO4
|
| 1 << VIRTIO_NET_F_GUEST_CSUM
|
||||||
| 1 << VIRTIO_NET_F_GUEST_TSO6
|
| 1 << VIRTIO_NET_F_GUEST_TSO4
|
||||||
| 1 << VIRTIO_NET_F_GUEST_ECN
|
| 1 << VIRTIO_NET_F_GUEST_TSO6
|
||||||
| 1 << VIRTIO_NET_F_GUEST_UFO
|
| 1 << VIRTIO_NET_F_GUEST_ECN
|
||||||
| 1 << VIRTIO_NET_F_HOST_TSO4
|
| 1 << VIRTIO_NET_F_GUEST_UFO
|
||||||
| 1 << VIRTIO_NET_F_HOST_TSO6
|
| 1 << VIRTIO_NET_F_HOST_TSO4
|
||||||
| 1 << VIRTIO_NET_F_HOST_ECN
|
| 1 << VIRTIO_NET_F_HOST_TSO6
|
||||||
| 1 << VIRTIO_NET_F_HOST_UFO
|
| 1 << VIRTIO_NET_F_HOST_ECN
|
||||||
| 1 << VIRTIO_NET_F_MRG_RXBUF
|
| 1 << VIRTIO_NET_F_HOST_UFO
|
||||||
| 1 << VIRTIO_NET_F_CTRL_VQ
|
| 1 << VIRTIO_NET_F_MRG_RXBUF
|
||||||
| 1 << VIRTIO_F_RING_EVENT_IDX
|
| 1 << VIRTIO_NET_F_CTRL_VQ
|
||||||
| 1 << VIRTIO_F_VERSION_1
|
| 1 << VIRTIO_F_RING_EVENT_IDX
|
||||||
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits();
|
| 1 << VIRTIO_F_VERSION_1
|
||||||
|
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits();
|
||||||
|
|
||||||
if mtu.is_some() {
|
if mtu.is_some() {
|
||||||
avail_features |= 1u64 << VIRTIO_NET_F_MTU;
|
avail_features |= 1u64 << VIRTIO_NET_F_MTU;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = VirtioNetConfig::default();
|
let mut config = VirtioNetConfig::default();
|
||||||
build_net_config_space(&mut config, mac_addr, num_queues, mtu, &mut avail_features);
|
build_net_config_space(&mut config, mac_addr, num_queues, mtu, &mut avail_features);
|
||||||
|
|
||||||
let avail_protocol_features = VhostUserProtocolFeatures::MQ
|
let avail_protocol_features = VhostUserProtocolFeatures::MQ
|
||||||
| VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS
|
| VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS
|
||||||
| VhostUserProtocolFeatures::REPLY_ACK
|
| VhostUserProtocolFeatures::REPLY_ACK
|
||||||
| VhostUserProtocolFeatures::INFLIGHT_SHMFD
|
| VhostUserProtocolFeatures::INFLIGHT_SHMFD
|
||||||
| VhostUserProtocolFeatures::LOG_SHMFD;
|
| VhostUserProtocolFeatures::LOG_SHMFD;
|
||||||
|
|
||||||
let (mut acked_features, acked_protocol_features) =
|
let (mut acked_features, acked_protocol_features) =
|
||||||
vu.negotiate_features_vhost_user(avail_features, avail_protocol_features)?;
|
vu.negotiate_features_vhost_user(avail_features, avail_protocol_features)?;
|
||||||
|
|
||||||
let backend_num_queues =
|
let backend_num_queues =
|
||||||
if acked_protocol_features & VhostUserProtocolFeatures::MQ.bits() != 0 {
|
if acked_protocol_features & VhostUserProtocolFeatures::MQ.bits() != 0 {
|
||||||
vu.socket_handle()
|
vu.socket_handle()
|
||||||
.get_queue_num()
|
.get_queue_num()
|
||||||
.map_err(Error::VhostUserGetQueueMaxNum)?
|
.map_err(Error::VhostUserGetQueueMaxNum)? as usize
|
||||||
as usize
|
} else {
|
||||||
} else {
|
DEFAULT_QUEUE_NUMBER
|
||||||
DEFAULT_QUEUE_NUMBER
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if num_queues > backend_num_queues {
|
if num_queues > backend_num_queues {
|
||||||
error!("vhost-user-net requested too many queues ({}) since the backend only supports {}\n",
|
error!("vhost-user-net requested too many queues ({}) since the backend only supports {}\n",
|
||||||
num_queues, backend_num_queues);
|
num_queues, backend_num_queues);
|
||||||
return Err(Error::BadQueueNum);
|
return Err(Error::BadQueueNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the control queue feature has been negotiated, let's increase
|
// If the control queue feature has been negotiated, let's increase
|
||||||
// the number of queues.
|
// the number of queues.
|
||||||
let vu_num_queues = num_queues;
|
let vu_num_queues = num_queues;
|
||||||
if acked_features & (1 << VIRTIO_NET_F_CTRL_VQ) != 0 {
|
if acked_features & (1 << VIRTIO_NET_F_CTRL_VQ) != 0 {
|
||||||
num_queues += 1;
|
num_queues += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the virtio feature to set the MAC address is exposed to
|
// Make sure the virtio feature to set the MAC address is exposed to
|
||||||
// the guest, even if it hasn't been negotiated with the backend.
|
// the guest, even if it hasn't been negotiated with the backend.
|
||||||
acked_features |= 1 << VIRTIO_NET_F_MAC;
|
acked_features |= 1 << VIRTIO_NET_F_MAC;
|
||||||
|
|
||||||
(
|
(
|
||||||
acked_features,
|
acked_features,
|
||||||
// If part of the available features that have been acked,
|
// If part of the available features that have been acked,
|
||||||
// the PROTOCOL_FEATURES bit must be already set through
|
// the PROTOCOL_FEATURES bit must be already set through
|
||||||
// the VIRTIO acked features as we know the guest would
|
// the VIRTIO acked features as we know the guest would
|
||||||
// never ack it, thus the feature would be lost.
|
// never ack it, thus the feature would be lost.
|
||||||
acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
|
acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
|
||||||
acked_protocol_features,
|
acked_protocol_features,
|
||||||
vu_num_queues,
|
vu_num_queues,
|
||||||
config,
|
config,
|
||||||
)
|
false,
|
||||||
};
|
)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Net {
|
Ok(Net {
|
||||||
id,
|
id,
|
||||||
@ -193,6 +201,7 @@ impl Net {
|
|||||||
acked_features,
|
acked_features,
|
||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
min_queues: DEFAULT_QUEUE_NUMBER as u16,
|
min_queues: DEFAULT_QUEUE_NUMBER as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
vu_common: VhostUserCommon {
|
vu_common: VhostUserCommon {
|
||||||
|
@ -348,16 +348,16 @@ where
|
|||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
state: Option<VsockState>,
|
state: Option<VsockState>,
|
||||||
) -> io::Result<Vsock<B>> {
|
) -> io::Result<Vsock<B>> {
|
||||||
let (avail_features, acked_features) = if let Some(state) = state {
|
let (avail_features, acked_features, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-vsock {}", id);
|
info!("Restoring virtio-vsock {}", id);
|
||||||
(state.avail_features, state.acked_features)
|
(state.avail_features, state.acked_features, true)
|
||||||
} else {
|
} else {
|
||||||
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
|
||||||
|
|
||||||
if iommu {
|
if iommu {
|
||||||
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
}
|
}
|
||||||
(avail_features, 0)
|
(avail_features, 0, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Vsock {
|
Ok(Vsock {
|
||||||
@ -368,6 +368,7 @@ where
|
|||||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||||
queue_sizes: QUEUE_SIZES.to_vec(),
|
queue_sizes: QUEUE_SIZES.to_vec(),
|
||||||
min_queues: NUM_QUEUES as u16,
|
min_queues: NUM_QUEUES as u16,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -216,7 +216,7 @@ impl Watchdog {
|
|||||||
state: Option<WatchdogState>,
|
state: Option<WatchdogState>,
|
||||||
) -> io::Result<Watchdog> {
|
) -> io::Result<Watchdog> {
|
||||||
let mut last_ping_time = None;
|
let mut last_ping_time = None;
|
||||||
let (avail_features, acked_features) = if let Some(state) = state {
|
let (avail_features, acked_features, paused) = if let Some(state) = state {
|
||||||
info!("Restoring virtio-watchdog {}", id);
|
info!("Restoring virtio-watchdog {}", id);
|
||||||
|
|
||||||
// When restoring enable the watchdog if it was previously enabled.
|
// When restoring enable the watchdog if it was previously enabled.
|
||||||
@ -226,9 +226,9 @@ impl Watchdog {
|
|||||||
last_ping_time = Some(Instant::now());
|
last_ping_time = Some(Instant::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
(state.avail_features, state.acked_features)
|
(state.avail_features, state.acked_features, true)
|
||||||
} else {
|
} else {
|
||||||
(1u64 << VIRTIO_F_VERSION_1, 0)
|
(1u64 << VIRTIO_F_VERSION_1, 0, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let timer_fd = timerfd_create().map_err(|e| {
|
let timer_fd = timerfd_create().map_err(|e| {
|
||||||
@ -246,6 +246,7 @@ impl Watchdog {
|
|||||||
avail_features,
|
avail_features,
|
||||||
acked_features,
|
acked_features,
|
||||||
min_queues: 1,
|
min_queues: 1,
|
||||||
|
paused: Arc::new(AtomicBool::new(paused)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
id,
|
id,
|
||||||
|
@ -4135,7 +4135,6 @@ impl DeviceManager {
|
|||||||
if let Some(migratable) = &node.migratable {
|
if let Some(migratable) = &node.migratable {
|
||||||
info!("Restoring {} from DeviceManager", node.id);
|
info!("Restoring {} from DeviceManager", node.id);
|
||||||
if let Some(snapshot) = snapshot.snapshots.get(&node.id) {
|
if let Some(snapshot) = snapshot.snapshots.get(&node.id) {
|
||||||
migratable.lock().unwrap().pause()?;
|
|
||||||
migratable.lock().unwrap().restore(*snapshot.clone())?;
|
migratable.lock().unwrap().restore(*snapshot.clone())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(MigratableError::Restore(anyhow!(
|
return Err(MigratableError::Restore(anyhow!(
|
||||||
|
Loading…
Reference in New Issue
Block a user