pci: Adding support for printing the device's address on a DMA map and unmap errors

Signed-off-by: Arvind Vasudev <avasudev@crusoeenergy.com>
This commit is contained in:
Arvind Vasudev 2025-01-13 09:24:51 -08:00 committed by Rob Bradford
parent 8c07294691
commit 81eca69b40

View File

@ -48,10 +48,10 @@ pub(crate) const VFIO_COMMON_ID: &str = "vfio_common";
pub enum VfioPciError { pub enum VfioPciError {
#[error("Failed to create user memory region: {0}")] #[error("Failed to create user memory region: {0}")]
CreateUserMemoryRegion(#[source] HypervisorVmError), CreateUserMemoryRegion(#[source] HypervisorVmError),
#[error("Failed to DMA map: {0}")] #[error("Failed to DMA map: {0} for device {1}")]
DmaMap(#[source] vfio_ioctls::VfioError), DmaMap(#[source] vfio_ioctls::VfioError, PciBdf),
#[error("Failed to DMA unmap: {0}")] #[error("Failed to DMA unmap: {0} for device {1}")]
DmaUnmap(#[source] vfio_ioctls::VfioError), DmaUnmap(#[source] vfio_ioctls::VfioError, PciBdf),
#[error("Failed to enable INTx: {0}")] #[error("Failed to enable INTx: {0}")]
EnableIntx(#[source] VfioError), EnableIntx(#[source] VfioError),
#[error("Failed to enable MSI: {0}")] #[error("Failed to enable MSI: {0}")]
@ -1410,6 +1410,7 @@ pub struct VfioPciDevice {
common: VfioCommon, common: VfioCommon,
iommu_attached: bool, iommu_attached: bool,
memory_slot_allocator: MemorySlotAllocator, memory_slot_allocator: MemorySlotAllocator,
bdf: PciBdf,
} }
impl VfioPciDevice { impl VfioPciDevice {
@ -1451,6 +1452,7 @@ impl VfioPciDevice {
common, common,
iommu_attached, iommu_attached,
memory_slot_allocator, memory_slot_allocator,
bdf,
}; };
Ok(vfio_pci_device) Ok(vfio_pci_device)
@ -1656,7 +1658,7 @@ impl VfioPciDevice {
user_memory_region.size, user_memory_region.size,
user_memory_region.host_addr, user_memory_region.host_addr,
) )
.map_err(VfioPciError::DmaMap)?; .map_err(|e| VfioPciError::DmaMap(e, self.bdf))?;
} }
} }
} }
@ -1717,7 +1719,7 @@ impl VfioPciDevice {
if !self.iommu_attached { if !self.iommu_attached {
self.container self.container
.vfio_dma_map(iova, size, user_addr) .vfio_dma_map(iova, size, user_addr)
.map_err(VfioPciError::DmaMap)?; .map_err(|e| VfioPciError::DmaMap(e, self.bdf))?;
} }
Ok(()) Ok(())
@ -1727,7 +1729,7 @@ impl VfioPciDevice {
if !self.iommu_attached { if !self.iommu_attached {
self.container self.container
.vfio_dma_unmap(iova, size) .vfio_dma_unmap(iova, size)
.map_err(VfioPciError::DmaUnmap)?; .map_err(|e| VfioPciError::DmaUnmap(e, self.bdf))?;
} }
Ok(()) Ok(())