mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: vsock: improve error handling
On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
cfc639de35
commit
727b704606
@@ -16,6 +16,7 @@ mod unix;
|
|||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
|
|
||||||
use packet::VsockPacket;
|
use packet::VsockPacket;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
pub use self::device::Vsock;
|
pub use self::device::Vsock;
|
||||||
pub use self::unix::{VsockUnixBackend, VsockUnixError};
|
pub use self::unix::{VsockUnixBackend, VsockUnixError};
|
||||||
@@ -63,29 +64,43 @@ mod defs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub enum VsockError {
|
pub enum VsockError {
|
||||||
/// The vsock data/buffer virtio descriptor length is smaller than expected.
|
/// The vsock data/buffer virtio descriptor length is smaller than expected.
|
||||||
|
#[error("The vsock data/buffer virtio descriptor length is smaller than expected")]
|
||||||
BufDescTooSmall,
|
BufDescTooSmall,
|
||||||
/// The vsock data/buffer virtio descriptor is expected, but missing.
|
/// The vsock data/buffer virtio descriptor is expected, but missing.
|
||||||
|
#[error("The vsock data/buffer virtio descriptor is expected, but missing")]
|
||||||
BufDescMissing,
|
BufDescMissing,
|
||||||
/// Chained GuestMemory error.
|
/// Chained GuestMemory error.
|
||||||
|
#[error("Guest memory error")]
|
||||||
GuestMemory,
|
GuestMemory,
|
||||||
|
/// Chained GuestMemory access error.
|
||||||
|
#[error("Guest memory access error")]
|
||||||
|
GuestMemoryAccess(#[source] vm_memory::GuestMemoryError),
|
||||||
/// Bounds check failed on guest memory pointer.
|
/// Bounds check failed on guest memory pointer.
|
||||||
|
#[error("Bounds check failed on guest memory pointer")]
|
||||||
GuestMemoryBounds,
|
GuestMemoryBounds,
|
||||||
/// The vsock header descriptor length is too small.
|
/// The vsock header descriptor length is too small.
|
||||||
|
#[error("The vsock header descriptor length is too small: {0}")]
|
||||||
HdrDescTooSmall(u32),
|
HdrDescTooSmall(u32),
|
||||||
/// The vsock header descriptor is expected, but missing.
|
/// The vsock header descriptor is expected, but missing.
|
||||||
|
#[error("The vsock header descriptor is expected, but missing")]
|
||||||
HdrDescMissing,
|
HdrDescMissing,
|
||||||
/// The vsock header `len` field holds an invalid value.
|
/// The vsock header `len` field holds an invalid value.
|
||||||
|
#[error("The vsock header len field holds an invalid value: {0}")]
|
||||||
InvalidPktLen(u32),
|
InvalidPktLen(u32),
|
||||||
/// A data fetch was attempted when no data was available.
|
/// A data fetch was attempted when no data was available.
|
||||||
|
#[error("A data fetch was attempted when no data was available")]
|
||||||
NoData,
|
NoData,
|
||||||
/// A data buffer was expected for the provided packet, but it is missing.
|
/// A data buffer was expected for the provided packet, but it is missing.
|
||||||
|
#[error("A data buffer was expected for the provided packet, but it is missing")]
|
||||||
PktBufMissing,
|
PktBufMissing,
|
||||||
/// Encountered an unexpected write-only virtio descriptor.
|
/// Encountered an unexpected write-only virtio descriptor.
|
||||||
|
#[error("Encountered an unexpected write-only virtio descriptor")]
|
||||||
UnreadableDescriptor,
|
UnreadableDescriptor,
|
||||||
/// Encountered an unexpected read-only virtio descriptor.
|
/// Encountered an unexpected read-only virtio descriptor.
|
||||||
|
#[error("Encountered an unexpected read-only virtio descriptor")]
|
||||||
UnwritableDescriptor,
|
UnwritableDescriptor,
|
||||||
}
|
}
|
||||||
type Result<T> = std::result::Result<T, VsockError>;
|
type Result<T> = std::result::Result<T, VsockError>;
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ impl VsockPacket {
|
|||||||
desc_chain
|
desc_chain
|
||||||
.memory()
|
.memory()
|
||||||
.read_slice(hdr.as_mut_slice(), guest_hdr_addr)
|
.read_slice(hdr.as_mut_slice(), guest_hdr_addr)
|
||||||
.map_err(|_| VsockError::GuestMemory)?;
|
.map_err(VsockError::GuestMemoryAccess)?;
|
||||||
|
|
||||||
let mut pkt = Self {
|
let mut pkt = Self {
|
||||||
guest_hdr_addr,
|
guest_hdr_addr,
|
||||||
@@ -361,7 +361,7 @@ impl VsockPacket {
|
|||||||
desc_chain
|
desc_chain
|
||||||
.memory()
|
.memory()
|
||||||
.read_slice(&mut owned[offset..offset + to_copy], desc.addr())
|
.read_slice(&mut owned[offset..offset + to_copy], desc.addr())
|
||||||
.map_err(|_| VsockError::GuestMemory)?;
|
.map_err(VsockError::GuestMemoryAccess)?;
|
||||||
offset += to_copy;
|
offset += to_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ impl VsockPacket {
|
|||||||
desc_chain
|
desc_chain
|
||||||
.memory()
|
.memory()
|
||||||
.read_slice(hdr.as_mut_slice(), guest_hdr_addr)
|
.read_slice(hdr.as_mut_slice(), guest_hdr_addr)
|
||||||
.map_err(|_| VsockError::GuestMemory)?;
|
.map_err(VsockError::GuestMemoryAccess)?;
|
||||||
|
|
||||||
// Prior to Linux v6.3 there are two descriptors
|
// Prior to Linux v6.3 there are two descriptors
|
||||||
let (buf_size, buf_addr) = if head.has_next() {
|
let (buf_size, buf_addr) = if head.has_next() {
|
||||||
@@ -506,7 +506,7 @@ impl VsockPacket {
|
|||||||
|
|
||||||
guest_mem
|
guest_mem
|
||||||
.write(self.hdr(), self.guest_hdr_addr)
|
.write(self.hdr(), self.guest_hdr_addr)
|
||||||
.map_err(|_| VsockError::GuestMemory)?;
|
.map_err(VsockError::GuestMemoryAccess)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user