Skip to contentSkip to conversation

KVM: nVMX: Track vmx emulation errors

PATCH In review Fred Griffoul 2 participants 2 messages Jan 20 – Feb 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: nVMX: Track vmx emulation errors

From: Fred Griffoul <[email protected]>

Add a new kvm_stat vcpu counter called "nested_errors" to track the number of errors returned to an L1 hypervisor when emulated VMX instructions fail.

This counter should help monitor nVMX health and troubleshoot issues with L1 hypervisors.

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/vmx/nested.c       | 2 ++
 arch/x86/kvm/x86.c              | 1 +
 3 files changed, 4 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 5a3bfa293e8b..a3aaccd6e6aa 100644
@@ -1674,6 +1674,7 @@ struct kvm_vcpu_stat {
 	u64 preemption_other;
 	u64 guest_mode;
 	u64 notify_window_exits;
+	u64 nested_errors;
 };
 
 struct x86_instruction_info;
arch/x86/kvm/vmx/nested.c +2 -0
index 6137e5307d0f..2e1394151945 100644
@@ -162,6 +162,7 @@ static int nested_vmx_succeed(struct kvm_vcpu *vcpu)
 
 static int nested_vmx_failInvalid(struct kvm_vcpu *vcpu)
 {
+	++vcpu->stat.nested_errors;
 	vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu)
 			& ~(X86_EFLAGS_PF | X86_EFLAGS_AF | X86_EFLAGS_ZF |
 			    X86_EFLAGS_SF | X86_EFLAGS_OF))
@@ -172,6 +173,7 @@ static int nested_vmx_failInvalid(struct kvm_vcpu *vcpu)
 static int nested_vmx_failValid(struct kvm_vcpu *vcpu,
 				u32 vm_instruction_error)
 {
+	++vcpu->stat.nested_errors;
 	vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu)
 			& ~(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF |
 			    X86_EFLAGS_SF | X86_EFLAGS_OF))
arch/x86/kvm/x86.c +1 -0
index ff8812f3a129..475c8a2d704e 100644
@@ -299,6 +299,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
 	STATS_DESC_COUNTER(VCPU, preemption_other),
 	STATS_DESC_IBOOLEAN(VCPU, guest_mode),
 	STATS_DESC_COUNTER(VCPU, notify_window_exits),
+	STATS_DESC_COUNTER(VCPU, nested_errors),
 };
 
 const struct kvm_stats_header kvm_vcpu_stats_header = {

base-commit: 0499add8efd72456514c6218c062911ccc922a99

Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · Fred Griffoul

From: Fred Griffoul <[email protected]>

Add a new kvm_stat vcpu counter called "nested_errors" to track the number of errors returned to an L1 hypervisor when emulated VMX instructions fail.

This is too broad/vague, and very imperfect. E.g. if a guest is tripping on a specific VMREAD for whatever reason, it will pollute the count and make it hard to detect more serious issues like VM-Entry failures. And if VMCS shadowing is in use, KVM could easily underreport meaningful errors.

I also dislike implementing this for nVMX but not nSVM. nSVM doesn't have the same ISA surface and so many of the errors simply don't exist, but at the very least VMRUN failures should be accounted.

And counting VM-Fail but not faults is rather odd if the goal is to monitor L1 hypervisor health.

Quoted 2 lines

This counter should help monitor nVMX health and troubleshoot issues with L1 hypervisors.

There are lots of ways to monitor the health of L1 hypervisors, it's not clear to me why we need a KVM-provide stat for VM-Fail.