Re: [PATCH v4 1/2] pinctrl: stm32: Fix the unit of the hwspinlock timeout
From: sashiko-bot
Date: Wed Oct 14 2026 - 12:32:36 EST
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pinctrl: stm32: same-CPU starvation with HWLOCK_IN_ATOMIC on PREEMPT_RT
--
commit 635cf6ace8c829d5e8fd3222bc79311f9ac07fc2
Author: Ju Nan <junan76@xxxxxxx>
pinctrl: stm32: Fix the unit of the hwspinlock timeout
This commit updates the hardware spinlock timeout parameter passed to
hwspin_lock_timeout_in_atomic(). It modifies the timeout constant name and
changes its value from microseconds to milliseconds across the stm32 pinctrl
driver to match the expected API units.
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
[ ... ]
> @@ -946,7 +946,7 @@ static int stm32_pmx_set_mode(struct stm32_gpio_bank *bank,
>
> if (pctl->hwlock) {
> err = hwspin_lock_timeout_in_atomic(pctl->hwlock,
> - HWSPNLCK_TIMEOUT);
> + HWSPNLCK_TIMEOUT_MS);
[Severity: High]
Does calling hwspin_lock_timeout_in_atomic() here cause a same-CPU starvation
issue on PREEMPT_RT?
Because hwspin_lock_timeout_in_atomic() uses the HWLOCK_IN_ATOMIC mode,
it implements the timeout by busy-waiting via udelay() and assumes preemption
is disabled by the caller.
However, on PREEMPT_RT, spin_lock_irqsave(&bank->lock) acquires an rt_mutex
which leaves preemption enabled.
If thread A acquires pctl->hwlock and is preempted, and thread B on the
same CPU subsequently acquires a different bank's lock and attempts to acquire
this shared pctl->hwlock, thread B will busy-wait.
Since thread B loops in a busy-wait for the entire 1ms timeout, thread A is
starved and cannot run to release the hardware lock, resulting in a guaranteed
spurious -ETIMEDOUT failure for thread B.
> if (err) {
> dev_err(pctl->dev, "Can't get hwspinlock\n");
> goto unlock;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014160917.139241-2-junan76@xxxxxxx?part=1