]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: arm64: pmu: Fix cycle counter truncation
authorMarc Zyngier <maz@kernel.org>
Thu, 3 Oct 2019 17:02:08 +0000 (18:02 +0100)
committerMarc Zyngier <maz@kernel.org>
Sun, 20 Oct 2019 09:47:07 +0000 (10:47 +0100)
commit3d3e3cafdc6a9819d1ee15632012872c33d9d4ae
tree3ba0f3b6e9dc1c02ec973ca96dabf3f068d32375
parent3a9527121a36d10e81fe39475a76144099c51db0
KVM: arm64: pmu: Fix cycle counter truncation

When a counter is disabled, its value is sampled before the event
is being disabled, and the value written back in the shadow register.

In that process, the value gets truncated to 32bit, which is adequate
for any counter but the cycle counter (defined as a 64bit counter).

This obviously results in a corrupted counter, and things like
"perf record -e cycles" not working at all when run in a guest...
A similar, but less critical bug exists in kvm_pmu_get_counter_value.

Make the truncation conditional on the counter not being the cycle
counter, which results in a minor code reorganisation.

Fixes: 911ce5009ef1 ("KVM: arm/arm64: Support chained PMU counters")
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Reported-by: Julien Thierry <julien.thierry.kdev@gmail.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
virt/kvm/arm/pmu.c