@@ -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
@@ -1034,13 +1044,23 @@ fn attach_balloon_device(
10341044 attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
10351045}
10361046
1047+ #[ cfg( target_arch = "x86_64" ) ]
10371048fn attach_cpu_container_device ( vmm : & mut Vmm , vcpu_count : u8 ) -> Result < ( ) , StartMicrovmError > {
10381049 let cpu_container = Arc :: new ( Mutex :: new ( CpuContainer :: new (
10391050 & mut vmm. resource_allocator ,
10401051 vcpu_count,
10411052 ) ?) ) ;
10421053 vmm. acpi_device_manager
1043- . attach_cpu_container ( cpu_container. clone ( ) , vmm. vm . fd ( ) ) ;
1054+ . attach_cpu_container ( cpu_container. clone ( ) , vmm. vm . fd ( ) )
1055+ . map_err ( StartMicrovmError :: AttachCpuContainerDevice ) ?;
1056+ vmm. mmio_device_manager
1057+ . register_mmio_cpu_container_for_boot (
1058+ vmm. vm . fd ( ) ,
1059+ & mut vmm. resource_allocator ,
1060+ cpu_container,
1061+ )
1062+ . map_err ( StartMicrovmError :: RegisterMmioDevice ) ?;
1063+
10441064 Ok ( ( ) )
10451065}
10461066
@@ -1154,10 +1174,13 @@ pub mod tests {
11541174 #[ cfg( target_arch = "aarch64" ) ]
11551175 let resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
11561176
1177+ #[ cfg( target_arch = "x86_64" ) ]
1178+ let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
1179+ #[ cfg( target_arch = "aarch64" ) ]
11571180 let mmio_device_manager = MMIODeviceManager :: new ( ) ;
11581181
11591182 #[ cfg( target_arch = "x86_64" ) ]
1160- let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1183+ let mut acpi_device_manager = ACPIDeviceManager :: new ( ) ;
11611184
11621185 #[ cfg( target_arch = "x86_64" ) ]
11631186 let pio_device_manager = PortIODeviceManager :: new (
@@ -1175,15 +1198,22 @@ pub mod tests {
11751198 )
11761199 . unwrap ( ) ;
11771200
1178- #[ cfg( target_arch = "x86_64" ) ]
1179- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1180-
11811201 #[ cfg( target_arch = "x86_64" ) ]
11821202 {
1203+ setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
11831204 let cpu_container = Arc :: new ( Mutex :: new (
11841205 CpuContainer :: new ( & mut resource_allocator, 1 ) . unwrap ( ) ,
11851206 ) ) ;
1186- acpi_device_manager. attach_cpu_container ( cpu_container. clone , vm. fd ( ) )
1207+ acpi_device_manager
1208+ . attach_cpu_container ( cpu_container. clone ( ) , vm. fd ( ) )
1209+ . unwrap ( ) ;
1210+ mmio_device_manager
1211+ . register_mmio_cpu_container_for_boot (
1212+ vm. fd ( ) ,
1213+ & mut resource_allocator,
1214+ cpu_container,
1215+ )
1216+ . unwrap ( ) ;
11871217 }
11881218
11891219 #[ cfg( target_arch = "aarch64" ) ]
0 commit comments