From: sashiko-bot@kernel.org
To: "Enric Balletbo i Serra" <eballetb@redhat.com>
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event
Date: Mon, 26 Oct 2026 09:44:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-184830@kernel.org> (raw)
In-Reply-To: <20261026-nxp-stm-fixes-v1-2-20a64a4ea454@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clocksource: nxp-stm: overshoot race in nxp_stm_clockevent_set_next_event()
--
commit 45f273b782a28cec6ef30880d738a9cb690edce9
Author: Enric Balletbo i Serra <eballetb@redhat.com>
clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event
This patch fixes the overshoot check in nxp_stm_clockevent_set_next_event()
by using a signed comparison between the target comparator value and the
current counter value to avoid missed matches and 32-bit wraparound stalls.
> diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c
> index ee249fed1b918..ed7662a4e2bc4 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);
[Severity: High]
Can the counter still advance past val before nxp_stm_clockevent_enable()
arms the channel comparator in drivers/clocksource/timer-nxp-stm.c?
At the beginning of nxp_stm_clockevent_set_next_event(), channel 0 is
disabled before programming STM_CMP0:
nxp_stm_clockevent_disable(stm_timer);
...
val = nxp_stm_clockevent_read_counter(stm_timer) + delta;
writel(val, STM_CMP0(stm_timer->base));
Unlike timer-imx-gpt where the compare interrupt remains enabled while
writing TCMP, writing STM_CMP0 in the NXP STM does not arm the comparator
until nxp_stm_clockevent_enable() writes STM_CCR_CEN to STM_CCR0.
Because now is read from STM_CNT before nxp_stm_clockevent_enable() is
called, if now is sampled just below val (so (int)(val - now) <= 0 is false)
and STM_CNT reaches or passes val before the subsequent write to STM_CCR0
takes effect in hardware, the match occurs while channel 0 is still disabled
and is missed.
Should nxp_stm_clockevent_enable(stm_timer) be called before reading now for
the overshoot check, with nxp_stm_clockevent_disable(stm_timer) called on
the -ETIME path?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026-nxp-stm-fixes-v1-0-20a64a4ea454@redhat.com?part=2
next prev parent reply other threads:[~2026-10-26 9:44 UTC|newest]
Thread overview: 11+ 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 ` Enric Balletbo i Serra
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
2026-10-26 8:44 ` [PATCH 2/3] clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event Enric Balletbo i Serra via B4 Relay
2026-10-26 8:44 ` Enric Balletbo i Serra
2026-10-26 9:44 ` sashiko-bot [this message]
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 8:44 ` Enric Balletbo i Serra
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=sashiko-outbox-184830@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eballetb@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.