From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8727606A32F for ; Thu, 3 Dec 2026 08:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=mnvJMukJ; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fu0leyP+ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=djE4ykDsDNOasjhIgqtkBJRctLQ8q+uhJvxjl+T3ZcM=; b=mnvJMukJ1GJ0oqAJMxKFtjvfhG 3mk00gOP4amHRTTDH6+G6JXRc7pfooC2EB4/dcZxwfNZTxXtMKpT/SaSI22002LqrjSbPy53ayXhD BNMvuas/B5/xQALr8M0T+Y306E2QMkiX5HUONU/xrH7J5WKrn6Oir8VzJ00wUb/8o1faXCElMeOKS oSnthvuYFoNtfrdpIm/+Rth8JpJtTizQK01jpGJZfXuf6Ywh8z55kF5vfjIE1LflA1Rr3ZYdUSK4e MnLTDjNERMuOsNgR21RSxXORPtLLhvp6Ug3jKBzz0JuFTUUbl9eHzhMzg3LnSBQweD0rjd07JXJww oQeePEUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ21X-0000000Dp0W-3uCG; Thu, 03 Dec 2026 08:18:39 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ21W-0000000Dozi-2TIb for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 08:18:38 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id A511F623D0; Thu, 3 Dec 2026 08:18:37 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b7dec9d.16c0.1a23994d4ed.Coremail.junan76@163.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > 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