@@ -42,7 +42,9 @@ use crate::construct_kvm_mpidrs;
42
42
use crate :: device_manager:: legacy:: PortIODeviceManager ;
43
43
use crate :: device_manager:: mmio:: MMIODeviceManager ;
44
44
use crate :: device_manager:: persist:: MMIODevManagerConstructorArgs ;
45
- use crate :: guest_config:: templates:: { GetCpuTemplate , GetCpuTemplateError , GuestConfigError } ;
45
+ use crate :: guest_config:: templates:: {
46
+ CpuConfiguration , GetCpuTemplate , GetCpuTemplateError , GuestConfigError ,
47
+ } ;
46
48
use crate :: persist:: { MicrovmState , MicrovmStateError } ;
47
49
use crate :: resources:: VmResources ;
48
50
use crate :: vmm_config:: boot_source:: BootConfig ;
@@ -785,38 +787,48 @@ pub fn configure_system_for_boot(
785
787
786
788
let cpu_template = vm_config. cpu_template . get_cpu_template ( ) ?;
787
789
790
+ // Construct the base CpuConfiguration to apply CPU template onto.
788
791
#[ cfg( target_arch = "x86_64" ) ]
789
- {
792
+ let cpu_config = {
790
793
use crate :: guest_config:: cpuid;
791
- // Construct the base CpuConfiguration to apply CPU template onto.
792
794
let cpuid = cpuid:: Cpuid :: try_from ( cpuid:: RawCpuid :: from ( vmm. vm . supported_cpuid ( ) . clone ( ) ) )
793
795
. map_err ( GuestConfigError :: CpuidFromRaw ) ?;
794
796
let msr_index_list = cpu_template. get_msr_index_list ( ) ;
795
797
let msrs = vcpus[ 0 ]
796
798
. kvm_vcpu
797
799
. get_msrs ( msr_index_list)
798
800
. map_err ( GuestConfigError :: VcpuIoctl ) ?;
799
- let cpu_config = crate :: guest_config:: x86_64:: CpuConfiguration { cpuid, msrs } ;
801
+ CpuConfiguration { cpuid, msrs }
802
+ } ;
800
803
801
- // Apply CPU template to the base CpuConfiguration.
802
- let cpu_config = crate :: guest_config:: x86_64:: CpuConfiguration :: apply_template (
803
- cpu_config,
804
- & cpu_template,
805
- ) ?;
804
+ #[ cfg( target_arch = "aarch64" ) ]
805
+ let cpu_config = {
806
+ let regs = vcpus[ 0 ]
807
+ . kvm_vcpu
808
+ . get_regs ( & cpu_template. reg_list ( ) )
809
+ . map_err ( GuestConfigError ) ?;
810
+ CpuConfiguration { regs }
811
+ } ;
806
812
807
- let vcpu_config = VcpuConfig {
808
- vcpu_count : vm_config. vcpu_count ,
809
- smt : vm_config. smt ,
810
- cpu_config,
811
- } ;
813
+ // Apply CPU template to the base CpuConfiguration.
814
+ let cpu_config = CpuConfiguration :: apply_template ( cpu_config, & cpu_template) ?;
812
815
813
- for vcpu in vcpus. iter_mut ( ) {
814
- vcpu. kvm_vcpu
815
- . configure ( vmm. guest_memory ( ) , entry_addr, & vcpu_config)
816
- . map_err ( Error :: VcpuConfigure )
817
- . map_err ( Internal ) ?;
818
- }
816
+ let vcpu_config = VcpuConfig {
817
+ vcpu_count : vm_config. vcpu_count ,
818
+ smt : vm_config. smt ,
819
+ cpu_config,
820
+ } ;
819
821
822
+ // Configure vCPUs with normalizing and setting the generated CPU configuration.
823
+ for vcpu in vcpus. iter_mut ( ) {
824
+ vcpu. kvm_vcpu
825
+ . configure ( vmm. guest_memory ( ) , entry_addr, & vcpu_config)
826
+ . map_err ( Error :: VcpuConfigure )
827
+ . map_err ( Internal ) ?;
828
+ }
829
+
830
+ #[ cfg( target_arch = "x86_64" ) ]
831
+ {
820
832
// Write the kernel command line to guest memory. This is x86_64 specific, since on
821
833
// aarch64 the command line will be specified through the FDT.
822
834
let cmdline_size = boot_cmdline
@@ -840,32 +852,6 @@ pub fn configure_system_for_boot(
840
852
}
841
853
#[ cfg( target_arch = "aarch64" ) ]
842
854
{
843
- // Construct the base CpuConfiguration to apply CPU template onto.
844
- let regs = vcpus[ 0 ]
845
- . kvm_vcpu
846
- . get_regs ( & cpu_template. reg_list ( ) )
847
- . map_err ( GuestConfigError ) ?;
848
- let cpu_config = crate :: guest_config:: aarch64:: CpuConfiguration { regs } ;
849
-
850
- // Apply CPU template to the base CpuConfiguration.
851
- let cpu_config = crate :: guest_config:: aarch64:: CpuConfiguration :: apply_template (
852
- cpu_config,
853
- & cpu_template,
854
- ) ?;
855
-
856
- let vcpu_config = VcpuConfig {
857
- vcpu_count : vm_config. vcpu_count ,
858
- smt : vm_config. smt ,
859
- cpu_config,
860
- } ;
861
-
862
- for vcpu in vcpus. iter_mut ( ) {
863
- vcpu. kvm_vcpu
864
- . configure ( vmm. guest_memory ( ) , entry_addr, & vcpu_config)
865
- . map_err ( Error :: VcpuConfigure )
866
- . map_err ( Internal ) ?;
867
- }
868
-
869
855
let vcpu_mpidr = vcpus
870
856
. iter_mut ( )
871
857
. map ( |cpu| cpu. kvm_vcpu . get_mpidr ( ) )
0 commit comments