Re:[PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume
From: Ju Nan
Date: Wed Dec 02 2026 - 20:47:03 EST
At 2026-12-02 17:30:05, "Lee Jones" <lee@xxxxxxxxxx> 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;
> }
>
>--
>2.56.1.911.g883d8bcb20-goog
Hi Lee,
Can we do this without holding `&pctl->irqmux_lock` ? since `pctl->irqmux_map` is not touched.
Reviewed-by: Ju Nan <junan76@xxxxxxx>
Thanks,
Ju Nan