Skip to contentSkip to conversation

watchdog: sbsa: Test WDOG_HW_RUNNING bit in suspend and resume

PATCH In review Wang Wensheng 2 participants 4 messages Mar 1, 2023 – Mar 4, 2023 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: sbsa: Test WDOG_HW_RUNNING bit in suspend and resume

If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit and keep it alive before anyone else would open it. When system suspend, the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then the sbsa_gwdt would reach timeout since no one touch it during system suspend.

To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the sbsa_gwdt if the bit is set, then reopen it accordingly in resume process.

---
 drivers/watchdog/sbsa_gwdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/sbsa_gwdt.c +2 -2
index 9791c74aebd4..60875a710e43 100644
@@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
 {
 	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
 		sbsa_gwdt_stop(&gwdt->wdd);
 
 	return 0;
@@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
 {
 	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
 		sbsa_gwdt_start(&gwdt->wdd);
 
 	return 0;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 20 lines · Wang Wensheng

If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit and keep it alive before anyone else would open it. When system suspend, the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then the sbsa_gwdt would reach timeout since no one touch it during system suspend.

To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the sbsa_gwdt if the bit is set, then reopen it accordingly in resume process.

---
  drivers/watchdog/sbsa_gwdt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/sbsa_gwdt.c +0 -0
index 9791c74aebd4..60875a710e43 100644

drivers/watchdog/sbsa_gwdt.c static int __maybe_unused sbsa_gwdt_suspend(struct device *dev) · line 364

Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c +1 -1
@@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
  {
  	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
  		sbsa_gwdt_stop(&gwdt->wdd);

That will not stop the watchdog if it is currently open (active) and if it wasn't running when the module was loaded.

Guenter

Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c +1 -1
  	return 0;
@@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
  {
  	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
  		sbsa_gwdt_start(&gwdt->wdd);
 
  	return 0;
maintainer
#2 lore raw
Quoted 16 lines · Guenter Roeck
Quoted 15 lines · Wang Wensheng

If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit and keep it alive before anyone else would open it. When system suspend, the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then the sbsa_gwdt would reach timeout since no one touch it during system suspend.

To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the sbsa_gwdt if the bit is set, then reopen it accordingly in resume process.

---
  drivers/watchdog/sbsa_gwdt.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

drivers/watchdog/sbsa_gwdt.c static int __maybe_unused sbsa_gwdt_suspend(struct device *dev) · line 363

Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c +1 -1
index 9791c74aebd4..60875a710e43 100644
@@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
   {
       struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
-    if (watchdog_active(&gwdt->wdd))
+    if (watchdog_hw_running(&gwdt->wdd))
           sbsa_gwdt_stop(&gwdt->wdd);

That will not stop the watchdog if it is currently open (active) and if it wasn't running when the module was loaded.

I just sent a patch which fixes the problem in the watchdog core.

Guenter

Quoted 11 lines

Guenter

Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c +1 -1
       return 0;
@@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
   {
       struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
-    if (watchdog_active(&gwdt->wdd))
+    if (watchdog_hw_running(&gwdt->wdd))
           sbsa_gwdt_start(&gwdt->wdd);
       return 0;
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Wang Wensheng
Quoted 11 lines · Wang Wensheng

If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit and keep it alive before anyone else would open it. When system suspend, the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then the sbsa_gwdt would reach timeout since no one touch it during system suspend.

To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the sbsa_gwdt if the bit is set, then reopen it accordingly in resume process.

Prerequisite: "watchdog: core: Always set WDOG_HW_RUNNING when starting watchdog"

Guenter

Quoted 26 lines
---
  drivers/watchdog/sbsa_gwdt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/sbsa_gwdt.c +2 -2
index 9791c74aebd4..60875a710e43 100644
@@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
  {
  	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
  		sbsa_gwdt_stop(&gwdt->wdd);
 
  	return 0;
@@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
  {
  	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
  		sbsa_gwdt_start(&gwdt->wdd);
 
  	return 0;