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: firecracker-microvm#2709

Signed-off-by: Andreea Florescu <fandree@amazon.com>
  • Loading branch information
andreeaflorescu authored and alindima committed Nov 23, 2021
1 parent a8ddffa commit 4ca1f08
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,30 @@ pub fn build_microvm_for_boot(
let vcpu_config = vm_resources.vcpu_config();
let entry_addr = load_kernel(boot_config, &guest_memory)?;
let initrd = load_initrd_from_config(boot_config, &guest_memory)?;
// Clone the command-line so that a failed boot doesn't pollute the original.
#[allow(unused_mut)]
let mut boot_cmdline = boot_config.cmdline.clone();

let mut boot_cmdline = kernel::cmdline::Cmdline::new(arch::CMDLINE_MAX_SIZE);
// Timestamp for measuring microVM boot duration.
let request_ts = TimestampUs::default();

// 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,
event_manager,
Expand Down Expand Up @@ -360,6 +377,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 4ca1f08

Please sign in to comment.