@@ -19,7 +19,9 @@ use super::resources::ResourceAllocator;
19
19
#[ cfg( target_arch = "aarch64" ) ]
20
20
use crate :: arch:: DeviceType ;
21
21
#[ cfg( target_arch = "x86_64" ) ]
22
- use crate :: devices:: acpi:: cpu_container:: CpuContainer ;
22
+ use crate :: devices:: acpi:: cpu_container:: {
23
+ CpuContainer , CpuContainerConstructorArgs , CpuContainerError , CpuContainerState ,
24
+ } ;
23
25
#[ cfg( target_arch = "x86_64" ) ]
24
26
use crate :: devices:: acpi:: vmgenid:: { VMGenIDState , VMGenIdConstructorArgs , VmGenId , VmGenIdError } ;
25
27
use crate :: devices:: virtio:: balloon:: persist:: { BalloonConstructorArgs , BalloonState } ;
@@ -59,6 +61,9 @@ pub enum DevicePersistError {
59
61
Balloon ( #[ from] BalloonError ) ,
60
62
/// Block: {0}
61
63
Block ( #[ from] BlockError ) ,
64
+ /// CpuContainer: {0}
65
+ #[ cfg( target_arch = "x86_64" ) ]
66
+ CpuContainer ( #[ from] CpuContainerError ) ,
62
67
/// Device manager: {0}
63
68
DeviceManager ( #[ from] super :: mmio:: MmioError ) ,
64
69
/// Mmio transport
@@ -155,6 +160,13 @@ pub struct ConnectedLegacyState {
155
160
pub device_info : MMIODeviceInfo ,
156
161
}
157
162
163
+ #[ cfg( target_arch = "x86_64" ) ]
164
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
165
+ pub struct ConnectedCpuContainerState {
166
+ pub device_state : CpuContainerState ,
167
+ pub device_info : MMIODeviceInfo ,
168
+ }
169
+
158
170
/// Holds the MMDS data store version.
159
171
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
160
172
pub enum MmdsVersionState {
@@ -198,6 +210,9 @@ pub struct DeviceStates {
198
210
pub mmds_version : Option < MmdsVersionState > ,
199
211
/// Entropy device state.
200
212
pub entropy_device : Option < ConnectedEntropyState > ,
213
+ /// Cpu Container device state.
214
+ #[ cfg( target_arch = "x86_64" ) ]
215
+ pub cpu_container : Option < ConnectedCpuContainerState > ,
201
216
}
202
217
203
218
/// A type used to extract the concrete `Arc<Mutex<T>>` for each of the device
@@ -253,6 +268,9 @@ pub enum ACPIDeviceManagerRestoreError {
253
268
Interrupt ( #[ from] kvm_ioctls:: Error ) ,
254
269
/// Could not create VMGenID device: {0}
255
270
VMGenID ( #[ from] VmGenIdError ) ,
271
+ /// Could not create CpuContainer device: {0}
272
+ #[ cfg( target_arch = "x86_64" ) ]
273
+ CpuContainer ( #[ from] CpuContainerError ) ,
256
274
}
257
275
258
276
#[ cfg( target_arch = "x86_64" ) ]
@@ -292,11 +310,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
292
310
type Error = DevicePersistError ;
293
311
294
312
fn save ( & self ) -> Self :: State {
313
+ use crate :: devices:: bus:: BusDevice :: * ;
295
314
let mut states = DeviceStates :: default ( ) ;
315
+ #[ allow( unused_variables) ]
296
316
let _: Result < ( ) , ( ) > = self . for_each_device ( |devtype, devid, device_info, bus_dev| {
297
- if * devtype == crate :: arch:: DeviceType :: BootTimer {
298
- // No need to save BootTimer state.
299
- return Ok ( ( ) ) ;
317
+ match bus_dev {
318
+ BootTimer ( _) => return Ok ( ( ) ) ,
319
+ #[ cfg( target_arch = "x86_64" ) ]
320
+ CpuContainer ( x) => {
321
+ states. cpu_container = Some ( ConnectedCpuContainerState {
322
+ device_state : x. lock ( ) . expect ( "Poisoned lock" ) . save ( ) ,
323
+ device_info : device_info. clone ( ) ,
324
+ } ) ;
325
+ return Ok ( ( ) ) ;
326
+ }
327
+ _ => ( ) ,
300
328
}
301
329
302
330
#[ cfg( target_arch = "aarch64" ) ]
@@ -653,6 +681,17 @@ impl<'a> Persist<'a> for MMIODeviceManager {
653
681
) ?;
654
682
}
655
683
684
+ #[ cfg( target_arch = "x86_64" ) ]
685
+ if let Some ( container) = & state. cpu_container {
686
+ let ctor_args = CpuContainerConstructorArgs { vm } ;
687
+ let device = Arc :: new ( Mutex :: new ( CpuContainer :: restore (
688
+ ctor_args,
689
+ & container. device_state ,
690
+ ) ?) ) ;
691
+
692
+ dev_manager. register_mmio_cpu_container ( vm, device, & container. device_info ) ?;
693
+ }
694
+
656
695
Ok ( dev_manager)
657
696
}
658
697
}
0 commit comments