[PATCH v2 4/5] KVM: selftests: Use VFIO selftests library to pick IOMMU mode in irq_test

From: David Matlack

Date: Mon Nov 02 2026 - 19:28:54 EST


Use the VFIO selftests library to pick the IOMMU mode in irq_test and drop
probe_iommu_type(). Pass NULL to iommu_init() when the user does not
specify a mode with -t, and skip the test if the requested mode (or, if
NULL, any mode) is not available.

The VFIO selftests library now automatically picks the IOMMU mode that is
most likely to work on the current system, so there is no need for each
test to probe for a mode itself.

Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Link: https://lore.kernel.org/kvm/aiIG2L_KdPwuxYA1@xxxxxxxxxx/
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
tools/testing/selftests/kvm/irq_test.c | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c
index 791e576c334c..8a345472df5f 100644
--- a/tools/testing/selftests/kvm/irq_test.c
+++ b/tools/testing/selftests/kvm/irq_test.c
@@ -148,22 +148,6 @@ static void kvm_set_empty_gsi_routing(struct kvm_vm *vm)
vm_ioctl(vm, KVM_SET_GSI_ROUTING, &routing);
}

-static const char *probe_iommu_type(void)
-{
- int io_fd;
-
- io_fd = open("/dev/iommu", O_RDONLY);
- if (io_fd >= 0) {
- close(io_fd);
- return MODE_IOMMUFD;
- }
-
- io_fd = __open_path_or_exit("/dev/vfio/vfio", O_RDONLY,
- "Is VFIO (or IOMMUFD) loaded and enabled?");
- close(io_fd);
- return MODE_VFIO_TYPE1_IOMMU;
-}
-
static void help(const char *name)
{
printf("Usage: %s [-a] [-d <segment:bus:device.function>] [-e] [-h] [-i nr_irqs] [-m] [-n] [-t iommu_type] [-v nr_vcpus] [-x]\n", name);
@@ -266,8 +250,8 @@ int main(int argc, char **argv)
}

if (device_bdf) {
- if (!iommu_type)
- iommu_type = probe_iommu_type();
+ __TEST_REQUIRE(iommu_mode_is_available(iommu_type), "%s",
+ iommu_mode_unavailable_msg(iommu_type));
iommu = iommu_init(iommu_type);
device = vfio_pci_device_init(device_bdf, iommu);
msix = vfio_setup_msi(device);
--
2.56.0.385.gac671c819a-goog