[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251110-iova-ranges-v1-4-4d441cf5bf6d@fb.com>
Date: Mon, 10 Nov 2025 13:10:44 -0800
From: Alex Mastro <amastro@...com>
To: Alex Williamson <alex@...zbot.org>, David Matlack <dmatlack@...gle.com>,
Shuah Khan <shuah@...nel.org>
CC: <kvm@...r.kernel.org>, <linux-kselftest@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, Alex Mastro <amastro@...com>,
Jason Gunthorpe
<jgg@...pe.ca>
Subject: [PATCH 4/4] vfio: selftests: update vfio_dma_mapping_test to
allocate iovas
vfio_dma_mapping_test currently uses iova=vaddr as part of DMA mapping
validation. The assumption that these IOVAs are legal has held up on all
the hardware we've tested so far, but but is not guaranteed. Make the
test more robust by using iova_allocator to vend IOVAs, which queries
legally accessible IOVAs from the underlying IOMMUFD or VFIO container.
Signed-off-by: Alex Mastro <amastro@...com>
---
tools/testing/selftests/vfio/vfio_dma_mapping_test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
index 37c2a342df8d..c1a015385b0f 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
@@ -95,6 +95,7 @@ static int iommu_mapping_get(const char *bdf, u64 iova,
FIXTURE(vfio_dma_mapping_test) {
struct vfio_pci_device *device;
+ struct iova_allocator iova_allocator;
};
FIXTURE_VARIANT(vfio_dma_mapping_test) {
@@ -118,11 +119,16 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB |
FIXTURE_SETUP(vfio_dma_mapping_test)
{
+ int ret;
+
self->device = vfio_pci_device_init(device_bdf, variant->iommu_mode);
+ ret = iova_allocator_init(self->device, &self->iova_allocator);
+ VFIO_ASSERT_EQ(ret, 0);
}
FIXTURE_TEARDOWN(vfio_dma_mapping_test)
{
+ iova_allocator_deinit(&self->iova_allocator);
vfio_pci_device_cleanup(self->device);
}
@@ -144,7 +150,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
else
ASSERT_NE(region.vaddr, MAP_FAILED);
- region.iova = (u64)region.vaddr;
+ region.iova = iova_allocator_alloc(&self->iova_allocator, size);
region.size = size;
vfio_pci_dma_map(self->device, ®ion);
--
2.47.3
Powered by blists - more mailing lists