summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-10-01 09:18:26 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2019-10-03 06:07:59 -0400
commit24c29b7ac0da3e2eb589553f7a98bade6d0a0e60 (patch)
tree2c5caab599aefbcd498265f273429974bd46f954
parent6e06983dde969c15eb4fdab77f0eda8b18ea28e6 (diff)
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 <vkuznets@redhat.com> Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com> Cc: Jim Mattson <jmattson@google.com> Fixes: e2ada66ec418 ("kvm: x86: Add Intel PMU MSRs to msrs_to_save[]", 2019-08-21) Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8072acaaf028..31607174f442 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5105,13 +5105,14 @@ out:
5105 5105
5106static void kvm_init_msr_list(void) 5106static void kvm_init_msr_list(void)
5107{ 5107{
5108 struct x86_pmu_capability x86_pmu;
5108 u32 dummy[2]; 5109 u32 dummy[2];
5109 unsigned i, j; 5110 unsigned i, j;
5110 5111
5111 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4, 5112 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
5112 "Please update the fixed PMCs in msrs_to_save[]"); 5113 "Please update the fixed PMCs in msrs_to_save[]");
5113 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_GENERIC != 32, 5114
5114 "Please update the generic perfctr/eventsel MSRs in msrs_to_save[]"); 5115 perf_get_x86_pmu_capability(&x86_pmu);
5115 5116
5116 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) { 5117 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
5117 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0) 5118 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
@@ -5153,6 +5154,15 @@ static void kvm_init_msr_list(void)
5153 intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2) 5154 intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2)
5154 continue; 5155 continue;
5155 break; 5156 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;
5156 } 5166 }
5157 default: 5167 default:
5158 break; 5168 break;