KVM: Proposed uAPI for querying GSI and irqbypass status
This RFC proposes a new KVM uAPI to allow a VMM to programmatically query the status of a GSI, with a particular focus on determining the success or failure of Irqbypass.
1. Motivation
The primary motivation for this uAPI is to bridge the operational gap between the VMM and KVM at the kernel level regarding interrupt virtualization status:
* KVM (Kernel) holds the precise, live runtime status of each GSI (such as whether Irqbypass is active, pending, or has encountered a setup error). However, it completely lacks the high-level semantic details of those GSIs—it does not understand which logical function or physical hardware device they represent.
* The VMM (Userspace) possesses the complete context of the guest's interrupt topology. It knows exactly which GSI belongs to which passthrough or emulated device because it orchestrated the setup. Yet, the VMM has no stable, programmatic way to query the actual runtime execution status of these GSIs once passed to the kernel.
Currently, diagnosing when a high-performance interrupt path falls back to software mediation is highly problematic:
* While some architectures (like ARM64) expose virtual ITS states via debugfs, this implementation is highly architecture-specific and fragile.
* debugfs is not a stable API, is prone to breaking changes across kernel versions, and is entirely unsuitable for programmatic production monitoring and fleet-wide observability.
This is not an ARM-specific problem; it is a general, cross-architecture limitation within KVM's Irqbypass and interrupt routing subsystem. By introducing an architecture-neutral uAPI, we allow the VMM to marry its topological knowledge with KVM's live execution state.
2. Main Design Idea
Based on recent community discussions, this proposal follows a set of agreed-upon design principles:
* Architecture-Neutral: The API is a generic ioctl on the VM file descriptor, using the GSI abstraction.
* Extensible: The API provides an in-struct union with a dedicated size reservation. This avoids the complexity of userspace and kernel managing separate data allocations or chasing userspace pointers.
* Decoupled: It is a KVM ioctl, maintaining the separation between the KVM and VFIO subsystems.
* "Pull" Model: The VMM explicitly queries the state of a GSI on demand.
We propose a new ioctl on the VM file descriptor: KVM_GET_GSI_STATE.
3. Proposed API Definition
The following sample code defines the proposed ioctl and its associated data structures.
/* To be included in <linux/kvm.h> */
/*
* KVM_GET_GSI_STATE: Get the status of a specific GSI.
*
* The user passes a pointer to struct kvm_gsi_state. The kernel fills in
* the status flags, performance counters, and the architecture-specific
* union members directly.
*/
/* Generic flags indicating high-level status */
/*
* The GSI's route is theoretically compatible with hardware bypass
* on this host (e.g. is an MSI route and GICv4/VT-d is present). */
#define KVM_GSI_STATE_FLAG_BYPASSABLE (1 << 0)
/* An IRQFD is currently active and bound to this GSI */
#define KVM_GSI_STATE_FLAG_HAS_IRQFD (1 << 1)
/* The irqbypass path is fully enabled and active in hardware */
#define KVM_GSI_STATE_FLAG_BYPASS_ACTIVE (1 << 2)
/* Example architecture-specific failure reasons for ARM64 */
#define KVM_ARM_GSI_FAILURE_REASON_NONE 0 #define KVM_ARM_GSI_FAILURE_REASON_NO_ITS 1 /* No ITS/GICv4 support */ #define KVM_ARM_GSI_FAILURE_REASON_NO_MSI_ADDR 2 /* MSI address unset */ #define KVM_ARM_GSI_FAILURE_REASON_GIC_HW_REJECT 3 /* GIC rejected map */ #define KVM_ARM_GSI_FAILURE_REASON_INVALID_STATE 4 /* Guest state block */
struct kvm_gsi_state {
__u32 gsi; /* IN: The GSI to query */
__u32 flags; /* OUT: High-level status flags */
__u64 counter_success; /* OUT: Generic counter for successful bypass */
__u64 counter_failure; /* OUT: Generic counter for failed bypass */ union {
struct kvm_arm_gsi_state {
__u32 failure_reason; /* OUT: Last reason for bypass failure */
__u32 padding; /* OUT: Explicit padding alignment */
__u64 vgic_its_vlpis_hw;/* OUT: counter for directly injected vLPIs */
} arm64;
/* Pad union to 128 bytes to allow future arch growth */
__u64 pad[16];
};
};#define KVM_GET_GSI_STATE _IOWR(KVMIO, 0xXX, struct kvm_gsi_state)
4. Implementation Sketch
The KVM_GET_GSI_STATE ioctl handler would perform the following high-level steps:
1. Find the GSI Route: The handler would take the input gsi and look it up in the VM's kvm->irq_routing table to find the corresponding kvm_kernel_irq_routing_entry.
2. Evaluate Bypass Capability: The kernel checks if the GSI routing entry type and target are capable of utilizing hardware bypass under the current host hardware configuration. If so, KVM sets KVM_GSI_STATE_FLAG_BYPASSABLE.
3. Locate the Irqfd Context: The kernel searches its registered irqfds. If an active kvm_kernel_irqfd is bound to this GSI, KVM sets KVM_GSI_STATE_FLAG_HAS_IRQFD. This context is the key to finding the active bypass status, as it contains the irq_bypass_consumer.
4. Inspect Irqbypass Status:
If an active irqfd is found, the handler inspects consumer->producer. If a physical producer is successfully paired and the hardware-level link is fully established, KVM sets KVM_GSI_STATE_FLAG_BYPASS_ACTIVE.
5. Gather Performance Counters: To implement the counters, new atomic64_t fields for success_count and failure_count would be added to the struct kvm_kernel_irqfd. These counters are essential for a VMM that polls on a semi-regular basis to detect if the bypass state has changed or flapped over time (e.g., during vCPU migrations, routing updates, or device resets). By observing increases in these counters across poll intervals, the VMM can detect bypass path instability or dynamic teardowns without requiring high-overhead asynchronous event notifications. The ioctl handler simply reads these atomic values.
6. Architecture-Specific Logic (ARM64 Example): The kernel detects the target architecture and directly populates the corresponding arm64 nested struct within the kvm_gsi_state union:
* Inspect the vGIC state for the virtual interrupt corresponding to the GSI.
* Check internal flags that were set during the kvm_vgic_v4_set_forwarding call to determine the reason for a failure. For example, if vgic_its_resolve_lpi failed because the MSI address was zero, this would have been recorded, and KVM would populate failure_reason with KVM_ARM_GSI_FAILURE_REASON_NO_MSI_ADDR.
* Check if the host GIC supports the required features (ITS, GICv4), populating failure_reason with KVM_ARM_GSI_FAILURE_REASON_NO_ITS if not.
* Read KVM-internal counters to populate fields like vgic_its_vlpis_hw.
* Copy the populated kvm_gsi_state structure back to userspace in a single memory transaction.
5. Open Questions and Points for Discussion
1. Structure and Flags: Are the proposed kvm_gsi_state and nested arm64 union structures sufficiently comprehensive? Are the flag names clear?
2. Failure Reasons: Are there other common Irqbypass failure modes on ARM64 (or other architectures) that should be included in the enumeration?
3. Performance Counters: Is adding atomic counters to the kvm_kernel_irqfd struct the right approach, or should this be handled in a different data structure to avoid bloating the Irqfd context?
4. Extensibility: Does the nested union and its 128-byte pad provide enough headroom for other architectures (like x86 posted interrupts or RISC-V) to implement their diagnostic payloads in the future?
We believe this new API would be a significant step forward for the observability and manageability of KVM in production environments. We look forward to the community's feedback on this proposal.
Hi Jing,
Quoted 30 lines · Jing Zhang
This RFC proposes a new KVM uAPI to allow a VMM to programmatically query the status of a GSI, with a particular focus on determining the success or failure of Irqbypass.
1. Motivation
The primary motivation for this uAPI is to bridge the operational gap between the VMM and KVM at the kernel level regarding interrupt virtualization status:
* KVM (Kernel) holds the precise, live runtime status of each GSI (such as whether Irqbypass is active, pending, or has encountered a setup error). However, it completely lacks the high-level semantic details of those GSIs—it does not understand which logical function or physical hardware device they represent.
* The VMM (Userspace) possesses the complete context of the guest's interrupt topology. It knows exactly which GSI belongs to which passthrough or emulated device because it orchestrated the setup. Yet, the VMM has no stable, programmatic way to query the actual runtime execution status of these GSIs once passed to the kernel.
Currently, diagnosing when a high-performance interrupt path falls back to software mediation is highly problematic:
* While some architectures (like ARM64) expose virtual ITS states via debugfs, this implementation is highly architecture-specific and fragile.
Quoted 9 lines
* debugfs is not a stable API, is prone to breaking changes across kernel versions, and is entirely unsuitable for programmatic production monitoring and fleet-wide observability.
This is not an ARM-specific problem; it is a general, cross-architecture limitation within KVM's Irqbypass and interrupt routing subsystem. By introducing an architecture-neutral uAPI, we allow the VMM to marry its topological knowledge with KVM's live execution state.
I am trying to understand the benefit of introducing an new uAPI for this. I have been using irqbypass with arm64, and I would debug performance problems solely based on /proc/interrutps.
On the host side you see a vector per interrupt and a new vector per vcpu for the doorbell interrupt in case the vcpu was not scheduled.
Based on that I can tell if irqbypass was active or not, and in case I have /proc/interrupts from the guest, I can get a percentage of the fallback software path per-VM.
A uAPI will not give much extra info, see my comment below.
[...]
Quoted 33 lines
/* To be included in <
linux/kvm.h> *//*
*KVM_GET_GSI_STATE: Get the status of a specific GSI.
*
* The user passes a pointer to structkvm_gsi_state. The kernel fills in
* the status flags, performance counters, and the architecture-specific
* union members directly.
*//* Generic flags indicating high-level status */
/*
* The GSI's route is theoretically compatible with hardware bypass
* on this host (e.g. is an MSI route and GICv4/VT-d is present). */
#defineKVM_GSI_STATE_FLAG_BYPASSABLE(1 << 0)/* An IRQFD is currently active and bound to this GSI */
#defineKVM_GSI_STATE_FLAG_HAS_IRQFD(1 << 1)/* The irqbypass path is fully enabled and active in hardware */
#defineKVM_GSI_STATE_FLAG_BYPASS_ACTIVE(1 << 2)/* Example architecture-specific failure reasons for ARM64 */
#define KVM_ARM_GSI_FAILURE_REASON_NONE 0 #define KVM_ARM_GSI_FAILURE_REASON_NO_ITS 1 /* No ITS/GICv4 support */ #define KVM_ARM_GSI_FAILURE_REASON_NO_MSI_ADDR 2 /* MSI address unset */ #define KVM_ARM_GSI_FAILURE_REASON_GIC_HW_REJECT 3 /* GIC rejected map */ #define KVM_ARM_GSI_FAILURE_REASON_INVALID_STATE 4 /* Guest state block */
Quoted 4 lines
struct
kvm_gsi_state{__u32 gsi; /* IN: The GSI to query */ __u32 flags; /* OUT: High-level status flags */ __u64 counter_success; /* OUT: Generic counter for successful bypass */
I do not think that is possible on arm64, the host does not know about the interrupts directly injected to the guest, so it can not maitain such a counter.
Thanks,
Mostafa
Quoted 97 lines · Mostafa Saleh
Hi Jing,
Quoted 30 lines · Jing Zhang
This RFC proposes a new KVM uAPI to allow a VMM to programmatically query the status of a GSI, with a particular focus on determining the success or failure of Irqbypass.
1. Motivation
The primary motivation for this uAPI is to bridge the operational gap between the VMM and KVM at the kernel level regarding interrupt virtualization status:
* KVM (Kernel) holds the precise, live runtime status of each GSI (such as whether Irqbypass is active, pending, or has encountered a setup error). However, it completely lacks the high-level semantic details of those GSIs—it does not understand which logical function or physical hardware device they represent.
* The VMM (Userspace) possesses the complete context of the guest's interrupt topology. It knows exactly which GSI belongs to which passthrough or emulated device because it orchestrated the setup. Yet, the VMM has no stable, programmatic way to query the actual runtime execution status of these GSIs once passed to the kernel.
Currently, diagnosing when a high-performance interrupt path falls back to software mediation is highly problematic:
* While some architectures (like ARM64) expose virtual ITS states via debugfs, this implementation is highly architecture-specific and fragile.
Quoted 9 lines
* debugfs is not a stable API, is prone to breaking changes across kernel versions, and is entirely unsuitable for programmatic production monitoring and fleet-wide observability.
This is not an ARM-specific problem; it is a general, cross-architecture limitation within KVM's Irqbypass and interrupt routing subsystem. By introducing an architecture-neutral uAPI, we allow the VMM to marry its topological knowledge with KVM's live execution state.
I am trying to understand the benefit of introducing an new uAPI for this. I have been using irqbypass with arm64, and I would debug performance problems solely based on
/proc/interrutps.On the host side you see a vector per interrupt and a new vector per vcpu for the doorbell interrupt in case the vcpu was not scheduled.
Based on that I can tell if irqbypass was active or not, and in case I have
/proc/interruptsfrom the guest, I can get a percentage of the fallback software path per-VM.A uAPI will not give much extra info, see my comment below.
[...]
Quoted 33 lines
/* To be included in <
linux/kvm.h> *//*
*KVM_GET_GSI_STATE: Get the status of a specific GSI.
*
* The user passes a pointer to structkvm_gsi_state. The kernel fills in
* the status flags, performance counters, and the architecture-specific
* union members directly.
*//* Generic flags indicating high-level status */
/*
* The GSI's route is theoretically compatible with hardware bypass
* on this host (e.g. is an MSI route and GICv4/VT-d is present). */
#defineKVM_GSI_STATE_FLAG_BYPASSABLE(1 << 0)/* An IRQFD is currently active and bound to this GSI */
#defineKVM_GSI_STATE_FLAG_HAS_IRQFD(1 << 1)/* The irqbypass path is fully enabled and active in hardware */
#defineKVM_GSI_STATE_FLAG_BYPASS_ACTIVE(1 << 2)/* Example architecture-specific failure reasons for ARM64 */
#define KVM_ARM_GSI_FAILURE_REASON_NONE 0 #define KVM_ARM_GSI_FAILURE_REASON_NO_ITS 1 /* No ITS/GICv4 support */ #define KVM_ARM_GSI_FAILURE_REASON_NO_MSI_ADDR 2 /* MSI address unset */ #define KVM_ARM_GSI_FAILURE_REASON_GIC_HW_REJECT 3 /* GIC rejected map */ #define KVM_ARM_GSI_FAILURE_REASON_INVALID_STATE 4 /* Guest state block */Quoted 4 lines
struct
kvm_gsi_state{__u32 gsi; /* IN: The GSI to query */ __u32 flags; /* OUT: High-level status flags */ __u64 counter_success; /* OUT: Generic counter for successful bypass */
Quoted 7 lines
I do not think that is possible on arm64, the host does not know about the interrupts directly injected to the guest, so it can not maitain such a counter.
Thanks,
Mostafa
Hi Mostafa,
Thank you for taking the time to review this RFC and for your valuable feedback.
To clarify the primary motivation here: the goal of this new uAPI is to enable programmatic, stable, and fine-grained monitoring of interrupt bypass status in production environments, where existing mechanisms like debugfs are simply not viable.
Here are a few key reasons why we believe a dedicated uAPI/ioctl is necessary rather than relying on debugfs:
1. Production Hardening and Access Restrictions: In many hardened production or cloud environments, debugfs is completely disabled (CONFIG_DEBUG_FS=n), unmounted, or heavily restricted due to security and performance overhead concerns. Relying on it means the Virtual Machine Monitor (VMM) loses all visibility into interrupt performance regressions in the very environment where monitoring matters most.
2. Lack of ABI Stability: As you know, debugfs makes no ABI stability guarantees. Its output format can change between kernel versions without notice. Basing production monitoring and telemetry pipelines on scraping debugfs is fragile and prone to breaking during kernel upgrades.
3. Programmatic Efficiency: Scraping and parsing text files from userspace is inefficient for high-frequency or fleet-wide monitoring. A binary ioctl interface (KVM_GET_GSI_STATE) provides a lightweight, deterministic, and highly scalable way for the VMM to query state on demand.
4. Marrying Topology with Live State: KVM holds the runtime status of the bypass, but only userspace (the VMM) understands the full topology (i.e., which GSI belongs to which passthrough device). This uAPI allows the VMM to programmatically marry its topological knowledge with KVM's live execution state without relying on side-band manual debugging tools.
While interfaces in debugfs are fantastic for manual, retroactive debugging on a developer workstation, they are not Dependable for fleet-wide observability. This RFC aims to provide a proactive monitoring solution that aligns KVM with production operational requirements across architectures (both ARM and x86).
Would love to hear your thoughts on this perspective.
Thanks,
Jing
Hi Jing,
Quoted 13 lines · Jing Zhang
Quoted 12 lines · Mostafa Saleh
Hi Jing,
Quoted 8 lines · Jing Zhang
This RFC proposes a new KVM uAPI to allow a VMM to programmatically query the status of a GSI, with a particular focus on determining the success or failure of Irqbypass.
1. Motivation
The primary motivation for this uAPI is to bridge the operational gap
[...]
Quoted 57 lines
Quoted 15 lines
Quoted 10 lines
/* The irqbypass path is fully enabled and active in hardware */
#defineKVM_GSI_STATE_FLAG_BYPASS_ACTIVE(1 << 2)/* Example architecture-specific failure reasons for ARM64 */
#define KVM_ARM_GSI_FAILURE_REASON_NONE 0 #define KVM_ARM_GSI_FAILURE_REASON_NO_ITS 1 /* No ITS/GICv4 support */ #define KVM_ARM_GSI_FAILURE_REASON_NO_MSI_ADDR 2 /* MSI address unset */ #define KVM_ARM_GSI_FAILURE_REASON_GIC_HW_REJECT 3 /* GIC rejected map */ #define KVM_ARM_GSI_FAILURE_REASON_INVALID_STATE 4 /* Guest state block */Quoted 4 lines
struct
kvm_gsi_state{__u32 gsi; /* IN: The GSI to query */ __u32 flags; /* OUT: High-level status flags */ __u64 counter_success; /* OUT: Generic counter for successful bypass */Quoted 7 lines
I do not think that is possible on arm64, the host does not know about the interrupts directly injected to the guest, so it can not maitain such a counter.
Thanks,
MostafaHi Mostafa,
Thank you for taking the time to review this RFC and for your valuable feedback.
To clarify the primary motivation here: the goal of this new uAPI is to enable programmatic, stable, and fine-grained monitoring of interrupt bypass status in production environments, where existing mechanisms like debugfs are simply not viable.
Here are a few key reasons why we believe a dedicated uAPI/ioctl is necessary rather than relying on debugfs:
1. Production Hardening and Access Restrictions: In many hardened production or cloud environments, debugfs is completely disabled (CONFIG_DEBUG_FS=n), unmounted, or heavily restricted due to security and performance overhead concerns. Relying on it means the Virtual Machine Monitor (VMM) loses all visibility into interrupt performance regressions in the very environment where monitoring matters most.
2. Lack of ABI Stability: As you know, debugfs makes no ABI stability guarantees. Its output format can change between kernel versions without notice. Basing production monitoring and telemetry pipelines on scraping debugfs is fragile and prone to breaking during kernel upgrades.
3. Programmatic Efficiency: Scraping and parsing text files from userspace is inefficient for high-frequency or fleet-wide monitoring. A binary ioctl interface (KVM_GET_GSI_STATE) provides a lightweight, deterministic, and highly scalable way for the VMM to query state on demand.
4. Marrying Topology with Live State: KVM holds the runtime status of the bypass, but only userspace (the VMM) understands the full topology (i.e., which GSI belongs to which passthrough device). This uAPI allows the VMM to programmatically marry its topological knowledge with KVM's live execution state without relying on side-band manual debugging tools.
Quoted 7 lines
While interfaces in debugfs are fantastic for manual, retroactive debugging on a developer workstation, they are not Dependable for fleet-wide observability. This RFC aims to provide a proactive monitoring solution that aligns KVM with production operational requirements across architectures (both ARM and x86).
Would love to hear your thoughts on this perspective.
I agree that debugfs is not suitable for that purpose.
My main concerns are:
1- Why is /proc/interrupts not enough, it should show whether the interrupts are going through the host (not bypassed) and it should show when the host get a doorbell if the vCPU was not resident.
2- Technical feasibility on arm64. Since the host does not have visibility into interrupts directly injected into the guest, it cannot accurately maintain the proposed counters vgic_its_vlpis_hw.
Thanks,
Mostafa
Quoted 3 lines
Thanks,
Jing
Marc Zyngier
maintainerQuoted 4 lines · Mostafa Saleh
Hi Jing,
On Fri, Jul 31, 2026 at 10:26:26AM -0700, Jing Zhang wrote:
[drop the LLM generated stuff]
Quoted 6 lines
Quoted 6 lines
While interfaces in debugfs are fantastic for manual, retroactive debugging on a developer workstation, they are not Dependable for fleet-wide observability. This RFC aims to provide a proactive monitoring solution that aligns KVM with production operational requirements across architectures (both ARM and x86).
Quoted 8 lines
Quoted 1 line
Would love to hear your thoughts on this perspective.
I agree that debugfs is not suitable for that purpose.
My main concerns are:
1- Why is/proc/interruptsnot enough, it should show whether the interrupts are going through the host (not bypassed) and it should show when the host get a doorbell if the vCPU was not resident.
This.
Also, there is a very long standing ask to represent the output of /proc/interrupts as a structured set, retrieved through a generic kernel interface. I.e. *not* something KVM specific. Everybody asks, nobody does. As usual.
And if you are interested in things being "Dependable for fleet-wide observability" (I *love* the LLM-generated jargon), there is no way you can make sense of what the guest sees without looking at the full picture, i.e. the full machine.
Quoted 3 lines
2- Technical feasibility on arm64. Since the host does not have visibility into interrupts directly injected into the guest, it cannot accurately maintain the proposed counters
vgic_its_vlpis_hw.
And GICv5 is going to make things even less observable, as only doorbells fire on the host. My take is that for these, a PMU-type interface is better suited.
But in general, a KVM-specific for something that is a system-wide problem is IMO the wrong approach. You may want to put tglx in that loop and see what he has to say.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Sean Christopherson
reviewerQuoted 24 lines · Marc Zyngier
Quoted 4 lines · Mostafa Saleh
Hi Jing,
On Fri, Jul 31, 2026 at 10:26:26AM -0700, Jing Zhang wrote:
[drop the LLM generated stuff]
Quoted 6 lines
Quoted 6 lines
While interfaces in debugfs are fantastic for manual, retroactive debugging on a developer workstation, they are not Dependable for fleet-wide observability. This RFC aims to provide a proactive monitoring solution that aligns KVM with production operational requirements across architectures (both ARM and x86).
Quoted 8 lines
Quoted 1 line
Would love to hear your thoughts on this perspective.
I agree that debugfs is not suitable for that purpose.
My main concerns are:
1- Why is/proc/interruptsnot enough, it should show whether the interrupts are going through the host (not bypassed) and it should show when the host get a doorbell if the vCPU was not resident.
Quoted 5 lines
This.
Also, there is a very long standing ask to represent the output of
/proc/interruptsas a structured set, retrieved through a generic kernel interface. I.e. *not* something KVM specific.
+1 to not making this level of detail KVM specific. Ideally, I'd want more than what /proc/interrupts offers, e.g. it'd be nice to capture what "mode" an IRQ is configured for (normal/remapped, IRQ bypass, x86's posted MSI, etc.). But that's an argument for extending /proc/irq and/or providing structured output of _that_, not for throwing something into KVM.