Skip to content

Commit 4400cf5

Browse files
ehanklandbonzini
authored andcommitted
KVM: x86: Fix perfctr WRMSR for running counters
Correct the logic in intel_pmu_set_msr() for fixed and general purpose counters. This was recently changed to set pmc->counter without taking in to account the value of pmc_read_counter() which will be incorrect if the counter is currently running and non-zero; this changes back to the old logic which accounted for the value of currently running counters. Signed-off-by: Eric Hankland <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a835023 commit 4400cf5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,12 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
260260
break;
261261
default:
262262
if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0))) {
263-
if (msr_info->host_initiated)
264-
pmc->counter = data;
265-
else
266-
pmc->counter = (s32)data;
263+
if (!msr_info->host_initiated)
264+
data = (s64)(s32)data;
265+
pmc->counter += data - pmc_read_counter(pmc);
267266
return 0;
268267
} else if ((pmc = get_fixed_pmc(pmu, msr))) {
269-
pmc->counter = data;
268+
pmc->counter += data - pmc_read_counter(pmc);
270269
return 0;
271270
} else if ((pmc = get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0))) {
272271
if (data == pmc->eventsel)

0 commit comments

Comments
 (0)