From 6ce158fb86b034c8a12bee4d65baba452ef42d6a Mon Sep 17 00:00:00 2001 From: Sonny Rao Date: Tue, 27 Mar 2018 17:12:58 -0700 Subject: [PATCH] crosvm: support VM shutdown via SystemEvent ARM systems don't have an exit event fd like x86, instead one of the Vcpus will exit with the SystemEvent reason and put a code into the kvm run union of either shutdown, reboot, or crash. We currently don't handle reboot or crash differently but can do so in the future. BUG=chromium:797868 TEST=./build_test passes on all architectures TEST=crosvm runs on kevin - manually test shutdown via maitred Change-Id: I455cbe1ac653f61a1e9eae1ce22922d14cff4e3c Reviewed-on: https://chromium-review.googlesource.com/982531 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Sonny Rao Reviewed-by: Dylan Reid --- kvm/src/lib.rs | 12 ++++++++++-- src/linux.rs | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index de938b65fd..04810b2067 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -696,7 +696,9 @@ pub enum VcpuExit<'a> { Watchdog, S390Tsch, Epr, - SystemEvent, + /// The cpu triggered a system level event which is specified by the type field. + /// The possible events are shutdown, reset, or crash. + SystemEvent(u32 /* event_type*/, u64 /* flags */), } /// A wrapper around creating and using a VCPU. @@ -803,7 +805,13 @@ impl Vcpu { KVM_EXIT_WATCHDOG => Ok(VcpuExit::Watchdog), KVM_EXIT_S390_TSCH => Ok(VcpuExit::S390Tsch), KVM_EXIT_EPR => Ok(VcpuExit::Epr), - KVM_EXIT_SYSTEM_EVENT => Ok(VcpuExit::SystemEvent), + KVM_EXIT_SYSTEM_EVENT => { + // Safe because we know the exit reason told us this union + // field is valid + let event_type = unsafe { run.__bindgen_anon_1.system_event.type_ }; + let event_flags = unsafe { run.__bindgen_anon_1.system_event.flags }; + Ok(VcpuExit::SystemEvent(event_type, event_flags)) + }, r => panic!("unknown kvm exit reason: {}", r), } } else { diff --git a/src/linux.rs b/src/linux.rs index e599740cc9..0ea188b5bc 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -468,6 +468,9 @@ fn run_vcpu(vcpu: Vcpu, } VcpuExit::Hlt => break, VcpuExit::Shutdown => break, + VcpuExit::SystemEvent(_, _) => + //TODO handle reboot and crash events + kill_signaled.store(true, Ordering::SeqCst), r => warn!("unexpected vcpu exit: {:?}", r), } }