OSDN Git Service

KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode
authorKrish Sadhukhan <krish.sadhukhan@oracle.com>
Wed, 9 Jun 2021 18:03:39 +0000 (14:03 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Jun 2021 17:09:36 +0000 (13:09 -0400)
Add the following per-VCPU statistic to KVM debugfs to show if a given
VCPU is in guest mode:

guest_mode

Also add this as a per-VM statistic to KVM debugfs to show the total number
of VCPUs that are in guest mode in a given VM.

Signed-off-by: Krish Sadhukhan <Krish.Sadhukhan@oracle.com>
Message-Id: <20210609180340.104248-3-krish.sadhukhan@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/debugfs.c
arch/x86/kvm/kvm_cache_regs.h
arch/x86/kvm/x86.c

index 921de30..bea7290 100644 (file)
@@ -1180,6 +1180,7 @@ struct kvm_vcpu_stat {
        u64 nested_run;
        u64 directed_yield_attempted;
        u64 directed_yield_successful;
+       u64 guest_mode;
 };
 
 struct x86_instruction_info;
index 7e818d6..95a9841 100644 (file)
@@ -17,6 +17,15 @@ static int vcpu_get_timer_advance_ns(void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
 
+static int vcpu_get_guest_mode(void *data, u64 *val)
+{
+       struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
+       *val = vcpu->stat.guest_mode;
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(vcpu_guest_mode_fops, vcpu_get_guest_mode, NULL, "%lld\n");
+
 static int vcpu_get_tsc_offset(void *data, u64 *val)
 {
        struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
@@ -45,6 +54,8 @@ DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bi
 
 void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
 {
+       debugfs_create_file("guest_mode", 0444, debugfs_dentry, vcpu,
+                           &vcpu_guest_mode_fops);
        debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu,
                            &vcpu_tsc_offset_fops);
 
index 3db5c42..ebddbd3 100644 (file)
@@ -162,6 +162,7 @@ static inline u64 kvm_read_edx_eax(struct kvm_vcpu *vcpu)
 static inline void enter_guest_mode(struct kvm_vcpu *vcpu)
 {
        vcpu->arch.hflags |= HF_GUEST_MASK;
+       vcpu->stat.guest_mode = 1;
 }
 
 static inline void leave_guest_mode(struct kvm_vcpu *vcpu)
@@ -172,6 +173,8 @@ static inline void leave_guest_mode(struct kvm_vcpu *vcpu)
                vcpu->arch.load_eoi_exitmap_pending = false;
                kvm_make_request(KVM_REQ_LOAD_EOI_EXITMAP, vcpu);
        }
+
+       vcpu->stat.guest_mode = 0;
 }
 
 static inline bool is_guest_mode(struct kvm_vcpu *vcpu)
index 8d88e45..0e2dbc7 100644 (file)
@@ -250,6 +250,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        VCPU_STAT("nested_run", nested_run),
        VCPU_STAT("directed_yield_attempted", directed_yield_attempted),
        VCPU_STAT("directed_yield_successful", directed_yield_successful),
+       VCPU_STAT("guest_mode", guest_mode),
        VM_STAT("mmu_shadow_zapped", mmu_shadow_zapped),
        VM_STAT("mmu_pte_write", mmu_pte_write),
        VM_STAT("mmu_pde_zapped", mmu_pde_zapped),