]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfio: selftests: Centralize IOMMU mode name definitions
authorAlex Mastro <amastro@fb.com>
Wed, 14 Jan 2026 18:57:16 +0000 (10:57 -0800)
committerAlex Williamson <alex@shazbot.org>
Mon, 19 Jan 2026 17:06:29 +0000 (10:06 -0700)
Replace scattered string literals with MODE_* macros in iommu.h. This
provides a single source of truth for IOMMU mode name strings.

Signed-off-by: Alex Mastro <amastro@fb.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Tested-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20260114-map-mmio-test-v3-1-44e036d95e64@fb.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
tools/testing/selftests/vfio/lib/iommu.c
tools/testing/selftests/vfio/vfio_dma_mapping_test.c

index 5c9b9dc6d993803f085ed3494e90616b5aff318f..e9a3386a47193a4b9424f0cc60ba3f579d7d9fcb 100644 (file)
@@ -61,6 +61,12 @@ iova_t iommu_hva2iova(struct iommu *iommu, void *vaddr);
 
 struct iommu_iova_range *iommu_iova_ranges(struct iommu *iommu, u32 *nranges);
 
+#define MODE_VFIO_TYPE1_IOMMU "vfio_type1_iommu"
+#define MODE_VFIO_TYPE1V2_IOMMU "vfio_type1v2_iommu"
+#define MODE_IOMMUFD_COMPAT_TYPE1 "iommufd_compat_type1"
+#define MODE_IOMMUFD_COMPAT_TYPE1V2 "iommufd_compat_type1v2"
+#define MODE_IOMMUFD "iommufd"
+
 /*
  * Generator for VFIO selftests fixture variants that replicate across all
  * possible IOMMU modes. Tests must define FIXTURE_VARIANT_ADD_IOMMU_MODE()
index 58b7fb7430d4f2efc9d15251a2fec76b9b4b9aa3..035dac069d6016e208cd75baef6b0b2fba3306c0 100644 (file)
 #include "../../../kselftest.h"
 #include <libvfio.h>
 
-const char *default_iommu_mode = "iommufd";
+const char *default_iommu_mode = MODE_IOMMUFD;
 
 /* Reminder: Keep in sync with FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(). */
 static const struct iommu_mode iommu_modes[] = {
        {
-               .name = "vfio_type1_iommu",
+               .name = MODE_VFIO_TYPE1_IOMMU,
                .container_path = "/dev/vfio/vfio",
                .iommu_type = VFIO_TYPE1_IOMMU,
        },
        {
-               .name = "vfio_type1v2_iommu",
+               .name = MODE_VFIO_TYPE1V2_IOMMU,
                .container_path = "/dev/vfio/vfio",
                .iommu_type = VFIO_TYPE1v2_IOMMU,
        },
        {
-               .name = "iommufd_compat_type1",
+               .name = MODE_IOMMUFD_COMPAT_TYPE1,
                .container_path = "/dev/iommu",
                .iommu_type = VFIO_TYPE1_IOMMU,
        },
        {
-               .name = "iommufd_compat_type1v2",
+               .name = MODE_IOMMUFD_COMPAT_TYPE1V2,
                .container_path = "/dev/iommu",
                .iommu_type = VFIO_TYPE1v2_IOMMU,
        },
        {
-               .name = "iommufd",
+               .name = MODE_IOMMUFD,
        },
 };
 
index 3bf984b337ac9d27d7c45c5a763f393449c27e7c..3d2f44f9c62fb154a587076cfc710af55b2383f3 100644 (file)
@@ -165,7 +165,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
         * IOMMUFD compatibility-mode does not support huge mappings when
         * using VFIO_TYPE1_IOMMU.
         */
-       if (!strcmp(variant->iommu_mode, "iommufd_compat_type1"))
+       if (!strcmp(variant->iommu_mode, MODE_IOMMUFD_COMPAT_TYPE1))
                mapping_size = SZ_4K;
 
        ASSERT_EQ(0, rc);