summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorXiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>2019-11-11 18:32:02 +0800
committerCommit Bot <commit-bot@chromium.org>2020-03-06 01:50:11 +0000
commitea6cf66ab537ea554c53fa8723f5bd20b8ec98bf (patch)
tree97459fb0112c4860a9e631dca89e78028dda00ad /src/linux.rs
parentdc7f52bdb76a8f3b3cf6260bc0d861758956991e (diff)
downloadcrosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar.gz
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar.bz2
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar.lz
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar.xz
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.tar.zst
crosvm-ea6cf66ab537ea554c53fa8723f5bd20b8ec98bf.zip
Vfio: multi vfio group support
current one container contains one group only, but one container could
contain multi groups actually. The main gap that current code to
support multi groups is that container will be initialized multi times
when multi groups exist, as each group will initialize container one time.

This patch extracts the code which should run one time only on a
container, so when the first group is added into container, this
container initialize code will run once. The container once initialize
code contains:
a. Set iommu driver type as VfioType1V2
b. Setup Iommu table on each guest memory region
c. create vfio_kvm device, so kernel kvm and vfio is associated.

BUG=chromium:992270
TEST=passthrough two/three vfio devices into guest, these devices belong
to different vfio groups, then check these devices function in guest.

Change-Id: I94c9c86f70f49957a5e5c1dfd2c7d823ad042320
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2078970
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 10f96b8..4a87f7d 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -32,8 +32,8 @@ use audio_streams::shm_streams::NullShmStreamSource;
 use devices::virtio::EventDevice;
 use devices::virtio::{self, VirtioDevice};
 use devices::{
-    self, HostBackendDeviceProvider, PciDevice, VfioDevice, VfioPciDevice, VirtioPciDevice,
-    XhciController,
+    self, HostBackendDeviceProvider, PciDevice, VfioContainer, VfioDevice, VfioPciDevice,
+    VirtioPciDevice, XhciController,
 };
 use io_jail::{self, Minijail};
 use kvm::*;
@@ -1176,7 +1176,11 @@ fn create_devices(
     let usb_controller = Box::new(XhciController::new(mem.clone(), usb_provider));
     pci_devices.push((usb_controller, simple_jail(&cfg, "xhci")?));
 
-    if cfg.vfio.is_some() {
+    if let Some(vfio_path) = &cfg.vfio {
+        let vfio_container = Arc::new(Mutex::new(
+            VfioContainer::new().map_err(Error::CreateVfioDevice)?,
+        ));
+
         let (vfio_host_socket_irq, vfio_device_socket_irq) =
             msg_socket::pair::<VmIrqResponse, VmIrqRequest>().map_err(Error::CreateSocket)?;
         control_sockets.push(TaggedControlSocket::VmIrq(vfio_host_socket_irq));
@@ -1185,9 +1189,9 @@ fn create_devices(
             msg_socket::pair::<VmMemoryResponse, VmMemoryRequest>().map_err(Error::CreateSocket)?;
         control_sockets.push(TaggedControlSocket::VmMemory(vfio_host_socket_mem));
 
-        let vfio_path = cfg.vfio.as_ref().unwrap().as_path();
-        let vfiodevice =
-            VfioDevice::new(vfio_path, vm, mem.clone()).map_err(Error::CreateVfioDevice)?;
+        let vfio_path = vfio_path.as_path();
+        let vfiodevice = VfioDevice::new(vfio_path, vm, mem, vfio_container.clone())
+            .map_err(Error::CreateVfioDevice)?;
         let vfiopcidevice = Box::new(VfioPciDevice::new(
             vfiodevice,
             vfio_device_socket_irq,