]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
KVM: arm64: PMU: Fix period computation for 64bit counters with 32bit overflow
authorMarc Zyngier <maz@kernel.org>
Mon, 5 Dec 2022 12:05:51 +0000 (12:05 +0000)
committerMarc Zyngier <maz@kernel.org>
Mon, 5 Dec 2022 12:05:51 +0000 (12:05 +0000)
Fix the bogus masking when computing the period of a 64bit counter
with 32bit overflow. It really should be treated like a 32bit counter
for the purpose of the period.

Reported-by: Ricardo Koller <ricarkol@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/Y4jbosgHbUDI0WF4@google.com
arch/arm64/kvm/pmu-emul.c

index d8ea3994308613087862ce31ffa69ebf23e4756e..24908400e190616f317b9e6725b4605c12d1c8a4 100644 (file)
@@ -461,14 +461,10 @@ static u64 compute_period(struct kvm_pmc *pmc, u64 counter)
 {
        u64 val;
 
-       if (kvm_pmc_is_64bit(pmc)) {
-               if (!kvm_pmc_has_64bit_overflow(pmc))
-                       val = -(counter & GENMASK(31, 0));
-               else
-                       val = (-counter) & GENMASK(63, 0);
-       } else {
+       if (kvm_pmc_is_64bit(pmc) && kvm_pmc_has_64bit_overflow(pmc))
+               val = (-counter) & GENMASK(63, 0);
+       else
                val = (-counter) & GENMASK(31, 0);
-       }
 
        return val;
 }