Add a new debugfs statistic to show how many VCPUs have run nested guests. This statistic considers only the first time a given VCPU successfully runs a nested guest. Signed-off-by: Krish Sadhukhan <Krish.Sadhukhan@xxxxxxxxxx> Suggested-by: Jim Mattson <jmattson@xxxxxxxxxx> --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/svm.c | 5 ++++- arch/x86/kvm/vmx/vmx.c | 5 ++++- arch/x86/kvm/x86.c | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index cf8557b2b90f..a19fe2cfaa93 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1138,6 +1138,7 @@ struct kvm_vm_stat { ulong lpages; ulong nx_lpage_splits; ulong max_mmu_page_hash_collisions; + ulong vcpus_ran_nested; }; struct kvm_vcpu_stat { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 57c351640355..d1871c51411f 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3876,8 +3876,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) /* Track VMRUNs that have made past consistency checking */ if (svm->nested.nested_run_pending && svm->vmcb->control.exit_code != SVM_EXIT_ERR && - svm->vmcb->control.exit_code != SVM_EXIT_NPF) + svm->vmcb->control.exit_code != SVM_EXIT_NPF) { + if (!vcpu->stat.nested_runs) + ++vcpu->kvm->stat.vcpus_ran_nested; ++vcpu->stat.nested_runs; + } svm->nested.nested_run_pending = 0; } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index fa8df7ab2756..dc29aa926be6 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6845,8 +6845,11 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) * checking. */ if (vmx->nested.nested_run_pending && - !vmx->exit_reason.failed_vmentry) + !vmx->exit_reason.failed_vmentry) { + if (!vcpu->stat.nested_runs) + ++vcpu->kvm->stat.vcpus_ran_nested; ++vcpu->stat.nested_runs; + } vmx->nested.nested_run_pending = 0; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6d1f51f6c344..cbca3609a152 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -257,6 +257,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { VM_STAT("largepages", lpages, .mode = 0444), VM_STAT("nx_largepages_splitted", nx_lpage_splits, .mode = 0444), VM_STAT("max_mmu_page_hash_collisions", max_mmu_page_hash_collisions), + VM_STAT("vcpus_ran_nested", vcpus_ran_nested), { NULL } }; -- 2.27.0