armlinux-device-driverkvminterrupt-handlingvfio

Interrupt handling for assigned Device through VFIO


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?


Solution

  • 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.