vmm: Add iommu=on|off option for --device

Having the virtual IOMMU created with --iommu is one thing, but we also
need a way to decide if a VFIO device should be attached to the 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-07 09:03:58 -07:00
committed by Samuel Ortiz
parent 3bb51d4d5e
commit 5fc3f37c9b
5 changed files with 32 additions and 4 deletions

View File

@@ -353,6 +353,9 @@ components:
properties:
path:
type: string
iommu:
type: boolean
default: false
VhostUserConfig:
required:

View File

@@ -572,12 +572,29 @@ impl ConsoleConfig {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DeviceConfig {
pub path: PathBuf,
#[serde(default)]
pub iommu: bool,
}
impl DeviceConfig {
pub fn parse(device: &str) -> Result<Self> {
// Split the parameters based on the comma delimiter
let params_list: Vec<&str> = device.split(',').collect();
let mut path_str: &str = "";
let mut iommu_str: &str = "";
for param in params_list.iter() {
if param.starts_with("path=") {
path_str = &param[5..];
} else if param.starts_with("iommu=") {
iommu_str = &param[6..];
}
}
Ok(DeviceConfig {
path: PathBuf::from(device),
path: PathBuf::from(path_str),
iommu: parse_iommu(iommu_str)?,
})
}
}
@@ -843,7 +860,11 @@ impl VmConfig {
if let Some(device_list) = &vm_params.devices {
let mut device_config_list = Vec::new();
for item in device_list.iter() {
device_config_list.push(DeviceConfig::parse(item)?);
let device_config = DeviceConfig::parse(item)?;
if device_config.iommu {
iommu = true;
}
device_config_list.push(device_config);
}
devices = Some(device_config_list);
}