Commit e5cb94ba authored by Marc Zyngier's avatar Marc Zyngier Committed by Will Deacon
Browse files

arm64: Fix sampling the "stable" virtual counter in preemptible section



Ben reports that when running with CONFIG_DEBUG_PREEMPT, using
__arch_counter_get_cntvct_stable() results in well deserves warnings,
as we access a per-CPU variable without preemption disabled.

Fix the issue by disabling preemption on reading the counter. We can
probably do a lot better by not disabling preemption on systems that
do not require horrible workarounds to return a valid counter value,
but this plugs the issue for the time being.

Fixes: 29cc0f3a ("arm64: Force the use of CNTVCT_EL0 in __delay()")
Reported-by: default avatarBen Horgan <ben.horgan@arm.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/aZw3EGs4rbQvbAzV@e134344.arm.com


Tested-by: default avatarBen Horgan <ben.horgan@arm.com>
Tested-by: default avatarAndré Draszik <andre.draszik@linaro.org>
Signed-off-by: default avatarWill Deacon <will@kernel.org>
parent a8f78680
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -32,7 +32,11 @@ static inline unsigned long xloops_to_cycles(unsigned long xloops)
 * Note that userspace cannot change the offset behind our back either,
 * as the vcpu mutex is held as long as KVM_RUN is in progress.
 */
#define __delay_cycles()	__arch_counter_get_cntvct_stable()
static cycles_t notrace __delay_cycles(void)
{
	guard(preempt_notrace)();
	return __arch_counter_get_cntvct_stable();
}

void __delay(unsigned long cycles)
{