Skip to content

Commit a77fa0b

Browse files
Alex Mastroawilliam
authored andcommitted
vfio: selftests: fix map limit tests to use last available iova
Use the newly available vfio_pci_iova_ranges() to determine the last legal IOVA, and use this as the basis for vfio_dma_map_limit_test tests. Fixes: de8d1f2 ("vfio: selftests: add end of address space DMA map/unmap tests") Reviewed-by: David Matlack <[email protected]> Tested-by: David Matlack <[email protected]> Signed-off-by: Alex Mastro <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent 7c44656 commit a77fa0b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tools/testing/selftests/vfio/vfio_dma_mapping_test.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <sys/mman.h>
44
#include <unistd.h>
55

6+
#include <uapi/linux/types.h>
7+
#include <linux/iommufd.h>
68
#include <linux/limits.h>
79
#include <linux/mman.h>
810
#include <linux/sizes.h>
@@ -219,7 +221,10 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES();
219221
FIXTURE_SETUP(vfio_dma_map_limit_test)
220222
{
221223
struct vfio_dma_region *region = &self->region;
224+
struct iommu_iova_range *ranges;
222225
u64 region_size = getpagesize();
226+
iova_t last_iova;
227+
u32 nranges;
223228

224229
/*
225230
* Over-allocate mmap by double the size to provide enough backing vaddr
@@ -232,8 +237,13 @@ FIXTURE_SETUP(vfio_dma_map_limit_test)
232237
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
233238
ASSERT_NE(region->vaddr, MAP_FAILED);
234239

235-
/* One page prior to the end of address space */
236-
region->iova = ~(iova_t)0 & ~(region_size - 1);
240+
ranges = vfio_pci_iova_ranges(self->device, &nranges);
241+
VFIO_ASSERT_NOT_NULL(ranges);
242+
last_iova = ranges[nranges - 1].last;
243+
free(ranges);
244+
245+
/* One page prior to the last iova */
246+
region->iova = last_iova & ~(region_size - 1);
237247
region->size = region_size;
238248
}
239249

@@ -276,6 +286,7 @@ TEST_F(vfio_dma_map_limit_test, overflow)
276286
struct vfio_dma_region *region = &self->region;
277287
int rc;
278288

289+
region->iova = ~(iova_t)0 & ~(region->size - 1);
279290
region->size = self->mmap_size;
280291

281292
rc = __vfio_pci_dma_map(self->device, region);

0 commit comments

Comments
 (0)