mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
pci: vfio_user: replace unwrap() with explicit error
VfioUserDmaMapping::map panicked when find_region returned an anonymous mmap region. Change this so a user gets an error instead of a panic. When the VMM hotplugs a region into a guest that also has a vfio-user device, all region's handlers are called. With the anonymous memory backing (no file=, shared=on, or hugepages), region.file_offset() returns None and the .unwrap() panics the VMM. Replace the unwrap with an explicit error and use checked_add for the offset combine. Signed-off-by: Dylan Reid <dgreid@fb.com>
This commit is contained in:
@@ -578,9 +578,12 @@ impl<M: GuestAddressSpace + Sync + Send> ExternalDmaMapping for VfioUserDmaMappi
|
||||
)));
|
||||
}
|
||||
|
||||
// Unwrap is safe as we only do vfio with shared mem with a backing file.
|
||||
let file_offset = region.file_offset().unwrap();
|
||||
let offset = region_offset + file_offset.start();
|
||||
let file_offset = region.file_offset().ok_or_else(|| {
|
||||
std::io::Error::other(format!("region for gpa 0x{gpa:x} has no backing file"))
|
||||
})?;
|
||||
let offset = region_offset
|
||||
.checked_add(file_offset.start())
|
||||
.ok_or_else(|| std::io::Error::other("offset overflow in DMA map"))?;
|
||||
|
||||
self.client
|
||||
.lock()
|
||||
|
||||
Reference in New Issue
Block a user