@@ -356,18 +356,6 @@ pub fn get_snapshot_data_version(
356356 Ok ( data_version)
357357}
358358
359- /// Error type for [`validate_cpu_vendor`].
360- #[ cfg( target_arch = "x86_64" ) ]
361- #[ derive( Debug , thiserror:: Error , PartialEq , Eq ) ]
362- pub enum ValidateCpuVendorError {
363- /// Failed to read host vendor.
364- #[ error( "Failed to read host vendor: {0}" ) ]
365- Host ( #[ from] crate :: cpu_config:: x86_64:: cpuid:: common:: GetCpuidError ) ,
366- /// Failed to read snapshot vendor.
367- #[ error( "Failed to read snapshot vendor" ) ]
368- Snapshot ,
369- }
370-
371359/// Validates that snapshot CPU vendor matches the host CPU vendor.
372360///
373361/// # Errors
@@ -376,38 +364,32 @@ pub enum ValidateCpuVendorError {
376364/// - Failed to read host vendor.
377365/// - Failed to read snapshot vendor.
378366#[ cfg( target_arch = "x86_64" ) ]
379- pub fn validate_cpu_vendor ( microvm_state : & MicrovmState ) -> Result < bool , ValidateCpuVendorError > {
380- let host_vendor_id = get_vendor_id_from_host ( ) ?;
381-
382- let snapshot_vendor_id = microvm_state. vcpu_states [ 0 ]
383- . cpuid
384- . vendor_id ( )
385- . ok_or ( ValidateCpuVendorError :: Snapshot ) ?;
386-
387- if host_vendor_id == snapshot_vendor_id {
388- info ! ( "Snapshot CPU vendor id: {:?}" , & snapshot_vendor_id) ;
389- Ok ( true )
390- } else {
391- error ! (
392- "Host CPU vendor id: {:?} differs from the snapshotted one: {:?}" ,
393- & host_vendor_id, & snapshot_vendor_id
394- ) ;
395- Ok ( false )
367+ pub fn validate_cpu_vendor ( microvm_state : & MicrovmState ) {
368+ let host_vendor_id = get_vendor_id_from_host ( ) ;
369+ let snapshot_vendor_id = microvm_state. vcpu_states [ 0 ] . cpuid . vendor_id ( ) ;
370+ match ( host_vendor_id, snapshot_vendor_id) {
371+ ( Ok ( host_id) , Some ( snapshot_id) ) => {
372+ info ! ( "Host CPU vendor ID: {host_id:?}" ) ;
373+ info ! ( "Snapshot CPU vendor ID: {snapshot_id:?}" ) ;
374+ if host_id != snapshot_id {
375+ warn ! ( "Host CPU vendor ID differs from the snapshotted one" , ) ;
376+ }
377+ }
378+ ( Ok ( host_id) , None ) => {
379+ info ! ( "Host CPU vendor ID: {host_id:?}" ) ;
380+ warn ! ( "Snapshot CPU vendor ID: couldn't get from the snapshot" ) ;
381+ }
382+ ( Err ( _) , Some ( snapshot_id) ) => {
383+ warn ! ( "Host CPU vendor ID: couldn't get from the host" ) ;
384+ info ! ( "Snapshot CPU vendor ID: {snapshot_id:?}" ) ;
385+ }
386+ ( Err ( _) , None ) => {
387+ warn ! ( "Host CPU vendor ID: couldn't get from the host" ) ;
388+ warn ! ( "Snapshot CPU vendor ID: couldn't get from the snapshot" ) ;
389+ }
396390 }
397391}
398392
399- /// Error type for [`validate_cpu_manufacturer_id`].
400- #[ cfg( target_arch = "aarch64" ) ]
401- #[ derive( Debug , thiserror:: Error , PartialEq , Eq ) ]
402- pub enum ValidateCpuManufacturerIdError {
403- /// Failed to read host vendor.
404- #[ error( "Failed to get manufacturer ID from host: {0}" ) ]
405- Host ( String ) ,
406- /// Failed to read host vendor.
407- #[ error( "Failed to get manufacturer ID from state: {0}" ) ]
408- Snapshot ( String ) ,
409- }
410-
411393/// Validate that Snapshot Manufacturer ID matches
412394/// the one from the Host
413395///
@@ -418,27 +400,30 @@ pub enum ValidateCpuManufacturerIdError {
418400/// - Failed to read host vendor.
419401/// - Failed to read snapshot vendor.
420402#[ cfg( target_arch = "aarch64" ) ]
421- pub fn validate_cpu_manufacturer_id (
422- microvm_state : & MicrovmState ,
423- ) -> Result < bool , ValidateCpuManufacturerIdError > {
424- let host_man_id = get_manufacturer_id_from_host ( )
425- . map_err ( |err| ValidateCpuManufacturerIdError :: Host ( err. to_string ( ) ) ) ?;
426-
427- for state in & microvm_state. vcpu_states {
428- let state_man_id = get_manufacturer_id_from_state ( & state. regs )
429- . map_err ( |err| ValidateCpuManufacturerIdError :: Snapshot ( err. to_string ( ) ) ) ?;
430-
431- if host_man_id != state_man_id {
432- error ! (
433- "Host CPU manufacturer ID: {} differs from snapshotted one: {}" ,
434- & host_man_id, & state_man_id
435- ) ;
436- return Ok ( false ) ;
437- } else {
438- info ! ( "Snapshot CPU manufacturer ID: {:?}" , & state_man_id) ;
403+ pub fn validate_cpu_manufacturer_id ( microvm_state : & MicrovmState ) {
404+ let host_cpu_id = get_manufacturer_id_from_host ( ) ;
405+ let snapshot_cpu_id = get_manufacturer_id_from_state ( & microvm_state. vcpu_states [ 0 ] . regs ) ;
406+ match ( host_cpu_id, snapshot_cpu_id) {
407+ ( Ok ( host_id) , Ok ( snapshot_id) ) => {
408+ info ! ( "Host CPU manufacturer ID: {host_id:?}" ) ;
409+ info ! ( "Snapshot CPU manufacturer ID: {snapshot_id:?}" ) ;
410+ if host_id != snapshot_id {
411+ warn ! ( "Host CPU manufacturer ID differs from the snapshotted one" , ) ;
412+ }
413+ }
414+ ( Ok ( host_id) , Err ( _) ) => {
415+ info ! ( "Host CPU manufacturer ID: {host_id:?}" ) ;
416+ warn ! ( "Snapshot CPU manufacturer ID: couldn't get from the snapshot" ) ;
417+ }
418+ ( Err ( _) , Ok ( snapshot_id) ) => {
419+ warn ! ( "Host CPU manufacturer ID: couldn't get from the host" ) ;
420+ info ! ( "Snapshot CPU manufacturer ID: {snapshot_id:?}" ) ;
421+ }
422+ ( Err ( _) , Err ( _) ) => {
423+ warn ! ( "Host CPU manufacturer ID: couldn't get from the host" ) ;
424+ warn ! ( "Snapshot CPU manufacturer ID: couldn't get from the snapshot" ) ;
439425 }
440426 }
441- Ok ( true )
442427}
443428/// Error type for [`snapshot_state_sanity_check`].
444429#[ derive( Debug , thiserror:: Error , PartialEq , Eq ) ]
@@ -449,14 +434,6 @@ pub enum SnapShotStateSanityCheckError {
449434 /// No memory region defined.
450435 #[ error( "No memory region defined." ) ]
451436 NoMemory ,
452- /// Failed to validate vCPU vendor.
453- #[ cfg( target_arch = "x86_64" ) ]
454- #[ error( "Failed to validate vCPU vendor: {0}" ) ]
455- ValidateCpuVendor ( #[ from] ValidateCpuVendorError ) ,
456- /// Failed to validate vCPU manufacturer id.
457- #[ error( "Failed to validate vCPU manufacturer id: {0}" ) ]
458- #[ cfg( target_arch = "aarch64" ) ]
459- ValidateCpuManufacturerId ( #[ from] ValidateCpuManufacturerIdError ) ,
460437}
461438
462439/// Performs sanity checks against the state file and returns specific errors.
@@ -478,9 +455,9 @@ pub fn snapshot_state_sanity_check(
478455 }
479456
480457 #[ cfg( target_arch = "x86_64" ) ]
481- validate_cpu_vendor ( microvm_state) ? ;
458+ validate_cpu_vendor ( microvm_state) ;
482459 #[ cfg( target_arch = "aarch64" ) ]
483- validate_cpu_manufacturer_id ( microvm_state) ? ;
460+ validate_cpu_manufacturer_id ( microvm_state) ;
484461
485462 Ok ( ( ) )
486463}
0 commit comments