diff options
author | Marc Zyngier <maz@kernel.org> | 2022-12-05 12:05:51 +0000 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2022-12-05 12:05:51 +0000 |
commit | 58ff6569bc6ec369482eb2d132868870380be64c (patch) | |
tree | 3f3a058282c6d2d768b4d36facfb797bf252ffa6 /arch/arm64 | |
parent | 64d6820d64c0a206e744bd8945374d563a76c16c (diff) | |
download | linux-stable-58ff6569bc6ec369482eb2d132868870380be64c.tar.gz linux-stable-58ff6569bc6ec369482eb2d132868870380be64c.tar.bz2 linux-stable-58ff6569bc6ec369482eb2d132868870380be64c.zip |
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
Diffstat (limited to 'arch/arm64')
-rw-r--r-- | arch/arm64/kvm/pmu-emul.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index d8ea39943086..24908400e190 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -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; } |