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=1796382753; b=MZhm2fSfaspB58jl7BGE1wweSheNjiiYIYLtlPr44hUlWbkqLfFSUfuDoW2QoFNxUYLu LBU4MdnWEmEmIG3VBQmri/ftj/hUXrGSGfkm35b9bMYjtj+j6UN2moKuyFBgDM3DWUkYE sQ9fLqEy5o+/ucn+SIOIBoV5Dy1Lnc2pX5DcGeUyllnCFt2LgwgBGvRfKdLDXDtqxEeUj mEPTri5LBn0XWO09o9/XDa16bL0tJrreb+Qd5IKt9U5brWgIAzTzVzO9DKBTNpFmrXCg2 DD5QWgIuPpoC/MGjRI1ydvEP94iTNYFIdkX93r5rM1d08j97LO43F+I8UMyjK1aBKqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382753; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=9POgeeu9FRnfLkD0fkf/XiahroXATqtEBXHI/f0qrT4=; b=htlD7FR9XnDnw6WyNeFrPr0hcqBz3O+K7tOyWLBRozmMRefoAvVuM5dCe/3Mlj0hrcDH xRUrohEB/lE193zisW3rlOX5OvF2ZC7rQ+jTcU0EZlOp3hxZDxea17xpIROY++eQqccsy p8wkZ1HfvkVBipf11tXuTlcg8j9S6hfxu1qTqPufrn+Qya3O1aORUCMnib2O9APX228l6 6bCWLjwiFASZiJsLSTRvElJODy9nJ+7bU1LjeMJTcu7FGaYnIpRGQ06uue/AIIRlNJb5E GYRF6tfQr2XDqOsnpxFA1iVS0jXX/LxrtZgX8cCZ3MifOuW9fjuCN5dFMxIc0ZG9w7w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1xIX34cv; 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 1BD25606A33F; Fri, 4 Dec 2026 11:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1xIX34cv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EB691F00A05; Fri, 4 Dec 2026 11:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382752; bh=9POgeeu9FRnfLkD0fkf/XiahroXATqtEBXHI/f0qrT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1xIX34cvdZJbaBnoABWbR5LmgsqmSooKbnsqgyMzSnp94xVAXxwMSKpZk97q3dVJ7 8UMEgAetvozTQ+y0t45BMaDOX1bBhvqdJpk6WrTMFl+S/IocL56bGQRl7ZYnSFZSjf Cmn+Nub3G0qemsJ01njVtf3aJoSEQEkXE641BQr0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Antonio Borneo , Guenter Roeck Subject: [PATCH 6.18 538/703] watchdog: stm32_iwdg: serialize accesses to EWCR register Date: Fri, 4 Dec 2026 19:07:17 +0900 Message-ID: <20261204100642.101497593@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Antonio Borneo commit abbf55699ff6a8830b864aa1fab9f24edc9e72a6 upstream. 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") Cc: stable@vger.kernel.org Signed-off-by: Antonio Borneo Link: https://patch.msgid.link/20261116132416.1184447-3-antonio.borneo@foss.st.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/watchdog/stm32_iwdg.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/drivers/watchdog/stm32_iwdg.c +++ b/drivers/watchdog/stm32_iwdg.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #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 watch { 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 watch /* 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 ir { 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); @@ -320,6 +331,8 @@ static int stm32_iwdg_probe(struct platf if (!wdt) return -ENOMEM; + spin_lock_init(&wdt->lock); + wdt->data = of_device_get_match_data(&pdev->dev); if (!wdt->data) return -ENODEV;