-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy patherror.rs
More file actions
222 lines (200 loc) · 6.66 KB
/
error.rs
File metadata and controls
222 lines (200 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2023 SUSE LLC
//
// Author: Carlos López <carlos.lopez@suse.com>
//! High level error typing for the public SVSM APIs.
//!
//! This module contains the generic [`SvsmError`] type, which may be returned
//! from any public API in this codebase to signal an error during SVSM
//! operation. Each variant of the type may give more specific information
//! about the source of the error.
//!
//! As a general rule, functions private to a given module may directly return
//! leaf error types, which are contained in [`SvsmError`] variants. Public
//! functions should return an [`SvsmError`] containing a leaf error type,
//! usually the one corresponding to that module. Each module should provide
//! a way to convert a leaf error into a SvsmError via the [`From`] trait.
#[cfg(feature = "attest")]
use crate::attest::AttestationError;
#[cfg(feature = "block")]
use crate::block::BlockDeviceError;
use crate::cpu::vc::VcError;
use crate::fs::FsError;
use crate::fw_cfg::FwCfgError;
use crate::insn_decode::InsnError;
use crate::mm::alloc::AllocError;
use crate::sev::SevSnpError;
use crate::sev::ghcb::GhcbError;
use crate::sev::msr_protocol::GhcbMsrError;
use crate::syscall::ObjError;
use crate::task::TaskError;
use crate::tdx::TdxError;
use crate::utils::immut_after_init::ImmutAfterInitError;
#[cfg(feature = "virtio-drivers")]
use crate::virtio::VirtioError;
#[cfg(feature = "vsock")]
use crate::vsock::VsockError;
use elf::ElfError;
use syscall::SysCallError;
/// Errors related to APIC handling. These may originate from multiple
/// layers in the system.
#[derive(Clone, Copy, Debug)]
pub enum ApicError {
/// An error arising because APIC emulation is disabled.
Disabled,
/// An error related to APIC emulation.
Emulation,
/// An error related to APIC registration.
Registration,
}
/// Errors related to Attestation handling. These may originate from multiple
/// layers in the system. Added to protocol base for protocol error.
#[repr(u64)]
#[derive(Clone, Copy, Debug)]
pub enum AttestError {
/// An error related to attestation report.
Report = 0,
/// An error related to attestation manifest.
Manifest = 1,
/// An error related to attestation certificates.
Certificate = 2,
/// Error reported when size of the certificates exceeds the size of the supplied
/// certificate buffer. Required size in bytes is returned in RDX register.
CertificateSize = 3,
}
/// A generic error during SVSM operation.
#[derive(Clone, Copy, Debug)]
pub enum SvsmError {
/// Errors related to platform initialization.
PlatformInit,
/// Errors during ELF parsing and loading.
Elf(ElfError),
/// Errors related to GHCB
Ghcb(GhcbError),
/// Errors related to MSR protocol
GhcbMsr(GhcbMsrError),
/// Errors related to SEV-SNP operations, like PVALIDATE or RMPUPDATE
SevSnp(SevSnpError),
/// Errors related to TDX operations
Tdx(TdxError),
/// Generic errors related to memory management
Mem,
/// Errors related to the memory allocator
Alloc(AllocError),
/// Error reported when there is no VMSA set up.
MissingVMSA,
/// Error reported when there is no CAA (Calling Area Address) set up.
MissingCAA,
/// Error reported when there is no secrets page set up.
MissingSecrets,
/// Instruction decode related errors
Insn(InsnError),
/// Invalid address, usually provided by the guest
InvalidAddress,
/// Error reported when convert a usize to Bytes
InvalidBytes,
/// Error reported when converting to UTF-8
InvalidUtf8,
/// A fault occurred
Fault,
/// Errors related to firmware parsing
Firmware,
/// Errors related to console operation
Console,
/// Errors related to firmware configuration contents
FwCfg(FwCfgError),
/// Errors related to IGVM parameter parsing.
Igvm,
/// Errors related to ACPI parsing.
Acpi,
/// Errors from the filesystem.
FileSystem(FsError),
/// Obj related error
Obj(ObjError),
/// Task management errors,
Task(TaskError),
/// Errors from #VC handler
Vc(VcError),
/// The operation is not supported.
NotSupported,
/// Generic errors related to APIC emulation.
Apic(ApicError),
/// Generic errors related to attestation handling.
Attestation(AttestError),
/// Errors related to Hyper-V.
HyperV(u16),
/// Errors related to Virtio drivers.
#[cfg(feature = "virtio-drivers")]
Virtio(VirtioError),
/// Errors related to block devices.
#[cfg(feature = "block")]
Block(BlockDeviceError),
/// Errors related to attesting SVSM's launch evidence.
#[cfg(feature = "attest")]
TeeAttestation(AttestationError),
/// Errors related to ImmutAfterInitCell
ImmutAfterInit(ImmutAfterInitError),
/// Errors related to vsock.
#[cfg(feature = "vsock")]
Vsock(VsockError),
}
impl From<ElfError> for SvsmError {
fn from(err: ElfError) -> Self {
Self::Elf(err)
}
}
impl From<ApicError> for SvsmError {
fn from(err: ApicError) -> Self {
Self::Apic(err)
}
}
impl From<AttestError> for SvsmError {
fn from(err: AttestError) -> Self {
Self::Attestation(err)
}
}
impl From<ObjError> for SvsmError {
fn from(err: ObjError) -> Self {
Self::Obj(err)
}
}
#[cfg(feature = "virtio-drivers")]
impl From<VirtioError> for SvsmError {
fn from(err: VirtioError) -> Self {
Self::Virtio(err)
}
}
#[cfg(feature = "block")]
impl From<BlockDeviceError> for SvsmError {
fn from(err: BlockDeviceError) -> Self {
Self::Block(err)
}
}
#[cfg(feature = "vsock")]
impl From<VsockError> for SvsmError {
fn from(err: VsockError) -> Self {
Self::Vsock(err)
}
}
impl From<SvsmError> for SysCallError {
fn from(err: SvsmError) -> Self {
match err {
SvsmError::Alloc(AllocError::OutOfMemory) => SysCallError::ENOMEM,
SvsmError::FileSystem(FsError::FileExists) => SysCallError::EEXIST,
SvsmError::FileSystem(FsError::WriteOnly) => SysCallError::EWRONLY,
SvsmError::FileSystem(FsError::ReadOnly) => SysCallError::ERDONLY,
SvsmError::FileSystem(FsError::FileNotFound) | SvsmError::Obj(ObjError::NotFound) => {
SysCallError::ENOTFOUND
}
SvsmError::NotSupported => SysCallError::ENOTSUPP,
SvsmError::FileSystem(FsError::Inval)
| SvsmError::Obj(ObjError::InvalidHandle)
| SvsmError::Mem
| SvsmError::InvalidAddress
| SvsmError::InvalidBytes
| SvsmError::InvalidUtf8 => SysCallError::EINVAL,
_ => SysCallError::UNKNOWN,
}
}
}