summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorRob Bradford <robert.bradford@intel.com>2018-02-14 15:20:03 +0000
committerchrome-bot <chrome-bot@chromium.org>2018-02-14 17:05:23 -0800
commit8091a2a525f4a9de2f5493d396ce904779a7715f (patch)
treeb87dcf1c3e64e8a6a21b288ce60b24b5d71f726e /src/linux.rs
parent30ebd272d69c64e691054f31d75b324ad20ec905 (diff)
downloadcrosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar.gz
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar.bz2
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar.lz
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar.xz
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.tar.zst
crosvm-8091a2a525f4a9de2f5493d396ce904779a7715f.zip
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 <robert.bradford@intel.com>
Change-Id: I771251ff1cdf762ca68c0781dc7de9f95cc1fcfe
Reviewed-on: https://chromium-review.googlesource.com/919165
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 789c2de..9d215c7 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();