@@ -110,6 +110,14 @@ pub struct VmResources {
110110}
111111
112112impl VmResources {
113+ /// Whether this [`VmResources`] object contains any devices that require host kernel access
114+ /// into guest memory.
115+ pub fn has_any_io_devices ( & self ) -> bool {
116+ !self . block . devices . is_empty ( )
117+ || self . vsock . get ( ) . is_some ( )
118+ || self . net_builder . iter ( ) . next ( ) . is_some ( )
119+ }
120+
113121 /// Configures Vmm resources as described by the `config_json` param.
114122 pub fn from_json (
115123 config_json : & str ,
@@ -217,6 +225,11 @@ impl VmResources {
217225 BalloonConfigError :: IncompatibleWith ( "huge pages" ) ,
218226 ) ) ;
219227 }
228+ if self . machine_config . mem_config . secret_free {
229+ return Err ( ResourcesError :: BalloonDevice (
230+ BalloonConfigError :: IncompatibleWith ( "secret freedom" ) ,
231+ ) ) ;
232+ }
220233 }
221234
222235 SharedDeviceType :: Vsock ( vsock) => {
@@ -256,12 +269,23 @@ impl VmResources {
256269 return Err ( MachineConfigError :: IncompatibleBalloonSize ) ;
257270 }
258271
272+ #[ cfg( target_arch = "x86_64" ) ]
273+ if self . has_any_io_devices ( ) && self . machine_config . mem_config . secret_free {
274+ return Err ( MachineConfigError :: Incompatible ( "secret freedom" , "I/O" ) ) ;
275+ }
276+
259277 if self . balloon . get ( ) . is_some ( ) && updated. huge_pages != HugePageConfig :: None {
260278 return Err ( MachineConfigError :: Incompatible (
261279 "balloon device" ,
262280 "huge pages" ,
263281 ) ) ;
264282 }
283+ if self . balloon . get ( ) . is_some ( ) && updated. mem_config . secret_free {
284+ return Err ( MachineConfigError :: Incompatible (
285+ "balloon device" ,
286+ "secret freedom" ,
287+ ) ) ;
288+ }
265289 self . machine_config = updated;
266290
267291 Ok ( ( ) )
@@ -320,6 +344,10 @@ impl VmResources {
320344 return Err ( BalloonConfigError :: IncompatibleWith ( "huge pages" ) ) ;
321345 }
322346
347+ if self . machine_config . mem_config . secret_free {
348+ return Err ( BalloonConfigError :: IncompatibleWith ( "secret freedom" ) ) ;
349+ }
350+
323351 self . balloon . set ( config)
324352 }
325353
@@ -343,6 +371,11 @@ impl VmResources {
343371 & mut self ,
344372 block_device_config : BlockDeviceConfig ,
345373 ) -> Result < ( ) , DriveError > {
374+ #[ cfg( target_arch = "x86_64" ) ]
375+ if self . machine_config . mem_config . secret_free {
376+ return Err ( DriveError :: NoSecretFreeIOOnX86 ) ;
377+ }
378+
346379 self . block . insert ( block_device_config)
347380 }
348381
@@ -351,12 +384,22 @@ impl VmResources {
351384 & mut self ,
352385 body : NetworkInterfaceConfig ,
353386 ) -> Result < ( ) , NetworkInterfaceError > {
387+ #[ cfg( target_arch = "x86_64" ) ]
388+ if self . machine_config . mem_config . secret_free {
389+ return Err ( NetworkInterfaceError :: NoSecretFreeIOOnX86 ) ;
390+ }
391+
354392 let _ = self . net_builder . build ( body) ?;
355393 Ok ( ( ) )
356394 }
357395
358396 /// Sets a vsock device to be attached when the VM starts.
359397 pub fn set_vsock_device ( & mut self , config : VsockDeviceConfig ) -> Result < ( ) , VsockConfigError > {
398+ #[ cfg( target_arch = "x86_64" ) ]
399+ if self . machine_config . mem_config . secret_free {
400+ return Err ( VsockConfigError :: NoSecretFreeIOOnX86 ) ;
401+ }
402+
360403 self . vsock . insert ( config)
361404 }
362405
0 commit comments