From: Enric Balletbo i Serra via B4 Relay <devnull+eballetb.redhat.com@kernel.org>
To: Daniel Lezcano <daniel.lezcano@kernel.org>,
Thomas Gleixner <tglx@kernel.org>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-rt-devel@lists.linux.dev,
Enric Balletbo i Serra <eballetb@redhat.com>
Subject: [PATCH 2/3] clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event
Date: Mon, 26 Oct 2026 09:44:33 +0100 [thread overview]
Message-ID: <20261026-nxp-stm-fixes-v1-2-20a64a4ea454@redhat.com> (raw)
In-Reply-To: <20261026-nxp-stm-fixes-v1-0-20a64a4ea454@redhat.com>
From: Enric Balletbo i Serra <eballetb@redhat.com>
The NXP STM generates an interrupt only on exact match between STM_CNT
and STM_CMP0. If the counter passes the comparator value before the
overshoot check runs, the match is missed and the hardware must count
through all 2^32 ticks (~32.2s at 133 MHz) before firing, causing soft
lockups.
The existing overshoot check:
if (val > nxp_stm_clockevent_read_counter(stm_timer) + delta)
simplifies to checking if counter_before > counter_after, which only
detects a 32-bit counter wrap and misses the normal overshoot case where
the counter advances past val.
Use a signed comparison on the difference between the target and current
counter values instead, following the established pattern in
timer-imx-gpt. If the counter has reached or passed val, the signed
difference goes to zero or negative and we return -ETIME so the
clockevents layer retries immediately.
Fixes: cec32ac75827 ("clocksource/drivers/nxp-timer: Add the System Timer Module for the s32gx platforms")
Signed-off-by: Enric Balletbo i Serra <eballetb@redhat.com>
---
drivers/clocksource/timer-nxp-stm.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c
index ee249fed1b91..ed7662a4e2bc 100644
--- a/drivers/clocksource/timer-nxp-stm.c
+++ b/drivers/clocksource/timer-nxp-stm.c
@@ -247,7 +247,7 @@ static int nxp_stm_clockevent_shutdown(struct clock_event_device *ced)
static int nxp_stm_clockevent_set_next_event(unsigned long delta, struct clock_event_device *ced)
{
struct stm_timer *stm_timer = ced_to_stm(ced);
- u32 val;
+ u32 val, now;
nxp_stm_clockevent_disable(stm_timer);
@@ -258,16 +258,12 @@ static int nxp_stm_clockevent_set_next_event(unsigned long delta, struct clock_e
writel(val, STM_CMP0(stm_timer->base));
/*
- * The counter is shared across the channels and can not be
- * stopped while we are setting the next event. If the delta
- * is very small it is possible the counter increases above
- * the computed 'val'. The min_delta value specified when
- * registering the clockevent will prevent that. The second
- * case is if the counter wraps while we compute the 'val' and
- * before writing the comparator register. We read the counter,
- * check if we are back in time and abort the timer with -ETIME.
+ * If the counter reached or passed 'val' during or before the
+ * write to the comparator, the hardware match will be missed,
+ * resulting in a full 32-bit (32.2s) wraparound lockup.
*/
- if (val > nxp_stm_clockevent_read_counter(stm_timer) + delta)
+ now = nxp_stm_clockevent_read_counter(stm_timer);
+ if ((int)(val - now) <= 0)
return -ETIME;
nxp_stm_clockevent_enable(stm_timer);
--
2.52.0
next prev parent reply other threads:[~2026-10-26 8:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 8:44 [PATCH 0/3] Fix NXP STM clockevent bugs causing lockups Enric Balletbo i Serra via B4 Relay
2026-10-26 8:44 ` [PATCH 1/3] clocksource/drivers/nxp-stm: Fix max_delta overflow on 64-bit platforms Enric Balletbo i Serra via B4 Relay
2026-10-26 8:44 ` Enric Balletbo i Serra via B4 Relay [this message]
2026-10-26 9:44 ` [PATCH 2/3] clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event sashiko-bot
2026-10-26 18:11 ` Enric Balletbo i Serra
2026-10-26 8:44 ` [PATCH 3/3] clocksource/drivers/nxp-stm: Increase min_delta to 20us for PREEMPT_RT Enric Balletbo i Serra via B4 Relay
2026-10-26 9:59 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261026-nxp-stm-fixes-v1-2-20a64a4ea454@redhat.com \
--to=devnull+eballetb.redhat.com@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=daniel.lezcano@kernel.org \
--cc=eballetb@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=rostedt@goodmis.org \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®