@@ -356,18 +356,6 @@ pub fn get_snapshot_data_version(
356
356
Ok ( data_version)
357
357
}
358
358
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
-
371
359
/// Validates that snapshot CPU vendor matches the host CPU vendor.
372
360
///
373
361
/// # Errors
@@ -376,38 +364,32 @@ pub enum ValidateCpuVendorError {
376
364
/// - Failed to read host vendor.
377
365
/// - Failed to read snapshot vendor.
378
366
#[ 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
+ }
396
390
}
397
391
}
398
392
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
-
411
393
/// Validate that Snapshot Manufacturer ID matches
412
394
/// the one from the Host
413
395
///
@@ -418,27 +400,30 @@ pub enum ValidateCpuManufacturerIdError {
418
400
/// - Failed to read host vendor.
419
401
/// - Failed to read snapshot vendor.
420
402
#[ 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" ) ;
439
425
}
440
426
}
441
- Ok ( true )
442
427
}
443
428
/// Error type for [`snapshot_state_sanity_check`].
444
429
#[ derive( Debug , thiserror:: Error , PartialEq , Eq ) ]
@@ -449,14 +434,6 @@ pub enum SnapShotStateSanityCheckError {
449
434
/// No memory region defined.
450
435
#[ error( "No memory region defined." ) ]
451
436
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 ) ,
460
437
}
461
438
462
439
/// Performs sanity checks against the state file and returns specific errors.
@@ -478,9 +455,9 @@ pub fn snapshot_state_sanity_check(
478
455
}
479
456
480
457
#[ cfg( target_arch = "x86_64" ) ]
481
- validate_cpu_vendor ( microvm_state) ? ;
458
+ validate_cpu_vendor ( microvm_state) ;
482
459
#[ cfg( target_arch = "aarch64" ) ]
483
- validate_cpu_manufacturer_id ( microvm_state) ? ;
460
+ validate_cpu_manufacturer_id ( microvm_state) ;
484
461
485
462
Ok ( ( ) )
486
463
}
0 commit comments