Skip to content

Commit 3cd9b8d

Browse files
bchaliosManciukic
authored andcommitted
pci: support snapshotting VirtIO PCI devices
Support serializing the device-specific and transport state of a VirtIO device that uses the PCI transport. Signed-off-by: Babis Chalios <[email protected]>
1 parent 656f870 commit 3cd9b8d

File tree

5 files changed

+551
-68
lines changed

5 files changed

+551
-68
lines changed

src/vmm/src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ pub fn build_microvm_from_snapshot(
451451
// Restore the boot source config paths.
452452
vm_resources.boot_source.config = microvm_state.vm_info.boot_source;
453453

454+
let vm = Arc::new(vm);
455+
454456
// Restore devices states.
455457
// Restoring VMGenID injects an interrupt in the guest to notify it about the new generation
456458
// ID. As a result, we need to restore DeviceManager after restoring the KVM state, otherwise
@@ -473,7 +475,7 @@ pub fn build_microvm_from_snapshot(
473475
instance_info: instance_info.clone(),
474476
shutdown_exit_code: None,
475477
kvm,
476-
vm: Arc::new(vm),
478+
vm,
477479
uffd,
478480
vcpus_handles: Vec::new(),
479481
vcpus_exit_evt,

src/vmm/src/device_manager/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ impl DeviceManager {
357357
Self::do_kick_device(mmio_transport_locked.device());
358358
Ok(())
359359
});
360+
// Go through PCI VirtIO devices
361+
for device in self.pci_devices.virtio_devices.values() {
362+
let virtio_device = device.lock().expect("Poisoned lock").virtio_device();
363+
Self::do_kick_device(virtio_device);
364+
}
360365
}
361366

362367
fn do_mark_virtio_queue_memory_dirty(
@@ -380,6 +385,12 @@ impl DeviceManager {
380385
Self::do_mark_virtio_queue_memory_dirty(mmio_transport_locked.device(), mem);
381386
Ok(())
382387
});
388+
389+
// Go through PCI VirtIO devices
390+
for device in self.pci_devices.virtio_devices.values() {
391+
let virtio_device = device.lock().expect("Poisoned lock").virtio_device();
392+
Self::do_mark_virtio_queue_memory_dirty(virtio_device, mem);
393+
}
383394
}
384395
}
385396

@@ -416,7 +427,7 @@ pub enum DevicePersistError {
416427

417428
pub struct DeviceRestoreArgs<'a> {
418429
pub mem: &'a GuestMemoryMmap,
419-
pub vm: &'a Vm,
430+
pub vm: &'a Arc<Vm>,
420431
pub event_manager: &'a mut EventManager,
421432
pub vcpus_exit_evt: &'a EventFd,
422433
pub vm_resources: &'a mut VmResources,
@@ -491,6 +502,12 @@ impl<'a> Persist<'a> for DeviceManager {
491502
// Restore PCI devices
492503
let pci_ctor_args = PciDevicesConstructorArgs {
493504
resource_allocator: &resource_allocator,
505+
vm: constructor_args.vm.clone(),
506+
mem: constructor_args.mem,
507+
vm_resources: constructor_args.vm_resources,
508+
instance_id: constructor_args.instance_id,
509+
restored_from_file: constructor_args.restored_from_file,
510+
event_manager: constructor_args.event_manager,
494511
};
495512
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)?;
496513

0 commit comments

Comments
 (0)