]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
vfio: selftests: add iova range query helpers
authorAlex Mastro <amastro@fb.com>
Tue, 11 Nov 2025 18:48:24 +0000 (10:48 -0800)
committerAlex Williamson <alex@shazbot.org>
Wed, 12 Nov 2025 15:04:42 +0000 (08:04 -0700)
commit7c44656ab3ea6f8429027ed14c23b314502e2541
treeb354a79ad9aa56e2115cae4763b8c6a2bf953f49
parent6146a0f1dfae5d37442a9ddcba012add260bceb0
vfio: selftests: add iova range query helpers

VFIO selftests need to map IOVAs from legally accessible ranges, which
could vary between hardware. Tests in vfio_dma_mapping_test.c are making
excessively strong assumptions about which IOVAs can be mapped.

Add vfio_iommu_iova_ranges(), which queries IOVA ranges from the
IOMMUFD or VFIO container associated with the device. The queried ranges
are normalized to IOMMUFD's iommu_iova_range representation so that
handling of IOVA ranges up the stack can be implementation-agnostic.
iommu_iova_range and vfio_iova_range are equivalent, so bias to using the
new interface's struct.

Query IOMMUFD's ranges with IOMMU_IOAS_IOVA_RANGES.
Query VFIO container's ranges with VFIO_IOMMU_GET_INFO and
VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE.

The underlying vfio_iommu_type1_info buffer-related functionality has
been kept generic so the same helpers can be used to query other
capability chain information, if needed.

Reviewed-by: David Matlack <dmatlack@google.com>
Tested-by: David Matlack <dmatlack@google.com>
Signed-off-by: Alex Mastro <amastro@fb.com>
Link: https://lore.kernel.org/r/20251111-iova-ranges-v3-1-7960244642c5@fb.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
tools/testing/selftests/vfio/lib/include/vfio_util.h
tools/testing/selftests/vfio/lib/vfio_pci_device.c