@@ -27,7 +27,6 @@
* "fast" reads, whereas the "type" is an explicit value.
*/
#define INTEL_RDPMC_FIXED INTEL_PMC_FIXED_RDPMC_BASE
-#define INTEL_RDPMC_FAST BIT(31)
#define MSR_PMC_FULL_WIDTH_BIT (MSR_IA32_PMC0 - MSR_IA32_PERFCTR0)
@@ -72,10 +71,25 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu,
struct kvm_pmc *counters;
unsigned int num_counters;
- if (idx & INTEL_RDPMC_FAST)
- *mask &= GENMASK_ULL(31, 0);
+ /*
+ * The encoding of ECX for RDPMC is different for architectural versus
+ * non-architecturals PMUs (PMUs with version '0'). For architectural
+ * PMUs, bits 31:16 specify the PMC type and bits 15:0 specify the PMC
+ * index. For non-architectural PMUs, bit 31 is a "fast" flag, and
+ * bits 30:0 specify the PMC index.
+ *
+ * Yell and reject attempts to read PMCs for a non-architectural PMU,
+ * as KVM doesn't support such PMUs.
+ */
+ if (WARN_ON_ONCE(!pmu->version))
+ return NULL;
- idx &= ~(INTEL_RDPMC_FIXED | INTEL_RDPMC_FAST);
+ /*
+ * Fixed PMCs are supported on all architectural PMUs. Note, KVM only
+ * emulates fixed PMCs for PMU v2+, but the flag itself is still valid,
+ * i.e. let RDPMC fail due to accessing a non-existent counter.
+ */
+ idx &= ~INTEL_RDPMC_FIXED;
if (fixed) {
counters = pmu->fixed_counters;
num_counters = pmu->nr_arch_fixed_counters;