3

I'm trying to understand how Interrupt handling works for a device assigned to VM (Guest KVM) through VFIO but didn't get any clue on how it happens?

Let's say, I have a device which is directly assigned(Device pass-through) to Guest VM through VFIO and there comes a Hardware interrupt for the that particular device?

What happens next?

Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199

1 Answers1

8

An interrupt from the device is received by the host kernel and routed to an interrupt handler registered by the vfio bus driver, vfio-pci or vfio-platform. That interrupt handler simply relays the interrupt to an eventfd that the user (QEMU) has configured via ioctl. When KVM is used, the user is able to connect the interrupt signalling eventfd from vfio directly to an interrupt injecting irqfd in KVM. This avoids bouncing the interrupt out to QEMU userspace for injection into the guest, though that path is an option if KVM irqfd support is not available.

For a level-triggered interrupt, we must also mask the interrupt interrupt in the host to prevent the device from continuing to interrupt the host while the interrupt is serviced by the guest. We therefore mask the interrupt prior to signaling the eventfd and use a slightly different KVM irqfd called a resampling irqfd, that registers a second eventfd-irqfd pair for signaling the unmask from KVM to vfio.

Various hardware technologies augment this for better efficiency. Intel APICv allows interrupts to be injected directly into the guest without a vmexit in some circumstances. This is handled entirely within KVM. Intel Posted Interrupts will allow interrupts to bypass the host completely when the correct vCPU is running on the processor receiving the hardware interrupt. ARM IRQ Forwarding allows the guest to manage the unmasking of interrupts avoiding the resampling irqfd overhead.

  • Just follow up questions from Source point of view, I can see that for vfio-platform "eventfd_signal(irq_ctx->trigger, 1); " would signal the interrupt to KVM guest but I could not find out where in QEMU source eventfd call is made and configured via IOCTL's ? Also I didn't get that point when KVM is involved QEMU is able to connect the Interrupt signaling eventfd from VFIO directly to an interrupt injecting irqfd in KVM. – Amit Singh Tomar Apr 20 '15 at 12:27
  • In Eric's v12 branch, the eventfd connection is made in platform.c:vfio_set_trigger_irqfd(). This enable the kernel module to notify the eventfd setup in the intp->interrupt event notifier. The irqfd is setup via vfio_start_irqfd_injection() in that same file. Eventfds are a mechanism for the kernel to send a signal to a file descriptor, generally for userspace signaling. IRQfds are a mechanism for userspace to signal the kernel via a file descriptor for the purpose of injecting an interrupt into a VM. If we use the same file descriptor for both, we can transparently connect vfio to kvm. – Alex Williamson Apr 21 '15 at 14:54