@@ -33,6 +33,7 @@ pub mod generated;
33
33
34
34
use std:: fs:: File ;
35
35
36
+ use layout:: CMDLINE_START ;
36
37
use linux_loader:: configurator:: linux:: LinuxBootConfigurator ;
37
38
use linux_loader:: configurator:: pvh:: PvhBootConfigurator ;
38
39
use linux_loader:: configurator:: { BootConfigurator , BootParams } ;
@@ -49,7 +50,6 @@ use crate::acpi::create_acpi_tables;
49
50
use crate :: arch:: { BootProtocol , SYSTEM_MEM_SIZE , SYSTEM_MEM_START } ;
50
51
use crate :: cpu_config:: templates:: { CustomCpuTemplate , GuestConfigError } ;
51
52
use crate :: cpu_config:: x86_64:: CpuConfiguration ;
52
- use crate :: device_manager:: resources:: ResourceAllocator ;
53
53
use crate :: initrd:: InitrdConfig ;
54
54
use crate :: utils:: { mib_to_bytes, u64_to_usize} ;
55
55
use crate :: vmm_config:: machine_config:: MachineConfig ;
@@ -184,15 +184,28 @@ pub fn configure_system_for_boot(
184
184
& boot_cmdline,
185
185
)
186
186
. 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 (
188
190
& vmm. guest_memory ,
189
191
& mut vmm. resource_allocator ,
190
- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
191
- cmdline_size,
192
- initrd,
193
192
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
+ }
196
209
197
210
// Create ACPI tables and write them in guest memory
198
211
// For the time being we only support ACPI in x86_64
@@ -207,32 +220,6 @@ pub fn configure_system_for_boot(
207
220
Ok ( ( ) )
208
221
}
209
222
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
-
236
223
fn configure_pvh (
237
224
guest_mem : & GuestMemoryMmap ,
238
225
cmdline_addr : GuestAddress ,
@@ -474,6 +461,7 @@ mod tests {
474
461
use linux_loader:: loader:: bootparam:: boot_e820_entry;
475
462
476
463
use super :: * ;
464
+ use crate :: device_manager:: resources:: ResourceAllocator ;
477
465
use crate :: test_utils:: { arch_mem, single_region_mem} ;
478
466
479
467
#[ test]
@@ -497,94 +485,35 @@ mod tests {
497
485
let no_vcpus = 4 ;
498
486
let gm = single_region_mem ( 0x10000 ) ;
499
487
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 ) ;
509
489
assert ! ( matches!(
510
- config_err . unwrap_err( ) ,
511
- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
490
+ err . unwrap_err( ) ,
491
+ mptable:: MptableError :: NotEnoughMemory
512
492
) ) ;
513
493
514
494
// Now assigning some memory that falls before the 32bit memory hole.
515
495
let mem_size = mib_to_bytes ( 128 ) ;
516
496
let gm = arch_mem ( mem_size) ;
517
497
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 ( ) ;
538
501
539
502
// Now assigning some memory that is equal to the start of the 32bit memory hole.
540
503
let mem_size = mib_to_bytes ( 3328 ) ;
541
504
let gm = arch_mem ( mem_size) ;
542
505
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 ( ) ;
563
509
564
510
// Now assigning some memory that falls after the 32bit memory hole.
565
511
let mem_size = mib_to_bytes ( 3330 ) ;
566
512
let gm = arch_mem ( mem_size) ;
567
513
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 ( ) ;
588
517
}
589
518
590
519
#[ test]
0 commit comments