@@ -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 ;
@@ -183,15 +183,28 @@ pub fn configure_system_for_boot(
183
183
& boot_cmdline,
184
184
)
185
185
. 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 (
187
189
& vmm. guest_memory ,
188
190
& mut vmm. resource_allocator ,
189
- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
190
- cmdline_size,
191
- initrd,
192
191
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
+ }
195
208
196
209
// Create ACPI tables and write them in guest memory
197
210
// For the time being we only support ACPI in x86_64
@@ -205,32 +218,6 @@ pub fn configure_system_for_boot(
205
218
Ok ( ( ) )
206
219
}
207
220
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
-
234
221
fn configure_pvh (
235
222
guest_mem : & GuestMemoryMmap ,
236
223
cmdline_addr : GuestAddress ,
@@ -472,6 +459,7 @@ mod tests {
472
459
use linux_loader:: loader:: bootparam:: boot_e820_entry;
473
460
474
461
use super :: * ;
462
+ use crate :: device_manager:: resources:: ResourceAllocator ;
475
463
use crate :: test_utils:: { arch_mem, single_region_mem} ;
476
464
477
465
#[ test]
@@ -495,94 +483,35 @@ mod tests {
495
483
let no_vcpus = 4 ;
496
484
let gm = single_region_mem ( 0x10000 ) ;
497
485
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 ) ;
507
487
assert ! ( matches!(
508
- config_err . unwrap_err( ) ,
509
- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
488
+ err . unwrap_err( ) ,
489
+ mptable:: MptableError :: NotEnoughMemory
510
490
) ) ;
511
491
512
492
// Now assigning some memory that falls before the 32bit memory hole.
513
493
let mem_size = mib_to_bytes ( 128 ) ;
514
494
let gm = arch_mem ( mem_size) ;
515
495
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 ( ) ;
536
499
537
500
// Now assigning some memory that is equal to the start of the 32bit memory hole.
538
501
let mem_size = mib_to_bytes ( 3328 ) ;
539
502
let gm = arch_mem ( mem_size) ;
540
503
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 ( ) ;
561
507
562
508
// Now assigning some memory that falls after the 32bit memory hole.
563
509
let mem_size = mib_to_bytes ( 3330 ) ;
564
510
let gm = arch_mem ( mem_size) ;
565
511
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 ( ) ;
586
515
}
587
516
588
517
#[ test]
0 commit comments