mirror-linux/drivers/clocksource
Naohiko Shimizu eaa9bb1d39 riscv: clocksource: Fix stimecmp update hazard on RV32
On RV32, updating the 64-bit stimecmp (or vstimecmp) CSR requires two
separate 32-bit writes. A race condition exists if the timer triggers
during these two writes.

The RISC-V Privileged Specification (e.g., Section 3.2.1 for mtimecmp)
recommends a specific 3-step sequence to avoid spurious interrupts
when updating 64-bit comparison registers on 32-bit systems:

1. Set the low-order bits (stimecmp) to all ones (ULONG_MAX).
2. Set the high-order bits (stimecmph) to the desired value.
3. Set the low-order bits (stimecmp) to the desired value.

Current implementation writes the LSB first without ensuring a future
value, which may lead to a transient state where the 64-bit comparison
is incorrectly evaluated as "expired" by the hardware. This results in
spurious timer interrupts.

This patch adopts the spec-recommended 3-step sequence to ensure the
intermediate 64-bit state is never smaller than the current time.

Fixes: 9f7a8ff639 ("RISC-V: Prefer sstc extension if available")
Signed-off-by: Naohiko Shimizu <naohiko.shimizu@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://patch.msgid.link/20260104135938.524-2-naohiko.shimizu@gmail.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>
2026-01-14 17:42:46 -07:00
..
Kconfig clocksource/drivers: Add Realtek system timer driver 2025-11-26 11:25:15 +01:00
Makefile clocksource/drivers: Add Realtek system timer driver 2025-11-26 11:25:15 +01:00
acpi_pm.c clocksource: acpi_pm: Add external callback for suspend/resume 2024-09-06 14:49:20 +02:00
arc_timer.c
arm_arch_timer.c clocksource/drivers/arm_arch_timer_mmio: Switch over to standalone driver 2025-09-23 12:31:50 +02:00
arm_arch_timer_mmio.c clocksource/drivers/arm_arch_timer_mmio: Prevent driver unbind 2025-11-26 11:24:47 +01:00
arm_global_timer.c clocksource/drivers/arm_global_timer: Add auto-detection for initial prescaler values 2025-09-23 12:41:58 +02:00
armv7m_systick.c
asm9260_timer.c clocksource/drivers/asm9260: Add missing clk_disable_unprepare in asm9260_timer_init 2024-09-06 14:49:21 +02:00
bcm2835_timer.c clocksource: Explicitly include correct DT includes 2023-08-28 13:30:57 -05:00
bcm_kona_timer.c clocksource/drivers/bcm_kona: Convert to SPDX identifier 2022-05-18 11:08:59 +02:00
clksrc-dbx500-prcmu.c
clksrc_st_lpc.c
clps711x-timer.c clocksource/drivers/clps711x: Fix resource leaks in error paths 2025-09-23 12:42:27 +02:00
dummy_timer.c
dw_apb_timer.c clocksource/drivers/dw_apb: Remove unused dw_apb_clockevent functions 2024-11-13 13:49:33 +01:00
dw_apb_timer_of.c clocksource/drivers/dw_apb_timer_of: Fix probe failure 2021-12-10 17:46:54 +01:00
em_sti.c clocksource: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:51 -07:00
exynos_mct.c clocksource/drivers/exynos_mct: Fixed a spelling error 2025-03-07 17:55:59 +01:00
hyperv_timer.c clocksource: hyper-v: Skip unnecessary checks for the root partition 2025-09-08 22:10:46 +00:00
i8253.c clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable() 2025-05-05 15:34:49 +02:00
ingenic-ost.c clocksource/drivers/ingenic: Use devm_clk_get_enabled() helpers 2024-09-06 14:49:20 +02:00
ingenic-sysost.c clocksource/drivers/ingenic-sysost: Convert from round_rate() to determine_rate() 2025-09-23 12:41:50 +02:00
ingenic-timer.c clocksource/drivers/ingenic-timer: Use pm_sleep_ptr() macro 2023-06-19 16:17:42 +02:00
jcore-pit.c irqchip/jcore-aic, clocksource/drivers/jcore: Fix jcore-pit interrupt request 2025-02-17 23:27:49 +01:00
mips-gic-timer.c clocksource: mips-gic-timer: Enable counter when CPUs start 2025-02-21 10:19:14 +01:00
mmio.c
mps2-timer.c
mxs_timer.c
nomadik-mtu.c clocksource: Explicitly include correct DT includes 2023-08-28 13:30:57 -05:00
numachip.c
renesas-ostm.c clocksource/drivers/renesas-ostm: Unconditionally enable reprobe support 2025-05-16 13:33:11 +02:00
samsung_pwm_timer.c of: remove internal arguments from of_property_for_each_u32() 2024-07-25 06:53:47 -05:00
scx200_hrt.c clocksource/drivers/scx200: Add module owner 2025-09-23 10:21:24 +02:00
sh_cmt.c clocksource/drivers/sh_cmt: Always leave device running after probe 2025-11-26 11:24:40 +01:00
sh_mtu2.c Timekeeping and clocksource/event driver updates the second batch: 2023-04-29 10:24:30 -07:00
sh_tmu.c clocksource: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:51 -07:00
timer-armada-370-xp.c syscore: Pass context data to callbacks 2025-11-14 10:01:52 +01:00
timer-atmel-pit.c
timer-atmel-st.c
timer-atmel-tcb.c clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware 2023-10-13 12:56:50 +02:00
timer-cadence-ttc.c clocksource/drivers/cadence-ttc: Add missing clk_disable_unprepare in ttc_setup_clockevent 2024-09-06 14:49:21 +02:00
timer-clint.c riscv: Use IPIs for remote cache/TLB flushes by default 2024-04-29 10:49:26 -07:00
timer-cs5535.c clocksource/drivers/cs5535: Add module owner 2025-09-23 10:52:23 +02:00
timer-davinci.c clocksource/drivers/davinci: Fix memory leak in davinci_timer_register when init fails 2023-04-24 16:56:13 +02:00
timer-digicolor.c clocksource/drivers/digicolor: Convert to SPDX identifier 2022-05-18 11:08:59 +02:00
timer-econet-en751221.c clocksource/timer-econet-en751221: Convert comma to semicolon 2025-09-23 10:56:13 +02:00
timer-ep93xx.c clocksource/drivers/ep93xx: Fix error handling during probe 2023-12-27 15:37:11 +01:00
timer-fsl-ftm.c
timer-fttmr010.c
timer-goldfish.c clocksource/drivers: Add a goldfish-timer clocksource 2022-04-11 11:48:01 +02:00
timer-gx6605s.c
timer-gxp.c clocksource/drivers/gpx: Remove redundant casts 2024-11-13 13:49:33 +01:00
timer-imx-gpt.c clocksource/drivers/imx: Fix -Wunused-but-set-variable warning 2024-01-22 13:11:02 +01:00
timer-imx-sysctr.c clocksource/drivers/imx-sysctr: Add i.MX95 support 2024-02-18 10:45:36 +01:00
timer-imx-tpm.c clocksource/drivers/imx-tpm: Fix next event not taking effect sometime 2024-09-02 10:04:15 +02:00
timer-integrator-ap.c clocksource: Explicitly include correct DT includes 2023-08-28 13:30:57 -05:00
timer-ixp4xx.c clocksource/drivers/ixp4xx: Drop boardfile probe path 2022-05-18 11:08:52 +02:00
timer-keystone.c
timer-loongson1-pwm.c clocksource/drivers/loongson1: Set variable ls1x_timer_lock storage-class-specifier to static 2023-08-18 12:13:03 +02:00
timer-lpc32xx.c clocksource/drivers/lpc32xx: Convert to SPDX identifier 2022-05-18 11:08:59 +02:00
timer-mediatek-cpux.c clocksource/drivers/timer-mediatek: Split out CPUXGPT timers 2023-04-24 16:56:13 +02:00
timer-mediatek.c clocksource/drivers/timer-mediatek: Split out CPUXGPT timers 2023-04-24 16:56:13 +02:00
timer-meson6.c
timer-microchip-pit64b.c clocksource/drivers/timer-microchip-pit64b: Add delay timer 2023-02-13 13:10:17 +01:00
timer-milbeaut.c
timer-mp-csky.c
timer-msc313e.c clocksource/drivers/msc313e: Add support for ssd20xd-based platforms 2021-12-20 13:28:39 +01:00
timer-npcm7xx.c clocksource/drivers/timer-npcm7xx: Enable timer 1 clock before use 2022-12-02 12:48:28 +01:00
timer-nxp-pit.c clocksource/drivers/nxp-pit: Prevent driver unbind 2025-11-26 11:24:57 +01:00
timer-nxp-stm.c clocksource/drivers/nxp-stm: Prevent driver unbind 2025-11-26 11:25:03 +01:00
timer-of.c clocksource/drivers/timer-of: Remove percpu irq related code 2024-09-02 10:04:15 +02:00
timer-of.h clocksource/drivers/timer-of: Remove percpu irq related code 2024-09-02 10:04:15 +02:00
timer-orion.c arm: Handle KCOV __init vs inline mismatches 2025-07-21 21:43:39 -07:00
timer-owl.c
timer-pistachio.c clocksource/drivers/pistachio: Convert to SPDX identifier 2022-05-18 11:08:59 +02:00
timer-probe.c
timer-pxa.c
timer-qcom.c clocksource/drivers/qcom: Remove clockevents shutdown call on offlining 2024-10-31 10:41:43 +01:00
timer-ralink.c clocksource/drivers/ralink: Fix resource leaks in init error path 2025-11-26 11:24:34 +01:00
timer-rda.c clocksource/drivers/rda: Add sched_clock_register for RDA8810PL SoC 2025-11-26 11:25:11 +01:00
timer-realtek.c clocksource/drivers: Add Realtek system timer driver 2025-11-26 11:25:15 +01:00
timer-riscv.c riscv: clocksource: Fix stimecmp update hazard on RV32 2026-01-14 17:42:46 -07:00
timer-rockchip.c
timer-rtl-otto.c clocksource/drivers/timer-rtl-otto: Simplify documentation 2025-09-23 12:41:26 +02:00
timer-sp.h
timer-sp804.c clocksource/drivers/timer-sp804: Fix read_current_timer() issue when clock source is not registered 2025-11-26 11:24:32 +01:00
timer-sprd.c clocksource/drivers/sprd: Enable register for timer counter from 32 bit to 64 bit 2025-11-26 11:24:26 +01:00
timer-stm32-lp.c clocksource/drivers/stm32-lp: Drop unused module alias 2025-11-26 11:25:15 +01:00
timer-stm32.c clocksource/drivers/stm32: Fix all kernel-doc warnings 2024-01-22 13:15:38 +01:00
timer-sun4i.c clocksource/drivers/timer-sun4i: Add CLOCK_EVT_FEAT_DYNIRQ 2023-02-13 13:10:17 +01:00
timer-sun5i.c clocksource/drivers/sun5i: Add module owner 2025-09-23 10:51:44 +02:00
timer-tegra.c clocksource/drivers/timer-tegra: Remove clockevents shutdown call on offlining 2024-10-31 10:41:43 +01:00
timer-tegra186.c clocksource/drivers/timer-tegra186: Don't print superfluous errors 2025-09-23 12:41:39 +02:00
timer-ti-32k.c clocksource/drivers/ti-32K: Fix misuse of "/**" comment 2024-01-22 13:16:32 +01:00
timer-ti-dm-systimer.c clocksource/drivers/arm_arch_timer: Use of_property_present() for non-boolean properties 2024-11-13 13:49:33 +01:00
timer-ti-dm.c clocksource/drivers/timer-ti-dm : Capture functionality for OMAP DM timer 2025-09-23 12:32:40 +02:00
timer-versatile.c
timer-vt8500.c
timer-zevio.c