Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vfio: selftests: Add iommufd_compat_type1{,v2} modes

Add new IOMMU modes for using iommufd in compatibility mode with
VFIO_TYPE1_IOMMU and VFIO_TYPE1v2_IOMMU.

In these modes, VFIO selftests will open /dev/iommu and treats it as a
container FD (as if it had opened /dev/vfio/vfio) and the kernel
translates the container ioctls to iommufd calls transparently.

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-28-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

David Matlack and committed by
Alex Williamson
d1a17495 0969c685

+23 -3
+3 -1
tools/testing/selftests/vfio/lib/include/vfio_util.h
··· 60 60 */ 61 61 #define FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(...) \ 62 62 FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1_iommu, ##__VA_ARGS__); \ 63 - FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1v2_iommu, ##__VA_ARGS__) 63 + FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1v2_iommu, ##__VA_ARGS__); \ 64 + FIXTURE_VARIANT_ADD_IOMMU_MODE(iommufd_compat_type1, ##__VA_ARGS__); \ 65 + FIXTURE_VARIANT_ADD_IOMMU_MODE(iommufd_compat_type1v2, ##__VA_ARGS__) 64 66 65 67 struct vfio_pci_bar { 66 68 struct vfio_region_info info;
+10
tools/testing/selftests/vfio/lib/vfio_pci_device.c
··· 376 376 .container_path = "/dev/vfio/vfio", 377 377 .iommu_type = VFIO_TYPE1v2_IOMMU, 378 378 }, 379 + { 380 + .name = "iommufd_compat_type1", 381 + .container_path = "/dev/iommu", 382 + .iommu_type = VFIO_TYPE1_IOMMU, 383 + }, 384 + { 385 + .name = "iommufd_compat_type1v2", 386 + .container_path = "/dev/iommu", 387 + .iommu_type = VFIO_TYPE1v2_IOMMU, 388 + }, 379 389 }; 380 390 381 391 const char *default_iommu_mode = "vfio_type1_iommu";
+10 -2
tools/testing/selftests/vfio/vfio_dma_mapping_test.c
··· 128 128 const int flags = variant->mmap_flags; 129 129 struct vfio_dma_region region; 130 130 struct iommu_mapping mapping; 131 + u64 mapping_size = size; 131 132 int rc; 132 133 133 134 region.vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); ··· 151 150 if (rc == -EOPNOTSUPP) 152 151 goto unmap; 153 152 153 + /* 154 + * IOMMUFD compatibility-mode does not support huge mappings when 155 + * using VFIO_TYPE1_IOMMU. 156 + */ 157 + if (!strcmp(variant->iommu_mode, "iommufd_compat_type1")) 158 + mapping_size = SZ_4K; 159 + 154 160 ASSERT_EQ(0, rc); 155 161 printf("Found IOMMU mappings for IOVA 0x%lx:\n", region.iova); 156 162 printf("PGD: 0x%016lx\n", mapping.pgd); ··· 166 158 printf("PMD: 0x%016lx\n", mapping.pmd); 167 159 printf("PTE: 0x%016lx\n", mapping.pte); 168 160 169 - switch (size) { 161 + switch (mapping_size) { 170 162 case SZ_4K: 171 163 ASSERT_NE(0, mapping.pte); 172 164 break; ··· 180 172 ASSERT_NE(0, mapping.pud); 181 173 break; 182 174 default: 183 - VFIO_FAIL("Unrecognized size: 0x%lx\n", size); 175 + VFIO_FAIL("Unrecognized size: 0x%lx\n", mapping_size); 184 176 } 185 177 186 178 unmap: