@@ -31,12 +31,13 @@ pub mod xstate;
31
31
#[ allow( missing_docs) ]
32
32
pub mod generated;
33
33
34
+ use std:: cmp:: max;
34
35
use std:: fs:: File ;
35
36
36
37
use kvm:: Kvm ;
37
38
use layout:: {
38
- CMDLINE_START , FIRST_ADDR_PAST_32BITS , FIRST_ADDR_PAST_64BITS_MMIO , MMIO32_MEM_SIZE ,
39
- MMIO32_MEM_START , MMIO64_MEM_SIZE , MMIO64_MEM_START , PCI_MMCONFIG_SIZE , PCI_MMCONFIG_START ,
39
+ CMDLINE_START , MMIO32_MEM_SIZE , MMIO32_MEM_START , MMIO64_MEM_SIZE , MMIO64_MEM_START ,
40
+ PCI_MMCONFIG_SIZE , PCI_MMCONFIG_START ,
40
41
} ;
41
42
use linux_loader:: configurator:: linux:: LinuxBootConfigurator ;
42
43
use linux_loader:: configurator:: pvh:: PvhBootConfigurator ;
@@ -59,7 +60,7 @@ use crate::initrd::InitrdConfig;
59
60
use crate :: utils:: { align_down, u64_to_usize, usize_to_u64} ;
60
61
use crate :: vmm_config:: machine_config:: MachineConfig ;
61
62
use crate :: vstate:: memory:: {
62
- Address , GuestAddress , GuestMemory , GuestMemoryMmap , GuestMemoryRegion ,
63
+ Address , GuestAddress , GuestMemory , GuestMemoryMmap , GuestMemoryRegion , GuestRegionType ,
63
64
} ;
64
65
use crate :: vstate:: vcpu:: KvmVcpuConfigureError ;
65
66
use crate :: { Vcpu , VcpuConfig , Vm , logger} ;
@@ -253,10 +254,6 @@ fn configure_pvh(
253
254
initrd : & Option < InitrdConfig > ,
254
255
) -> Result < ( ) , ConfigurationError > {
255
256
const XEN_HVM_START_MAGIC_VALUE : u32 = 0x336e_c578 ;
256
- let first_addr_past_32bits = GuestAddress ( FIRST_ADDR_PAST_32BITS ) ;
257
- let end_32bit_gap_start = GuestAddress ( MMIO32_MEM_START ) ;
258
- let first_addr_past_64bits = GuestAddress ( FIRST_ADDR_PAST_64BITS_MMIO ) ;
259
- let end_64bit_gap_start = GuestAddress ( MMIO64_MEM_START ) ;
260
257
let himem_start = GuestAddress ( layout:: HIMEM_START ) ;
261
258
262
259
// Vector to hold modules (currently either empty or holding initrd).
@@ -294,36 +291,21 @@ fn configure_pvh(
294
291
type_ : E820_RESERVED ,
295
292
..Default :: default ( )
296
293
} ) ;
297
- let last_addr = guest_mem. last_addr ( ) ;
298
294
299
- if last_addr > first_addr_past_64bits {
300
- memmap. push ( hvm_memmap_table_entry {
301
- addr : first_addr_past_64bits. raw_value ( ) ,
302
- size : last_addr. unchecked_offset_from ( first_addr_past_64bits) + 1 ,
303
- type_ : MEMMAP_TYPE_RAM ,
304
- ..Default :: default ( )
305
- } ) ;
306
- }
307
-
308
- if last_addr > first_addr_past_32bits {
295
+ for region in guest_mem
296
+ . iter ( )
297
+ . filter ( |region| region. region_type ( ) == GuestRegionType :: Dram )
298
+ {
299
+ // the first 1MB is reserved for the kernel
300
+ let addr = max ( himem_start, region. start_addr ( ) ) ;
309
301
memmap. push ( hvm_memmap_table_entry {
310
- addr : first_addr_past_32bits. raw_value ( ) ,
311
- size : ( end_64bit_gap_start. unchecked_offset_from ( first_addr_past_32bits) )
312
- . min ( last_addr. unchecked_offset_from ( first_addr_past_32bits) + 1 ) ,
302
+ addr : addr. raw_value ( ) ,
303
+ size : region. last_addr ( ) . unchecked_offset_from ( addr) + 1 ,
313
304
type_ : MEMMAP_TYPE_RAM ,
314
305
..Default :: default ( )
315
306
} ) ;
316
307
}
317
308
318
- memmap. push ( hvm_memmap_table_entry {
319
- addr : himem_start. raw_value ( ) ,
320
- size : end_32bit_gap_start
321
- . unchecked_offset_from ( himem_start)
322
- . min ( last_addr. unchecked_offset_from ( himem_start) + 1 ) ,
323
- type_ : MEMMAP_TYPE_RAM ,
324
- ..Default :: default ( )
325
- } ) ;
326
-
327
309
// Construct the hvm_start_info structure and serialize it into
328
310
// boot_params. This will be stored at PVH_INFO_START address, and %rbx
329
311
// will be initialized to contain PVH_INFO_START prior to starting the
@@ -368,10 +350,6 @@ fn configure_64bit_boot(
368
350
const KERNEL_HDR_MAGIC : u32 = 0x5372_6448 ;
369
351
const KERNEL_LOADER_OTHER : u8 = 0xff ;
370
352
const KERNEL_MIN_ALIGNMENT_BYTES : u32 = 0x0100_0000 ; // Must be non-zero.
371
- let first_addr_past_32bits = GuestAddress ( FIRST_ADDR_PAST_32BITS ) ;
372
- let end_32bit_gap_start = GuestAddress ( MMIO32_MEM_START ) ;
373
- let first_addr_past_64bits = GuestAddress ( FIRST_ADDR_PAST_64BITS_MMIO ) ;
374
- let end_64bit_gap_start = GuestAddress ( MMIO64_MEM_START ) ;
375
353
376
354
let himem_start = GuestAddress ( layout:: HIMEM_START ) ;
377
355
@@ -409,35 +387,20 @@ fn configure_64bit_boot(
409
387
E820_RESERVED ,
410
388
) ?;
411
389
412
- let last_addr = guest_mem. last_addr ( ) ;
413
-
414
- if last_addr > first_addr_past_64bits {
415
- add_e820_entry (
416
- & mut params,
417
- first_addr_past_64bits. raw_value ( ) ,
418
- last_addr. unchecked_offset_from ( first_addr_past_64bits) + 1 ,
419
- E820_RAM ,
420
- ) ?;
421
- }
422
-
423
- if last_addr > first_addr_past_32bits {
390
+ for region in guest_mem
391
+ . iter ( )
392
+ . filter ( |region| region. region_type ( ) == GuestRegionType :: Dram )
393
+ {
394
+ // the first 1MB is reserved for the kernel
395
+ let addr = max ( himem_start, region. start_addr ( ) ) ;
424
396
add_e820_entry (
425
397
& mut params,
426
- first_addr_past_32bits. raw_value ( ) ,
427
- ( end_64bit_gap_start. unchecked_offset_from ( first_addr_past_32bits) )
428
- . min ( last_addr. unchecked_offset_from ( first_addr_past_32bits) + 1 ) ,
398
+ addr. raw_value ( ) ,
399
+ region. last_addr ( ) . unchecked_offset_from ( addr) + 1 ,
429
400
E820_RAM ,
430
401
) ?;
431
402
}
432
403
433
- add_e820_entry (
434
- & mut params,
435
- himem_start. raw_value ( ) ,
436
- ( last_addr. unchecked_offset_from ( himem_start) + 1 )
437
- . min ( end_32bit_gap_start. unchecked_offset_from ( himem_start) ) ,
438
- E820_RAM ,
439
- ) ?;
440
-
441
404
LinuxBootConfigurator :: write_bootparams (
442
405
& BootParams :: new ( & params, GuestAddress ( layout:: ZERO_PAGE_START ) ) ,
443
406
guest_mem,
@@ -573,6 +536,7 @@ mod tests {
573
536
use linux_loader:: loader:: bootparam:: boot_e820_entry;
574
537
575
538
use super :: * ;
539
+ use crate :: arch:: x86_64:: layout:: FIRST_ADDR_PAST_32BITS ;
576
540
use crate :: test_utils:: { arch_mem, single_region_mem} ;
577
541
use crate :: utils:: mib_to_bytes;
578
542
use crate :: vstate:: resources:: ResourceAllocator ;
0 commit comments