summary refs log tree commit diff
path: root/arch/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-10-18 16:45:13 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-19 15:07:43 -0700
commit8eceba31c0d2842d8d7bfaa84253121709b1ee81 (patch)
tree35de26e27c5e5a9f91bbdad3ee0ca34f6f1f5b99 /arch/src/lib.rs
parentf02fdd1f663760fc884073ea74fffb39a3f4ea4c (diff)
downloadcrosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar.gz
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar.bz2
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar.lz
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar.xz
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.tar.zst
crosvm-8eceba31c0d2842d8d7bfaa84253121709b1ee81.zip
devices: make PCI work in --disable-sandbox mode
Make the Minijail part of the PCI device tuple optional so that an empty
jail is not created for --disable-sandbox.

BUG=None
TEST=Boot crosvm in both --multiprocess and --disable-sandbox modes

Change-Id: Ibb3f2dbf33ca19910ee7448ea823b2772e09ecc5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1290289
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'arch/src/lib.rs')
-rw-r--r--arch/src/lib.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/arch/src/lib.rs b/arch/src/lib.rs
index c56b6f0..565227a 100644
--- a/arch/src/lib.rs
+++ b/arch/src/lib.rs
@@ -18,7 +18,8 @@ use std::sync::{Arc, Mutex};
 
 use devices::virtio::VirtioDevice;
 use devices::{
-    Bus, BusError, PciDevice, PciDeviceError, PciInterruptPin, PciRoot, ProxyDevice, Serial,
+    Bus, BusDevice, BusError, PciDevice, PciDeviceError, PciInterruptPin, PciRoot, ProxyDevice,
+    Serial,
 };
 use io_jail::Minijail;
 use kvm::{Datamatch, IoeventAddress, Kvm, Vcpu, Vm};
@@ -67,7 +68,8 @@ pub trait LinuxArch {
     /// * `virtio_devs` - Function to generate a list of virtio devices.
     fn build_vm<F>(components: VmComponents, virtio_devs: F) -> Result<RunnableLinuxVm>
     where
-        F: FnOnce(&GuestMemory, &EventFd) -> Result<Vec<(Box<PciDevice + 'static>, Minijail)>>;
+        F: FnOnce(&GuestMemory, &EventFd)
+            -> Result<Vec<(Box<PciDevice + 'static>, Option<Minijail>)>>;
 }
 
 /// Errors for device manager.
@@ -135,7 +137,7 @@ impl fmt::Display for DeviceRegistrationError {
 
 /// Creates a root PCI device for use by this Vm.
 pub fn generate_pci_root(
-    devices: Vec<(Box<PciDevice + 'static>, Minijail)>,
+    devices: Vec<(Box<PciDevice + 'static>, Option<Minijail>)>,
     mmio_bus: &mut Bus,
     resources: &mut SystemAllocator,
     vm: &mut Vm,
@@ -172,9 +174,13 @@ pub fn generate_pci_root(
                 .map_err(DeviceRegistrationError::RegisterIoevent)?;
             keep_fds.push(event.as_raw_fd());
         }
-        let proxy = ProxyDevice::new(device, &jail, keep_fds)
-            .map_err(DeviceRegistrationError::ProxyDeviceCreation)?;
-        let arced_dev = Arc::new(Mutex::new(proxy));
+        let arced_dev: Arc<Mutex<BusDevice>> = if let Some(jail) = jail {
+            let proxy = ProxyDevice::new(device, &jail, keep_fds)
+                .map_err(DeviceRegistrationError::ProxyDeviceCreation)?;
+            Arc::new(Mutex::new(proxy))
+        } else {
+            Arc::new(Mutex::new(device))
+        };
         root.add_device(arced_dev.clone());
         for range in &ranges {
             mmio_bus