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 <keiichiw@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
This commit is contained in:
David Stevens 2022-08-01 18:33:41 +09:00 committed by crosvm LUCI
parent 0fb4cb0baf
commit 0b846e26f5
3 changed files with 16 additions and 1 deletions

View file

@ -1167,6 +1167,10 @@ pub struct RunCommand {
/// for this device
pub vfio: Vec<VfioCommand>,
#[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<VfioCommand>,
@ -1861,6 +1865,7 @@ impl TryFrom<RunCommand> 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

View file

@ -1400,6 +1400,8 @@ pub struct Config {
pub vcpu_count: Option<usize>,
#[cfg(unix)]
pub vfio: Vec<super::sys::config::VfioCommand>,
#[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),

View file

@ -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<V: VmArch, Vcpu: VcpuArch>(
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,