@@ -38,6 +38,7 @@ use crate::cpu_config::templates::{
38
38
CpuConfiguration , CustomCpuTemplate , GetCpuTemplate , GetCpuTemplateError , GuestConfigError ,
39
39
KvmCapability ,
40
40
} ;
41
+ use crate :: cpu_config:: x86_64:: cpuid:: { self , Cpuid } ;
41
42
#[ cfg( target_arch = "x86_64" ) ]
42
43
use crate :: device_manager:: acpi:: ACPIDeviceManager ;
43
44
#[ cfg( target_arch = "x86_64" ) ]
@@ -86,6 +87,9 @@ pub enum StartMicrovmError {
86
87
/// Unable to attach the VMGenID device: {0}
87
88
#[ cfg( target_arch = "x86_64" ) ]
88
89
AttachVmgenidDevice ( kvm_ioctls:: Error ) ,
90
+ /// Unable to attach the CpuContainer device: {0}
91
+ #[ cfg( target_arch = "x86_64" ) ]
92
+ AttachCpuContainerDevice ( kvm_ioctls:: Error ) ,
89
93
/// System configuration error: {0}
90
94
ConfigureSystem ( crate :: arch:: ConfigurationError ) ,
91
95
/// Failed to create guest config: {0}
@@ -179,10 +183,10 @@ fn create_vmm_and_vcpus(
179
183
. map_err ( VmmError :: EventFd )
180
184
. map_err ( Internal ) ?;
181
185
182
- let mut resource_allocator = ResourceAllocator :: new ( ) ?;
186
+ let resource_allocator = ResourceAllocator :: new ( ) ?;
183
187
184
188
// Instantiate the MMIO device manager.
185
- let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
189
+ let mmio_device_manager = MMIODeviceManager :: new ( ) ;
186
190
187
191
// Instantiate ACPI device manager.
188
192
#[ cfg( target_arch = "x86_64" ) ]
@@ -553,14 +557,20 @@ pub fn build_microvm_from_snapshot(
553
557
554
558
#[ cfg( target_arch = "x86_64" ) ]
555
559
{
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
+ } ;
561
570
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
+ }
564
574
565
575
// Inject the notification to VMGenID that we have resumed from a snapshot.
566
576
// 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
1040
1050
vcpu_count,
1041
1051
) ?) ) ;
1042
1052
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
+
1044
1063
Ok ( ( ) )
1045
1064
}
1046
1065
@@ -1154,10 +1173,13 @@ pub mod tests {
1154
1173
#[ cfg( target_arch = "aarch64" ) ]
1155
1174
let resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
1156
1175
1176
+ #[ cfg( target_arch = "x86_64" ) ]
1177
+ let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
1178
+ #[ cfg( target_arch = "aarch64" ) ]
1157
1179
let mmio_device_manager = MMIODeviceManager :: new ( ) ;
1158
1180
1159
1181
#[ cfg( target_arch = "x86_64" ) ]
1160
- let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1182
+ let mut acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1161
1183
1162
1184
#[ cfg( target_arch = "x86_64" ) ]
1163
1185
let pio_device_manager = PortIODeviceManager :: new (
@@ -1175,15 +1197,22 @@ pub mod tests {
1175
1197
)
1176
1198
. unwrap ( ) ;
1177
1199
1178
- #[ cfg( target_arch = "x86_64" ) ]
1179
- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1180
-
1181
1200
#[ cfg( target_arch = "x86_64" ) ]
1182
1201
{
1202
+ setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1183
1203
let cpu_container = Arc :: new ( Mutex :: new (
1184
1204
CpuContainer :: new ( & mut resource_allocator, 1 ) . unwrap ( ) ,
1185
1205
) ) ;
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 ( ) ;
1187
1216
}
1188
1217
1189
1218
#[ cfg( target_arch = "aarch64" ) ]
0 commit comments