Skip to content

Commit e7d65e4

Browse files
Walter Changdlezcano
authored andcommitted
clocksource/drivers/arm_arch_timer: Disable timer before programming CVAL
Due to the fact that the use of `writeq_relaxed()` to program CVAL is not guaranteed to be atomic, it is necessary to disable the timer before programming CVAL. However, if the MMIO timer is already enabled and has not yet expired, there is a possibility of unexpected behavior occurring: when the CPU enters the idle state during this period, and if the CPU's local event is earlier than the broadcast event, the following process occurs: tick_broadcast_enter() tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER) __tick_broadcast_oneshot_control() ___tick_broadcast_oneshot_control() tick_broadcast_set_event() clockevents_program_event() set_next_event_mem() During this process, the MMIO timer remains enabled while programming CVAL. To prevent such behavior, disable timer explicitly prior to programming CVAL. Fixes: 8b82c4f ("clocksource/drivers/arm_arch_timer: Move MMIO timer programming over to CVAL") Cc: stable@vger.kernel.org Signed-off-by: Walter Chang <walter.chang@mediatek.com> Acked-by: Marc Zyngier <maz@kernel.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20230717090735.19370-1-walter.chang@mediatek.com
1 parent c42b7a3 commit e7d65e4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/clocksource/arm_arch_timer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,13 @@ static __always_inline void set_next_event_mem(const int access, unsigned long e
774774
u64 cnt;
775775

776776
ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk);
777+
778+
/* Timer must be disabled before programming CVAL */
779+
if (ctrl & ARCH_TIMER_CTRL_ENABLE) {
780+
ctrl &= ~ARCH_TIMER_CTRL_ENABLE;
781+
arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk);
782+
}
783+
777784
ctrl |= ARCH_TIMER_CTRL_ENABLE;
778785
ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
779786

0 commit comments

Comments
 (0)