@@ -17,6 +17,10 @@ use super::mmio::*;
1717use super :: resources:: ResourceAllocator ;
1818#[ cfg( target_arch = "aarch64" ) ]
1919use crate :: arch:: DeviceType ;
20+ #[ cfg( target_arch = "x86_64" ) ]
21+ use crate :: devices:: acpi:: cpu_container:: {
22+ CpuContainer , CpuContainerConstructorArgs , CpuContainerError , CpuContainerState ,
23+ } ;
2024use crate :: devices:: acpi:: vmgenid:: { VMGenIDState , VMGenIdConstructorArgs , VmGenId , VmGenIdError } ;
2125use crate :: devices:: virtio:: balloon:: persist:: { BalloonConstructorArgs , BalloonState } ;
2226use crate :: devices:: virtio:: balloon:: { Balloon , BalloonError } ;
@@ -55,6 +59,9 @@ pub enum DevicePersistError {
5559 Balloon ( #[ from] BalloonError ) ,
5660 /// Block: {0}
5761 Block ( #[ from] BlockError ) ,
62+ /// CpuContainer: {0}
63+ #[ cfg( target_arch = "x86_64" ) ]
64+ CpuContainer ( #[ from] CpuContainerError ) ,
5865 /// Device manager: {0}
5966 DeviceManager ( #[ from] super :: mmio:: MmioError ) ,
6067 /// Mmio transport
@@ -151,6 +158,13 @@ pub struct ConnectedLegacyState {
151158 pub device_info : MMIODeviceInfo ,
152159}
153160
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+
154168/// Holds the MMDS data store version.
155169#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
156170pub enum MmdsVersionState {
@@ -194,6 +208,9 @@ pub struct DeviceStates {
194208 pub mmds_version : Option < MmdsVersionState > ,
195209 /// Entropy device state.
196210 pub entropy_device : Option < ConnectedEntropyState > ,
211+ /// Cpu Container device state.
212+ #[ cfg( target_arch = "x86_64" ) ]
213+ pub cpu_container : Option < ConnectedCpuContainerState > ,
197214}
198215
199216/// A type used to extract the concrete `Arc<Mutex<T>>` for each of the device
@@ -245,6 +262,9 @@ pub enum ACPIDeviceManagerRestoreError {
245262 Interrupt ( #[ from] kvm_ioctls:: Error ) ,
246263 /// Could not create VMGenID device: {0}
247264 VMGenID ( #[ from] VmGenIdError ) ,
265+ /// Could not create CpuContainer device: {0}
266+ #[ cfg( target_arch = "x86_64" ) ]
267+ CpuContainer ( #[ from] CpuContainerError ) ,
248268}
249269
250270impl < ' a > Persist < ' a > for ACPIDeviceManager {
@@ -283,11 +303,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
283303 type Error = DevicePersistError ;
284304
285305 fn save ( & self ) -> Self :: State {
306+ use crate :: devices:: bus:: BusDevice :: * ;
286307 let mut states = DeviceStates :: default ( ) ;
308+ #[ allow( unused_variables) ]
287309 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+ _ => ( ) ,
291321 }
292322
293323 #[ cfg( target_arch = "aarch64" ) ]
@@ -644,6 +674,17 @@ impl<'a> Persist<'a> for MMIODeviceManager {
644674 ) ?;
645675 }
646676
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+
647688 Ok ( dev_manager)
648689 }
649690}
0 commit comments