@@ -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
@@ -1034,13 +1044,23 @@ fn attach_balloon_device(
1034
1044
attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
1035
1045
}
1036
1046
1047
+ #[ cfg( target_arch = "x86_64" ) ]
1037
1048
fn attach_cpu_container_device ( vmm : & mut Vmm , vcpu_count : u8 ) -> Result < ( ) , StartMicrovmError > {
1038
1049
let cpu_container = Arc :: new ( Mutex :: new ( CpuContainer :: new (
1039
1050
& mut vmm. resource_allocator ,
1040
1051
vcpu_count,
1041
1052
) ?) ) ;
1042
1053
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
+
1044
1064
Ok ( ( ) )
1045
1065
}
1046
1066
@@ -1154,10 +1174,13 @@ pub mod tests {
1154
1174
#[ cfg( target_arch = "aarch64" ) ]
1155
1175
let resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
1156
1176
1177
+ #[ cfg( target_arch = "x86_64" ) ]
1178
+ let mut mmio_device_manager = MMIODeviceManager :: new ( ) ;
1179
+ #[ cfg( target_arch = "aarch64" ) ]
1157
1180
let mmio_device_manager = MMIODeviceManager :: new ( ) ;
1158
1181
1159
1182
#[ cfg( target_arch = "x86_64" ) ]
1160
- let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1183
+ let mut acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1161
1184
1162
1185
#[ cfg( target_arch = "x86_64" ) ]
1163
1186
let pio_device_manager = PortIODeviceManager :: new (
@@ -1175,15 +1198,22 @@ pub mod tests {
1175
1198
)
1176
1199
. unwrap ( ) ;
1177
1200
1178
- #[ cfg( target_arch = "x86_64" ) ]
1179
- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1180
-
1181
1201
#[ cfg( target_arch = "x86_64" ) ]
1182
1202
{
1203
+ setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1183
1204
let cpu_container = Arc :: new ( Mutex :: new (
1184
1205
CpuContainer :: new ( & mut resource_allocator, 1 ) . unwrap ( ) ,
1185
1206
) ) ;
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 ( ) ;
1187
1217
}
1188
1218
1189
1219
#[ cfg( target_arch = "aarch64" ) ]
0 commit comments