Skip to content

Commit 017cf1a

Browse files
andreeaflorescudianpopa
authored andcommitted
split the boot args in regular args and init args
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 depth implementing it directly in upstream is not straightforward. See: rust-vmm/linux-loader#92. Fixes: #2709 Signed-off-by: Andreea Florescu <[email protected]>
1 parent 6cbffe0 commit 017cf1a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/vmm/src/builder.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,26 @@ pub fn build_microvm_for_boot(
337337
// Clone the command-line so that a failed boot doesn't pollute the original.
338338
#[allow(unused_mut)]
339339
let mut boot_cmdline = linux_loader::cmdline::Cmdline::new(arch::CMDLINE_MAX_SIZE);
340-
boot_cmdline.insert_str(boot_config.cmdline.as_str())?;
340+
341+
// We're splitting the boot_args in regular parameters and init arguments.
342+
// This is needed because on x86_64 we're altering the boot arguments by
343+
// adding the virtio device configuration. We need to make sure that the init
344+
// parameters are last, specified after -- as specified in the kernel docs
345+
// (https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html).
346+
let init_and_regular = boot_config
347+
.cmdline
348+
.as_str()
349+
.split("--")
350+
.collect::<Vec<&str>>();
351+
if init_and_regular.len() > 2 {
352+
return Err(StartMicrovmError::KernelCmdline(
353+
"Too many `--` in kernel cmdline.".to_string(),
354+
));
355+
}
356+
let boot_args = init_and_regular[0];
357+
let init_params = init_and_regular.get(1);
358+
359+
boot_cmdline.insert_str(boot_args)?;
341360

342361
let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
343362
instance_info,
@@ -374,6 +393,10 @@ pub fn build_microvm_for_boot(
374393
attach_unixsock_vsock_device(&mut vmm, &mut boot_cmdline, unix_vsock, event_manager)?;
375394
}
376395

396+
if let Some(init) = init_params {
397+
boot_cmdline.insert_str(format!("--{}", init))?;
398+
}
399+
377400
#[cfg(target_arch = "aarch64")]
378401
attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline).map_err(Internal)?;
379402

0 commit comments

Comments
 (0)