From 97a1e5e1d25c049735967f3c5a098c4c31e984fe Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Sun, 26 Apr 2020 10:39:11 +0800 Subject: [PATCH] vmm: Exit VMM event loop after guest shutdown for AArch64 X86 and AArch64 work in different ways to shutdown a VM. X86 exit VMM event loop through ACPI device; AArch64 need to exit from CPU loop of a SystemEvent. Signed-off-by: Michael Zhao --- vmm/src/cpu.rs | 16 ++++++++++++++++ vmm/src/lib.rs | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index a3ee18daa..3e0280003 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -23,6 +23,8 @@ use arch::EntryPoint; #[cfg(target_arch = "x86_64")] use arch::{CpuidPatch, CpuidReg}; use devices::{interrupt_controller::InterruptController, BusDevice}; +#[cfg(target_arch = "aarch64")] +use kvm_bindings::KVM_SYSTEM_EVENT_SHUTDOWN; #[cfg(target_arch = "x86_64")] use kvm_bindings::{ kvm_fpu, kvm_lapic_state, kvm_mp_state, kvm_regs, kvm_sregs, kvm_vcpu_events, kvm_xcrs, @@ -368,6 +370,20 @@ impl Vcpu { // Triple fault to trigger a reboot Ok(false) } + #[cfg(target_arch = "aarch64")] + VcpuExit::SystemEvent(event_type, flags) => { + // On Aarch64, when the VM is shutdown, run() returns + // VcpuExit::SystemEvent with reason KVM_SYSTEM_EVENT_SHUTDOWN + if event_type == KVM_SYSTEM_EVENT_SHUTDOWN { + Ok(false) + } else { + error!( + "Unexpected system event with type 0x{:x}, flags 0x{:x}", + event_type, flags + ); + Err(Error::VcpuUnhandledKvmExit) + } + } r => { error!("Unexpected exit reason on vcpu run: {:?}", r); Err(Error::VcpuUnhandledKvmExit) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 0581ea81a..2bb2f2d94 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -365,7 +365,8 @@ impl Vmm { #[cfg(not(feature = "acpi"))] { if self.vm.is_some() { - return self.vm_shutdown(); + self.exit_evt.write(1).unwrap(); + return Ok(()); } }