@@ -19,7 +19,9 @@ use super::resources::ResourceAllocator;
1919#[ cfg( target_arch = "aarch64" ) ]
2020use crate :: arch:: DeviceType ;
2121#[ 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+ } ;
2325#[ cfg( target_arch = "x86_64" ) ]
2426use crate :: devices:: acpi:: vmgenid:: { VMGenIDState , VMGenIdConstructorArgs , VmGenId , VmGenIdError } ;
2527use crate :: devices:: virtio:: balloon:: persist:: { BalloonConstructorArgs , BalloonState } ;
@@ -59,6 +61,9 @@ pub enum DevicePersistError {
5961 Balloon ( #[ from] BalloonError ) ,
6062 /// Block: {0}
6163 Block ( #[ from] BlockError ) ,
64+ /// CpuContainer: {0}
65+ #[ cfg( target_arch = "x86_64" ) ]
66+ CpuContainer ( #[ from] CpuContainerError ) ,
6267 /// Device manager: {0}
6368 DeviceManager ( #[ from] super :: mmio:: MmioError ) ,
6469 /// Mmio transport
@@ -155,6 +160,13 @@ pub struct ConnectedLegacyState {
155160 pub device_info : MMIODeviceInfo ,
156161}
157162
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+
158170/// Holds the MMDS data store version.
159171#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
160172pub enum MmdsVersionState {
@@ -198,6 +210,9 @@ pub struct DeviceStates {
198210 pub mmds_version : Option < MmdsVersionState > ,
199211 /// Entropy device state.
200212 pub entropy_device : Option < ConnectedEntropyState > ,
213+ /// Cpu Container device state.
214+ #[ cfg( target_arch = "x86_64" ) ]
215+ pub cpu_container : Option < ConnectedCpuContainerState > ,
201216}
202217
203218/// A type used to extract the concrete `Arc<Mutex<T>>` for each of the device
@@ -253,6 +268,9 @@ pub enum ACPIDeviceManagerRestoreError {
253268 Interrupt ( #[ from] kvm_ioctls:: Error ) ,
254269 /// Could not create VMGenID device: {0}
255270 VMGenID ( #[ from] VmGenIdError ) ,
271+ /// Could not create CpuContainer device: {0}
272+ #[ cfg( target_arch = "x86_64" ) ]
273+ CpuContainer ( #[ from] CpuContainerError ) ,
256274}
257275
258276#[ cfg( target_arch = "x86_64" ) ]
@@ -292,11 +310,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
292310 type Error = DevicePersistError ;
293311
294312 fn save ( & self ) -> Self :: State {
313+ use crate :: devices:: bus:: BusDevice :: * ;
295314 let mut states = DeviceStates :: default ( ) ;
315+ #[ allow( unused_variables) ]
296316 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+ _ => ( ) ,
300328 }
301329
302330 #[ cfg( target_arch = "aarch64" ) ]
@@ -653,6 +681,17 @@ impl<'a> Persist<'a> for MMIODeviceManager {
653681 ) ?;
654682 }
655683
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+
656695 Ok ( dev_manager)
657696 }
658697}
0 commit comments