Re: [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume
From: Antonio Borneo
Date: Wed Dec 02 2026 - 10:29:27 EST
On Wed, 2026-12-02 at 09:30 +0000, Lee Jones wrote:
> Four IRQ lines share each 32-bit EXTI mux register in SYSCFG, and on
> heterogeneous multi-core SoCs (such as STM32MP1) those registers are
> shared with a remote coprocessor. While stm32_gpio_domain_alloc()
> serialises regmap_field_write(pctl->irqmux[...]) with both
> pctl->irqmux_lock and pctl->hwlock, stm32_pinctrl_restore_gpio_regs()
> updates pctl->irqmux[offset] during resume without acquiring either
> lock, risking a read-modify-write race with the coprocessor.
>
> Acquire pctl->irqmux_lock and pctl->hwlock around the irqmux register
> restore in stm32_pinctrl_restore_gpio_regs().
>
> Fixes: e2f3cf18c3e2 ("pinctrl: stm32: add suspend/resume management")
> Closes: https://sashiko.dev/#/bug/linux-f428a25e-342d-4e81-bdba-0948cff6c22d
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---
> drivers/pinctrl/stm32/pinctrl-stm32.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index 01c8a646d9a0..897da5fafaf4 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -2094,9 +2094,27 @@ static int __maybe_unused stm32_pinctrl_restore_gpio_regs(
> return ret;
> }
>
> - if (pin_is_irq)
> + if (pin_is_irq) {
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pctl->irqmux_lock, flags);
> + if (pctl->hwlock) {
> + ret = hwspin_lock_timeout_in_atomic(pctl->hwlock,
> + HWSPNLCK_TIMEOUT_MS);
> + if (ret) {
> + dev_err(pctl->dev, "Can't get hwspinlock\n");
> + spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
> + return ret;
> + }
> + }
> +
> regmap_field_write(pctl->irqmux[offset], bank->bank_ioport_nr);
>
> + if (pctl->hwlock)
> + hwspin_unlock_in_atomic(pctl->hwlock);
> + spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
> + }
> +
> return 0;
> }
>
Reviewed-by: Antonio Borneo <antonio.borneo@xxxxxxxxxxx>
Thanks,
Antonio