On 2025-05-30 02:25 PM, Jason Gunthorpe wrote:
On Fri, May 30, 2025 at 09:50:22AM -0700, David Matlack wrote:
I'll explore doing this. For a single dimension this looks possible. But for multiple dimensions (e.g. cross product of iommu_mode and backing_src) I don't see a clear way to do it. But that's just after a cursory look.
Explicitly list all the combinations with macros?
Enhance the userspace tests allow code to generate the variants? Kernel tests can do this:
I got a chance to play around with generating fixture variants today and eneded up with this, which I think is pretty clean.
tools/testing/selftests/vfio/lib/include/vfio_util.h:
#define ALL_IOMMU_MODES_VARIANT_ADD(...) \ __IOMMU_MODE_VARIANT_ADD(vfio_type1_iommu, ##__VA_ARGS__); \ __IOMMU_MODE_VARIANT_ADD(vfio_type1v2_iommu, ##__VA_ARGS__); \ __IOMMU_MODE_VARIANT_ADD(iommufd_compat_type1, ##__VA_ARGS__); \ __IOMMU_MODE_VARIANT_ADD(iommufd_compat_type1v2, ##__VA_ARGS__); \ __IOMMU_MODE_VARIANT_ADD(iommufd, ##__VA_ARGS__)
tools/testing/selftests/vfio/vfio_dma_mapping_test.c:
#define __IOMMU_MODE_VARIANT_ADD(_iommu_mode, _name, _size, _mmap_flags) \ FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, _iommu_mode ## _name) \ { \ .iommu_mode = #_iommu_mode, \ .size = (_size), \ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | (_mmap_flags), \ }
ALL_IOMMU_MODES_VARIANT_ADD(anonymous, 0, 0); ALL_IOMMU_MODES_VARIANT_ADD(anonymous_hugetlb_2mb, SZ_2M, MAP_HUGETLB | MAP_HUGE_2MB); ALL_IOMMU_MODES_VARIANT_ADD(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB | MAP_HUGE_1GB);
#undef __IOMMU_MODE_VARIANT_ADD
Let me know if you think this looks reasonable.