Skip to content

Commit 0f1e172

Browse files
author
Marc Zyngier
committed
KVM: arm64: PMU: Only narrow counters that are not 64bit wide
The current PMU emulation sometimes narrows counters to 32bit if the counter isn't the cycle counter. As this is going to change with PMUv3p5 where the counters are all 64bit, fix the couple of cases where this happens unconditionally. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Reiji Watanabe <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 001d85b commit 0f1e172

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

arch/arm64/kvm/pmu-emul.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,17 @@ static void kvm_pmu_release_perf_event(struct kvm_pmc *pmc)
151151
*/
152152
static void kvm_pmu_stop_counter(struct kvm_vcpu *vcpu, struct kvm_pmc *pmc)
153153
{
154-
u64 counter, reg, val;
154+
u64 reg, val;
155155

156156
if (!pmc->perf_event)
157157
return;
158158

159-
counter = kvm_pmu_get_counter_value(vcpu, pmc->idx);
159+
val = kvm_pmu_get_counter_value(vcpu, pmc->idx);
160160

161-
if (pmc->idx == ARMV8_PMU_CYCLE_IDX) {
161+
if (pmc->idx == ARMV8_PMU_CYCLE_IDX)
162162
reg = PMCCNTR_EL0;
163-
val = counter;
164-
} else {
163+
else
165164
reg = PMEVCNTR0_EL0 + pmc->idx;
166-
val = lower_32_bits(counter);
167-
}
168165

169166
__vcpu_sys_reg(vcpu, reg) = val;
170167

@@ -414,7 +411,8 @@ static void kvm_pmu_counter_increment(struct kvm_vcpu *vcpu,
414411

415412
/* Increment this counter */
416413
reg = __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1;
417-
reg = lower_32_bits(reg);
414+
if (!kvm_pmu_idx_is_64bit(vcpu, i))
415+
reg = lower_32_bits(reg);
418416
__vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg;
419417

420418
/* No overflow? move on */

0 commit comments

Comments
 (0)