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 v2 3/3] clocksource/drivers/nxp-stm: Increase min_delta to 20us for PREEMPT_RT
Date: Mon, 02 Nov 2026 21:25:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-194195@kernel.org> (raw)
In-Reply-To: <20261102-nxp-stm-fixes-v2-3-8ca2706f30ef@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] clocksource/drivers/nxp-stm: overshoot check precedes channel enable
--
commit 1283cc4078852e277605e923b00287b73e75d175
Author: Enric Balletbo i Serra <eballetb@redhat.com>
clocksource/drivers/nxp-stm: Increase min_delta to 20us for PREEMPT_RT
This commit increases the clockevent min_delta from 2us to 20us in
nxp_stm_clockevent_starting_cpu() to prevent 32-second timer wraparound
lockups under heavy bus contention on PREEMPT_RT kernels.
> diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c
> index ed7662a4e2bc4..a1a0e23d33426 100644
> --- a/drivers/clocksource/timer-nxp-stm.c
> +++ b/drivers/clocksource/timer-nxp-stm.c
> @@ -335,14 +335,18 @@ static int nxp_stm_clockevent_starting_cpu(unsigned int cpu)
> /*
> * The timings measurement show reading the counter register
> * and writing to the comparator register takes as a maximum
> - * value 1100 ns at 133MHz rate frequency. The timer must be
> - * set above this value and to be secure we set the minimum
> - * value equal to 2000ns, so 2us.
> + * value 1100 ns at 133MHz rate frequency. However, under heavy
> + * bus contention on PREEMPT_RT, 2us is too tight and can allow
> + * the counter to pass the match value before the channel-enable
> + * write takes effect, leading to 32s wraparounds.
> *
> - * minimum ticks = (rate / MICRO) * 2
> + * Increase to 20us to guarantee the comparator channel is fully
> + * enabled before the match value is reached.
> + *
> + * minimum ticks = (rate / MICRO) * 20
> */
> clockevents_config_and_register(&stm_timer->ced, stm_timer->rate,
> - (stm_timer->rate / MICRO) * 2, 0x7FFFFFFFU);
> + (stm_timer->rate / MICRO) * 20, 0x7FFFFFFFU);
[Severity: Medium]
As reported by Sashiko on v1 [1], does increasing min_delta to 20us in
nxp_stm_clockevent_starting_cpu() actually guarantee that the comparator
channel is enabled before the match value is reached?
Looking at drivers/clocksource/timer-nxp-stm.c:
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, now;
nxp_stm_clockevent_disable(stm_timer);
stm_timer->delta = delta;
val = nxp_stm_clockevent_read_counter(stm_timer) + delta;
writel(val, STM_CMP0(stm_timer->base));
...
now = nxp_stm_clockevent_read_counter(stm_timer);
if ((int)(val - now) <= 0)
return -ETIME;
nxp_stm_clockevent_enable(stm_timer);
return 0;
}
nxp_stm_clockevent_disable() clears STM_CCR_CEN in STM_CCR0, and the
hardware only generates a match event when STM_CNT equals STM_CMP0 while
STM_CCR0[CEN] is enabled. Because nxp_stm_clockevent_enable() is called
after reading now and checking (int)(val - now) <= 0, the latency of writing
STM_CCR_CEN to STM_CCR0 is not covered by the -ETIME overshoot check.
For any programmed delta (20us or larger), if bus contention, an NMI, or
hypervisor/firmware delay between the two counter reads leaves val - now as
a small positive number of ticks, the overshoot check passes while the
channel is still disabled, and STM_CNT can pass val before the subsequent
nxp_stm_clockevent_enable() write takes effect in hardware.
Should nxp_stm_clockevent_set_next_event() enable the comparator channel
before reading now for the overshoot check (and call
nxp_stm_clockevent_disable() if (int)(val - now) <= 0 before returning
-ETIME) so the counter read is ordered after the STM_CCR0 write on the bus?
[1] https://lore.kernel.org/r/20261026-nxp-stm-fixes-v1-3-20a64a4ea454@redhat.com
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102-nxp-stm-fixes-v2-0-8ca2706f30ef@redhat.com?part=3
next prev parent reply other threads:[~2026-11-02 21:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 21:16 [PATCH v2 0/3] Fix NXP STM clockevent bugs causing lockups Enric Balletbo i Serra
2026-11-02 21:16 ` [PATCH v2 1/3] clocksource/drivers/nxp-stm: Fix max_delta overflow on 64-bit platforms Enric Balletbo i Serra
2026-11-02 21:16 ` [PATCH v2 2/3] clocksource/drivers/nxp-stm: Fix missed comparator match in set_next_event Enric Balletbo i Serra
2026-11-02 21:16 ` [PATCH v2 3/3] clocksource/drivers/nxp-stm: Increase min_delta to 20us for PREEMPT_RT Enric Balletbo i Serra
2026-11-02 21:25 ` sashiko-bot [this message]
2026-11-02 21:47 ` Enric Balletbo i Serra
2026-11-03 15:42 ` [PATCH v2 0/3] Fix NXP STM clockevent bugs causing lockups Sebastian Andrzej Siewior
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-194195@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 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®