[PATCH 2/2] vfio: selftests: Align __iommu_unmap() check with iommufd compat mode
From: Yi Lai
Date: Fri Mar 20 2026 - 00:04:14 EST
When __iommu_map() fails (as expected for MMIO in iommufd modes), the
test proceeds to call __iommu_unmap() for cleanup.
The behavior of unmapping a non-existent range differs between iommufd
native and compat modes:
- Native iommufd returns -ENOENT (failure).
- Compat iommufd returns 0 (success), mimicking legacy VFIO behavior.
The previous code asserted that __iommu_unmap() always fails, which
caused test failures in compat mode. Fix this by checking the return
value based on the iommufd mode.
Signed-off-by: Yi Lai <yi1.lai@xxxxxxxxx>
---
.../testing/selftests/vfio/vfio_dma_mapping_mmio_test.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
index 4f7ecdca0215..e6a2b2ff91f0 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
@@ -101,7 +101,14 @@ static void do_mmio_map_test(struct iommu *iommu,
iommu_unmap(iommu, ®ion);
} else {
VFIO_ASSERT_NE(__iommu_map(iommu, ®ion), 0);
- VFIO_ASSERT_NE(__iommu_unmap(iommu, ®ion, NULL), 0);
+ /*
+ * Native IOMMUFD returns -ENOENT and Compat IOMMUFD returns 0
+ * for unmapping a non-existent range.
+ */
+ if (!strcmp(iommu->mode->name, MODE_IOMMUFD))
+ VFIO_ASSERT_NE(__iommu_unmap(iommu, ®ion, NULL), 0);
+ else
+ VFIO_ASSERT_EQ(__iommu_unmap(iommu, ®ion, NULL), 0);
}
}
--
2.43.0