From 0b846e26f5093950b83a64cc749be5c45fa52702 Mon Sep 17 00:00:00 2001 From: David Stevens Date: Mon, 1 Aug 2022 18:33:41 +0900 Subject: [PATCH] crosvm: make iommu optional for vfio hotplug Add a flag to determine whether or not virtio-iommu is used to isolate hotplugged vfio devices. This removes the virtio-iommu from the default devices, since it was always present to accommodate the `crosvm vfio` command. BUG=b:231365736 TEST=boot ARCVM, observe no virtio-iommu Change-Id: Ie5d396299465633534039973eba26c0e1d8be21d Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3802107 Reviewed-by: Keiichi Watanabe Tested-by: David Stevens Reviewed-by: Daniel Verkamp Commit-Queue: David Stevens --- src/crosvm/cmdline.rs | 5 +++++ src/crosvm/config.rs | 4 ++++ src/crosvm/sys/unix.rs | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/crosvm/cmdline.rs b/src/crosvm/cmdline.rs index 2b40feee24..de53eb0f91 100644 --- a/src/crosvm/cmdline.rs +++ b/src/crosvm/cmdline.rs @@ -1167,6 +1167,10 @@ pub struct RunCommand { /// for this device pub vfio: Vec, #[cfg(unix)] + #[argh(switch)] + /// isolate all hotplugged passthrough vfio device behind virtio-iommu + pub vfio_isolate_hotplug: bool, + #[cfg(unix)] #[argh(option, arg_name = "PATH", from_str_fn(parse_vfio_platform))] /// path to sysfs of platform pass through pub vfio_platform: Vec, @@ -1861,6 +1865,7 @@ impl TryFrom for super::config::Config { { cfg.vfio.extend(cmd.vfio); cfg.vfio.extend(cmd.vfio_platform); + cfg.vfio_isolate_hotplug = cmd.vfio_isolate_hotplug; } // Now do validation of constructed config diff --git a/src/crosvm/config.rs b/src/crosvm/config.rs index 0acad70405..0481f42979 100644 --- a/src/crosvm/config.rs +++ b/src/crosvm/config.rs @@ -1400,6 +1400,8 @@ pub struct Config { pub vcpu_count: Option, #[cfg(unix)] pub vfio: Vec, + #[cfg(unix)] + pub vfio_isolate_hotplug: bool, pub vhost_net: bool, #[cfg(unix)] pub vhost_net_device_path: PathBuf, @@ -1589,6 +1591,8 @@ impl Default for Config { vcpu_count: None, #[cfg(unix)] vfio: Vec::new(), + #[cfg(unix)] + vfio_isolate_hotplug: false, vhost_net: false, #[cfg(unix)] vhost_net_device_path: PathBuf::from(VHOST_NET_PATH), diff --git a/src/crosvm/sys/unix.rs b/src/crosvm/sys/unix.rs index 1431de1e07..3bdec297e0 100644 --- a/src/crosvm/sys/unix.rs +++ b/src/crosvm/sys/unix.rs @@ -1615,7 +1615,8 @@ where &mut devices, )?; - let iommu_host_tube = if !iommu_attached_endpoints.is_empty() || !hp_endpoints_ranges.is_empty() + let iommu_host_tube = if !iommu_attached_endpoints.is_empty() + || (cfg.vfio_isolate_hotplug && !hp_endpoints_ranges.is_empty()) { let (iommu_host_tube, iommu_device_tube) = Tube::pair().context("failed to create tube")?; let iommu_dev = create_iommu_device( @@ -1878,6 +1879,11 @@ fn handle_vfio_command( add: bool, hp_interrupt: bool, ) -> VmResponse { + let iommu_host_tube = if cfg.vfio_isolate_hotplug { + iommu_host_tube + } else { + &None + }; let ret = if add { add_vfio_device( linux,