]> 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)
commiteee70501cad33fcc7448d8aa92ccfb9c65974119
tree3ba0f3b6e9dc1c02ec973ca96dabf3f068d32375
parent52b7759f73b03afc7cba59d3686ec69261291235
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: 9a5a1b24df82 ("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