Commit 58ff6569 authored by Marc Zyngier's avatar Marc Zyngier
Browse files

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: default avatarRicardo Koller <ricarkol@google.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/Y4jbosgHbUDI0WF4@google.com
parent 64d6820d
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -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
	if (kvm_pmc_is_64bit(pmc) && kvm_pmc_has_64bit_overflow(pmc))
		val = (-counter) & GENMASK(63, 0);
	} else {
	else
		val = (-counter) & GENMASK(31, 0);
	}

	return val;
}