From 8d1b970f65f006f61465b17253d598687ae2b9f1 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Mon, 13 May 2024 23:41:31 -0700 Subject: [PATCH] work on loading cmdline --- crates/xen/xenclient/src/boot.rs | 5 ++-- crates/xen/xenclient/src/lib.rs | 2 +- crates/xen/xenclient/src/x86pv.rs | 3 +-- crates/xen/xenclient/src/x86pvh.rs | 38 ++++++++++++++++++++++++------ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/crates/xen/xenclient/src/boot.rs b/crates/xen/xenclient/src/boot.rs index 8955b1c..376b882 100644 --- a/crates/xen/xenclient/src/boot.rs +++ b/crates/xen/xenclient/src/boot.rs @@ -224,12 +224,12 @@ impl BootSetup { Ok(domain) } - pub async fn boot(&mut self, domain: &mut BootDomain, cmdline: &str) -> Result<()> { + pub async fn boot(&mut self, domain: &mut BootDomain) -> Result<()> { let domain_info = self.call.get_domain_info(self.domid).await?; let shared_info_frame = domain_info.shared_info_frame; self.platform.setup_page_tables(domain).await?; self.platform - .setup_start_info(domain, cmdline, shared_info_frame) + .setup_start_info(domain, shared_info_frame) .await?; self.platform.setup_hypercall_page(domain).await?; self.platform.bootlate(domain).await?; @@ -289,7 +289,6 @@ pub trait BootSetupPlatform: Clone { async fn setup_start_info( &mut self, domain: &mut BootDomain, - cmdline: &str, shared_info_frame: u64, ) -> Result<()>; diff --git a/crates/xen/xenclient/src/lib.rs b/crates/xen/xenclient/src/lib.rs index 0e70d40..0779452 100644 --- a/crates/xen/xenclient/src/lib.rs +++ b/crates/xen/xenclient/src/lib.rs @@ -291,7 +291,7 @@ impl XenClient { &config.cmdline, ) .await?; - boot.boot(&mut domain, &config.cmdline).await?; + boot.boot(&mut domain).await?; } { diff --git a/crates/xen/xenclient/src/x86pv.rs b/crates/xen/xenclient/src/x86pv.rs index 1154411..604239c 100644 --- a/crates/xen/xenclient/src/x86pv.rs +++ b/crates/xen/xenclient/src/x86pv.rs @@ -754,7 +754,6 @@ impl BootSetupPlatform for X86PvPlatform { async fn setup_start_info( &mut self, domain: &mut BootDomain, - cmdline: &str, shared_info_frame: u64, ) -> Result<()> { let start_info_segment = self @@ -800,7 +799,7 @@ impl BootSetupPlatform for X86PvPlatform { (*info).console.evtchn = console.0; (*info).mod_start = domain.initrd_segment.vstart; (*info).mod_len = domain.initrd_segment.size; - for (i, c) in cmdline.chars().enumerate() { + for (i, c) in domain.cmdline.chars().enumerate() { (*info).cmdline[i] = c as c_char; } (*info).cmdline[MAX_GUEST_CMDLINE - 1] = 0; diff --git a/crates/xen/xenclient/src/x86pvh.rs b/crates/xen/xenclient/src/x86pvh.rs index 4bd7a33..dce218f 100644 --- a/crates/xen/xenclient/src/x86pvh.rs +++ b/crates/xen/xenclient/src/x86pvh.rs @@ -42,6 +42,10 @@ pub struct HvmStartInfo { pub reserved: u32, } +const HVM_START_MAX_CMDLINE_SIZE: usize = 1024; +const HVM_START_MAX_MEMMAP_ENTRIES: usize = 8; +const HVM_START_MAX_MODLIST_COUNT: usize = 8; + #[repr(C)] #[derive(Default, Copy, Clone, Debug)] pub struct HvmModlistEntry { @@ -552,7 +556,6 @@ impl BootSetupPlatform for X86PvhPlatform { } async fn alloc_magic_pages(&mut self, domain: &mut BootDomain) -> Result<()> { - let memmap = self.construct_memmap()?; let mut special_array = vec![0u64; X86_HVM_NR_SPECIAL_PAGES as usize]; for i in 0..X86_HVM_NR_SPECIAL_PAGES { special_array[i as usize] = special_pfn(i as u32); @@ -629,8 +632,10 @@ impl BootSetupPlatform for X86PvhPlatform { .await?; let mut start_info_size = size_of::(); - start_info_size += domain.cmdline.len() + 1; - start_info_size += size_of::() * memmap.len(); + start_info_size += HVM_START_MAX_CMDLINE_SIZE; + start_info_size += size_of::() * HVM_START_MAX_MEMMAP_ENTRIES; + start_info_size += size_of::() * HVM_START_MAX_MODLIST_COUNT; + start_info_size += 1; self.start_info_segment = Some(domain.alloc_segment(0, start_info_size as u64).await?); let pt = domain @@ -670,7 +675,7 @@ impl BootSetupPlatform for X86PvhPlatform { Ok(()) } - async fn setup_start_info(&mut self, domain: &mut BootDomain, _: &str, _: u64) -> Result<()> { + async fn setup_start_info(&mut self, domain: &mut BootDomain, _: u64) -> Result<()> { let memmap = self.construct_memmap()?; let start_info_segment = self .start_info_segment @@ -695,16 +700,19 @@ impl BootSetupPlatform for X86PvhPlatform { (start_info_segment.pfn << self.page_shift()) + size_of::() as u64; (*info).memmap_paddr = (start_info_segment.pfn << self.page_shift()) + size_of::() as u64 - + domain.cmdline.len() as u64 - + 1; + + HVM_START_MAX_CMDLINE_SIZE as u64; (*info).memmap_entries = memmap.len() as u32; (*info).rsdp_paddr = self.acpi_modules[0].guest_addr; + (*info).nr_modules = 1; + (*info).modlist_paddr = (start_info_segment.pfn << self.page_shift()) + + size_of::() as u64 + + (size_of::() * HVM_START_MAX_MEMMAP_ENTRIES) as u64; }; let cmdline_ptr = (ptr + size_of::() as u64) as *mut u8; for (i, c) in domain.cmdline.chars().enumerate() { unsafe { *cmdline_ptr.add(i) = c as u8 }; } - let entries = (ptr + size_of::() as u64 + domain.cmdline.len() as u64 + 1) + let entries = (ptr + size_of::() as u64 + HVM_START_MAX_CMDLINE_SIZE as u64) as *mut HvmMemmapTableEntry; let entries = unsafe { std::slice::from_raw_parts_mut(entries, memmap.len()) }; for (i, e820) in memmap.iter().enumerate() { @@ -714,6 +722,22 @@ impl BootSetupPlatform for X86PvhPlatform { entry.typ = e820.typ; entry.reserved = 0; } + let modlist = (ptr + + (size_of::() + + HVM_START_MAX_CMDLINE_SIZE + + (size_of::() * HVM_START_MAX_MEMMAP_ENTRIES)) + as u64) as *mut HvmModlistEntry; + let modlist_cmdline_paddr = (start_info_segment.pfn << self.page_shift()) + + (size_of::() + + HVM_START_MAX_CMDLINE_SIZE + + (size_of::() * HVM_START_MAX_MEMMAP_ENTRIES) + + (size_of::() * HVM_START_MAX_MODLIST_COUNT)) + as u64; + unsafe { + (*modlist).paddr = domain.initrd_segment.pfn << self.page_shift(); + (*modlist).size = domain.initrd_segment.size; + (*modlist).cmdline_paddr = modlist_cmdline_paddr as u64; + } Ok(()) }