Skip to content

Commit 03b7c2d

Browse files
Alex Mastroawilliam
authored andcommitted
vfio: selftests: Centralize IOMMU mode name definitions
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>
1 parent ffc987b commit 03b7c2d

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

tools/testing/selftests/vfio/lib/include/libvfio/iommu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ iova_t iommu_hva2iova(struct iommu *iommu, void *vaddr);
6161

6262
struct iommu_iova_range *iommu_iova_ranges(struct iommu *iommu, u32 *nranges);
6363

64+
#define MODE_VFIO_TYPE1_IOMMU "vfio_type1_iommu"
65+
#define MODE_VFIO_TYPE1V2_IOMMU "vfio_type1v2_iommu"
66+
#define MODE_IOMMUFD_COMPAT_TYPE1 "iommufd_compat_type1"
67+
#define MODE_IOMMUFD_COMPAT_TYPE1V2 "iommufd_compat_type1v2"
68+
#define MODE_IOMMUFD "iommufd"
69+
6470
/*
6571
* Generator for VFIO selftests fixture variants that replicate across all
6672
* possible IOMMU modes. Tests must define FIXTURE_VARIANT_ADD_IOMMU_MODE()

tools/testing/selftests/vfio/lib/iommu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@
2020
#include "../../../kselftest.h"
2121
#include <libvfio.h>
2222

23-
const char *default_iommu_mode = "iommufd";
23+
const char *default_iommu_mode = MODE_IOMMUFD;
2424

2525
/* Reminder: Keep in sync with FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(). */
2626
static const struct iommu_mode iommu_modes[] = {
2727
{
28-
.name = "vfio_type1_iommu",
28+
.name = MODE_VFIO_TYPE1_IOMMU,
2929
.container_path = "/dev/vfio/vfio",
3030
.iommu_type = VFIO_TYPE1_IOMMU,
3131
},
3232
{
33-
.name = "vfio_type1v2_iommu",
33+
.name = MODE_VFIO_TYPE1V2_IOMMU,
3434
.container_path = "/dev/vfio/vfio",
3535
.iommu_type = VFIO_TYPE1v2_IOMMU,
3636
},
3737
{
38-
.name = "iommufd_compat_type1",
38+
.name = MODE_IOMMUFD_COMPAT_TYPE1,
3939
.container_path = "/dev/iommu",
4040
.iommu_type = VFIO_TYPE1_IOMMU,
4141
},
4242
{
43-
.name = "iommufd_compat_type1v2",
43+
.name = MODE_IOMMUFD_COMPAT_TYPE1V2,
4444
.container_path = "/dev/iommu",
4545
.iommu_type = VFIO_TYPE1v2_IOMMU,
4646
},
4747
{
48-
.name = "iommufd",
48+
.name = MODE_IOMMUFD,
4949
},
5050
};
5151

tools/testing/selftests/vfio/vfio_dma_mapping_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)
165165
* IOMMUFD compatibility-mode does not support huge mappings when
166166
* using VFIO_TYPE1_IOMMU.
167167
*/
168-
if (!strcmp(variant->iommu_mode, "iommufd_compat_type1"))
168+
if (!strcmp(variant->iommu_mode, MODE_IOMMUFD_COMPAT_TYPE1))
169169
mapping_size = SZ_4K;
170170

171171
ASSERT_EQ(0, rc);

0 commit comments

Comments
 (0)