Skip to contentSkip to conversation

watchdog: sp805_wdt: re-enable the clock in the restart handler

PATCH Superseded David Yang 3 participants 3 messages Nov 20 Watchdog device drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

David Yang

author
#0 lore raw

PATCH 1/1 watchdog: sp805_wdt: re-enable the clock in the restart handler

wdt_restart() fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core calls wdt_disable() which disables wdt->clk. No reset comes.

Re-enable the clock in it as in npcm_wdt.

---
 drivers/watchdog/sp805_wdt.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/watchdog/sp805_wdt.c +3 -0
index a14ff7ac0db4..20b2fbb7334d 100644
@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
 {
 	struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
 
+	/* For reset, we start the WDT clock and leave it running. */
+	clk_prepare_enable(wdt->clk);
+
 	writel_relaxed(UNLOCK, wdt->base + WDTLOCK);
 	writel_relaxed(0, wdt->base + WDTCONTROL);
 	writel_relaxed(0, wdt->base + WDTLOAD);
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] watchdog: sp805_wdt: sleeping clk_prepare_enable() call in wdt_restart() - [Low] watchdog…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] watchdog: sp805_wdt: sleeping clk_prepare_enable() call in wdt_restart()
- [Low] watchdog: sp805_wdt: missing Fixes trailer for wdt_restart() clock fix
--

commit 800a9ee3ac4d2d74f9b4e848c39474209c8cef7f
Author: David Yang <[email protected]>

Quoted 10 lines

watchdog: sp805_wdt: re-enable the clock in the restart handler

wdt_restart() fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core calls wdt_disable() which disables wdt->clk. No reset comes.

Re-enable the clock in it as in npcm_wdt.

[Severity: Low]
Should this bug fix include a Fixes tag for the commit that introduced wdt_restart()?

Fixes 6c5c0d48b686 ("watchdog: sp805: add restart handler")

drivers/watchdog/sp805_wdt.c wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) · line 142

Quoted 10 lines
drivers/watchdog/sp805_wdt.c +2 -0
index a14ff7ac0db48..20b2fbb7334db 100644
@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
 {
 	struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
 
+	/* For reset, we start the WDT clock and leave it running. */
+	clk_prepare_enable(wdt->clk);

[Severity: High]
Can wdt_restart() call clk_prepare_enable()?

do_kernel_restart() invokes restart handlers via atomic_notifier_call_chain(&restart_handler_list, ...) under rcu_read_lock() with local interrupts disabled, whereas clk_prepare() acquires the sleeping prepare_lock mutex and calls ->prepare() callbacks. When wdt->clk is unprepared (either because the watchdog was never started or because wdt_disable() called clk_disable_unprepare()), this sleeps in atomic context and can deadlock or hang system reboot.

Unlike sp805_wdt, npcm_wdt prepares its clock at probe time via devm_clk_get_optional_prepared() and uses clk_enable() / clk_disable() at runtime so that npcm_wdt_restart() only calls atomic-safe clk_enable().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to David Yang
Quoted 17 lines · David Yang

wdt_restart() fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core calls wdt_disable() which disables wdt->clk. No reset comes.

Re-enable the clock in it as in npcm_wdt.

---
  drivers/watchdog/sp805_wdt.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/watchdog/sp805_wdt.c +0 -0
index a14ff7ac0db4..20b2fbb7334d 100644

drivers/watchdog/sp805_wdt.c wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) · line 146

Quoted 9 lines
drivers/watchdog/sp805_wdt.c +3 -0
@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
  {
  	struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
 
+	/* For reset, we start the WDT clock and leave it running. */
+	clk_prepare_enable(wdt->clk);
+
  	writel_relaxed(UNLOCK, wdt->base + WDTLOCK);
  	writel_relaxed(0, wdt->base + WDTCONTROL);
  	writel_relaxed(0, wdt->base + WDTLOAD);

This probably needs a fix similar to commit 4e83ea5b2219 ("watchdog: npcm:
fix sleeping clock call in restart handler") - leave the clock prepared all the time and only enable / disable it when starting or stopping the watchdog.

Guenter