@@ -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 ;
@@ -184,15 +184,28 @@ pub fn configure_system_for_boot(
184184 & boot_cmdline,
185185 )
186186 . map_err ( ConfigurationError :: LoadCommandline ) ?;
187- configure_system (
187+
188+ // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
189+ mptable:: setup_mptable (
188190 & vmm. guest_memory ,
189191 & mut vmm. resource_allocator ,
190- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
191- cmdline_size,
192- initrd,
193192 vcpu_config. vcpu_count ,
194- entry_point. protocol ,
195- ) ?;
193+ )
194+ . map_err ( ConfigurationError :: MpTableSetup ) ?;
195+
196+ match entry_point. protocol {
197+ BootProtocol :: PvhBoot => {
198+ configure_pvh ( & vmm. guest_memory , GuestAddress ( CMDLINE_START ) , initrd) ?;
199+ }
200+ BootProtocol :: LinuxBoot => {
201+ configure_64bit_boot (
202+ & vmm. guest_memory ,
203+ GuestAddress ( CMDLINE_START ) ,
204+ cmdline_size,
205+ initrd,
206+ ) ?;
207+ }
208+ }
196209
197210 // Create ACPI tables and write them in guest memory
198211 // For the time being we only support ACPI in x86_64
@@ -207,32 +220,6 @@ pub fn configure_system_for_boot(
207220 Ok ( ( ) )
208221}
209222
210- /// Configures the system and should be called once per vm before starting vcpu threads.
211- fn configure_system (
212- guest_mem : & GuestMemoryMmap ,
213- resource_allocator : & mut ResourceAllocator ,
214- cmdline_addr : GuestAddress ,
215- cmdline_size : usize ,
216- initrd : & Option < InitrdConfig > ,
217- num_cpus : u8 ,
218- boot_prot : BootProtocol ,
219- ) -> Result < ( ) , ConfigurationError > {
220- // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
221- mptable:: setup_mptable ( guest_mem, resource_allocator, num_cpus)
222- . map_err ( ConfigurationError :: MpTableSetup ) ?;
223-
224- match boot_prot {
225- BootProtocol :: PvhBoot => {
226- configure_pvh ( guest_mem, cmdline_addr, initrd) ?;
227- }
228- BootProtocol :: LinuxBoot => {
229- configure_64bit_boot ( guest_mem, cmdline_addr, cmdline_size, initrd) ?;
230- }
231- }
232-
233- Ok ( ( ) )
234- }
235-
236223fn configure_pvh (
237224 guest_mem : & GuestMemoryMmap ,
238225 cmdline_addr : GuestAddress ,
@@ -474,6 +461,7 @@ mod tests {
474461 use linux_loader:: loader:: bootparam:: boot_e820_entry;
475462
476463 use super :: * ;
464+ use crate :: device_manager:: resources:: ResourceAllocator ;
477465 use crate :: test_utils:: { arch_mem, single_region_mem} ;
478466
479467 #[ test]
@@ -497,94 +485,35 @@ mod tests {
497485 let no_vcpus = 4 ;
498486 let gm = single_region_mem ( 0x10000 ) ;
499487 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
500- let config_err = configure_system (
501- & gm,
502- & mut resource_allocator,
503- GuestAddress ( 0 ) ,
504- 0 ,
505- & None ,
506- 1 ,
507- BootProtocol :: LinuxBoot ,
508- ) ;
488+ let err = mptable:: setup_mptable ( & gm, & mut resource_allocator, 1 ) ;
509489 assert ! ( matches!(
510- config_err . unwrap_err( ) ,
511- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
490+ err . unwrap_err( ) ,
491+ mptable:: MptableError :: NotEnoughMemory
512492 ) ) ;
513493
514494 // Now assigning some memory that falls before the 32bit memory hole.
515495 let mem_size = mib_to_bytes ( 128 ) ;
516496 let gm = arch_mem ( mem_size) ;
517497 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
518- configure_system (
519- & gm,
520- & mut resource_allocator,
521- GuestAddress ( 0 ) ,
522- 0 ,
523- & None ,
524- no_vcpus,
525- BootProtocol :: LinuxBoot ,
526- )
527- . unwrap ( ) ;
528- configure_system (
529- & gm,
530- & mut resource_allocator,
531- GuestAddress ( 0 ) ,
532- 0 ,
533- & None ,
534- no_vcpus,
535- BootProtocol :: PvhBoot ,
536- )
537- . unwrap ( ) ;
498+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
499+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
500+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
538501
539502 // Now assigning some memory that is equal to the start of the 32bit memory hole.
540503 let mem_size = mib_to_bytes ( 3328 ) ;
541504 let gm = arch_mem ( mem_size) ;
542505 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
543- configure_system (
544- & gm,
545- & mut resource_allocator,
546- GuestAddress ( 0 ) ,
547- 0 ,
548- & None ,
549- no_vcpus,
550- BootProtocol :: LinuxBoot ,
551- )
552- . unwrap ( ) ;
553- configure_system (
554- & gm,
555- & mut resource_allocator,
556- GuestAddress ( 0 ) ,
557- 0 ,
558- & None ,
559- no_vcpus,
560- BootProtocol :: PvhBoot ,
561- )
562- . unwrap ( ) ;
506+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
507+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
508+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
563509
564510 // Now assigning some memory that falls after the 32bit memory hole.
565511 let mem_size = mib_to_bytes ( 3330 ) ;
566512 let gm = arch_mem ( mem_size) ;
567513 let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
568- configure_system (
569- & gm,
570- & mut resource_allocator,
571- GuestAddress ( 0 ) ,
572- 0 ,
573- & None ,
574- no_vcpus,
575- BootProtocol :: LinuxBoot ,
576- )
577- . unwrap ( ) ;
578- configure_system (
579- & gm,
580- & mut resource_allocator,
581- GuestAddress ( 0 ) ,
582- 0 ,
583- & None ,
584- no_vcpus,
585- BootProtocol :: PvhBoot ,
586- )
587- . unwrap ( ) ;
514+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
515+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
516+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
588517 }
589518
590519 #[ test]
0 commit comments