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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-10-04 12:06:34 -07:00 committed by Samuel Ortiz
parent 32d07e40cc
commit 278ab05cbc
3 changed files with 15 additions and 2 deletions

View File

@ -219,7 +219,7 @@ fn main() {
.long("vsock")
.help(
"Virtio VSOCK parameters \"cid=<context_id>,\
sock=<socket_path>\"",
sock=<socket_path>,iommu=on|off\"",
)
.takes_value(true)
.min_values(1)

View File

@ -364,3 +364,6 @@ components:
sock:
type: string
description: Path to UNIX domain socket, used to proxy vsock connections.
iommu:
type: boolean
default: false

View File

@ -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 = &param[4..];
} else if param.starts_with("sock=") {
sock_str = &param[5..];
} else if param.starts_with("iommu=") {
iommu_str = &param[6..];
}
}
@ -677,6 +682,7 @@ impl VsockConfig {
Ok(VsockConfig {
cid: cid_str.parse::<u64>().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);
}