@@ -60,7 +60,9 @@ struct vfio_iommu_mode {
*/
#define FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(...) \
FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1_iommu, ##__VA_ARGS__); \
-FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1v2_iommu, ##__VA_ARGS__)
+FIXTURE_VARIANT_ADD_IOMMU_MODE(vfio_type1v2_iommu, ##__VA_ARGS__); \
+FIXTURE_VARIANT_ADD_IOMMU_MODE(iommufd_compat_type1, ##__VA_ARGS__); \
+FIXTURE_VARIANT_ADD_IOMMU_MODE(iommufd_compat_type1v2, ##__VA_ARGS__)
struct vfio_pci_bar {
struct vfio_region_info info;
@@ -376,6 +376,16 @@ static const struct vfio_iommu_mode iommu_modes[] = {
.container_path = "/dev/vfio/vfio",
.iommu_type = VFIO_TYPE1v2_IOMMU,
},
+ {
+ .name = "iommufd_compat_type1",
+ .container_path = "/dev/iommu",
+ .iommu_type = VFIO_TYPE1_IOMMU,
+ },
+ {
+ .name = "iommufd_compat_type1v2",
+ .container_path = "/dev/iommu",
+ .iommu_type = VFIO_TYPE1v2_IOMMU,
+ },
};
const char *default_iommu_mode = "vfio_type1_iommu";
@@ -128,6 +128,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
const int flags = variant->mmap_flags;
struct vfio_dma_region region;
struct iommu_mapping mapping;
+ u64 mapping_size = size;
const u64 iova = 0;
int rc;
@@ -150,6 +151,13 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
if (rc == -EOPNOTSUPP)
goto unmap;
+ /*
+ * IOMMUFD compatibility-mode does not support huge mappings when
+ * using VFIO_TYPE1_IOMMU.
+ */
+ if (!strcmp(variant->iommu_mode, "iommufd_compat_type1"))
+ mapping_size = SZ_4K;
+
ASSERT_EQ(0, rc);
printf("Found IOMMU mappings for IOVA 0x%lx:\n", iova);
printf("PGD: 0x%016lx\n", mapping.pgd);
@@ -158,7 +166,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
printf("PMD: 0x%016lx\n", mapping.pmd);
printf("PTE: 0x%016lx\n", mapping.pte);
- switch (size) {
+ switch (mapping_size) {
case SZ_4K:
ASSERT_NE(0, mapping.pte);
break;
@@ -172,7 +180,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
ASSERT_NE(0, mapping.pud);
break;
default:
- VFIO_FAIL("Unrecognized size: 0x%lx\n", size);
+ VFIO_FAIL("Unrecognized size: 0x%lx\n", mapping_size);
}
unmap:
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. Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/lib/include/vfio_util.h | 4 +++- tools/testing/selftests/vfio/lib/vfio_pci_device.c | 10 ++++++++++ tools/testing/selftests/vfio/vfio_dma_mapping_test.c | 12 ++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-)