From: Antonio Borneo <antonio.borneo@foss.st.com>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Russell King <linux@armlinux.org.uk>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
Yannick Fertre <yannick.fertre@foss.st.com>,
Christophe Roullier <christophe.roullier@foss.st.com>,
<devicetree@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: "Antonio Borneo" <antonio.borneo@foss.st.com>,
linux-watchdog@vger.kernel.org,
"Clément Le Goffic" <clement.legoffic@foss.st.com>,
"Amelie Delaunay" <amelie.delaunay@foss.st.com>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v4 02/15] watchdog: stm32_iwdg: serialize accesses to EWCR register
Date: Mon, 16 Nov 2026 14:24:03 +0100 [thread overview]
Message-ID: <20261116132416.1184447-3-antonio.borneo@foss.st.com> (raw)
In-Reply-To: <20261116132416.1184447-1-antonio.borneo@foss.st.com>
On STM32MP1xx platforms, EWCR contains both the pretimeout
interrupt configuration and a write-only bit used to acknowledge
the interrupt.
On SMP systems, the read-modify-write operation in the pretimeout
IRQ handler can race with writes that update the pretimeout
configuration.
Protect these accesses with a spinlock to prevent concurrent
updates.
Don't use the helpers reg_read()/reg_write() in the critical
sections as they rely on relaxed memory access, which are not
ordered against locking.
Fixes: 3ab1663af6c1 ("watchdog: stm32_iwdg: Add pretimeout support")
Signed-off-by: Antonio Borneo <antonio.borneo@foss.st.com>
---
drivers/watchdog/stm32_iwdg.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 2bac4ce5ed3f8..487764b51667c 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -19,6 +19,7 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
+#include <linux/spinlock.h>
#include <linux/watchdog.h>
#define DEFAULT_TIMEOUT 10
@@ -82,6 +83,7 @@ struct stm32_iwdg {
struct clk *clk_lsi;
struct clk *clk_pclk;
unsigned int rate;
+ spinlock_t lock; /* serialize IWDG_EWCR register access */
};
static inline u32 reg_read(void __iomem *base, u32 reg)
@@ -98,6 +100,7 @@ static int stm32_iwdg_start(struct watchdog_device *wdd)
{
struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd);
u32 tout, ptot, presc, iwdg_rlr, iwdg_ewcr, iwdg_pr, iwdg_sr;
+ unsigned long flags;
int ret;
dev_dbg(wdd->parent, "%s\n", __func__);
@@ -124,8 +127,11 @@ static int stm32_iwdg_start(struct watchdog_device *wdd)
/* set prescaler & reload registers */
reg_write(wdt->regs, IWDG_PR, iwdg_pr);
reg_write(wdt->regs, IWDG_RLR, iwdg_rlr);
- if (wdt->data->has_early_wakeup)
- reg_write(wdt->regs, IWDG_EWCR, iwdg_ewcr | EWCR_EWIE);
+ if (wdt->data->has_early_wakeup) {
+ spin_lock_irqsave(&wdt->lock, flags);
+ writel(iwdg_ewcr | EWCR_EWIE, wdt->regs + IWDG_EWCR);
+ spin_unlock_irqrestore(&wdt->lock, flags);
+ }
reg_write(wdt->regs, IWDG_KR, KR_KEY_ENABLE);
/* wait for the registers to be updated (max 100ms) */
@@ -185,11 +191,16 @@ static irqreturn_t stm32_iwdg_isr(int irq, void *wdog_arg)
{
struct watchdog_device *wdd = wdog_arg;
struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd);
+ unsigned long flags;
u32 reg;
- reg = reg_read(wdt->regs, IWDG_EWCR);
+ spin_lock_irqsave(&wdt->lock, flags);
+
+ reg = readl(wdt->regs + IWDG_EWCR);
reg |= EWCR_EWIC;
- reg_write(wdt->regs, IWDG_EWCR, reg);
+ writel(reg, wdt->regs + IWDG_EWCR);
+
+ spin_unlock_irqrestore(&wdt->lock, flags);
watchdog_notify_pretimeout(wdd);
@@ -323,6 +334,8 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
if (!wdt)
return -ENOMEM;
+ spin_lock_init(&wdt->lock);
+
wdt->data = of_device_get_match_data(&pdev->dev);
if (!wdt->data)
return -ENODEV;
--
2.34.1
next prev parent reply other threads:[~2026-11-16 13:24 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 13:24 [PATCH v4 00/15] Update watchdogs support on STM32MP platforms Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 01/15] watchdog: stm32_iwdg: set driver data before requesting interrupt Antonio Borneo
2026-11-16 13:24 ` Antonio Borneo [this message]
2026-11-16 13:24 ` [PATCH v4 03/15] watchdog: stm32_iwdg: get hardware version during probe Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 04/15] watchdog: stm32_iwdg: detect whether the watchdog is running Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 05/15] watchdog: stm32_iwdg: add pretimeout support for iwdg v4.0 Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 06/15] ARM: stm32: enable arm smc watchdog on stm32mp1xx Antonio Borneo
2026-11-16 14:33 ` Guenter Roeck
2026-11-16 16:45 ` Antonio Borneo
2026-11-16 18:00 ` Guenter Roeck
2026-11-16 18:26 ` Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 07/15] dt-bindings: watchdog: st,stm32-iwdg: add access-controllers property Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 08/15] ARM: dts: stm32: add iwdg1 node on stm32mp151 SoC Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 09/15] ARM: dts: stm32: enable iwdg1 on stm32mp15x ST boards Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 10/15] ARM: dts: stm32: move arm smc watchdog to stm32mp151 SoC Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 11/15] ARM: dts: stm32: enable arm smc watchdog on stm32mp15x scmi boards Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 12/15] ARM: dts: stm32: add watchdog0 alias on ST stm32mp1xx boards Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 13/15] arm64: dts: st: add iwdg1 and iwdg2 support to stm32mp231 Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 14/15] arm64: dts: st: add iwdg1 and iwdg2 support to stm32mp251 Antonio Borneo
2026-11-16 13:24 ` [PATCH v4 15/15] arm64: dts: st: enable iwdg2 on stm32mp2xx ST boards Antonio Borneo
2026-11-16 14:37 ` [PATCH v4 00/15] Update watchdogs support on STM32MP platforms Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116132416.1184447-3-antonio.borneo@foss.st.com \
--to=antonio.borneo@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=amelie.delaunay@foss.st.com \
--cc=christophe.roullier@foss.st.com \
--cc=clement.legoffic@foss.st.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linux@roeck-us.net \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=wim@linux-watchdog.org \
--cc=yannick.fertre@foss.st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®