@@ -33,6 +33,7 @@ pub mod generated;
3333
3434use std:: fs:: File ;
3535
36+ use layout:: CMDLINE_START ;
3637use linux_loader:: configurator:: linux:: LinuxBootConfigurator ;
3738use linux_loader:: configurator:: pvh:: PvhBootConfigurator ;
3839use linux_loader:: configurator:: { BootConfigurator , BootParams } ;
@@ -49,7 +50,6 @@ use crate::acpi::create_acpi_tables;
4950use crate :: arch:: { BootProtocol , SYSTEM_MEM_SIZE , SYSTEM_MEM_START } ;
5051use crate :: cpu_config:: templates:: { CustomCpuTemplate , GuestConfigError } ;
5152use crate :: cpu_config:: x86_64:: CpuConfiguration ;
52- use crate :: device_manager:: resources:: ResourceAllocator ;
5353use crate :: initrd:: InitrdConfig ;
5454use crate :: utils:: { mib_to_bytes, u64_to_usize} ;
5555use crate :: vmm_config:: machine_config:: MachineConfig ;
@@ -183,15 +183,28 @@ pub fn configure_system_for_boot(
183183 & boot_cmdline,
184184 )
185185 . map_err ( ConfigurationError :: LoadCommandline ) ?;
186- configure_system (
186+
187+ // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
188+ mptable:: setup_mptable (
187189 & vmm. guest_memory ,
188190 & mut vmm. resource_allocator ,
189- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
190- cmdline_size,
191- initrd,
192191 vcpu_config. vcpu_count ,
193- entry_point. protocol ,
194- ) ?;
192+ )
193+ . map_err ( ConfigurationError :: MpTableSetup ) ?;
194+
195+ match entry_point. protocol {
196+ BootProtocol :: PvhBoot => {
197+ configure_pvh ( & vmm. guest_memory , GuestAddress ( CMDLINE_START ) , initrd) ?;
198+ }
199+ BootProtocol :: LinuxBoot => {
200+ configure_64bit_boot (
201+ & vmm. guest_memory ,
202+ GuestAddress ( CMDLINE_START ) ,
203+ cmdline_size,
204+ initrd,
205+ ) ?;
206+ }
207+ }
195208
196209 // Create ACPI tables and write them in guest memory
197210 // For the time being we only support ACPI in x86_64
@@ -206,32 +219,6 @@ pub fn configure_system_for_boot(
206219 Ok ( ( ) )
207220}
208221
209- /// Configures the system and should be called once per vm before starting vcpu threads.
210- fn configure_system (
211- guest_mem : & GuestMemoryMmap ,
212- resource_allocator : & mut ResourceAllocator ,
213- cmdline_addr : GuestAddress ,
214- cmdline_size : usize ,
215- initrd : & Option < InitrdConfig > ,
216- num_cpus : u8 ,
217- boot_prot : BootProtocol ,
218- ) -> Result < ( ) , ConfigurationError > {
219- // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
220- mptable:: setup_mptable ( guest_mem, resource_allocator, num_cpus)
221- . map_err ( ConfigurationError :: MpTableSetup ) ?;
222-
223- match boot_prot {
224- BootProtocol :: PvhBoot => {
225- configure_pvh ( guest_mem, cmdline_addr, initrd) ?;
226- }
227- BootProtocol :: LinuxBoot => {
228- configure_64bit_boot ( guest_mem, cmdline_addr, cmdline_size, initrd) ?;
229- }
230- }
231-
232- Ok ( ( ) )
233- }
234-
235222fn configure_pvh (
236223 guest_mem : & GuestMemoryMmap ,
237224 cmdline_addr : GuestAddress ,
@@ -473,6 +460,7 @@ mod tests {
473460 use linux_loader:: loader:: bootparam:: boot_e820_entry;
474461
475462 use super :: * ;
463+ use crate :: device_manager:: resources:: ResourceAllocator ;
476464 use crate :: test_utils:: { arch_mem, single_region_mem} ;
477465
478466 #[ test]
@@ -496,94 +484,35 @@ mod tests {
496484 let no_vcpus = 4 ;
497485 let gm = single_region_mem ( 0x10000 ) ;
498486 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
499- let config_err = configure_system (
500- & gm,
501- & mut resource_allocator,
502- GuestAddress ( 0 ) ,
503- 0 ,
504- & None ,
505- 1 ,
506- BootProtocol :: LinuxBoot ,
507- ) ;
487+ let err = mptable:: setup_mptable ( & gm, & mut resource_allocator, 1 ) ;
508488 assert ! ( matches!(
509- config_err . unwrap_err( ) ,
510- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
489+ err . unwrap_err( ) ,
490+ mptable:: MptableError :: NotEnoughMemory
511491 ) ) ;
512492
513493 // Now assigning some memory that falls before the 32bit memory hole.
514494 let mem_size = mib_to_bytes ( 128 ) ;
515495 let gm = arch_mem ( mem_size) ;
516496 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
517- configure_system (
518- & gm,
519- & mut resource_allocator,
520- GuestAddress ( 0 ) ,
521- 0 ,
522- & None ,
523- no_vcpus,
524- BootProtocol :: LinuxBoot ,
525- )
526- . unwrap ( ) ;
527- configure_system (
528- & gm,
529- & mut resource_allocator,
530- GuestAddress ( 0 ) ,
531- 0 ,
532- & None ,
533- no_vcpus,
534- BootProtocol :: PvhBoot ,
535- )
536- . unwrap ( ) ;
497+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
498+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
499+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
537500
538501 // Now assigning some memory that is equal to the start of the 32bit memory hole.
539502 let mem_size = mib_to_bytes ( 3328 ) ;
540503 let gm = arch_mem ( mem_size) ;
541504 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
542- configure_system (
543- & gm,
544- & mut resource_allocator,
545- GuestAddress ( 0 ) ,
546- 0 ,
547- & None ,
548- no_vcpus,
549- BootProtocol :: LinuxBoot ,
550- )
551- . unwrap ( ) ;
552- configure_system (
553- & gm,
554- & mut resource_allocator,
555- GuestAddress ( 0 ) ,
556- 0 ,
557- & None ,
558- no_vcpus,
559- BootProtocol :: PvhBoot ,
560- )
561- . unwrap ( ) ;
505+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
506+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
507+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
562508
563509 // Now assigning some memory that falls after the 32bit memory hole.
564510 let mem_size = mib_to_bytes ( 3330 ) ;
565511 let gm = arch_mem ( mem_size) ;
566512 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
567- configure_system (
568- & gm,
569- & mut resource_allocator,
570- GuestAddress ( 0 ) ,
571- 0 ,
572- & None ,
573- no_vcpus,
574- BootProtocol :: LinuxBoot ,
575- )
576- . unwrap ( ) ;
577- configure_system (
578- & gm,
579- & mut resource_allocator,
580- GuestAddress ( 0 ) ,
581- 0 ,
582- & None ,
583- no_vcpus,
584- BootProtocol :: PvhBoot ,
585- )
586- . unwrap ( ) ;
513+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
514+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
515+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
587516 }
588517
589518 #[ test]
0 commit comments