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 <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao 2020-04-26 10:39:11 +08:00 committed by Rob Bradford
parent 5cd1730bc4
commit 97a1e5e1d2
2 changed files with 18 additions and 1 deletions

View File

@ -23,6 +23,8 @@ use arch::EntryPoint;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use arch::{CpuidPatch, CpuidReg}; use arch::{CpuidPatch, CpuidReg};
use devices::{interrupt_controller::InterruptController, BusDevice}; use devices::{interrupt_controller::InterruptController, BusDevice};
#[cfg(target_arch = "aarch64")]
use kvm_bindings::KVM_SYSTEM_EVENT_SHUTDOWN;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use kvm_bindings::{ use kvm_bindings::{
kvm_fpu, kvm_lapic_state, kvm_mp_state, kvm_regs, kvm_sregs, kvm_vcpu_events, kvm_xcrs, 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 // Triple fault to trigger a reboot
Ok(false) 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 => { r => {
error!("Unexpected exit reason on vcpu run: {:?}", r); error!("Unexpected exit reason on vcpu run: {:?}", r);
Err(Error::VcpuUnhandledKvmExit) Err(Error::VcpuUnhandledKvmExit)

View File

@ -365,7 +365,8 @@ impl Vmm {
#[cfg(not(feature = "acpi"))] #[cfg(not(feature = "acpi"))]
{ {
if self.vm.is_some() { if self.vm.is_some() {
return self.vm_shutdown(); self.exit_evt.write(1).unwrap();
return Ok(());
} }
} }