summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/vmx/capabilities.h
diff options
context:
space:
mode:
authorLike Xu <like.xu@linux.intel.com>2020-05-29 15:43:45 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-06-01 04:26:09 -0400
commit27461da31089ace6966e4f1695cba7eb87ffbe4f (patch)
tree1f638cd94d2d9d5f393dfb9cbdb3c943e383a97d /arch/x86/kvm/vmx/capabilities.h
parentcbd717585b8038d93c309176bb563a5c6de60ac7 (diff)
downloadlinux-stable-27461da31089ace6966e4f1695cba7eb87ffbe4f.tar.gz
linux-stable-27461da31089ace6966e4f1695cba7eb87ffbe4f.tar.bz2
linux-stable-27461da31089ace6966e4f1695cba7eb87ffbe4f.zip
KVM: x86/pmu: Support full width counting
Intel CPUs have a new alternative MSR range (starting from MSR_IA32_PMC0) for GP counters that allows writing the full counter width. Enable this range from a new capability bit (IA32_PERF_CAPABILITIES.FW_WRITE[bit 13]). The guest would query CPUID to get the counter width, and sign extends the counter values as needed. The traditional MSRs always limit to 32bit, even though the counter internally is larger (48 or 57 bits). When the new capability is set, use the alternative range which do not have these restrictions. This lowers the overhead of perf stat slightly because it has to do less interrupts to accumulate the counter value. Signed-off-by: Like Xu <like.xu@linux.intel.com> Message-Id: <20200529074347.124619-3-like.xu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/vmx/capabilities.h')
-rw-r--r--arch/x86/kvm/vmx/capabilities.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h
index 8903475f751e..4bbd8b448d22 100644
--- a/arch/x86/kvm/vmx/capabilities.h
+++ b/arch/x86/kvm/vmx/capabilities.h
@@ -18,6 +18,8 @@ extern int __read_mostly pt_mode;
#define PT_MODE_SYSTEM 0
#define PT_MODE_HOST_GUEST 1
+#define PMU_CAP_FW_WRITES (1ULL << 13)
+
struct nested_vmx_msrs {
/*
* We only store the "true" versions of the VMX capability MSRs. We
@@ -367,4 +369,13 @@ static inline bool vmx_pt_mode_is_host_guest(void)
return pt_mode == PT_MODE_HOST_GUEST;
}
+static inline u64 vmx_get_perf_capabilities(void)
+{
+ /*
+ * Since counters are virtualized, KVM would support full
+ * width counting unconditionally, even if the host lacks it.
+ */
+ return PMU_CAP_FW_WRITES;
+}
+
#endif /* __KVM_X86_VMX_CAPS_H */