From ab38a77c011843485fe6690e12acfec3a9af517e Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Mon, 4 May 2026 23:31:49 -0700 Subject: [PATCH] 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 --- pci/src/vfio_user.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index fd6b55d72..0a1c24cff 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -578,9 +578,12 @@ impl 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()