Re: [PATCH 3/3] KVM: selftests: Use VFIO selftests library to pick IOMMU mode in IRQ test

From: Sean Christopherson

Date: Mon Nov 02 2026 - 12:14:21 EST


On Mon, Nov 02, 2026, Sean Christopherson wrote:
> On Thu, Oct 29, 2026, David Matlack wrote:
> > 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,7 @@ 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));
>
> This is very unhelpful when neither IOMMUFD nor VFIO is available, especially
> why the user doesn't explicitly provide the desired mode:
>
> # ./irq_test -d 0000:6f:01.0 -i 10000
> Random seed: 0x79d386bd
> 1..0 # SKIP - Requirement not met: iommu_mode_is_available(iommu_type)
>
> I helped write the test and I had to go read the code to figure out what iommu_type
> would be, and then read the VFIO library to see how it reacted to a NULL pointer.
>
> How about something like this as fixup:
>
> diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c
> index f9c11d80a306..63205afc04d1 100644
> --- a/tools/testing/selftests/kvm/irq_test.c
> +++ b/tools/testing/selftests/kvm/irq_test.c
> @@ -250,7 +250,9 @@ int main(int argc, char **argv)
> }
>
> if (device_bdf) {
> - TEST_REQUIRE(iommu_mode_is_available(iommu_type));
> + __TEST_REQUIRE(iommu_mode_is_available(iommu_type),
> + "IOMMU mode(s) '%s' not available",
> + iommu_type ? iommu_type : "IOMMU and/or VFIO");
> iommu = iommu_init(iommu_type);
> device = vfio_pci_device_init(device_bdf, iommu);
> msix = vfio_setup_msi(device);
>
> to yield:
>
> # ./irq_test -d 0000:6f:01.0 -i 10000 -t vfio_type1_iommu
> Random seed: 0x14e21328
> 1..0 # SKIP - IOMMU mode(s) 'vfio_type1_iommu' not available
> # ./irq_test -d 0000:6f:01.0 -i 10000
> Random seed: 0x160225ae
> 1..0 # SKIP - IOMMU mode(s) 'IOMMU and/or VFIO' not available

Side topic, it would be nice if iommu_mode_lookup() printed out the known modes
when this is hit:

VFIO_FAIL("Unrecognized IOMMU mode: %s\n", iommu_mode);