@@ -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 ;
@@ -186,15 +186,28 @@ pub fn configure_system_for_boot(
186186 & boot_cmdline,
187187 )
188188 . map_err ( ConfigurationError :: LoadCommandline ) ?;
189- configure_system (
189+
190+ // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
191+ mptable:: setup_mptable (
190192 & vmm. guest_memory ,
191193 & mut vmm. resource_allocator ,
192- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
193- cmdline_size,
194- initrd,
195194 vcpu_config. vcpu_count ,
196- entry_point. protocol ,
197- ) ?;
195+ )
196+ . map_err ( ConfigurationError :: MpTableSetup ) ?;
197+
198+ match entry_point. protocol {
199+ BootProtocol :: PvhBoot => {
200+ configure_pvh ( & vmm. guest_memory , GuestAddress ( CMDLINE_START ) , initrd) ?;
201+ }
202+ BootProtocol :: LinuxBoot => {
203+ configure_64bit_boot (
204+ & vmm. guest_memory ,
205+ GuestAddress ( CMDLINE_START ) ,
206+ cmdline_size,
207+ initrd,
208+ ) ?;
209+ }
210+ }
198211
199212 // Create ACPI tables and write them in guest memory
200213 // For the time being we only support ACPI in x86_64
@@ -209,32 +222,6 @@ pub fn configure_system_for_boot(
209222 Ok ( ( ) )
210223}
211224
212- /// Configures the system and should be called once per vm before starting vcpu threads.
213- fn configure_system (
214- guest_mem : & GuestMemoryMmap ,
215- resource_allocator : & mut ResourceAllocator ,
216- cmdline_addr : GuestAddress ,
217- cmdline_size : usize ,
218- initrd : & Option < InitrdConfig > ,
219- num_cpus : u8 ,
220- boot_prot : BootProtocol ,
221- ) -> Result < ( ) , ConfigurationError > {
222- // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
223- mptable:: setup_mptable ( guest_mem, resource_allocator, num_cpus)
224- . map_err ( ConfigurationError :: MpTableSetup ) ?;
225-
226- match boot_prot {
227- BootProtocol :: PvhBoot => {
228- configure_pvh ( guest_mem, cmdline_addr, initrd) ?;
229- }
230- BootProtocol :: LinuxBoot => {
231- configure_64bit_boot ( guest_mem, cmdline_addr, cmdline_size, initrd) ?;
232- }
233- }
234-
235- Ok ( ( ) )
236- }
237-
238225fn configure_pvh (
239226 guest_mem : & GuestMemoryMmap ,
240227 cmdline_addr : GuestAddress ,
@@ -476,6 +463,7 @@ mod tests {
476463 use linux_loader:: loader:: bootparam:: boot_e820_entry;
477464
478465 use super :: * ;
466+ use crate :: device_manager:: resources:: ResourceAllocator ;
479467 use crate :: test_utils:: { arch_mem, single_region_mem} ;
480468
481469 #[ test]
@@ -499,94 +487,35 @@ mod tests {
499487 let no_vcpus = 4 ;
500488 let gm = single_region_mem ( 0x10000 ) ;
501489 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
502- let config_err = configure_system (
503- & gm,
504- & mut resource_allocator,
505- GuestAddress ( 0 ) ,
506- 0 ,
507- & None ,
508- 1 ,
509- BootProtocol :: LinuxBoot ,
510- ) ;
490+ let err = mptable:: setup_mptable ( & gm, & mut resource_allocator, 1 ) ;
511491 assert ! ( matches!(
512- config_err . unwrap_err( ) ,
513- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
492+ err . unwrap_err( ) ,
493+ mptable:: MptableError :: NotEnoughMemory
514494 ) ) ;
515495
516496 // Now assigning some memory that falls before the 32bit memory hole.
517497 let mem_size = mib_to_bytes ( 128 ) ;
518498 let gm = arch_mem ( mem_size) ;
519499 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
520- configure_system (
521- & gm,
522- & mut resource_allocator,
523- GuestAddress ( 0 ) ,
524- 0 ,
525- & None ,
526- no_vcpus,
527- BootProtocol :: LinuxBoot ,
528- )
529- . unwrap ( ) ;
530- configure_system (
531- & gm,
532- & mut resource_allocator,
533- GuestAddress ( 0 ) ,
534- 0 ,
535- & None ,
536- no_vcpus,
537- BootProtocol :: PvhBoot ,
538- )
539- . unwrap ( ) ;
500+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
501+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
502+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
540503
541504 // Now assigning some memory that is equal to the start of the 32bit memory hole.
542505 let mem_size = mib_to_bytes ( 3328 ) ;
543506 let gm = arch_mem ( mem_size) ;
544507 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
545- configure_system (
546- & gm,
547- & mut resource_allocator,
548- GuestAddress ( 0 ) ,
549- 0 ,
550- & None ,
551- no_vcpus,
552- BootProtocol :: LinuxBoot ,
553- )
554- . unwrap ( ) ;
555- configure_system (
556- & gm,
557- & mut resource_allocator,
558- GuestAddress ( 0 ) ,
559- 0 ,
560- & None ,
561- no_vcpus,
562- BootProtocol :: PvhBoot ,
563- )
564- . unwrap ( ) ;
508+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
509+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
510+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
565511
566512 // Now assigning some memory that falls after the 32bit memory hole.
567513 let mem_size = mib_to_bytes ( 3330 ) ;
568514 let gm = arch_mem ( mem_size) ;
569515 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
570- configure_system (
571- & gm,
572- & mut resource_allocator,
573- GuestAddress ( 0 ) ,
574- 0 ,
575- & None ,
576- no_vcpus,
577- BootProtocol :: LinuxBoot ,
578- )
579- . unwrap ( ) ;
580- configure_system (
581- & gm,
582- & mut resource_allocator,
583- GuestAddress ( 0 ) ,
584- 0 ,
585- & None ,
586- no_vcpus,
587- BootProtocol :: PvhBoot ,
588- )
589- . unwrap ( ) ;
516+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
517+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
518+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
590519 }
591520
592521 #[ test]
0 commit comments