KVM: x86: to track if L1 is running L2 VM
authorDongli Zhang <dongli.zhang@oracle.com>
Fri, 5 Mar 2021 22:57:47 +0000 (14:57 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 15 Mar 2021 08:28:02 +0000 (04:28 -0400)
The new per-cpu stat 'nested_run' is introduced in order to track if L1 VM
is running or used to run L2 VM.

An example of the usage of 'nested_run' is to help the host administrator
to easily track if any L1 VM is used to run L2 VM. Suppose there is issue
that may happen with nested virtualization, the administrator will be able
to easily narrow down and confirm if the issue is due to nested
virtualization via 'nested_run'. For example, whether the fix like
commit 88dddc11a8d6 ("KVM: nVMX: do not use dangling shadow VMCS after
guest reset") is required.

Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Message-Id: <20210305225747.7682-1-dongli.zhang@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/nested.c
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/x86.c

index 9bc091ecaaeb97fee3eca9650d8b249450f03192..e198837305ff3fab50b27a21ddad3f7becf66727 100644 (file)
@@ -1125,6 +1125,7 @@ struct kvm_vcpu_stat {
        u64 req_event;
        u64 halt_poll_success_ns;
        u64 halt_poll_fail_ns;
+       u64 nested_run;
 };
 
 struct x86_instruction_info;
index 35891d9a1099b3f54d146e0abb26b89c74075b2e..18c02e958a09f514c2f4f1831c9e06407ac94176 100644 (file)
@@ -494,6 +494,8 @@ int nested_svm_vmrun(struct vcpu_svm *svm)
        struct kvm_host_map map;
        u64 vmcb12_gpa;
 
+       ++svm->vcpu.stat.nested_run;
+
        if (is_smm(&svm->vcpu)) {
                kvm_queue_exception(&svm->vcpu, UD_VECTOR);
                return 1;
index bcca0b80e0d040be4ce9a4f9a2ee05d77e0c8257..bd1343a0896ec4b509d60e9c4989bf303792d74e 100644 (file)
@@ -3453,6 +3453,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
        u32 interrupt_shadow = vmx_get_interrupt_shadow(vcpu);
        enum nested_evmptrld_status evmptrld_status;
 
+       ++vcpu->stat.nested_run;
+
        if (!nested_vmx_check_permission(vcpu))
                return 1;
 
index 47e021bdcc94ab324d03057b881cad0dcfd78534..3ef64959a443a6c39ea597883e6c0d336451002c 100644 (file)
@@ -245,6 +245,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        VCPU_STAT("l1d_flush", l1d_flush),
        VCPU_STAT("halt_poll_success_ns", halt_poll_success_ns),
        VCPU_STAT("halt_poll_fail_ns", halt_poll_fail_ns),
+       VCPU_STAT("nested_run", nested_run),
        VM_STAT("mmu_shadow_zapped", mmu_shadow_zapped),
        VM_STAT("mmu_pte_write", mmu_pte_write),
        VM_STAT("mmu_pde_zapped", mmu_pde_zapped),