From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796285917; b=zpP36SU1tUcfF8MlywA7E4RXTxGTSf8nqgJ0sBFh5AyuQw0QNt/AKi9KohYIv1QoejvZ rXHgzaFzNXsB/gcKbsdlNPd7sx0mwSkp+VD3t6i5h1Cg/Rlm5gtEQpX6kBjR2ytWe3sS0 Nrwi66FSF/DBdWCxotiSh5o8y1MKUxlkwvqaC2doGfr/tlPa6noYgkG2mlmRpxgeoiGMF Ek2cxffZz8YYwb4myMhB4MHrNeWZbbGX8ksYePucD/ChXfkoZYEw/FUFgWZskUV1ZA0qO FHKY4iRQpamPXbkpcimaA7sr8E6XbSWkgXx2rvzlR5Hus3UlHgtzmmrSmI4FOhu5FkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796285917; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=djE4ykDsDNOasjhIgqtkBJRctLQ8q+uhJvxjl+T3ZcM=; b=1AQ7m7TAJ+5vQqpFJ82itcFoIKvre8OgnoNKJNrYpvjAErmakafqQr5egVjb1wEmCFyT NtDYZClL5f9aM1tOmJs66OGBrmBgZrnVNT8v9UJY5rwTLzLZu/pQ67qsli3Cz1KRkp/AK BeAV4X+dwbXJwsRxzP9+xgs+NLoq7Rsrq9nvVaosaJ48P3glvfwQb7XX0UwR4rxqpTc5s AbC+kb3AD7Bva/tMm6Kln+xuhL9yypSkb/kvg39xA4+F65+UnJ+tv1VlJS1bMjPzlNCP6 Gb4kqKI54dNoPy/8mnThyiY+xyrctdR2FAv4LRoY3HcdlYMnkT+3iNHyOeMc/ErzEew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fu0leyP+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D54C0606A322; Thu, 3 Dec 2026 08:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fu0leyP+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 380531F00893; Thu, 3 Dec 2026 08:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796285917; bh=djE4ykDsDNOasjhIgqtkBJRctLQ8q+uhJvxjl+T3ZcM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Fu0leyP+wxsG3ucQQ53qDnpyji0xCw31XY2HH0GQew0M66KBRy66QcPVOnhKWDnnP NR/v8SX8cpOkv1T7wTCC8EqYE+AVtYfnqc5O1Hwn4hC1QyvOx6PjeDJTQaQDnrkKIE d1sh/+3lGQTvEmbKujqwzMHewst35jmnv1TuqglM/Uwsfvk/qDiaGAbkGLpoYGcMIL rkUcFxcALW+ykFtLmMipHucJsNTOdSrr40n9yoFyzo+X3BkLnWXGrqlV9yMPvGKLux F6xPsHeWZYqW4nmhiuRAoPvJjj9RPG8BKmr9Z8M8Mt33MGVgeLb4RUGFwpsCW2To+A pNMhS9bWgIdCQ== Date: Thu, 3 Dec 2026 08:18:32 +0000 From: Lee Jones To: Ju Nan Cc: Antonio Borneo , Linus Walleij , Maxime Coquelin , Alexandre Torgue , linux-gpio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Message-ID: <20261203081832.GI98551@kernel.org> References: <5b7dec9d.16c0.1a23994d4ed.Coremail.junan76@163.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b7dec9d.16c0.1a23994d4ed.Coremail.junan76@163.com> > At 2026-12-02 17:30:05, "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@vger.kernel.org > >Signed-off-by: Lee Jones > >--- > > 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; > > } > > > >-- > > Hi Lee, > > Can we do this without holding `&pctl->irqmux_lock` ? since `pctl->irqmux_map` is not touched. No, I don't think so. For two reasons. 1. hwspin_lock_timeout_in_atomic() and hwspin_unlock_in_atomic() do not acquire the 'hwlock->lock' and do not disable preemption or interrupts themselves. As their name implies, they require the caller to already be in an atomic context so that the CPU cannot be preempted or interrupted whilst holding the hardware spinlock (which could otherwise stall the remote coprocessor past timeout). 2. In stm32_gpio_domain_alloc(), 'pctl->irqmux_lock' is the local lock used to serialise CPUs on the Linux side before acquiring 'pctl->hwlock' and calling regmap_field_write(). Acquiring 'pctl->irqmux_lock' here maintains the exact same locking strategy and prevents two local CPUs from racing on the same 'pctl->hwlock' without its internal spinlock. > Reviewed-by: Ju Nan Thank you. -- Lee Jones