Re: [PATCH v5 07/21] KVM: selftests: Verify IRQ bypass works in IRQ test

From: David Matlack

Date: Thu Jun 04 2026 - 19:36:26 EST


On Thu, Jun 4, 2026 at 4:14 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Thu, Jun 04, 2026, Sean Christopherson wrote:
> > On Thu, Jun 04, 2026, Sean Christopherson wrote:
> > > The shortlog is at best misleading. There are zero guarantees that IRQ bypass
> > > is supported and enabled.
> > >
> > > On Thu, Jun 04, 2026, Josh Hilke wrote:
> > > > From: David Matlack <dmatlack@xxxxxxxxxx>
> > > >
> > > > Trigger interrupts from a VFIO device instead of emulating interrupts
> > >
> > > It's not emulating, it's synthesizing. Emulating implies there's a device of
> > > some kind that the test is mimicking.
> > >
> > > > using KVM eventfds. This verifies that guests receive interrupts via IRQ
> > > > bypass.
> > >
> > > No, it verifies that delivery of a VFIO MSI-X through VFIO=>KVM works, and *may*
> > > verify IRQ bypass. And all of that very much relies on the eventfds to be in
> > > place.
> > >
> > > > @@ -119,7 +160,17 @@ int main(int argc, char **argv)
> > > > vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
> > > > vm_install_exception_handler(vm, vector, guest_irq_handler);
> > > >
> > > > - eventfd = kvm_new_eventfd();
> > > > + if (device_bdf) {
> > > > + iommu = iommu_init(default_iommu_mode);
> > >
> > > This needs:
> > >
> > > diff --git tools/testing/selftests/kvm/irq_test.c tools/testing/selftests/kvm/irq_test.c
> > > index cf4568718cee..2e7e100d4815 100644
> > > --- tools/testing/selftests/kvm/irq_test.c
> > > +++ tools/testing/selftests/kvm/irq_test.c
> > > @@ -235,6 +235,8 @@ int main(int argc, char **argv)
> > > }
> > >
> > > if (device_bdf) {
> > > + __open_path_or_exit("/dev/iommu", O_RDONLY, "Is IOMMUFD available?");
> > > +
> > > iommu = iommu_init(default_iommu_mode);
> >
> > *sigh*
> >
> > <rant>
> > This is beyond frustating. I have A PERFECTLY FUNCTIONAL KERNEL, but this test
> > VERY SUBTLY "defaults" to IOMMUFD. ARGH!!!!!
>
> Ok, here's what I ended up with. A param to let the user force a specific type:
>
> printf("-t Override the IOMMU type to use (vfio_type1_iommu or iommufd)\n");
>
>
> And then auto-probe logic to make a halfway decent guess as to which type/mode
> to use.
>
> 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", O_RDONLY,
> "Is VFIO (or IOMMUFD) loaded and enabled?");
> close(io_fd);
> return MODE_VFIO_TYPE1_IOMMU;
> }
>
> ...
>
> if (!iommu_type)
> iommu_type = probe_iommu_type();
>
> I'll probably throw a TODO in there, because the VFIO/IOMMU infrastructure really
> needs to handle this, *especially* since "default_iommu_mode" is globally visible.
> Hardcoding a "default" to an entirely optional thing is just evil.
>
> E.g. instead of iommu_init() => lookup_iommu_mode() using default_iommu_mode when
> passed a NULL pointer, have it choose the type that's most likely to work. Then
> the IRQ test can drop its probing logic.

Yeah, choosing the default IOMMU type is something the VFIO selftests
library can provide better helpers for. Feel free to leave a TODO to
replace this.