Skip to content

Commit aefc93e

Browse files
andreeaflorescualindima
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 debt 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 a8ddffa commit aefc93e

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/vmm/src/builder.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,30 @@ pub fn build_microvm_for_boot(
318318
let vcpu_config = vm_resources.vcpu_config();
319319
let entry_addr = load_kernel(boot_config, &guest_memory)?;
320320
let initrd = load_initrd_from_config(boot_config, &guest_memory)?;
321-
// Clone the command-line so that a failed boot doesn't pollute the original.
322-
#[allow(unused_mut)]
323-
let mut boot_cmdline = boot_config.cmdline.clone();
324-
321+
let mut boot_cmdline = kernel::cmdline::Cmdline::new(arch::CMDLINE_MAX_SIZE);
325322
// Timestamp for measuring microVM boot duration.
326323
let request_ts = TimestampUs::default();
327324

325+
// We're splitting the boot_args in regular parameters and init arguments.
326+
// This is needed because on x86_64 we're altering the boot arguments by
327+
// adding the virtio device configuration. We need to make sure that the init
328+
// parameters are last, specified after -- as specified in the kernel docs
329+
// (https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html).
330+
let init_and_regular = boot_config
331+
.cmdline
332+
.as_str()
333+
.split("--")
334+
.collect::<Vec<&str>>();
335+
if init_and_regular.len() > 2 {
336+
return Err(StartMicrovmError::KernelCmdline(
337+
"Too many `--` in kernel cmdline.".to_string(),
338+
));
339+
}
340+
let boot_args = init_and_regular[0];
341+
let init_params = init_and_regular.get(1);
342+
343+
boot_cmdline.insert_str(boot_args)?;
344+
328345
let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
329346
instance_info,
330347
event_manager,
@@ -360,6 +377,10 @@ pub fn build_microvm_for_boot(
360377
attach_unixsock_vsock_device(&mut vmm, &mut boot_cmdline, unix_vsock, event_manager)?;
361378
}
362379

380+
if let Some(init) = init_params {
381+
boot_cmdline.insert_str(format!("--{}", init))?;
382+
}
383+
363384
#[cfg(target_arch = "aarch64")]
364385
attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline).map_err(Internal)?;
365386

0 commit comments

Comments
 (0)