From 278ab05cbc6eae63d49eaeb6cd18c745d9b55d5e Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 4 Oct 2019 12:06:34 -0700 Subject: [PATCH] vmm: Add iommu=on|off option for --vsock Having the virtual IOMMU created with --iommu is one thing, but we also need a way to decide if a virtio-vsock device should be attached to this virtual IOMMU or not. That's why we introduce an extra option "iommu" with the value "on" or "off". By default, the device is not attached, which means "iommu=off". Signed-off-by: Sebastien Boeuf --- src/main.rs | 2 +- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e8576fcc9..9d2d72df2 100755 --- a/src/main.rs +++ b/src/main.rs @@ -219,7 +219,7 @@ fn main() { .long("vsock") .help( "Virtio VSOCK parameters \"cid=,\ - sock=\"", + sock=,iommu=on|off\"", ) .takes_value(true) .min_values(1) diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index fde659f8f..2db9e8b2f 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -364,3 +364,6 @@ components: sock: type: string description: Path to UNIX domain socket, used to proxy vsock connections. + iommu: + type: boolean + default: false diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 6ac94c444..a05933d4a 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -652,6 +652,8 @@ impl VhostUserNetConfig { pub struct VsockConfig { pub cid: u64, pub sock: PathBuf, + #[serde(default)] + pub iommu: bool, } impl VsockConfig { @@ -661,12 +663,15 @@ impl VsockConfig { let mut cid_str: &str = ""; let mut sock_str: &str = ""; + let mut iommu_str: &str = ""; for param in params_list.iter() { if param.starts_with("cid=") { cid_str = ¶m[4..]; } else if param.starts_with("sock=") { sock_str = ¶m[5..]; + } else if param.starts_with("iommu=") { + iommu_str = ¶m[6..]; } } @@ -677,6 +682,7 @@ impl VsockConfig { Ok(VsockConfig { cid: cid_str.parse::().map_err(Error::ParseVsockCidParam)?, sock: PathBuf::from(sock_str), + iommu: parse_iommu(iommu_str)?, }) } } @@ -855,7 +861,11 @@ impl VmConfig { if let Some(vsock_list) = &vm_params.vsock { let mut vsock_config_list = Vec::new(); for item in vsock_list.iter() { - vsock_config_list.push(VsockConfig::parse(item)?); + let vsock_config = VsockConfig::parse(item)?; + if vsock_config.iommu { + iommu = true; + } + vsock_config_list.push(vsock_config); } vsock = Some(vsock_config_list); }