Skip to content

Commit

Permalink
split the boot args in regular args and init args
Browse files Browse the repository at this point in the history
This split is needed because we're altering the kernel commandline
passed by Firecracker customers to add virtio device configuration (on
x86_64). The virtio config needs to be specified *before* the init.

This is not the ideal implementation of the fix, as it would make more
sense to have it in rust-vmm/linux-loader. Due to existing technical
debt implementing it directly in upstream is not straightforward.
See: rust-vmm/linux-loader#92.

Fixes: #2709

Signed-off-by: Andreea Florescu <fandree@amazon.com>
  • Loading branch information
andreeaflorescu authored and georgepisaltu committed Oct 20, 2021
1 parent 0cf718c commit 5c6ceae
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,26 @@ pub fn build_microvm_for_boot(
// Clone the command-line so that a failed boot doesn't pollute the original.
#[allow(unused_mut)]
let mut boot_cmdline = linux_loader::cmdline::Cmdline::new(arch::CMDLINE_MAX_SIZE);
boot_cmdline.insert_str(boot_config.cmdline.as_str())?;

// We're splitting the boot_args in regular parameters and init arguments.
// This is needed because on x86_64 we're altering the boot arguments by
// adding the virtio device configuration. We need to make sure that the init
// parameters are last, specified after -- as specified in the kernel docs
// (https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html).
let init_and_regular = boot_config
.cmdline
.as_str()
.split("--")
.collect::<Vec<&str>>();
if init_and_regular.len() > 2 {
return Err(StartMicrovmError::KernelCmdline(
"Too many `--` in kernel cmdline.".to_string(),
));
}
let boot_args = init_and_regular[0];
let init_params = init_and_regular.get(1);

boot_cmdline.insert_str(boot_args)?;

let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
instance_info,
Expand Down Expand Up @@ -374,6 +393,10 @@ pub fn build_microvm_for_boot(
attach_unixsock_vsock_device(&mut vmm, &mut boot_cmdline, unix_vsock, event_manager)?;
}

if let Some(init) = init_params {
boot_cmdline.insert_str(format!("--{}", init))?;
}

#[cfg(target_arch = "aarch64")]
attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline).map_err(Internal)?;

Expand Down

0 comments on commit 5c6ceae

Please sign in to comment.