From fb4769388baa697bf75b3b0f09c47af7dded9568 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 4 Oct 2019 11:18:49 -0700 Subject: [PATCH] vmm: Add iommu=on|off option for --rng Having the virtual IOMMU created with --iommu is one thing, but we also need a way to decide if a virtio-rng 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 | 10 ++++++--- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 27 +++++++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 99fd343db..443fa79ab 100755 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,8 @@ fn main() { } let default_vcpus = format! {"{}", config::DEFAULT_VCPUS}; - let default_memory = &format! {"size={}M", config::DEFAULT_MEMORY_MB}; + let default_memory = format! {"size={}M", config::DEFAULT_MEMORY_MB}; + let default_rng = format! {"src={}", config::DEFAULT_RNG_SOURCE}; let cmd_arguments = App::new("cloud-hypervisor") .version(crate_version!()) @@ -145,8 +146,11 @@ fn main() { .arg( Arg::with_name("rng") .long("rng") - .help("Path to entropy source") - .default_value(config::DEFAULT_RNG_SOURCE) + .help( + "Random number generator parameters \ + \"src=,iommu=on|off\"", + ) + .default_value(&default_rng) .group("vm-config"), ) .arg( diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index bbc9dc6b9..58b2ea895 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -256,6 +256,9 @@ components: src: type: string default: "/dev/urandom" + iommu: + type: boolean + default: false FsConfig: required: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 46eda043b..2bbcf3967 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -320,12 +320,29 @@ impl NetConfig { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RngConfig { pub src: PathBuf, + #[serde(default)] + pub iommu: bool, } impl RngConfig { pub fn parse(rng: &str) -> Result { + // Split the parameters based on the comma delimiter + let params_list: Vec<&str> = rng.split(',').collect(); + + let mut src_str: &str = ""; + let mut iommu_str: &str = ""; + + for param in params_list.iter() { + if param.starts_with("src=") { + src_str = ¶m[4..]; + } else if param.starts_with("iommu=") { + iommu_str = ¶m[6..]; + } + } + Ok(RngConfig { - src: PathBuf::from(rng), + src: PathBuf::from(src_str), + iommu: parse_iommu(iommu_str)?, }) } } @@ -334,6 +351,7 @@ impl Default for RngConfig { fn default() -> Self { RngConfig { src: PathBuf::from(DEFAULT_RNG_SOURCE), + iommu: false, } } } @@ -752,6 +770,11 @@ impl VmConfig { net = Some(net_config_list); } + let rng = RngConfig::parse(vm_params.rng)?; + if rng.iommu { + iommu = true; + } + let mut fs: Option> = None; if let Some(fs_list) = &vm_params.fs { let mut fs_config_list = Vec::new(); @@ -826,7 +849,7 @@ impl VmConfig { cmdline: CmdlineConfig::parse(vm_params.cmdline)?, disks, net, - rng: RngConfig::parse(vm_params.rng)?, + rng, fs, pmem, serial,