Skip to content

Commit 02d3905

Browse files
committed
refactor(vmm_builder): address comments
move interrupt controller into create_vmm_and_vcpus and fix aarm64 integration test Signed-off-by: tommady <[email protected]>
1 parent 1ff7e17 commit 02d3905

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/vmm/src/builder.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ pub mod aarch64 {
274274
vcpus.push(vcpu);
275275
}
276276

277-
setup_interrupt_controller(vm, vcpu_count)?;
278-
279277
Ok(vcpus)
280278
}
281279

@@ -317,6 +315,9 @@ pub mod aarch64 {
317315
let vcpus = create_vcpus(&mut vmm.vm, vm_config.vcpu_count, &vmm.vcpus_exit_evt)
318316
.map_err(StartMicrovmError::Internal)?;
319317

318+
setup_interrupt_controller(&mut vmm.vm, vm_config.vcpu_count)
319+
.map_err(StartMicrovmError::Internal)?;
320+
320321
Ok((vmm, vcpus))
321322
}
322323
}
@@ -459,6 +460,11 @@ pub mod x86_64 {
459460
kvm_capabilities,
460461
)?;
461462

463+
setup_interrupt_controller(&mut vmm.vm).map_err(StartMicrovmError::Internal)?;
464+
vmm.pio_device_manager
465+
.register_devices(vmm.vm.fd())
466+
.unwrap();
467+
462468
let vcpus = create_vcpus(&mut vmm.vm, vm_config.vcpu_count, &vmm.vcpus_exit_evt)
463469
.map_err(StartMicrovmError::Internal)?;
464470

@@ -477,10 +483,7 @@ fn build_vmm(
477483

478484
// Set up Kvm Vm and register memory regions.
479485
// Build custom CPU config if a custom template is provided.
480-
//
481-
// allow unused_mut for the aarch64 platform.
482-
#[allow(unused_mut)]
483-
let mut vm = Vm::new(kvm_capabilities)
486+
let vm = Vm::new(kvm_capabilities)
484487
.map_err(VmmError::Vm)
485488
.map_err(Internal)?;
486489
vm.memory_init(&guest_memory, vm_config.track_dirty_pages)
@@ -499,8 +502,6 @@ fn build_vmm(
499502
// Instantiate ACPI device manager.
500503
let acpi_device_manager = ACPIDeviceManager::new();
501504

502-
// For x86_64 we need to create the interrupt controller before calling `KVM_CREATE_VCPUS`
503-
// while on aarch64 we need to do it the other way around.
504505
#[cfg(target_arch = "x86_64")]
505506
let pio_device_manager = {
506507
// Serial device setup.
@@ -513,17 +514,9 @@ fn build_vmm(
513514
.map_err(VmmError::EventFd)
514515
.map_err(Internal)?;
515516

516-
x86_64::setup_interrupt_controller(&mut vm).map_err(Internal)?;
517-
518517
// create pio dev manager with legacy devices
519-
let pio_device_manager = {
520-
// TODO Remove these unwraps.
521-
let mut pio_dev_mgr = PortIODeviceManager::new(serial_device, reset_evt).unwrap();
522-
pio_dev_mgr.register_devices(vm.fd()).unwrap();
523-
pio_dev_mgr
524-
};
525-
526-
pio_device_manager
518+
// TODO: remove this unwrap
519+
PortIODeviceManager::new(serial_device, reset_evt).unwrap()
527520
};
528521

529522
Ok(Vmm {

src/vmm/src/device_manager/persist.rs

+3
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ impl<'a> Persist<'a> for MMIODeviceManager {
423423
for state in &state.legacy_devices {
424424
if state.type_ == DeviceType::Serial {
425425
let serial = setup_serial_device(std::io::stdin(), std::io::stdout())?;
426+
constructor_args
427+
.event_manager
428+
.add_subscriber(serial.clone());
426429

427430
constructor_args
428431
.resource_allocator

0 commit comments

Comments
 (0)