Skip to content

Commit 24c29b7

Browse files
committed
KVM: x86: omit absent pmu MSRs from MSR list
INTEL_PMC_MAX_GENERIC is currently 32, which exceeds the 18 contiguous MSR indices reserved by Intel for event selectors. Since some machines actually have MSRs past the reserved range, these may survive the filtering of msrs_to_save array and would be rejected by KVM_GET/SET_MSR. To avoid this, cut the list to whatever CPUID reports for the host's architectural PMU. Reported-by: Vitaly Kuznetsov <[email protected]> Suggested-by: Vitaly Kuznetsov <[email protected]> Cc: Jim Mattson <[email protected]> Fixes: e2ada66 ("kvm: x86: Add Intel PMU MSRs to msrs_to_save[]", 2019-08-21) Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6e06983 commit 24c29b7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5105,13 +5105,14 @@ long kvm_arch_vm_ioctl(struct file *filp,
51055105

51065106
static void kvm_init_msr_list(void)
51075107
{
5108+
struct x86_pmu_capability x86_pmu;
51085109
u32 dummy[2];
51095110
unsigned i, j;
51105111

51115112
BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
51125113
"Please update the fixed PMCs in msrs_to_save[]");
5113-
BUILD_BUG_ON_MSG(INTEL_PMC_MAX_GENERIC != 32,
5114-
"Please update the generic perfctr/eventsel MSRs in msrs_to_save[]");
5114+
5115+
perf_get_x86_pmu_capability(&x86_pmu);
51155116

51165117
for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
51175118
if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
@@ -5153,6 +5154,15 @@ static void kvm_init_msr_list(void)
51535154
intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2)
51545155
continue;
51555156
break;
5157+
case MSR_ARCH_PERFMON_PERFCTR0 ... MSR_ARCH_PERFMON_PERFCTR0 + 31:
5158+
if (msrs_to_save[i] - MSR_ARCH_PERFMON_PERFCTR0 >=
5159+
min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp))
5160+
continue;
5161+
break;
5162+
case MSR_ARCH_PERFMON_EVENTSEL0 ... MSR_ARCH_PERFMON_EVENTSEL0 + 31:
5163+
if (msrs_to_save[i] - MSR_ARCH_PERFMON_EVENTSEL0 >=
5164+
min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp))
5165+
continue;
51565166
}
51575167
default:
51585168
break;

0 commit comments

Comments
 (0)