@@ -17,6 +17,10 @@ use super::mmio::*;
17
17
use super :: resources:: ResourceAllocator ;
18
18
#[ cfg( target_arch = "aarch64" ) ]
19
19
use crate :: arch:: DeviceType ;
20
+ #[ cfg( target_arch = "x86_64" ) ]
21
+ use crate :: devices:: acpi:: cpu_container:: {
22
+ CpuContainer , CpuContainerConstructorArgs , CpuContainerError , CpuContainerState ,
23
+ } ;
20
24
use crate :: devices:: acpi:: vmgenid:: { VMGenIDState , VMGenIdConstructorArgs , VmGenId , VmGenIdError } ;
21
25
use crate :: devices:: virtio:: balloon:: persist:: { BalloonConstructorArgs , BalloonState } ;
22
26
use crate :: devices:: virtio:: balloon:: { Balloon , BalloonError } ;
@@ -55,6 +59,9 @@ pub enum DevicePersistError {
55
59
Balloon ( #[ from] BalloonError ) ,
56
60
/// Block: {0}
57
61
Block ( #[ from] BlockError ) ,
62
+ /// CpuContainer: {0}
63
+ #[ cfg( target_arch = "x86_64" ) ]
64
+ CpuContainer ( #[ from] CpuContainerError ) ,
58
65
/// Device manager: {0}
59
66
DeviceManager ( #[ from] super :: mmio:: MmioError ) ,
60
67
/// Mmio transport
@@ -151,6 +158,13 @@ pub struct ConnectedLegacyState {
151
158
pub device_info : MMIODeviceInfo ,
152
159
}
153
160
161
+ #[ cfg( target_arch = "x86_64" ) ]
162
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
163
+ pub struct ConnectedCpuContainerState {
164
+ pub device_state : CpuContainerState ,
165
+ pub device_info : MMIODeviceInfo ,
166
+ }
167
+
154
168
/// Holds the MMDS data store version.
155
169
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
156
170
pub enum MmdsVersionState {
@@ -194,6 +208,9 @@ pub struct DeviceStates {
194
208
pub mmds_version : Option < MmdsVersionState > ,
195
209
/// Entropy device state.
196
210
pub entropy_device : Option < ConnectedEntropyState > ,
211
+ /// Cpu Container device state.
212
+ #[ cfg( target_arch = "x86_64" ) ]
213
+ pub cpu_container : Option < ConnectedCpuContainerState > ,
197
214
}
198
215
199
216
/// A type used to extract the concrete `Arc<Mutex<T>>` for each of the device
@@ -245,6 +262,9 @@ pub enum ACPIDeviceManagerRestoreError {
245
262
Interrupt ( #[ from] kvm_ioctls:: Error ) ,
246
263
/// Could not create VMGenID device: {0}
247
264
VMGenID ( #[ from] VmGenIdError ) ,
265
+ /// Could not create CpuContainer device: {0}
266
+ #[ cfg( target_arch = "x86_64" ) ]
267
+ CpuContainer ( #[ from] CpuContainerError ) ,
248
268
}
249
269
250
270
impl < ' a > Persist < ' a > for ACPIDeviceManager {
@@ -283,11 +303,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
283
303
type Error = DevicePersistError ;
284
304
285
305
fn save ( & self ) -> Self :: State {
306
+ use crate :: devices:: bus:: BusDevice :: * ;
286
307
let mut states = DeviceStates :: default ( ) ;
308
+ #[ allow( unused_variables) ]
287
309
let _: Result < ( ) , ( ) > = self . for_each_device ( |devtype, devid, device_info, bus_dev| {
288
- if * devtype == crate :: arch:: DeviceType :: BootTimer {
289
- // No need to save BootTimer state.
290
- return Ok ( ( ) ) ;
310
+ match bus_dev {
311
+ BootTimer ( _) => return Ok ( ( ) ) ,
312
+ #[ cfg( target_arch = "x86_64" ) ]
313
+ CpuContainer ( x) => {
314
+ states. cpu_container = Some ( ConnectedCpuContainerState {
315
+ device_state : x. lock ( ) . expect ( "Poisoned lock" ) . save ( ) ,
316
+ device_info : device_info. clone ( ) ,
317
+ } ) ;
318
+ return Ok ( ( ) ) ;
319
+ }
320
+ _ => ( ) ,
291
321
}
292
322
293
323
#[ cfg( target_arch = "aarch64" ) ]
@@ -644,6 +674,17 @@ impl<'a> Persist<'a> for MMIODeviceManager {
644
674
) ?;
645
675
}
646
676
677
+ #[ cfg( target_arch = "x86_64" ) ]
678
+ if let Some ( container) = & state. cpu_container {
679
+ let ctor_args = CpuContainerConstructorArgs { vm } ;
680
+ let device = Arc :: new ( Mutex :: new ( CpuContainer :: restore (
681
+ ctor_args,
682
+ & container. device_state ,
683
+ ) ?) ) ;
684
+
685
+ dev_manager. register_mmio_cpu_container ( vm, device, & container. device_info ) ?;
686
+ }
687
+
647
688
Ok ( dev_manager)
648
689
}
649
690
}
0 commit comments