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 09:22:07 -0700 [thread overview]
Message-ID: <aiGmL-8RKlVPbBwZ@google.com> (raw)
In-Reply-To: <20260604020143.748245-8-jrhilke@google.com>
On Thu, Jun 04, 2026, Josh Hilke wrote:
> @@ -76,9 +109,10 @@ static void kvm_route_msi(struct kvm_vm *vm, u32 gsi, struct kvm_vcpu *vcpu,
>
> static void help(const char *name)
> {
> - printf("Usage: %s [-h]\n", name);
> + printf("Usage: %s [-d <segment:bus:device.function>] [-h]\n", name);
> printf("\n");
> printf("Tests KVM IRQ injection via irqfd using an emulated eventfd.\n");
> + printf("-d Use a VFIO device to send MSI-X interrupts instead of using an emulated eventfd\n");
printf("-d Use a VFIO device to send MSI-X interrupts instead of manually signaling the eventfd\n");
> printf("\n");
> exit(KSFT_FAIL);
> }
> @@ -100,14 +134,21 @@ int main(int argc, char **argv)
> u32 gsi = kvm_random_u64_in_range(&kvm_rng, 24, KVM_MAX_IRQ_ROUTES - 1);
> u8 vector = kvm_random_u64_in_range(&kvm_rng, 32, UINT8_MAX);
>
> - struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
> pthread_t vcpu_threads[KVM_MAX_VCPUS];
> + struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
> + struct vfio_pci_device *device = NULL;
> int nr_irqs = 1000, nr_vcpus = 1;
> - int i, j, c, eventfd;
> + const char *device_bdf = NULL;
> + int i, j, c, msix, eventfd;
> + struct iommu *iommu;
> struct kvm_vm *vm;
> + unsigned int irq;
I think it makes sense to track "irq" as a signed int, so that the !device path
can set it to -1. Then it can be printed somewhat blindly without being outright
wrong.
> - while ((c = getopt(argc, argv, "h")) != -1) {
> + while ((c = getopt(argc, argv, "d:h")) != -1) {
> switch (c) {
> + case 'd':
> + device_bdf = optarg;
> + break;
> case 'h':
> default:
> help(argv[0]);
> @@ -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);
> + device = vfio_pci_device_init(device_bdf, iommu);
> + msix = vfio_setup_msi(device);
> + irq = vfio_msix_to_host_irq(device_bdf, msix);
> + eventfd = device->msi_eventfds[msix];
> + printf("Using device %s MSI-X[%d] (IRQ-%u)\n", device_bdf, msix,
> + irq);
> + } else {
> + eventfd = kvm_new_eventfd();
> + }
>
> printf("Injecting interrupts for GSI %d (Vector 0x%x) %d times\n",
> gsi, vector, nr_irqs);
> @@ -147,8 +198,7 @@ int main(int argc, char **argv)
> "IRQ flag for vCPU %d not clear prior to test",
> vcpus[j]->id);
Print the IRQ in the assert. Ditto for the pCPU in the future. Providing more
debug information is nice, but it should *always* be secondary to providing info
in the assert/error itself.
TEST_ASSERT(GUEST_RECEIVED_INTERRUPT(vcpu, do_use_nmi),
"vCPU %d timed out waiting for %s (vector 0x%x) from GSI %d (via CPU %d)\n",
vcpu->id, do_use_nmi ? "NMI" : "IRQ",
do_use_nmi ? NMI_VECTOR : vector, gsi, irq_cpu);
>
> - /* Trigger interrupt */
> - eventfd_write(eventfd, 1);
> + trigger_interrupt(device, eventfd);
>
> clock_gettime(CLOCK_MONOTONIC, &start);
> for (;;) {
> --
> 2.54.0.1032.g2f8565e1d1-goog
>
next prev parent reply other threads:[~2026-06-04 16:22 UTC|newest]
Thread overview: 54+ 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:12 ` sashiko-bot
2026-06-04 16:12 ` Sean Christopherson
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:09 ` sashiko-bot
2026-06-04 20:01 ` Sean Christopherson
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 [this message]
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
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 2:09 ` sashiko-bot
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:09 ` sashiko-bot
2026-06-04 17:17 ` Sean Christopherson
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:13 ` sashiko-bot
2026-06-04 2:01 ` [PATCH v5 11/21] KVM: selftests: Verify IRQs wake up halted vCPUs " Josh Hilke
2026-06-04 2:15 ` sashiko-bot
2026-06-04 16:11 ` Sean Christopherson
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:21 ` sashiko-bot
2026-06-04 17:28 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 20/21] KVM: selftests: Make number of vCPUs configurable in " Josh Hilke
2026-06-04 2:20 ` sashiko-bot
2026-06-04 17:29 ` Sean Christopherson
2026-06-04 17:41 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 21/21] KVM: selftests: Add xAPIC support " Josh Hilke
2026-06-04 2:22 ` sashiko-bot
2026-06-04 17:34 ` Sean Christopherson
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=aiGmL-8RKlVPbBwZ@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