main, vmm: Add option to pass firmware parameter in payload

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-08-15 15:41:38 +01:00
parent 763ea7da42
commit 8ec5a248cd
2 changed files with 21 additions and 10 deletions

View File

@ -192,11 +192,18 @@ fn create_app<'a>(
.min_values(1) .min_values(1)
.group("vm-config"), .group("vm-config"),
) )
.arg(
Arg::new("firmware")
.long("firmware")
.help("Path to firmware that is loaded in an architectural specific way")
.takes_value(true)
.group("vm-config"),
)
.arg( .arg(
Arg::new("kernel") Arg::new("kernel")
.long("kernel") .long("kernel")
.help( .help(
"Path to loaded kernel. This may be a kernel or firmware that supports a PVH \ "Path to kernel to load. This may be a kernel or firmware that supports a PVH \
entry point (e.g. vmlinux) or architecture equivalent", entry point (e.g. vmlinux) or architecture equivalent",
) )
.takes_value(true) .takes_value(true)
@ -567,16 +574,15 @@ fn start_vmm(cmd_arguments: ArgMatches) -> Result<Option<String>, Error> {
) )
.map_err(Error::StartVmmThread)?; .map_err(Error::StartVmmThread)?;
let payload_present =
cmd_arguments.is_present("kernel") || cmd_arguments.is_present("firmware");
// Can't test for "vm-config" group as some have default values. The kernel (or tdx if enabled) // Can't test for "vm-config" group as some have default values. The kernel (or tdx if enabled)
// is the only required option for booting the VM. // is the only required option for booting the VM.
#[cfg(feature = "tdx")] #[cfg(feature = "tdx")]
let tdx_or_kernel_present = let payload_present = payload_present || cmd_arguments.is_present("tdx");
cmd_arguments.is_present("kernel") || cmd_arguments.is_present("tdx");
#[cfg(not(feature = "tdx"))] if payload_present {
let tdx_or_kernel_present = cmd_arguments.is_present("kernel");
if tdx_or_kernel_present {
let vm_params = config::VmParams::from_arg_matches(&cmd_arguments); let vm_params = config::VmParams::from_arg_matches(&cmd_arguments);
let vm_config = config::VmConfig::parse(vm_params).map_err(Error::ParsingConfig)?; let vm_config = config::VmConfig::parse(vm_params).map_err(Error::ParsingConfig)?;

View File

@ -343,6 +343,7 @@ pub struct VmParams<'a> {
pub cpus: &'a str, pub cpus: &'a str,
pub memory: &'a str, pub memory: &'a str,
pub memory_zones: Option<Vec<&'a str>>, pub memory_zones: Option<Vec<&'a str>>,
pub firmware: Option<&'a str>,
pub kernel: Option<&'a str>, pub kernel: Option<&'a str>,
pub initramfs: Option<&'a str>, pub initramfs: Option<&'a str>,
pub cmdline: Option<&'a str>, pub cmdline: Option<&'a str>,
@ -377,11 +378,10 @@ impl<'a> VmParams<'a> {
let memory_zones: Option<Vec<&str>> = args.values_of("memory-zone").map(|x| x.collect()); let memory_zones: Option<Vec<&str>> = args.values_of("memory-zone").map(|x| x.collect());
let rng = args.value_of("rng").unwrap(); let rng = args.value_of("rng").unwrap();
let serial = args.value_of("serial").unwrap(); let serial = args.value_of("serial").unwrap();
let firmware = args.value_of("firmware");
let kernel = args.value_of("kernel"); let kernel = args.value_of("kernel");
let initramfs = args.value_of("initramfs"); let initramfs = args.value_of("initramfs");
let cmdline = args.value_of("cmdline"); let cmdline = args.value_of("cmdline");
let disks: Option<Vec<&str>> = args.values_of("disk").map(|x| x.collect()); let disks: Option<Vec<&str>> = args.values_of("disk").map(|x| x.collect());
let net: Option<Vec<&str>> = args.values_of("net").map(|x| x.collect()); let net: Option<Vec<&str>> = args.values_of("net").map(|x| x.collect());
let console = args.value_of("console").unwrap(); let console = args.value_of("console").unwrap();
@ -405,6 +405,7 @@ impl<'a> VmParams<'a> {
cpus, cpus,
memory, memory,
memory_zones, memory_zones,
firmware,
kernel, kernel,
initramfs, initramfs,
cmdline, cmdline,
@ -2250,6 +2251,8 @@ impl RestoreConfig {
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct PayloadConfig { pub struct PayloadConfig {
#[serde(default)]
pub firmware: Option<PathBuf>,
#[serde(default)] #[serde(default)]
pub kernel: Option<PathBuf>, pub kernel: Option<PathBuf>,
#[serde(default)] #[serde(default)]
@ -2334,6 +2337,7 @@ impl VmConfig {
Some(self.cmdline.args.drain(..).collect()) Some(self.cmdline.args.drain(..).collect())
}, },
initramfs: self.initramfs.take().map(|i| i.path), initramfs: self.initramfs.take().map(|i| i.path),
..Default::default()
}) })
} }
@ -2671,11 +2675,12 @@ impl VmConfig {
numa = Some(numa_config_list); numa = Some(numa_config_list);
} }
let payload = if vm_params.kernel.is_some() { let payload = if vm_params.kernel.is_some() || vm_params.firmware.is_some() {
Some(PayloadConfig { Some(PayloadConfig {
kernel: vm_params.kernel.map(PathBuf::from), kernel: vm_params.kernel.map(PathBuf::from),
initramfs: vm_params.initramfs.map(PathBuf::from), initramfs: vm_params.initramfs.map(PathBuf::from),
cmdline: vm_params.cmdline.map(|s| s.to_string()), cmdline: vm_params.cmdline.map(|s| s.to_string()),
firmware: vm_params.firmware.map(PathBuf::from),
}) })
} else { } else {
None None