From 7b22116a40280f914368c21b0585217ecdc73ca6 Mon Sep 17 00:00:00 2001 From: tommady Date: Thu, 5 Dec 2024 11:24:17 +0000 Subject: [PATCH] refactor(builder): address comments address comments Signed-off-by: tommady --- src/vmm/src/builder.rs | 29 +++++++++++---------------- src/vmm/src/device_manager/persist.rs | 3 +++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/vmm/src/builder.rs b/src/vmm/src/builder.rs index ebffd1af2e1..0c83c2244a7 100644 --- a/src/vmm/src/builder.rs +++ b/src/vmm/src/builder.rs @@ -274,8 +274,6 @@ pub mod aarch64 { vcpus.push(vcpu); } - setup_interrupt_controller(vm, vcpu_count)?; - Ok(vcpus) } @@ -317,6 +315,9 @@ pub mod aarch64 { let vcpus = create_vcpus(&mut vmm.vm, vm_config.vcpu_count, &vmm.vcpus_exit_evt) .map_err(StartMicrovmError::Internal)?; + setup_interrupt_controller(&mut vmm.vm, vm_config.vcpu_count) + .map_err(StartMicrovmError::Internal)?; + Ok((vmm, vcpus)) } } @@ -459,6 +460,11 @@ pub mod x86_64 { kvm_capabilities, )?; + setup_interrupt_controller(&mut vmm.vm).map_err(StartMicrovmError::Internal)?; + vmm.pio_device_manager + .register_devices(vmm.vm.fd()) + .unwrap(); + let vcpus = create_vcpus(&mut vmm.vm, vm_config.vcpu_count, &vmm.vcpus_exit_evt) .map_err(StartMicrovmError::Internal)?; @@ -478,9 +484,7 @@ fn build_vmm( // Set up Kvm Vm and register memory regions. // Build custom CPU config if a custom template is provided. // - // allow unused_mut for the aarch64 platform. - #[allow(unused_mut)] - let mut vm = Vm::new(kvm_capabilities) + let vm = Vm::new(kvm_capabilities) .map_err(VmmError::Vm) .map_err(Internal)?; vm.memory_init(&guest_memory, vm_config.track_dirty_pages) @@ -499,8 +503,6 @@ fn build_vmm( // Instantiate ACPI device manager. let acpi_device_manager = ACPIDeviceManager::new(); - // For x86_64 we need to create the interrupt controller before calling `KVM_CREATE_VCPUS` - // while on aarch64 we need to do it the other way around. #[cfg(target_arch = "x86_64")] let pio_device_manager = { // Serial device setup. @@ -513,17 +515,9 @@ fn build_vmm( .map_err(VmmError::EventFd) .map_err(Internal)?; - x86_64::setup_interrupt_controller(&mut vm).map_err(Internal)?; - // create pio dev manager with legacy devices - let pio_device_manager = { - // TODO Remove these unwraps. - let mut pio_dev_mgr = PortIODeviceManager::new(serial_device, reset_evt).unwrap(); - pio_dev_mgr.register_devices(vm.fd()).unwrap(); - pio_dev_mgr - }; - - pio_device_manager + // TODO Remove this unwraps. + PortIODeviceManager::new(serial_device, reset_evt).unwrap() }; Ok(Vmm { @@ -802,6 +796,7 @@ pub fn build_microvm_from_snapshot( )?; #[cfg(target_arch = "x86_64")] event_manager.add_subscriber(vmm.pio_device_manager.stdio_serial.clone()); + #[cfg(target_arch = "aarch64")] let (mut vmm, mut vcpus) = aarch64::create_vmm_and_vcpus( instance_info, diff --git a/src/vmm/src/device_manager/persist.rs b/src/vmm/src/device_manager/persist.rs index 9400de57d7e..c95f1eefe88 100644 --- a/src/vmm/src/device_manager/persist.rs +++ b/src/vmm/src/device_manager/persist.rs @@ -423,6 +423,9 @@ impl<'a> Persist<'a> for MMIODeviceManager { for state in &state.legacy_devices { if state.type_ == DeviceType::Serial { let serial = setup_serial_device(std::io::stdin(), std::io::stdout())?; + constructor_args + .event_manager + .add_subscriber(serial.clone()); constructor_args .resource_allocator