Re: [PATCH v2 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges
From: Alex Williamson
Date: Tue Nov 11 2025 - 12:11:01 EST
On Tue, 11 Nov 2025 06:52:01 -0800
Alex Mastro <amastro@xxxxxx> 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` and IOVA
> range helpers are likely to be short lived, since they reside 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@xxxxxxxxxxx/#t
> [2] https://lore.kernel.org/all/20251107222058.2009244-1-dmatlack@xxxxxxxxxx/
> [3] https://lore.kernel.org/all/aRIoKJk0uwLD-yGr@xxxxxxxxxx/
>
> To: Alex Williamson <alex@xxxxxxxxxxx>
> To: David Matlack <dmatlack@xxxxxxxxxx>
> To: Shuah Khan <shuah@xxxxxxxxxx>
> To: Jason Gunthorpe <jgg@xxxxxxxx>
> Cc: kvm@xxxxxxxxxxxxxxx
> Cc: linux-kselftest@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Alex Mastro <amastro@xxxxxx>
>
> Changes in v2:
> - Fix various nits
> - calloc() where appropriate
> - Update overflow test to run regardless of iova range constraints
> - Change iova_allocator_init() to return an allocated struct
> - Unfold iova_allocator_alloc()
> - Fix iova allocator initial state bug
> - Update vfio_pci_driver_test to use iova allocator
> - Link to v1: https://lore.kernel.org/r/20251110-iova-ranges-v1-0-4d441cf5bf6d@xxxxxx
Minor comments, but otherwise LGTM and passes testing on a Kaby Lake
system with limited IOMMU address width. Thanks,
Alex