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

@ -72,7 +72,7 @@ takes the device's sysfs path as an argument. In our example it is
--cmdline "console=ttyS0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda3" \
--cpus 4 \
--memory size=512M \
--device /sys/bus/pci/devices/0000:01:00.0/
--device path=/sys/bus/pci/devices/0000:01:00.0/
```
The guest kernel will then detect the card reader on its PCI bus and provided

View File

@ -198,6 +198,10 @@ fn main() {
Arg::with_name("device")
.long("device")
.help("Direct device assignment parameter")
.help(
"Direct device assignment parameters \
\"path=<device_path>,iommu=on|off\"",
)
.takes_value(true)
.min_values(1)
.group("vm-config"),

View File

@ -51,4 +51,4 @@ write_files:
bash -c "echo 0000:00:06.0 > /sys/bus/pci/devices/0000\:00\:06.0/driver/unbind"
bash -c "echo 1af4 1041 > /sys/bus/pci/drivers/vfio-pci/new_id"
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda2 VFIOTAG" --disk path=/mnt/clear-cloudguest.img path=/mnt/cloudinit.img --cpus 1 --memory size=512M --rng --device /sys/bus/pci/devices/0000:00:06.0/
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda2 VFIOTAG" --disk path=/mnt/clear-cloudguest.img path=/mnt/cloudinit.img --cpus 1 --memory size=512M --rng --device path=/sys/bus/pci/devices/0000:00:06.0/

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);
}