vmm: cpu: Improve Error reporting

Remove unused enum members, improve error messages and implement
thiserror::Error.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-04-20 16:46:28 +01:00
parent 47529796d0
commit 0270d697ab

View File

@ -44,6 +44,7 @@ use std::os::unix::thread::JoinHandleExt;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::{cmp, io, result, thread}; use std::{cmp, io, result, thread};
use thiserror::Error;
use vm_device::BusDevice; use vm_device::BusDevice;
use vm_memory::GuestAddress; use vm_memory::GuestAddress;
use vm_memory::GuestMemoryAtomic; use vm_memory::GuestMemoryAtomic;
@ -56,75 +57,74 @@ use vmm_sys_util::signal::{register_signal_handler, SIGRTMIN};
pub const CPU_MANAGER_ACPI_SIZE: usize = 0xc; pub const CPU_MANAGER_ACPI_SIZE: usize = 0xc;
#[derive(Debug)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
/// Cannot create the vCPU. #[error("Error creating vCPU: {0}")]
VcpuCreate(anyhow::Error), VcpuCreate(#[source] anyhow::Error),
/// Cannot run the VCPUs. #[error("Error running bCPU: {0}")]
VcpuRun(anyhow::Error), VcpuRun(#[source] anyhow::Error),
/// Cannot spawn a new vCPU thread. #[error("Error spawning vCPU thread: {0}")]
VcpuSpawn(io::Error), VcpuSpawn(#[source] io::Error),
/// Cannot generate common CPUID #[error("Error generating common CPUID: {0}")]
CommonCpuId(arch::Error), CommonCpuId(#[source] arch::Error),
/// Error configuring VCPU #[error("Error configuring vCPU: {0}")]
VcpuConfiguration(arch::Error), VcpuConfiguration(#[source] arch::Error),
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
/// Error fetching prefered target #[error("Error fetching preferred target: {0}")]
VcpuArmPreferredTarget(hypervisor::HypervisorVmError), VcpuArmPreferredTarget(#[source] hypervisor::HypervisorVmError),
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
/// Error doing vCPU init on Arm. #[error("Error initialising vCPU: {0}")]
VcpuArmInit(hypervisor::HypervisorCpuError), VcpuArmInit(#[source] hypervisor::HypervisorCpuError),
/// Failed to join on vCPU threads #[error("Failed to join on vCPU threads: {0:?}")]
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>), ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
/// Cannot add legacy device to Bus. #[error("Error adding CpuManager to MMIO bus: {0}")]
BusError(vm_device::BusError), BusError(#[source] vm_device::BusError),
/// Asking for more vCPUs that we can have #[error("Requested vCPUs exceed maximum")]
DesiredVCpuCountExceedsMax, DesiredVCpuCountExceedsMax,
/// Cannot create seccomp filter #[error("Cannot create seccomp filter: {0}")]
CreateSeccompFilter(seccompiler::Error), CreateSeccompFilter(#[source] seccompiler::Error),
/// Cannot apply seccomp filter #[error("Cannot apply seccomp filter: {0}")]
ApplySeccompFilter(seccompiler::Error), ApplySeccompFilter(#[source] seccompiler::Error),
/// Error starting vCPU after restore #[error("Error starting vCPU after restore: {0}")]
StartRestoreVcpu(anyhow::Error), StartRestoreVcpu(#[source] anyhow::Error),
/// Error because an unexpected VmExit type was received. #[error("Unexpected VmExit")]
UnexpectedVmExit, UnexpectedVmExit,
/// Failed to allocate MMIO address #[error("Failed to allocate MMIO address for CpuManager")]
AllocateMmmioAddress, AllocateMmmioAddress,
#[cfg(feature = "tdx")] #[cfg(feature = "tdx")]
InitializeTdx(hypervisor::HypervisorCpuError), #[error("Error initializing TDX: {0}")]
InitializeTdx(#[source] hypervisor::HypervisorCpuError),
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
InitPmu(hypervisor::HypervisorCpuError), #[error("Error initializing PMU: {0}")]
InitPmu(#[source] hypervisor::HypervisorCpuError),
/// Failed scheduling the thread on the expected CPU set.
ScheduleCpuSet,
#[cfg(all(target_arch = "x86_64", feature = "gdb"))] #[cfg(all(target_arch = "x86_64", feature = "gdb"))]
/// Error on debug related CPU ops. #[error("Error during CPU debug: {0}")]
CpuDebug(hypervisor::HypervisorCpuError), CpuDebug(#[source] hypervisor::HypervisorCpuError),
#[cfg(all(target_arch = "x86_64", feature = "gdb"))] #[cfg(all(target_arch = "x86_64", feature = "gdb"))]
/// Failed to translate guest virtual address. #[error("Error translating virtual address: {0}")]
TranslateVirtualAddress(hypervisor::HypervisorCpuError), TranslateVirtualAddress(#[source] hypervisor::HypervisorCpuError),
#[cfg(all(feature = "amx", target_arch = "x86_64"))] #[cfg(all(feature = "amx", target_arch = "x86_64"))]
/// "Failed to setup AMX. #[error("Error setting up AMX: {0}")]
AmxEnable(anyhow::Error), AmxEnable(#[source] anyhow::Error),
} }
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;