* [PATCH 0/3 v4] KVM: nVMX: nSVM: Add more statistics to KVM debugfs
@ 2021-06-09 18:03 Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Krish Sadhukhan @ 2021-06-09 18:03 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, jmattson, seanjc, vkuznets, wanpengli, joro
v3 -> v4:
Made changes to patch# 3 to prevent the following compilation
error reported by kernel test robot:
arch/s390/kvm/../../../virt/kvm/kvm_main.c: In function 'kvm_vm_ioctl_create_vcpu':
>> arch/s390/kvm/../../../virt/kvm/kvm_main.c:3321:11: error: 'struct kvm_vm_stat' has no member named 'vcpus'
3321 | kvm->stat.vcpus++;
| ^
arch/s390/kvm/../../../virt/kvm/kvm_main.c:3398:11: error: 'struct kvm_vm_stat' has no member named 'vcpus'
3398 | kvm->stat.vcpus--;
| ^
[PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry
[PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU
[PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs
arch/x86/include/asm/kvm_host.h | 4 +++-
arch/x86/kvm/debugfs.c | 11 +++++++++++
arch/x86/kvm/kvm_cache_regs.h | 3 +++
arch/x86/kvm/svm/nested.c | 2 --
arch/x86/kvm/svm/svm.c | 6 ++++++
arch/x86/kvm/vmx/nested.c | 2 --
arch/x86/kvm/vmx/vmx.c | 13 ++++++++++++-
arch/x86/kvm/x86.c | 4 +++-
virt/kvm/kvm_main.c | 6 ++++++
9 files changed, 44 insertions(+), 7 deletions(-)
Krish Sadhukhan (3):
KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code
KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode
KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code
2021-06-09 18:03 [PATCH 0/3 v4] KVM: nVMX: nSVM: Add more statistics to KVM debugfs Krish Sadhukhan
@ 2021-06-09 18:03 ` Krish Sadhukhan
2021-06-10 14:25 ` Paolo Bonzini
2021-06-09 18:03 ` [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM Krish Sadhukhan
2 siblings, 1 reply; 7+ messages in thread
From: Krish Sadhukhan @ 2021-06-09 18:03 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, jmattson, seanjc, vkuznets, wanpengli, joro
Currently, the 'nested_run' statistic counts all guest-entry attempts,
including those that fail during vmentry checks on Intel and during
consistency checks on AMD. Convert this statistic to count only those
guest-entries that make it past these state checks and make it to guest
code. This will tell us the number of guest-entries that actually executed
or tried to execute guest code.
Also, rename this statistic to 'nested_runs' since it is a count.
Signed-off-by: Krish Sadhukhan <Krish.Sadhukhan@oracle.com>
---
arch/x86/include/asm/kvm_host.h | 2 +-
arch/x86/kvm/svm/nested.c | 2 --
arch/x86/kvm/svm/svm.c | 6 ++++++
arch/x86/kvm/vmx/nested.c | 2 --
arch/x86/kvm/vmx/vmx.c | 13 ++++++++++++-
arch/x86/kvm/x86.c | 2 +-
6 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 55efbacfc244..cf8557b2b90f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1170,7 +1170,7 @@ struct kvm_vcpu_stat {
u64 req_event;
u64 halt_poll_success_ns;
u64 halt_poll_fail_ns;
- u64 nested_run;
+ u64 nested_runs;
u64 directed_yield_attempted;
u64 directed_yield_successful;
};
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 5e8d8443154e..34fc74b0d58a 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -596,8 +596,6 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
struct kvm_host_map map;
u64 vmcb12_gpa;
- ++vcpu->stat.nested_run;
-
if (is_smm(vcpu)) {
kvm_queue_exception(vcpu, UD_VECTOR);
return 1;
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 4dd9b7856e5b..31646b5c4877 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3872,6 +3872,12 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
svm->next_rip = 0;
if (is_guest_mode(vcpu)) {
nested_sync_control_from_vmcb02(svm);
+
+ /* Track VMRUNs that have made past consistency checking */
+ if (svm->nested.nested_run_pending &&
+ svm->vmcb->control.exit_code != SVM_EXIT_ERR)
+ ++vcpu->stat.nested_runs;
+
svm->nested.nested_run_pending = 0;
}
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 6058a65a6ede..94f70c0af4a4 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3454,8 +3454,6 @@ 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;
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index f2fd447eed45..fa8df7ab2756 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6839,7 +6839,18 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
kvm_load_host_xsave_state(vcpu);
- vmx->nested.nested_run_pending = 0;
+ if (is_guest_mode(vcpu)) {
+ /*
+ * Track VMLAUNCH/VMRESUME that have made past guest state
+ * checking.
+ */
+ if (vmx->nested.nested_run_pending &&
+ !vmx->exit_reason.failed_vmentry)
+ ++vcpu->stat.nested_runs;
+
+ vmx->nested.nested_run_pending = 0;
+ }
+
vmx->idt_vectoring_info = 0;
if (unlikely(vmx->fail)) {
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5bd550eaf683..6d1f51f6c344 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -243,7 +243,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),
+ VCPU_STAT("nested_runs", nested_runs),
VCPU_STAT("directed_yield_attempted", directed_yield_attempted),
VCPU_STAT("directed_yield_successful", directed_yield_successful),
VM_STAT("mmu_shadow_zapped", mmu_shadow_zapped),
--
2.27.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode
2021-06-09 18:03 [PATCH 0/3 v4] KVM: nVMX: nSVM: Add more statistics to KVM debugfs Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
@ 2021-06-09 18:03 ` Krish Sadhukhan
2021-06-10 14:27 ` Paolo Bonzini
2021-06-09 18:03 ` [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM Krish Sadhukhan
2 siblings, 1 reply; 7+ messages in thread
From: Krish Sadhukhan @ 2021-06-09 18:03 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, jmattson, seanjc, vkuznets, wanpengli, joro
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>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/debugfs.c | 11 +++++++++++
arch/x86/kvm/kvm_cache_regs.h | 3 +++
arch/x86/kvm/x86.c | 1 +
4 files changed, 16 insertions(+)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index cf8557b2b90f..f6d5387bb88f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1173,6 +1173,7 @@ struct kvm_vcpu_stat {
u64 nested_runs;
u64 directed_yield_attempted;
u64 directed_yield_successful;
+ u64 guest_mode;
};
struct x86_instruction_info;
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index 7e818d64bb4d..95a98413dc32 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -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);
diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h
index 3db5c42c9ecd..ebddbd37a0bf 100644
--- a/arch/x86/kvm/kvm_cache_regs.h
+++ b/arch/x86/kvm/kvm_cache_regs.h
@@ -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)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6d1f51f6c344..baa953757911 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -246,6 +246,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
VCPU_STAT("nested_runs", nested_runs),
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),
--
2.27.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM
2021-06-09 18:03 [PATCH 0/3 v4] KVM: nVMX: nSVM: Add more statistics to KVM debugfs Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode Krish Sadhukhan
@ 2021-06-09 18:03 ` Krish Sadhukhan
2021-06-10 14:27 ` Paolo Bonzini
2 siblings, 1 reply; 7+ messages in thread
From: Krish Sadhukhan @ 2021-06-09 18:03 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, jmattson, seanjc, vkuznets, wanpengli, joro
'struct kvm' already has a member for tracking the number of VCPUs created
in a given VM. Add this as a new VM statistic to KVM debugfs. This statistic
can be a useful metric to track the usage of VCPUs on a host running
customer VMs.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Krish Sadhukhan <Krish.Sadhukhan@oracle.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/x86.c | 1 +
virt/kvm/kvm_main.c | 6 ++++++
3 files changed, 8 insertions(+)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f6d5387bb88f..8f61a3fc3d39 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;
};
struct kvm_vcpu_stat {
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index baa953757911..7a1ff3052488 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -258,6 +258,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", vcpus),
{ NULL }
};
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 6b4feb92dc79..a129a6734965 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3318,6 +3318,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
}
kvm->created_vcpus++;
+#ifdef CONFIG_X86
+ kvm->stat.vcpus++;
+#endif
mutex_unlock(&kvm->lock);
r = kvm_arch_vcpu_precreate(kvm, id);
@@ -3394,6 +3397,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
vcpu_decrement:
mutex_lock(&kvm->lock);
kvm->created_vcpus--;
+#ifdef CONFIG_X86
+ kvm->stat.vcpus--;
+#endif
mutex_unlock(&kvm->lock);
return r;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code
2021-06-09 18:03 ` [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
@ 2021-06-10 14:25 ` Paolo Bonzini
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2021-06-10 14:25 UTC (permalink / raw)
To: Krish Sadhukhan, kvm; +Cc: jmattson, seanjc, vkuznets, wanpengli, joro
On 09/06/21 20:03, Krish Sadhukhan wrote:
> Currently, the 'nested_run' statistic counts all guest-entry attempts,
> including those that fail during vmentry checks on Intel and during
> consistency checks on AMD. Convert this statistic to count only those
> guest-entries that make it past these state checks and make it to guest
> code. This will tell us the number of guest-entries that actually executed
> or tried to execute guest code.
>
> Also, rename this statistic to 'nested_runs' since it is a count.
Applied, but other statistics are also singular (l1d_flush,
directed_yield_attempted) so I removed the renaming.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM
2021-06-09 18:03 ` [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM Krish Sadhukhan
@ 2021-06-10 14:27 ` Paolo Bonzini
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2021-06-10 14:27 UTC (permalink / raw)
To: Krish Sadhukhan, kvm; +Cc: jmattson, seanjc, vkuznets, wanpengli, joro
On 09/06/21 20:03, Krish Sadhukhan wrote:
> 'struct kvm' already has a member for tracking the number of VCPUs created
> in a given VM. Add this as a new VM statistic to KVM debugfs. This statistic
> can be a useful metric to track the usage of VCPUs on a host running
> customer VMs.
>
> Reported-by: kernel test robot <lkp@intel.com>
Not sure why this "Reported-by", you can remove it.
Please add the statistic to all architectures, in order to avoid the #ifdef.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode
2021-06-09 18:03 ` [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode Krish Sadhukhan
@ 2021-06-10 14:27 ` Paolo Bonzini
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2021-06-10 14:27 UTC (permalink / raw)
To: Krish Sadhukhan, kvm; +Cc: jmattson, seanjc, vkuznets, wanpengli, joro
On 09/06/21 20:03, Krish Sadhukhan wrote:
> 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>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/debugfs.c | 11 +++++++++++
> arch/x86/kvm/kvm_cache_regs.h | 3 +++
> arch/x86/kvm/x86.c | 1 +
> 4 files changed, 16 insertions(+)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index cf8557b2b90f..f6d5387bb88f 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1173,6 +1173,7 @@ struct kvm_vcpu_stat {
> u64 nested_runs;
> u64 directed_yield_attempted;
> u64 directed_yield_successful;
> + u64 guest_mode;
> };
>
> struct x86_instruction_info;
> diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
> index 7e818d64bb4d..95a98413dc32 100644
> --- a/arch/x86/kvm/debugfs.c
> +++ b/arch/x86/kvm/debugfs.c
> @@ -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);
>
> diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h
> index 3db5c42c9ecd..ebddbd37a0bf 100644
> --- a/arch/x86/kvm/kvm_cache_regs.h
> +++ b/arch/x86/kvm/kvm_cache_regs.h
> @@ -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)
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 6d1f51f6c344..baa953757911 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -246,6 +246,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
> VCPU_STAT("nested_runs", nested_runs),
> 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),
>
Applied, thanks.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-06-10 14:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 18:03 [PATCH 0/3 v4] KVM: nVMX: nSVM: Add more statistics to KVM debugfs Krish Sadhukhan
2021-06-09 18:03 ` [PATCH 1/3 v4] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
2021-06-10 14:25 ` Paolo Bonzini
2021-06-09 18:03 ` [PATCH 2/3 v4] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode Krish Sadhukhan
2021-06-10 14:27 ` Paolo Bonzini
2021-06-09 18:03 ` [PATCH 3/3 v4] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM Krish Sadhukhan
2021-06-10 14:27 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).