diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 3d31a189d..44978e9c7 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -251,12 +251,7 @@ pub struct Vm { } impl Vm { - pub fn new( - config: Arc>, - exit_evt: EventFd, - reset_evt: EventFd, - vmm_path: PathBuf, - ) -> Result { + fn kvm_new() -> Result<(Kvm, Arc)> { let kvm = Kvm::new().map_err(Error::KvmNew)?; // Check required capabilities: @@ -272,14 +267,6 @@ impl Vm { return Err(Error::CapabilityMissing(Cap::SplitIrqchip)); } - let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path) - .map_err(Error::KernelFile)?; - - let initramfs = match &config.lock().unwrap().initramfs { - Some(initramfs) => Some(File::open(&initramfs.path).map_err(Error::InitramfsFile)?), - None => None, - }; - let fd: VmFd; loop { match kvm.create_vm() { @@ -303,7 +290,6 @@ impl Vm { fd.set_tss_address(arch::x86_64::layout::KVM_TSS_ADDRESS.raw_value() as usize) .map_err(Error::VmSetup)?; - let mut cpuid_patches = Vec::new(); // Create split irqchip // Only the local APIC is emulated in kernel, both PICs and IOAPIC // are not. @@ -312,6 +298,31 @@ impl Vm { cap.args[0] = ioapic::NUM_IOAPIC_PINS as u64; fd.enable_cap(&cap).map_err(Error::VmSetup)?; + Ok((kvm, fd)) + } + + pub fn new( + config: Arc>, + exit_evt: EventFd, + reset_evt: EventFd, + vmm_path: PathBuf, + ) -> Result { + let (kvm, fd) = Vm::kvm_new()?; + + let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path) + .map_err(Error::KernelFile)?; + + let initramfs = config + .lock() + .unwrap() + .initramfs + .as_ref() + .map(|i| File::open(&i.path)) + .transpose() + .map_err(Error::InitramfsFile)?; + + let mut cpuid_patches = Vec::new(); + // Patch tsc deadline timer bit cpuid_patches.push(cpu::CpuidPatch { function: 1,