SysTutorials

Tracking VM Exit Events in KVM

· updated April 12, 2026

VM exits occur when a guest VM transitions to hypervisor mode to handle privileged operations, I/O requests, or other events. Tracking exit counts and types helps identify performance bottlenecks, inefficient guest behavior, and hypervisor overhead.

Quick Exit Statistics

The debugfs interface provides a simple view of exit counts:

kvm_stat

kvm_stat ships with KVM (sometimes as /usr/share/kvm/kvm_stat) and reads KVM tracepoints to show a live breakdown of exit reasons and their frequencies across all VMs. Run it as root. It needs tracing support enabled in the kernel and debugfs mounted at /sys/kernel/debug.

If you’re running with SELinux or AppArmor, ensure your user has appropriate access to debugfs. On hardened systems, you may need to disable enforcing mode temporarily:

semanage fcontext -a -t debugfs_t "/sys/kernel/debug(/.*)?"
restorecon -Rv /sys/kernel/debug

Per-VM Exit Tracking

For per-VM statistics, check the VM-specific stats:

kvm_stat -p <qemu-pid>

This focuses the live view on one VM, showing which workloads generate the most exits. High exit rates from specific guests indicate either workload characteristics (expected) or tuning opportunities.

Detailed Tracing with perf

For performance analysis beyond raw counts, use perf to trace exit reasons with full context:

perf record -e kvm:kvm_exit -a sleep 30
perf script | grep kvm_exit | head -20

This captures exit events including the specific exit reason (e.g., EXIT_REASON_HLT, EXIT_REASON_IO_INSTRUCTION, EXIT_REASON_CPUID, EXIT_REASON_EPT_VIOLATION). Exit reasons vary by CPU architecture—x86_64 and ARM64 have different sets.

For more granular analysis, combine multiple KVM tracepoints:

perf record -e kvm:kvm_exit,kvm:kvm_entry,kvm:kvm_page_fault -a -p <pid>
perf report --stdio

This traces entries, exits, and page faults for a specific QEMU process, useful when debugging single VM performance issues.

ftrace Alternative

If perf isn’t available or you prefer kernel tracing directly:

echo 1 > /sys/kernel/debug/tracing/events/kvm/kvm_exit/enable
cat /sys/kernel/debug/tracing/trace_pipe

Capture to a file for later analysis:

echo 1 > /sys/kernel/debug/tracing/events/kvm/kvm_exit/enable
timeout 10 cat /sys/kernel/debug/tracing/trace_pipe > /tmp/kvm_exits.txt

Interpreting Exit Reasons

Common high-volume exits typically include:

Use perf stat -e kvm:* to get a quick breakdown across your running VMs, then drill into specific reasons with perf record and perf script filtering.

Kernel Requirements

Exit statistics require:

Check your kernel config:

grep -E 'CONFIG_KVM=|CONFIG_DEBUG_FS' /boot/config-$(uname -r)

For production workloads, reserve detailed tracing for specific troubleshooting windows—continuous high-frequency KVM event tracing adds measurable overhead.

2026 Best Practices and Advanced Techniques

For Tracking VM Exit Events in KVM, understanding both the fundamentals and modern practices ensures you can work efficiently and avoid common pitfalls. This guide extends the core article with practical advice for 2026 workflows.

Troubleshooting and Debugging

When issues arise, a systematic approach saves time. Start by checking logs for error messages or warnings. Test individual components in isolation before integrating them. Use verbose modes and debug flags to gather more information when standard output is not enough to diagnose the problem.

Performance Optimization

Security Considerations

Security should be built into workflows from the start. Use strong authentication methods, encrypt sensitive data in transit, and follow the principle of least privilege for access controls. Regular security audits and penetration testing help maintain system integrity.

These complementary tools expand your capabilities:

Integration with Modern Workflows

Consider automation and containerization for consistency across environments. Infrastructure as code tools enable reproducible deployments. CI/CD pipelines automate testing and deployment, reducing human error and speeding up delivery cycles.

Quick Reference

This extended guide covers the topic beyond the original article scope. For specialized needs, refer to official documentation or community resources. Practice in test environments before production deployment.

← All posts