The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Josh Hilke <jrhilke@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 David Matlack <dmatlack@google.com>,
	Alex Williamson <alex.williamson@redhat.com>
Subject: Re: [PATCH v5 07/21] KVM: selftests: Verify IRQ bypass works in IRQ test
Date: Thu, 4 Jun 2026 16:14:32 -0700	[thread overview]
Message-ID: <aiIG2L_KdPwuxYA1@google.com> (raw)
In-Reply-To: <aiHRIhxgBCy1TVfQ@google.com>

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@google.com>
> > > 
> > > 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.

  parent reply	other threads:[~2026-06-04 23:14 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  2:01 [PATCH v5 00/21] KVM: selftests: Link with VFIO selftests lib and test device interrupts Josh Hilke
2026-06-04  2:01 ` [PATCH v5 01/21] KVM: selftests: Build and link selftests/vfio/lib into KVM selftests Josh Hilke
2026-06-04  2:01 ` [PATCH v5 02/21] KVM: selftests: Add guest read/write macros Josh Hilke
2026-06-04  2:01 ` [PATCH v5 03/21] KVM: selftests: Rename guest_rng to kvm_rng Josh Hilke
2026-06-04  2:01 ` [PATCH v5 04/21] KVM: selftests: Add helper to generate random u64 in range [min,max] Josh Hilke
2026-06-04  2:01 ` [PATCH v5 05/21] KVM: selftests: Add IRQ injection test Josh Hilke
2026-06-04 16:19   ` Sean Christopherson
2026-06-04 16:26     ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 06/21] KVM: selftests: Add helper to get host IRQ from device MSIX for IRQ bypass test Josh Hilke
2026-06-04  2:01 ` [PATCH v5 07/21] KVM: selftests: Verify IRQ bypass works in IRQ test Josh Hilke
2026-06-04 16:22   ` Sean Christopherson
2026-06-04 17:56   ` Sean Christopherson
2026-06-04 19:25     ` Sean Christopherson
2026-06-04 19:52       ` Sean Christopherson
2026-06-04 23:14       ` Sean Christopherson [this message]
2026-06-04 23:35         ` David Matlack
2026-06-04  2:01 ` [PATCH v5 08/21] KVM: selftests: Add helpers to write proc IRQ affinity for " Josh Hilke
2026-06-04 19:35   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 09/21] KVM: selftests: Add helpers to print " Josh Hilke
2026-06-04  2:01 ` [PATCH v5 10/21] KVM: selftests: Verify interrupts are received when IRQ affinity changes in " Josh Hilke
2026-06-04  2:01 ` [PATCH v5 11/21] KVM: selftests: Verify IRQs wake up halted vCPUs " Josh Hilke
2026-06-04  2:01 ` [PATCH v5 12/21] KVM: selftests: Verify interrupts are received after modifying IRQ routes " Josh Hilke
2026-06-04 17:22   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 13/21] KVM: selftests: Make number of IRQs configurable " Josh Hilke
2026-06-04 17:35   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 14/21] KVM: selftests: Verify non-postable IRQ remapping " Josh Hilke
2026-06-04 17:22   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 15/21] KVM: selftests: Add kvm_gettid() wrapper and convert users Josh Hilke
2026-06-04  2:01 ` [PATCH v5 16/21] KVM: selftests: Add kvm_sched_getaffinity() " Josh Hilke
2026-06-04 17:23   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 17/21] KVM: selftests: Add pin_task_to_random_cpu() helper function for IRQ test Josh Hilke
2026-06-04  2:01 ` [PATCH v5 18/21] KVM: selftests: Verify vCPU migration during IRQ delivery in " Josh Hilke
2026-06-04 17:27   ` Sean Christopherson
2026-06-04  2:01 ` [PATCH v5 19/21] KVM: selftests: Print vCPU affinity on timeout during " Josh Hilke
2026-06-04  2:01 ` [PATCH v5 20/21] KVM: selftests: Make number of vCPUs configurable in " Josh Hilke
2026-06-04  2:01 ` [PATCH v5 21/21] KVM: selftests: Add xAPIC support " Josh Hilke
2026-06-04 20:22 ` [PATCH v5 00/21] KVM: selftests: Link with VFIO selftests lib and test device interrupts Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aiIG2L_KdPwuxYA1@google.com \
    --to=seanjc@google.com \
    --cc=alex.williamson@redhat.com \
    --cc=dmatlack@google.com \
    --cc=jrhilke@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox