From 8091a2a525f4a9de2f5493d396ce904779a7715f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 14 Feb 2018 15:20:03 +0000 Subject: [PATCH] crosvm: with vcpus > 1 cleanly shutdown jailed processes When creating a new vcpu, setup_vcpu() returns a JoinHandle which allows the main thread to wait for the vcpu threads to complete. Put this handle into a vector from which it will be later join()ed with to wait for its execution to complete. By ensuring that the thread's completion is waited for all the references to the ProxyDevice will be dropped and thus the jailed processes will be sent a shutdown message and they will cleanly exit. TEST="crosvm run --cpus=2 ..." and observe that the jailed processes are cleanly shutdown and not forcefully killed. BUG=812234 Signed-off-by: Rob Bradford Change-Id: I771251ff1cdf762ca68c0781dc7de9f95cc1fcfe Reviewed-on: https://chromium-review.googlesource.com/919165 Commit-Ready: Zach Reizner Tested-by: Zach Reizner Reviewed-by: Stephen Barber Reviewed-by: Dylan Reid Reviewed-by: Zach Reizner --- src/linux.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index 789c2de712..9d215c7488 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -757,11 +757,11 @@ pub fn run_config(cfg: Config) -> Result<()> { kernel_image, &CString::new(cmdline).unwrap())?; - let vcpu_handles = Vec::with_capacity(vcpu_count as usize); + let mut vcpu_handles = Vec::with_capacity(vcpu_count as usize); let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count + 1) as usize)); for cpu_id in 0..vcpu_count { let exit_evt = exit_evt.try_clone().map_err(Error::CloneEventFd)?; - setup_vcpu(&kvm, + let vcpu_handle = setup_vcpu(&kvm, &vm, cpu_id, vcpu_count, @@ -770,6 +770,7 @@ pub fn run_config(cfg: Config) -> Result<()> { kill_signaled.clone(), io_bus.clone(), mmio_bus.clone())?; + vcpu_handles.push(vcpu_handle); } vcpu_thread_barrier.wait();