[PATCH 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges

Alex Mastro posted 4 patches 2 months, 4 weeks ago
There is a newer version of this series
.../testing/selftests/vfio/lib/include/vfio_util.h |  22 +-
tools/testing/selftests/vfio/lib/vfio_pci_device.c | 226 ++++++++++++++++++++-
.../testing/selftests/vfio/vfio_dma_mapping_test.c |  25 ++-
3 files changed, 268 insertions(+), 5 deletions(-)
[PATCH 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges
Posted by Alex Mastro 2 months, 4 weeks ago
Not all IOMMUs support the same virtual address width as the processor,
for instance older Intel consumer platforms only support 39-bits of
IOMMU address space.  On such platforms, using the virtual address as
the IOVA and mappings at the top of the address space both fail.

VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges,
VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE and IOMMU_IOAS_IOVA_RANGES,
respectively.  These provide compatible arrays of ranges from which
we can construct a simple allocator and record the maximum supported
IOVA address.

Use this new allocator in place of reusing the virtual address, and
incorporate the maximum supported IOVA into the limit testing.  This
latter change doesn't test quite the same absolute end-of-address space
behavior but still seems to have some value.  Testing for overflow is
skipped when a reduced address space is supported as the desired errno
is not generated.

This series is based on Alex Williamson's "Incorporate IOVA range info"
[1] along with feedback from the discussion in David Matlack's "Skip
vfio_dma_map_limit_test if mapping returns -EINVAL" [2].

Given David's plans to split IOMMU concerns from devices as described in
[3], this series' home for `struct iova_allocator` is likely to be short
lived, since it resides in vfio_pci_device.c. I assume that the rework
can move this functionality to a more appropriate location next to other
IOMMU-focused code, once such a place exists.

[1] https://lore.kernel.org/all/20251108212954.26477-1-alex@shazbot.org/#t
[2] https://lore.kernel.org/all/20251107222058.2009244-1-dmatlack@google.com/
[3] https://lore.kernel.org/all/aRIoKJk0uwLD-yGr@google.com/

Signed-off-by: Alex Mastro <amastro@fb.com>
---
Alex Mastro (4):
      vfio: selftests: add iova range query helpers
      vfio: selftests: fix map limit tests to use last available iova
      vfio: selftests: add iova allocator
      vfio: selftests: update vfio_dma_mapping_test to allocate iovas

 .../testing/selftests/vfio/lib/include/vfio_util.h |  22 +-
 tools/testing/selftests/vfio/lib/vfio_pci_device.c | 226 ++++++++++++++++++++-
 .../testing/selftests/vfio/vfio_dma_mapping_test.c |  25 ++-
 3 files changed, 268 insertions(+), 5 deletions(-)
---
base-commit: 0ed3a30fd996cb0cac872432cf25185fda7e5316
change-id: 20251110-iova-ranges-1c09549fbf63

Best regards,
-- 
Alex Mastro <amastro@fb.com>
Re: [PATCH 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges
Posted by David Matlack 2 months, 4 weeks ago
On Mon, Nov 10, 2025 at 1:11 PM Alex Mastro <amastro@fb.com> wrote:
>
> Not all IOMMUs support the same virtual address width as the processor,
> for instance older Intel consumer platforms only support 39-bits of
> IOMMU address space.  On such platforms, using the virtual address as
> the IOVA and mappings at the top of the address space both fail.
>
> VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges,
> VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE and IOMMU_IOAS_IOVA_RANGES,
> respectively.  These provide compatible arrays of ranges from which
> we can construct a simple allocator and record the maximum supported
> IOVA address.
>
> Use this new allocator in place of reusing the virtual address, and
> incorporate the maximum supported IOVA into the limit testing.  This
> latter change doesn't test quite the same absolute end-of-address space
> behavior but still seems to have some value.  Testing for overflow is
> skipped when a reduced address space is supported as the desired errno
> is not generated.
>
> This series is based on Alex Williamson's "Incorporate IOVA range info"
> [1] along with feedback from the discussion in David Matlack's "Skip
> vfio_dma_map_limit_test if mapping returns -EINVAL" [2].
>
> Given David's plans to split IOMMU concerns from devices as described in
> [3], this series' home for `struct iova_allocator` is likely to be short
> lived, since it resides in vfio_pci_device.c. I assume that the rework
> can move this functionality to a more appropriate location next to other
> IOMMU-focused code, once such a place exists.

Yup, I'll rebase my iommu rework on top of this once it goes in, and
move the iova allocator to a new home.

And thanks for getting this out so quickly. We've had an unstaffed
internal task to get rid of iova=vaddr open for a few months now, so
I'm very happy to see it get fixed.