@@ -22,15 +22,17 @@ use std::fs::File;
22
22
23
23
use linux_loader:: loader:: pe:: PE as Loader ;
24
24
use linux_loader:: loader:: { Cmdline , KernelLoader } ;
25
- use vm_memory:: GuestMemoryError ;
25
+ use vm_memory:: { GuestMemoryError , GuestMemoryRegion } ;
26
26
27
27
use crate :: arch:: { BootProtocol , EntryPoint , arch_memory_regions_with_gap} ;
28
28
use crate :: cpu_config:: aarch64:: { CpuConfiguration , CpuConfigurationError } ;
29
29
use crate :: cpu_config:: templates:: CustomCpuTemplate ;
30
30
use crate :: initrd:: InitrdConfig ;
31
31
use crate :: utils:: { align_up, u64_to_usize, usize_to_u64} ;
32
32
use crate :: vmm_config:: machine_config:: MachineConfig ;
33
- use crate :: vstate:: memory:: { Address , Bytes , GuestAddress , GuestMemory , GuestMemoryMmap } ;
33
+ use crate :: vstate:: memory:: {
34
+ Address , Bytes , GuestAddress , GuestMemory , GuestMemoryMmap , GuestRegionType ,
35
+ } ;
34
36
use crate :: vstate:: vcpu:: KvmVcpuError ;
35
37
use crate :: { DeviceManager , Kvm , Vcpu , VcpuConfig , Vm , logger} ;
36
38
@@ -151,31 +153,29 @@ pub fn initrd_load_addr(guest_mem: &GuestMemoryMmap, initrd_size: usize) -> Opti
151
153
usize_to_u64 ( initrd_size) ,
152
154
usize_to_u64 ( super :: GUEST_PAGE_SIZE ) ,
153
155
) ;
154
- match GuestAddress ( get_fdt_addr ( guest_mem) ) . checked_sub ( rounded_size) {
155
- Some ( offset) => {
156
- if guest_mem. address_in_range ( offset) {
157
- Some ( offset. raw_value ( ) )
158
- } else {
159
- None
160
- }
161
- }
162
- None => None ,
163
- }
156
+ GuestAddress ( get_fdt_addr ( guest_mem) )
157
+ . checked_sub ( rounded_size)
158
+ . filter ( |& addr| guest_mem. address_in_range ( addr) )
159
+ . map ( |addr| addr. raw_value ( ) )
164
160
}
165
161
166
162
// Auxiliary function to get the address where the device tree blob is loaded.
167
163
fn get_fdt_addr ( mem : & GuestMemoryMmap ) -> u64 {
164
+ // Find the first (and only) DRAM region.
165
+ let dram_region = mem
166
+ . iter ( )
167
+ . find ( |region| region. region_type == GuestRegionType :: Dram )
168
+ . unwrap ( ) ;
169
+
168
170
// If the memory allocated is smaller than the size allocated for the FDT,
169
171
// we return the start of the DRAM so that
170
172
// we allow the code to try and load the FDT.
171
-
172
- if let Some ( addr) = mem. last_addr ( ) . checked_sub ( layout:: FDT_MAX_SIZE as u64 - 1 )
173
- && mem. address_in_range ( addr)
174
- {
175
- return addr. raw_value ( ) ;
176
- }
177
-
178
- layout:: DRAM_MEM_START
173
+ dram_region
174
+ . last_addr ( )
175
+ . checked_sub ( layout:: FDT_MAX_SIZE as u64 - 1 )
176
+ . filter ( |& addr| mem. address_in_range ( addr) )
177
+ . map ( |addr| addr. raw_value ( ) )
178
+ . unwrap_or ( layout:: DRAM_MEM_START )
179
179
}
180
180
181
181
/// Load linux kernel into guest memory.
0 commit comments