@@ -33,6 +33,7 @@ pub mod generated;
3333
3434use std:: fs:: File ;
3535
36+ use kvm:: Kvm ;
3637use layout:: {
3738 CMDLINE_START , FIRST_ADDR_PAST_32BITS , FIRST_ADDR_PAST_64BITS_MMIO , MMIO32_MEM_SIZE ,
3839 MMIO32_MEM_START , MMIO64_MEM_SIZE , MMIO64_MEM_START , PCI_MMCONFIG_SIZE , PCI_MMCONFIG_START ,
@@ -53,14 +54,15 @@ use crate::acpi::create_acpi_tables;
5354use crate :: arch:: { BootProtocol , SYSTEM_MEM_SIZE , SYSTEM_MEM_START , arch_memory_regions_with_gap} ;
5455use crate :: cpu_config:: templates:: { CustomCpuTemplate , GuestConfigError } ;
5556use crate :: cpu_config:: x86_64:: CpuConfiguration ;
57+ use crate :: device_manager:: DeviceManager ;
5658use crate :: initrd:: InitrdConfig ;
5759use crate :: utils:: { align_down, u64_to_usize, usize_to_u64} ;
5860use crate :: vmm_config:: machine_config:: MachineConfig ;
5961use crate :: vstate:: memory:: {
6062 Address , GuestAddress , GuestMemory , GuestMemoryMmap , GuestMemoryRegion ,
6163} ;
6264use crate :: vstate:: vcpu:: KvmVcpuConfigureError ;
63- use crate :: { Vcpu , VcpuConfig , Vmm , logger} ;
65+ use crate :: { Vcpu , VcpuConfig , Vm , logger} ;
6466
6567// Value taken from https://elixir.bootlin.com/linux/v5.10.68/source/arch/x86/include/uapi/asm/e820.h#L31
6668// Usable normal RAM
@@ -169,8 +171,11 @@ pub fn initrd_load_addr(guest_mem: &GuestMemoryMmap, initrd_size: usize) -> Opti
169171}
170172
171173/// Configures the system for booting Linux.
174+ #[ allow( clippy:: too_many_arguments) ]
172175pub fn configure_system_for_boot (
173- vmm : & mut Vmm ,
176+ kvm : & Kvm ,
177+ vm : & Vm ,
178+ device_manager : & mut DeviceManager ,
174179 vcpus : & mut [ Vcpu ] ,
175180 machine_config : & MachineConfig ,
176181 cpu_template : & CustomCpuTemplate ,
@@ -179,8 +184,7 @@ pub fn configure_system_for_boot(
179184 boot_cmdline : Cmdline ,
180185) -> Result < ( ) , ConfigurationError > {
181186 // Construct the base CpuConfiguration to apply CPU template onto.
182- let cpu_config =
183- CpuConfiguration :: new ( vmm. kvm . supported_cpuid . clone ( ) , cpu_template, & vcpus[ 0 ] ) ?;
187+ let cpu_config = CpuConfiguration :: new ( kvm. supported_cpuid . clone ( ) , cpu_template, & vcpus[ 0 ] ) ?;
184188 // Apply CPU template to the base CpuConfiguration.
185189 let cpu_config = CpuConfiguration :: apply_template ( cpu_config, cpu_template) ?;
186190
@@ -193,7 +197,7 @@ pub fn configure_system_for_boot(
193197 // Configure vCPUs with normalizing and setting the generated CPU configuration.
194198 for vcpu in vcpus. iter_mut ( ) {
195199 vcpu. kvm_vcpu
196- . configure ( vmm . vm . guest_memory ( ) , entry_point, & vcpu_config) ?;
200+ . configure ( vm. guest_memory ( ) , entry_point, & vcpu_config) ?;
197201 }
198202
199203 // Write the kernel command line to guest memory. This is x86_64 specific, since on
@@ -204,27 +208,27 @@ pub fn configure_system_for_boot(
204208 . expect ( "Cannot create cstring from cmdline string" ) ;
205209
206210 load_cmdline (
207- vmm . vm . guest_memory ( ) ,
211+ vm. guest_memory ( ) ,
208212 GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
209213 & boot_cmdline,
210214 )
211215 . map_err ( ConfigurationError :: LoadCommandline ) ?;
212216
213217 // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
214218 mptable:: setup_mptable (
215- vmm . vm . guest_memory ( ) ,
216- & vmm . device_manager . resource_allocator ,
219+ vm. guest_memory ( ) ,
220+ & device_manager. resource_allocator ,
217221 vcpu_config. vcpu_count ,
218222 )
219223 . map_err ( ConfigurationError :: MpTableSetup ) ?;
220224
221225 match entry_point. protocol {
222226 BootProtocol :: PvhBoot => {
223- configure_pvh ( vmm . vm . guest_memory ( ) , GuestAddress ( CMDLINE_START ) , initrd) ?;
227+ configure_pvh ( vm. guest_memory ( ) , GuestAddress ( CMDLINE_START ) , initrd) ?;
224228 }
225229 BootProtocol :: LinuxBoot => {
226230 configure_64bit_boot (
227- vmm . vm . guest_memory ( ) ,
231+ vm. guest_memory ( ) ,
228232 GuestAddress ( CMDLINE_START ) ,
229233 cmdline_size,
230234 initrd,
@@ -234,7 +238,7 @@ pub fn configure_system_for_boot(
234238
235239 // Create ACPI tables and write them in guest memory
236240 // For the time being we only support ACPI in x86_64
237- create_acpi_tables ( vmm . vm . guest_memory ( ) , & mut vmm . device_manager , vcpus) ?;
241+ create_acpi_tables ( vm. guest_memory ( ) , device_manager, vcpus) ?;
238242 Ok ( ( ) )
239243}
240244
0 commit comments