Skip to content

Commit b8e96c8

Browse files
dmatlackawilliam
authored andcommitted
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>
1 parent 5fabc49 commit b8e96c8

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

tools/testing/selftests/vfio/lib/include/libvfio/iommu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <libvfio/assert.h>
99

1010
typedef u64 iova_t;
11-
#define INVALID_IOVA UINT64_MAX
1211

1312
struct iommu_mode {
1413
const char *name;
@@ -57,7 +56,7 @@ static inline void iommu_unmap_all(struct iommu *iommu)
5756
VFIO_ASSERT_EQ(__iommu_unmap_all(iommu, NULL), 0);
5857
}
5958

60-
iova_t __iommu_hva2iova(struct iommu *iommu, void *vaddr);
59+
int __iommu_hva2iova(struct iommu *iommu, void *vaddr, iova_t *iova);
6160
iova_t iommu_hva2iova(struct iommu *iommu, void *vaddr);
6261

6362
struct iommu_iova_range *iommu_iova_ranges(struct iommu *iommu, u32 *nranges);

tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static inline void vfio_pci_msix_disable(struct vfio_pci_device *device)
103103
vfio_pci_irq_disable(device, VFIO_PCI_MSIX_IRQ_INDEX);
104104
}
105105

106-
static inline iova_t __to_iova(struct vfio_pci_device *device, void *vaddr)
106+
static inline int __to_iova(struct vfio_pci_device *device, void *vaddr, iova_t *iova)
107107
{
108-
return __iommu_hva2iova(device->iommu, vaddr);
108+
return __iommu_hva2iova(device->iommu, vaddr, iova);
109109
}
110110

111111
static inline iova_t to_iova(struct vfio_pci_device *device, void *vaddr)

tools/testing/selftests/vfio/lib/iommu.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static const struct iommu_mode *lookup_iommu_mode(const char *iommu_mode)
6767
VFIO_FAIL("Unrecognized IOMMU mode: %s\n", iommu_mode);
6868
}
6969

70-
iova_t __iommu_hva2iova(struct iommu *iommu, void *vaddr)
70+
int __iommu_hva2iova(struct iommu *iommu, void *vaddr, iova_t *iova)
7171
{
7272
struct dma_region *region;
7373

@@ -78,18 +78,22 @@ iova_t __iommu_hva2iova(struct iommu *iommu, void *vaddr)
7878
if (vaddr >= region->vaddr + region->size)
7979
continue;
8080

81-
return region->iova + (vaddr - region->vaddr);
81+
if (iova)
82+
*iova = region->iova + (vaddr - region->vaddr);
83+
84+
return 0;
8285
}
8386

84-
return INVALID_IOVA;
87+
return -ENOENT;
8588
}
8689

8790
iova_t iommu_hva2iova(struct iommu *iommu, void *vaddr)
8891
{
8992
iova_t iova;
93+
int ret;
9094

91-
iova = __iommu_hva2iova(iommu, vaddr);
92-
VFIO_ASSERT_NE(iova, INVALID_IOVA, "%p is not mapped into IOMMU\n", vaddr);
95+
ret = __iommu_hva2iova(iommu, vaddr, &iova);
96+
VFIO_ASSERT_EQ(ret, 0, "%p is not mapped into the iommu\n", vaddr);
9397

9498
return iova;
9599
}

tools/testing/selftests/vfio/vfio_dma_mapping_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
199199
ASSERT_EQ(rc, 0);
200200
ASSERT_EQ(unmapped, region.size);
201201
printf("Unmapped IOVA 0x%lx\n", region.iova);
202-
ASSERT_EQ(INVALID_IOVA, __to_iova(self->device, region.vaddr));
202+
ASSERT_NE(0, __to_iova(self->device, region.vaddr, NULL));
203203
ASSERT_NE(0, iommu_mapping_get(device_bdf, region.iova, &mapping));
204204

205205
ASSERT_TRUE(!munmap(region.vaddr, size));

0 commit comments

Comments
 (0)