@@ -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
@@ -206,32 +219,6 @@ pub fn configure_system_for_boot(
206
219
Ok ( ( ) )
207
220
}
208
221
209
- /// Configures the system and should be called once per vm before starting vcpu threads.
210
- fn configure_system (
211
- guest_mem : & GuestMemoryMmap ,
212
- resource_allocator : & mut ResourceAllocator ,
213
- cmdline_addr : GuestAddress ,
214
- cmdline_size : usize ,
215
- initrd : & Option < InitrdConfig > ,
216
- num_cpus : u8 ,
217
- boot_prot : BootProtocol ,
218
- ) -> Result < ( ) , ConfigurationError > {
219
- // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
220
- mptable:: setup_mptable ( guest_mem, resource_allocator, num_cpus)
221
- . map_err ( ConfigurationError :: MpTableSetup ) ?;
222
-
223
- match boot_prot {
224
- BootProtocol :: PvhBoot => {
225
- configure_pvh ( guest_mem, cmdline_addr, initrd) ?;
226
- }
227
- BootProtocol :: LinuxBoot => {
228
- configure_64bit_boot ( guest_mem, cmdline_addr, cmdline_size, initrd) ?;
229
- }
230
- }
231
-
232
- Ok ( ( ) )
233
- }
234
-
235
222
fn configure_pvh (
236
223
guest_mem : & GuestMemoryMmap ,
237
224
cmdline_addr : GuestAddress ,
@@ -473,6 +460,7 @@ mod tests {
473
460
use linux_loader:: loader:: bootparam:: boot_e820_entry;
474
461
475
462
use super :: * ;
463
+ use crate :: device_manager:: resources:: ResourceAllocator ;
476
464
use crate :: test_utils:: { arch_mem, single_region_mem} ;
477
465
478
466
#[ test]
@@ -496,94 +484,35 @@ mod tests {
496
484
let no_vcpus = 4 ;
497
485
let gm = single_region_mem ( 0x10000 ) ;
498
486
let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
499
- let config_err = configure_system (
500
- & gm,
501
- & mut resource_allocator,
502
- GuestAddress ( 0 ) ,
503
- 0 ,
504
- & None ,
505
- 1 ,
506
- BootProtocol :: LinuxBoot ,
507
- ) ;
487
+ let err = mptable:: setup_mptable ( & gm, & mut resource_allocator, 1 ) ;
508
488
assert ! ( matches!(
509
- config_err . unwrap_err( ) ,
510
- super :: ConfigurationError :: MpTableSetup ( mptable:: MptableError :: NotEnoughMemory )
489
+ err . unwrap_err( ) ,
490
+ mptable:: MptableError :: NotEnoughMemory
511
491
) ) ;
512
492
513
493
// Now assigning some memory that falls before the 32bit memory hole.
514
494
let mem_size = mib_to_bytes ( 128 ) ;
515
495
let gm = arch_mem ( mem_size) ;
516
496
let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
517
- configure_system (
518
- & gm,
519
- & mut resource_allocator,
520
- GuestAddress ( 0 ) ,
521
- 0 ,
522
- & None ,
523
- no_vcpus,
524
- BootProtocol :: LinuxBoot ,
525
- )
526
- . unwrap ( ) ;
527
- configure_system (
528
- & gm,
529
- & mut resource_allocator,
530
- GuestAddress ( 0 ) ,
531
- 0 ,
532
- & None ,
533
- no_vcpus,
534
- BootProtocol :: PvhBoot ,
535
- )
536
- . unwrap ( ) ;
497
+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
498
+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
499
+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
537
500
538
501
// Now assigning some memory that is equal to the start of the 32bit memory hole.
539
502
let mem_size = mib_to_bytes ( 3328 ) ;
540
503
let gm = arch_mem ( mem_size) ;
541
504
let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
542
- configure_system (
543
- & gm,
544
- & mut resource_allocator,
545
- GuestAddress ( 0 ) ,
546
- 0 ,
547
- & None ,
548
- no_vcpus,
549
- BootProtocol :: LinuxBoot ,
550
- )
551
- . unwrap ( ) ;
552
- configure_system (
553
- & gm,
554
- & mut resource_allocator,
555
- GuestAddress ( 0 ) ,
556
- 0 ,
557
- & None ,
558
- no_vcpus,
559
- BootProtocol :: PvhBoot ,
560
- )
561
- . unwrap ( ) ;
505
+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
506
+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
507
+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
562
508
563
509
// Now assigning some memory that falls after the 32bit memory hole.
564
510
let mem_size = mib_to_bytes ( 3330 ) ;
565
511
let gm = arch_mem ( mem_size) ;
566
512
let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
567
- configure_system (
568
- & gm,
569
- & mut resource_allocator,
570
- GuestAddress ( 0 ) ,
571
- 0 ,
572
- & None ,
573
- no_vcpus,
574
- BootProtocol :: LinuxBoot ,
575
- )
576
- . unwrap ( ) ;
577
- configure_system (
578
- & gm,
579
- & mut resource_allocator,
580
- GuestAddress ( 0 ) ,
581
- 0 ,
582
- & None ,
583
- no_vcpus,
584
- BootProtocol :: PvhBoot ,
585
- )
586
- . unwrap ( ) ;
513
+ mptable:: setup_mptable ( & gm, & mut resource_allocator, no_vcpus) . unwrap ( ) ;
514
+ configure_64bit_boot ( & gm, GuestAddress ( 0 ) , 0 , & None ) . unwrap ( ) ;
515
+ configure_pvh ( & gm, GuestAddress ( 0 ) , & None ) . unwrap ( ) ;
587
516
}
588
517
589
518
#[ test]
0 commit comments