Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: PMU: Fix period computation for 64bit counters with 32bit overflow

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

+3 -7
+3 -7
arch/arm64/kvm/pmu-emul.c
··· 461 461 { 462 462 u64 val; 463 463 464 - if (kvm_pmc_is_64bit(pmc)) { 465 - if (!kvm_pmc_has_64bit_overflow(pmc)) 466 - val = -(counter & GENMASK(31, 0)); 467 - else 468 - val = (-counter) & GENMASK(63, 0); 469 - } else { 464 + if (kvm_pmc_is_64bit(pmc) && kvm_pmc_has_64bit_overflow(pmc)) 465 + val = (-counter) & GENMASK(63, 0); 466 + else 470 467 val = (-counter) & GENMASK(31, 0); 471 - } 472 468 473 469 return val; 474 470 }