@@ -38,6 +38,7 @@ use crate::cpu_config::templates::{
3838 CpuConfiguration , CustomCpuTemplate , GetCpuTemplate , GetCpuTemplateError , GuestConfigError ,
3939 KvmCapability ,
4040} ;
41+ use crate :: cpu_config:: x86_64:: cpuid:: { self , Cpuid } ;
4142#[ cfg( target_arch = "x86_64" ) ]
4243use crate :: device_manager:: acpi:: ACPIDeviceManager ;
4344#[ cfg( target_arch = "x86_64" ) ]
@@ -86,6 +87,9 @@ pub enum StartMicrovmError {
8687 /// Unable to attach the VMGenID device: {0}
8788 #[ cfg( target_arch = "x86_64" ) ]
8889 AttachVmgenidDevice ( kvm_ioctls:: Error ) ,
90+ /// Unable to attach the CpuContainer device: {0}
91+ #[ cfg( target_arch = "x86_64" ) ]
92+ AttachCpuContainerDevice ( kvm_ioctls:: Error ) ,
8993 /// System configuration error: {0}
9094 ConfigureSystem ( crate :: arch:: ConfigurationError ) ,
9195 /// Failed to create guest config: {0}
@@ -179,10 +183,10 @@ fn create_vmm_and_vcpus(
179183 . map_err ( VmmError :: EventFd )
180184 . map_err ( Internal ) ?;
181185
182- let mut resource_allocator = ResourceAllocator :: new ( ) ?;
186+ let resource_allocator = ResourceAllocator :: new ( ) ?;
183187
184188 // Instantiate the MMIO device manager.
185- let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
189+ let mmio_device_manager = MMIODeviceManager :: new ( ) ;
186190
187191 // Instantiate ACPI device manager.
188192 #[ cfg( target_arch = "x86_64" ) ]
@@ -553,14 +557,20 @@ pub fn build_microvm_from_snapshot(
553557
554558 #[ cfg( target_arch = "x86_64" ) ]
555559 {
556- let acpi_ctor_args = ACPIDeviceManagerConstructorArgs {
557- mem : & guest_memory,
558- resource_allocator : & mut vmm. resource_allocator ,
559- vm : vmm. vm . fd ( ) ,
560- } ;
560+ if let Some ( BusDevice :: CpuContainer ( container) ) =
561+ vmm. get_bus_device ( DeviceType :: CpuContainer , "CpuContainer" )
562+ {
563+ let container_ref = container. clone ( ) ;
564+ let acpi_ctor_args = ACPIDeviceManagerConstructorArgs {
565+ mem : & guest_memory,
566+ resource_allocator : & mut vmm. resource_allocator ,
567+ vm : vmm. vm . fd ( ) ,
568+ cpu_container : container_ref,
569+ } ;
561570
562- vmm. acpi_device_manager =
563- ACPIDeviceManager :: restore ( acpi_ctor_args, & microvm_state. acpi_dev_state ) ?;
571+ vmm. acpi_device_manager =
572+ ACPIDeviceManager :: restore ( acpi_ctor_args, & microvm_state. acpi_dev_state ) ?;
573+ }
564574
565575 // Inject the notification to VMGenID that we have resumed from a snapshot.
566576 // This needs to happen before we resume vCPUs, so that we minimize the time between vCPUs
@@ -1040,7 +1050,16 @@ fn attach_cpu_container_device(vmm: &mut Vmm, vcpu_count: u8) -> Result<(), Star
10401050 vcpu_count,
10411051 ) ?) ) ;
10421052 vmm. acpi_device_manager
1043- . attach_cpu_container ( cpu_container. clone ( ) , vmm. vm . fd ( ) ) ;
1053+ . attach_cpu_container ( cpu_container. clone ( ) , vmm. vm . fd ( ) )
1054+ . map_err ( StartMicrovmError :: AttachCpuContainerDevice ) ?;
1055+ vmm. mmio_device_manager
1056+ . register_mmio_cpu_container_for_boot (
1057+ vmm. vm . fd ( ) ,
1058+ & mut vmm. resource_allocator ,
1059+ cpu_container,
1060+ )
1061+ . map_err ( StartMicrovmError :: RegisterMmioDevice ) ?;
1062+
10441063 Ok ( ( ) )
10451064}
10461065
@@ -1154,10 +1173,13 @@ pub mod tests {
11541173 #[ cfg( target_arch = "aarch64" ) ]
11551174 let resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
11561175
1176+ #[ cfg( target_arch = "x86_64" ) ]
1177+ let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
1178+ #[ cfg( target_arch = "aarch64" ) ]
11571179 let mmio_device_manager = MMIODeviceManager :: new ( ) ;
11581180
11591181 #[ cfg( target_arch = "x86_64" ) ]
1160- let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1182+ let mut acpi_device_manager = ACPIDeviceManager :: new ( ) ;
11611183
11621184 #[ cfg( target_arch = "x86_64" ) ]
11631185 let pio_device_manager = PortIODeviceManager :: new (
@@ -1175,15 +1197,22 @@ pub mod tests {
11751197 )
11761198 . unwrap ( ) ;
11771199
1178- #[ cfg( target_arch = "x86_64" ) ]
1179- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1180-
11811200 #[ cfg( target_arch = "x86_64" ) ]
11821201 {
1202+ setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
11831203 let cpu_container = Arc :: new ( Mutex :: new (
11841204 CpuContainer :: new ( & mut resource_allocator, 1 ) . unwrap ( ) ,
11851205 ) ) ;
1186- acpi_device_manager. attach_cpu_container ( cpu_container. clone , vm. fd ( ) )
1206+ acpi_device_manager
1207+ . attach_cpu_container ( cpu_container. clone ( ) , vm. fd ( ) )
1208+ . unwrap ( ) ;
1209+ mmio_device_manager
1210+ . register_mmio_cpu_container_for_boot (
1211+ vm. fd ( ) ,
1212+ & mut resource_allocator,
1213+ cpu_container,
1214+ )
1215+ . unwrap ( ) ;
11871216 }
11881217
11891218 #[ cfg( target_arch = "aarch64" ) ]
0 commit comments