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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-10-04 11:18:49 -07:00 committed by Samuel Ortiz
parent 20c4ed829a
commit fb4769388b
3 changed files with 35 additions and 5 deletions

View File

@ -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=<entropy_source_path>,iommu=on|off\"",
)
.default_value(&default_rng)
.group("vm-config"),
)
.arg(

View File

@ -256,6 +256,9 @@ components:
src:
type: string
default: "/dev/urandom"
iommu:
type: boolean
default: false
FsConfig:
required:

View File

@ -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<Self> {
// 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 = &param[4..];
} else if param.starts_with("iommu=") {
iommu_str = &param[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<Vec<FsConfig>> = 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,