@@ -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
@@ -205,32 +218,6 @@ pub fn configure_system_for_boot(
205218 Ok ( ( ) )
206219}
207220
208- /// Configures the system and should be called once per vm before starting vcpu threads.
209- fn configure_system (
210- guest_mem : & GuestMemoryMmap ,
211- resource_allocator : & mut ResourceAllocator ,
212- cmdline_addr : GuestAddress ,
213- cmdline_size : usize ,
214- initrd : & Option < InitrdConfig > ,
215- num_cpus : u8 ,
216- boot_prot : BootProtocol ,
217- ) -> Result < ( ) , ConfigurationError > {
218- // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
219- mptable:: setup_mptable ( guest_mem, resource_allocator, num_cpus)
220- . map_err ( ConfigurationError :: MpTableSetup ) ?;
221-
222- match boot_prot {
223- BootProtocol :: PvhBoot => {
224- configure_pvh ( guest_mem, cmdline_addr, initrd) ?;
225- }
226- BootProtocol :: LinuxBoot => {
227- configure_64bit_boot ( guest_mem, cmdline_addr, cmdline_size, initrd) ?;
228- }
229- }
230-
231- Ok ( ( ) )
232- }
233-
234221fn configure_pvh (
235222 guest_mem : & GuestMemoryMmap ,
236223 cmdline_addr : GuestAddress ,
@@ -472,6 +459,7 @@ mod tests {
472459 use linux_loader:: loader:: bootparam:: boot_e820_entry;
473460
474461 use super :: * ;
462+ use crate :: device_manager:: resources:: ResourceAllocator ;
475463 use crate :: test_utils:: { arch_mem, single_region_mem} ;
476464
477465 #[ test]
@@ -495,94 +483,35 @@ mod tests {
495483 let no_vcpus = 4 ;
496484 let gm = single_region_mem ( 0x10000 ) ;
497485 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
498- let config_err = configure_system (
499- & gm,
500- & mut resource_allocator,
501- GuestAddress ( 0 ) ,
502- 0 ,
503- & None ,
504- 1 ,
505- BootProtocol :: LinuxBoot ,
506- ) ;
486+ let err = mptable:: setup_mptable ( & gm, & mut resource_allocator, 1 ) ;
507487 assert ! ( matches!(
508- config_err . unwrap_err( ) ,
509- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
488+ err . unwrap_err( ) ,
489+ mptable:: MptableError :: NotEnoughMemory
510490 ) ) ;
511491
512492 // Now assigning some memory that falls before the 32bit memory hole.
513493 let mem_size = mib_to_bytes ( 128 ) ;
514494 let gm = arch_mem ( mem_size) ;
515495 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
516- configure_system (
517- & gm,
518- & mut resource_allocator,
519- GuestAddress ( 0 ) ,
520- 0 ,
521- & None ,
522- no_vcpus,
523- BootProtocol :: LinuxBoot ,
524- )
525- . unwrap ( ) ;
526- configure_system (
527- & gm,
528- & mut resource_allocator,
529- GuestAddress ( 0 ) ,
530- 0 ,
531- & None ,
532- no_vcpus,
533- BootProtocol :: PvhBoot ,
534- )
535- . unwrap ( ) ;
496+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
497+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
498+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
536499
537500 // Now assigning some memory that is equal to the start of the 32bit memory hole.
538501 let mem_size = mib_to_bytes ( 3328 ) ;
539502 let gm = arch_mem ( mem_size) ;
540503 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
541- configure_system (
542- & gm,
543- & mut resource_allocator,
544- GuestAddress ( 0 ) ,
545- 0 ,
546- & None ,
547- no_vcpus,
548- BootProtocol :: LinuxBoot ,
549- )
550- . unwrap ( ) ;
551- configure_system (
552- & gm,
553- & mut resource_allocator,
554- GuestAddress ( 0 ) ,
555- 0 ,
556- & None ,
557- no_vcpus,
558- BootProtocol :: PvhBoot ,
559- )
560- . unwrap ( ) ;
504+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
505+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
506+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
561507
562508 // Now assigning some memory that falls after the 32bit memory hole.
563509 let mem_size = mib_to_bytes ( 3330 ) ;
564510 let gm = arch_mem ( mem_size) ;
565511 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
566- configure_system (
567- & gm,
568- & mut resource_allocator,
569- GuestAddress ( 0 ) ,
570- 0 ,
571- & None ,
572- no_vcpus,
573- BootProtocol :: LinuxBoot ,
574- )
575- . unwrap ( ) ;
576- configure_system (
577- & gm,
578- & mut resource_allocator,
579- GuestAddress ( 0 ) ,
580- 0 ,
581- & None ,
582- no_vcpus,
583- BootProtocol :: PvhBoot ,
584- )
585- . unwrap ( ) ;
512+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
513+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
514+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
586515 }
587516
588517 #[ test]
0 commit comments