summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/vfio/lib/iommu.c
diff options
context:
space:
mode:
authorDavid Matlack <dmatlack@google.com>2025-11-26 23:17:32 +0000
committerAlex Williamson <alex@shazbot.org>2025-11-28 10:58:07 -0700
commitb8e96c8805ec25878ac971cad34732a6aabe34f6 (patch)
tree5146dc29200062227f090963d30d5aa2d36840f3 /tools/testing/selftests/vfio/lib/iommu.c
parent5fabc49abf7ac630babfb1525e242848d54038c1 (diff)
vfio: selftests: Eliminate INVALID_IOVA
Eliminate INVALID_IOVA as there are platforms where UINT64_MAX is a valid iova. Reviewed-by: Alex Mastro <amastro@fb.com> Tested-by: Alex Mastro <amastro@fb.com> Reviewed-by: Raghavendra Rao Ananta <rananta@google.com> Signed-off-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20251126231733.3302983-18-dmatlack@google.com Signed-off-by: Alex Williamson <alex@shazbot.org>
Diffstat (limited to 'tools/testing/selftests/vfio/lib/iommu.c')
-rw-r--r--tools/testing/selftests/vfio/lib/iommu.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/testing/selftests/vfio/lib/iommu.c b/tools/testing/selftests/vfio/lib/iommu.c
index 52f9cdf5f171..8079d43523f3 100644
--- a/tools/testing/selftests/vfio/lib/iommu.c
+++ b/tools/testing/selftests/vfio/lib/iommu.c
@@ -67,7 +67,7 @@ static const struct iommu_mode *lookup_iommu_mode(const char *iommu_mode)
VFIO_FAIL("Unrecognized IOMMU mode: %s\n", iommu_mode);
}
-iova_t __iommu_hva2iova(struct iommu *iommu, void *vaddr)
+int __iommu_hva2iova(struct iommu *iommu, void *vaddr, iova_t *iova)
{
struct dma_region *region;
@@ -78,18 +78,22 @@ iova_t __iommu_hva2iova(struct iommu *iommu, void *vaddr)
if (vaddr >= region->vaddr + region->size)
continue;
- return region->iova + (vaddr - region->vaddr);
+ if (iova)
+ *iova = region->iova + (vaddr - region->vaddr);
+
+ return 0;
}
- return INVALID_IOVA;
+ return -ENOENT;
}
iova_t iommu_hva2iova(struct iommu *iommu, void *vaddr)
{
iova_t iova;
+ int ret;
- iova = __iommu_hva2iova(iommu, vaddr);
- VFIO_ASSERT_NE(iova, INVALID_IOVA, "%p is not mapped into IOMMU\n", vaddr);
+ ret = __iommu_hva2iova(iommu, vaddr, &iova);
+ VFIO_ASSERT_EQ(ret, 0, "%p is not mapped into the iommu\n", vaddr);
return iova;
}