summary refs log tree commit diff
path: root/arch/src/lib.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2019-01-23 19:04:43 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-26 00:59:57 -0800
commit3ba0098d6764df4a7b2c885f0cf5263b4062c357 (patch)
tree87e285eb55498f152457ffacdf66345feb5ed037 /arch/src/lib.rs
parent1be25dc3d2ce8afe41d0fe7fe7b157c3f1787b50 (diff)
downloadcrosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar.gz
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar.bz2
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar.lz
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar.xz
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.tar.zst
crosvm-3ba0098d6764df4a7b2c885f0cf5263b4062c357.zip
crosvm: add debug labels to devices for improved SIGCHLD logs
Each device (Bus, Pci, Proxy, etc), gets a debug label associated with
it. When a child is spawned, the debug label for it is stored in
a map with the child's pid as the key. If a SIGCHLD is handled, this map
is used to print a more helpful message about exactly which child died.

BUG=None
TEST=run with sandboxing and a faulty child device
     check logs for message about child died
     the child should have a debug label

Change-Id: I61fbbee0a8e701249533a7a3a6a1ad48840f12e5
Reviewed-on: https://chromium-review.googlesource.com/1432835
Commit-Ready: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'arch/src/lib.rs')
-rw-r--r--arch/src/lib.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/arch/src/lib.rs b/arch/src/lib.rs
index 057c005..bc326eb 100644
--- a/arch/src/lib.rs
+++ b/arch/src/lib.rs
@@ -11,6 +11,7 @@ extern crate resources;
 extern crate sync;
 extern crate sys_util;
 
+use std::collections::BTreeMap;
 use std::fmt;
 use std::fs::File;
 use std::io::{Read, Seek, SeekFrom};
@@ -52,6 +53,7 @@ pub struct RunnableLinuxVm {
     pub irq_chip: Option<File>,
     pub io_bus: Bus,
     pub mmio_bus: Bus,
+    pub pid_debug_label_map: BTreeMap<u32, String>,
 }
 
 /// The device and optional jail.
@@ -144,9 +146,13 @@ pub fn generate_pci_root(
     mmio_bus: &mut Bus,
     resources: &mut SystemAllocator,
     vm: &mut Vm,
-) -> std::result::Result<(PciRoot, Vec<(u32, PciInterruptPin)>), DeviceRegistrationError> {
+) -> std::result::Result<
+    (PciRoot, Vec<(u32, PciInterruptPin)>, BTreeMap<u32, String>),
+    DeviceRegistrationError,
+> {
     let mut root = PciRoot::new();
     let mut pci_irqs = Vec::new();
+    let mut pid_labels = BTreeMap::new();
     for (dev_idx, (mut device, jail)) in devices.into_iter().enumerate() {
         let mut keep_fds = device.keep_fds();
         syslog::push_fds(&mut keep_fds);
@@ -182,6 +188,7 @@ pub fn generate_pci_root(
         let arced_dev: Arc<Mutex<BusDevice>> = if let Some(jail) = jail {
             let proxy = ProxyDevice::new(device, &jail, keep_fds)
                 .map_err(DeviceRegistrationError::ProxyDeviceCreation)?;
+            pid_labels.insert(proxy.pid() as u32, proxy.debug_label());
             Arc::new(Mutex::new(proxy))
         } else {
             Arc::new(Mutex::new(device))
@@ -193,7 +200,7 @@ pub fn generate_pci_root(
                 .map_err(DeviceRegistrationError::MmioInsert)?;
         }
     }
-    Ok((root, pci_irqs))
+    Ok((root, pci_irqs, pid_labels))
 }
 
 /// Errors for image loading.