diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 20f08d164..fa8b2af38 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -50,7 +50,7 @@ pub enum Error { impl From for super::Error { fn from(e: Error) -> super::Error { - super::Error::AArch64Setup(e) + super::Error::PlatformSpecific(e) } } @@ -185,10 +185,10 @@ pub fn initramfs_load_addr( if guest_mem.address_in_range(offset) { Ok(offset.raw_value()) } else { - Err(super::Error::AArch64Setup(Error::InitramfsAddress)) + Err(super::Error::PlatformSpecific(Error::InitramfsAddress)) } } - None => Err(super::Error::AArch64Setup(Error::InitramfsAddress)), + None => Err(super::Error::PlatformSpecific(Error::InitramfsAddress)), } } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index b404b790a..a3cab18eb 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -18,6 +18,7 @@ use std::collections::BTreeMap; use std::fmt; use std::result; use std::sync::Arc; +use thiserror::Error; use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult}; use versionize_derive::Versionize; use vm_migration::VersionMapped; @@ -26,31 +27,27 @@ type GuestMemoryMmap = vm_memory::GuestMemoryMmap; /// Type for returning error code. -#[derive(Debug)] +#[derive(Debug, Error)] pub enum Error { #[cfg(target_arch = "x86_64")] - /// X86_64 specific error triggered during system configuration. - X86_64Setup(x86_64::Error), + #[error("Platform specific error (x86_64): {0:?}")] + PlatformSpecific(x86_64::Error), #[cfg(target_arch = "aarch64")] - /// AArch64 specific error triggered during system configuration. - AArch64Setup(aarch64::Error), - /// The zero page extends past the end of guest_mem. - ZeroPagePastRamEnd, - /// Error writing the zero page of guest memory. - ZeroPageSetup(vm_memory::GuestMemoryError), - /// The memory map table extends past the end of guest memory. + #[error("Platform specific error (aarch64): {0:?}")] + PlatformSpecific(aarch64::Error), + #[error("The memory map table extends past the end of guest memory")] MemmapTablePastRamEnd, - /// Error writing memory map table to guest memory. + #[error("Error writing memory map table to guest memory")] MemmapTableSetup, - /// The hvm_start_info structure extends past the end of guest memory. + #[error("The hvm_start_info structure extends past the end of guest memory")] StartInfoPastRamEnd, - /// Error writing hvm_start_info to guest memory. + #[error("Error writing hvm_start_info to guest memory")] StartInfoSetup, - /// Failed to compute initramfs address. + #[error("Failed to compute initramfs address")] InitramfsAddress, - /// Error writing module entry to guest memory. - ModlistSetup(vm_memory::GuestMemoryError), - /// RSDP Beyond Guest Memory + #[error("Error writing module entry to guest memory: {0}")] + ModlistSetup(#[source] vm_memory::GuestMemoryError), + #[error("RSDP extends past the end of guest memory")] RsdpPastRamEnd, } diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 9bba3c8aa..3a1664d33 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -197,7 +197,7 @@ pub enum Error { impl From for super::Error { fn from(e: Error) -> super::Error { - super::Error::X86_64Setup(e) + super::Error::PlatformSpecific(e) } } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index b7a21a4c6..612a85457 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1180,7 +1180,9 @@ impl Vm { self.cpu_manager.lock().unwrap().boot_vcpus() as u64, ) .map_err(|e| { - Error::ConfigureSystem(arch::Error::AArch64Setup(arch::aarch64::Error::SetupGic(e))) + Error::ConfigureSystem(arch::Error::PlatformSpecific( + arch::aarch64::Error::SetupGic(e), + )) })?; // PMU interrupt sticks to PPI, so need to be added by 16 to get real irq number. @@ -1190,7 +1192,9 @@ impl Vm { .unwrap() .init_pmu(arch::aarch64::fdt::AARCH64_PMU_IRQ + 16) .map_err(|_| { - Error::ConfigureSystem(arch::Error::AArch64Setup(arch::aarch64::Error::VcpuInitPmu)) + Error::ConfigureSystem(arch::Error::PlatformSpecific( + arch::aarch64::Error::VcpuInitPmu, + )) })?; arch::configure_system(