Skip to content

Commit d574c53

Browse files
vittyvkbonzini
authored andcommitted
KVM: x86: move MSR_IA32_PERF_CAPABILITIES emulation to common x86 code
state_test/smm_test selftests are failing on AMD with: "Unexpected result from KVM_GET_MSRS, r: 51 (failed MSR was 0x345)" MSR_IA32_PERF_CAPABILITIES is an emulated MSR on Intel but it is not known to AMD code, we can move the emulation to common x86 code. For AMD, we basically just allow the host to read and write zero to the MSR. Fixes: 27461da ("KVM: x86/pmu: Support full width counting") Suggested-by: Jim Mattson <[email protected]> Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c34b26b commit d574c53

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,8 @@ static int svm_get_msr_feature(struct kvm_msr_entry *msr)
23582358
if (boot_cpu_has(X86_FEATURE_LFENCE_RDTSC))
23592359
msr->data |= MSR_F10H_DECFG_LFENCE_SERIALIZE;
23602360
break;
2361+
case MSR_IA32_PERF_CAPABILITIES:
2362+
return 0;
23612363
default:
23622364
return KVM_MSR_RET_INVALID;
23632365
}

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ static bool intel_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr)
180180
case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
181181
ret = pmu->version > 1;
182182
break;
183-
case MSR_IA32_PERF_CAPABILITIES:
184-
ret = 1;
185-
break;
186183
default:
187184
ret = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0) ||
188185
get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0) ||
@@ -224,12 +221,6 @@ static int intel_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
224221
case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
225222
msr_info->data = pmu->global_ovf_ctrl;
226223
return 0;
227-
case MSR_IA32_PERF_CAPABILITIES:
228-
if (!msr_info->host_initiated &&
229-
!guest_cpuid_has(vcpu, X86_FEATURE_PDCM))
230-
return 1;
231-
msr_info->data = vcpu->arch.perf_capabilities;
232-
return 0;
233224
default:
234225
if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) ||
235226
(pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) {
@@ -289,14 +280,6 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
289280
return 0;
290281
}
291282
break;
292-
case MSR_IA32_PERF_CAPABILITIES:
293-
if (!msr_info->host_initiated)
294-
return 1;
295-
if (guest_cpuid_has(vcpu, X86_FEATURE_PDCM) ?
296-
(data & ~vmx_get_perf_capabilities()) : data)
297-
return 1;
298-
vcpu->arch.perf_capabilities = data;
299-
return 0;
300283
default:
301284
if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) ||
302285
(pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) {

arch/x86/kvm/x86.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,20 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
28572857
return 1;
28582858
vcpu->arch.arch_capabilities = data;
28592859
break;
2860+
case MSR_IA32_PERF_CAPABILITIES: {
2861+
struct kvm_msr_entry msr_ent = {.index = msr, .data = 0};
2862+
2863+
if (!msr_info->host_initiated)
2864+
return 1;
2865+
if (guest_cpuid_has(vcpu, X86_FEATURE_PDCM) && kvm_get_msr_feature(&msr_ent))
2866+
return 1;
2867+
if (data & ~msr_ent.data)
2868+
return 1;
2869+
2870+
vcpu->arch.perf_capabilities = data;
2871+
2872+
return 0;
2873+
}
28602874
case MSR_EFER:
28612875
return set_efer(vcpu, msr_info);
28622876
case MSR_K7_HWCR:
@@ -3197,6 +3211,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
31973211
return 1;
31983212
msr_info->data = vcpu->arch.arch_capabilities;
31993213
break;
3214+
case MSR_IA32_PERF_CAPABILITIES:
3215+
if (!msr_info->host_initiated &&
3216+
!guest_cpuid_has(vcpu, X86_FEATURE_PDCM))
3217+
return 1;
3218+
msr_info->data = vcpu->arch.perf_capabilities;
3219+
break;
32003220
case MSR_IA32_POWER_CTL:
32013221
msr_info->data = vcpu->arch.msr_ia32_power_ctl;
32023222
break;

0 commit comments

Comments
 (0)