diff --git a/Cargo.lock b/Cargo.lock index 92681fc1b..cc25bb1a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,9 +516,9 @@ dependencies = [ [[package]] name = "linux-loader" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c819cc8275b0f2c1ed9feec455ca288b45d82932384a6a5f7a86812ee3427459" +checksum = "8a5e77493808403a6bd56a301a64ea6b9342e36ea845044bf0dfdf56fe52fa08" dependencies = [ "vm-memory", ] diff --git a/arch/Cargo.toml b/arch/Cargo.toml index b4cc4de9f..238cc1f52 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -15,7 +15,7 @@ anyhow = "1.0.44" byteorder = "1.4.3" hypervisor = { path = "../hypervisor" } libc = "0.2.102" -linux-loader = { version = "0.3.0", features = ["elf", "bzimage", "pe"] } +linux-loader = { version = "0.4.0", features = ["elf", "bzimage", "pe"] } log = "0.4.14" serde = { version = "1.0.130", features = ["rc"] } thiserror = "1.0.29" diff --git a/arch/src/aarch64/fdt.rs b/arch/src/aarch64/fdt.rs index 1b7165ff9..77863b1c9 100644 --- a/arch/src/aarch64/fdt.rs +++ b/arch/src/aarch64/fdt.rs @@ -82,7 +82,7 @@ type Result = result::Result; #[allow(clippy::too_many_arguments)] pub fn create_fdt( guest_mem: &GuestMemoryMmap, - cmdline: &CStr, + cmdline: &str, vcpu_mpidr: Vec, vcpu_topology: Option<(u8, u8, u8)>, device_info: &HashMap<(DeviceType, String), T, S>, @@ -111,7 +111,7 @@ pub fn create_fdt Vec<(GuestAddress, usize, Region #[allow(clippy::too_many_arguments)] pub fn configure_system( guest_mem: &GuestMemoryMmap, - cmdline_cstring: &CStr, + cmdline: &str, vcpu_mpidr: Vec, vcpu_topology: Option<(u8, u8, u8)>, device_info: &HashMap<(DeviceType, String), T, S>, @@ -148,7 +147,7 @@ pub fn configure_system super::Result<()> { let fdt_final = fdt::create_fdt( guest_mem, - cmdline_cstring, + cmdline, vcpu_mpidr, vcpu_topology, device_info, diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index e3760478c..b61ccdd9b 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -28,7 +28,7 @@ event_monitor = { path = "../event_monitor" } hypervisor = { path = "../hypervisor" } lazy_static = "1.4.0" libc = "0.2.102" -linux-loader = { version = "0.3.0", features = ["elf", "bzimage", "pe"] } +linux-loader = { version = "0.4.0", features = ["elf", "bzimage", "pe"] } log = "0.4.14" micro_http = { git = "https://github.com/firecracker-microvm/micro-http", branch = "main" } net_util = { path = "../net_util" } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 81d99d87e..cae848978 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -53,7 +53,6 @@ use std::cmp; use std::collections::BTreeMap; use std::collections::HashMap; use std::convert::TryInto; -use std::ffi::CString; #[cfg(target_arch = "x86_64")] use std::fmt; use std::fs::{File, OpenOptions}; @@ -112,9 +111,6 @@ pub enum Error { /// Cannot modify the command line CmdLineInsertStr(linux_loader::cmdline::Error), - /// Cannot convert command line into CString - CmdLineCString(std::ffi::NulError), - /// Cannot configure system ConfigureSystem(arch::Error), @@ -935,7 +931,7 @@ impl Vm { Ok(arch::InitramfsConfig { address, size }) } - fn get_cmdline(&mut self) -> Result { + fn get_cmdline(&mut self) -> Result { let mut cmdline = Cmdline::new(arch::CMDLINE_MAX_SIZE); cmdline .insert_str(self.config.lock().unwrap().cmdline.args.clone()) @@ -943,7 +939,7 @@ impl Vm { for entry in self.device_manager.lock().unwrap().cmdline_additions() { cmdline.insert_str(entry).map_err(Error::CmdLineInsertStr)?; } - CString::new(cmdline).map_err(Error::CmdLineCString) + Ok(cmdline) } #[cfg(target_arch = "aarch64")] @@ -988,7 +984,7 @@ impl Vm { #[cfg(target_arch = "x86_64")] fn load_kernel(&mut self) -> Result { info!("Loading kernel"); - let cmdline_cstring = self.get_cmdline()?; + let cmdline = self.get_cmdline()?; let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory(); let mem = guest_memory.memory(); let mut kernel = self.kernel.as_ref().unwrap(); @@ -1004,12 +1000,8 @@ impl Vm { } }; - linux_loader::loader::load_cmdline( - mem.deref(), - arch::layout::CMDLINE_START, - &cmdline_cstring, - ) - .map_err(Error::LoadCmdLine)?; + linux_loader::loader::load_cmdline(mem.deref(), arch::layout::CMDLINE_START, &cmdline) + .map_err(Error::LoadCmdLine)?; if let PvhEntryPresent(entry_addr) = entry_addr.pvh_boot_cap { // Use the PVH kernel entry point to boot the guest @@ -1072,7 +1064,7 @@ impl Vm { #[cfg(target_arch = "aarch64")] fn configure_system(&mut self) -> Result<()> { - let cmdline_cstring = self.get_cmdline()?; + let cmdline = self.get_cmdline()?; let vcpu_mpidrs = self.cpu_manager.lock().unwrap().get_mpidrs(); let vcpu_topology = self.cpu_manager.lock().unwrap().get_vcpu_topology(); let mem = self.memory_manager.lock().unwrap().boot_guest_memory(); @@ -1138,7 +1130,7 @@ impl Vm { arch::configure_system( &mem, - &cmdline_cstring, + cmdline.as_str(), vcpu_mpidrs, vcpu_topology, device_info, @@ -2617,7 +2609,7 @@ mod tests { let gic = create_gic(&vm, 1).unwrap(); assert!(create_fdt( &mem, - &CString::new("console=tty0").unwrap(), + "console=tty0", vec![0], Some((0, 0, 0)), &dev_info,