From 20c4ed829abf6aa182b4e285168c27e4a26bd9f5 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 2 Oct 2019 14:13:44 -0700 Subject: [PATCH] vmm: Add iommu=on|off option for --net Having the virtual IOMMU created with --iommu is one thing, but we also need a way to decide if a virtio-net 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 | 3 ++- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f81d98aa6..99fd343db 100755 --- a/src/main.rs +++ b/src/main.rs @@ -135,7 +135,8 @@ fn main() { .long("net") .help( "Network parameters \"tap=,\ - ip=,mask=,mac=\"", + ip=,mask=,mac=,\ + 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 ffb3239c7..bbc9dc6b9 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -244,6 +244,9 @@ components: type: string mac: type: string + iommu: + type: boolean + default: false RngConfig: required: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index dbb610437..46eda043b 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -259,6 +259,8 @@ pub struct NetConfig { pub ip: Ipv4Addr, pub mask: Ipv4Addr, pub mac: MacAddr, + #[serde(default)] + pub iommu: bool, } impl NetConfig { @@ -270,6 +272,7 @@ impl NetConfig { let mut ip_str: &str = ""; let mut mask_str: &str = ""; let mut mac_str: &str = ""; + let mut iommu_str: &str = ""; for param in params_list.iter() { if param.starts_with("tap=") { @@ -280,6 +283,8 @@ impl NetConfig { mask_str = ¶m[5..]; } else if param.starts_with("mac=") { mac_str = ¶m[4..]; + } else if param.starts_with("iommu=") { + iommu_str = ¶m[6..]; } } @@ -287,6 +292,7 @@ impl NetConfig { let mut ip: Ipv4Addr = Ipv4Addr::new(192, 168, 249, 1); let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0);; let mut mac: MacAddr = MacAddr::local_random(); + let iommu = parse_iommu(iommu_str)?; if !tap_str.is_empty() { tap = Some(tap_str.to_string()); @@ -301,7 +307,13 @@ impl NetConfig { mac = MacAddr::parse_str(mac_str).map_err(Error::ParseNetMacParam)?; } - Ok(NetConfig { tap, ip, mask, mac }) + Ok(NetConfig { + tap, + ip, + mask, + mac, + iommu, + }) } } @@ -731,7 +743,11 @@ impl VmConfig { if let Some(net_list) = &vm_params.net { let mut net_config_list = Vec::new(); for item in net_list.iter() { - net_config_list.push(NetConfig::parse(item)?); + let net_config = NetConfig::parse(item)?; + if net_config.iommu { + iommu = true; + } + net_config_list.push(net_config); } net = Some(net_config_list); }