Skip to contentSkip to conversation

watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

PATCH Superseded George Cherian 3 participants 5 messages Feb 8, 2023 – Feb 9, 2023 Watchdog device drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

Make sure to honour the max_hw_heartbeat_ms while programming the timeout value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to make sure the programmed value is within the permissible range.

Fixes abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
---
 drivers/watchdog/sbsa_gwdt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/watchdog/sbsa_gwdt.c +1 -0
index 9791c74aebd4..ee1039a652f1 100644
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
 {
 	struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
 
+	timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000);
 	wdd->timeout = timeout;
 
 	if (action)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 16 lines · George Cherian

Make sure to honour the max_hw_heartbeat_ms while programming the timeout value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to make sure the programmed value is within the permissible range.

Fixes abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
---
  drivers/watchdog/sbsa_gwdt.c | 1 +
  1 file changed, 1 insertion(+)
drivers/watchdog/sbsa_gwdt.c +0 -0
index 9791c74aebd4..ee1039a652f1 100644

drivers/watchdog/sbsa_gwdt.c static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd, · line 154

Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c +1 -0
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
  {
  	struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
 
+	timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000);
  	wdd->timeout = timeout;
 

Wrong order. wdd->timeout should still contain the requested timeout.

Guenter

#2 lore raw
Quoted 36 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, February 8, 2023 8:41 PM
To: George Cherian <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

----------------------------------------------------------------------

Quoted 3 lines · George Cherian

Make sure to honour the max_hw_heartbeat_ms while programming the timeout value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to make sure the programmed value is within

the permissible range.

Quoted 10 lines
Fixes abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
---
  drivers/watchdog/sbsa_gwdt.c | 1 +
  1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1

100644

drivers/watchdog/sbsa_gwdt.c static int sbsa_gwdt_set_timeout(struct

Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c +0 -0
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct

watchdog_device *wdd,

Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c +0 -0
  {
  	struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
 
Quoted 7 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c +1 -0
+	timeout = clamp_t(unsigned int, timeout, 1, wdd-

max_hw_heartbeat_ms
+/ 1000);
wdd->timeout = timeout;

Wrong order. wdd->timeout should still contain the requested timeout.

But then the requested timeout is not being set in HW. Isn't that a disconnect?

Quoted 2 lines

Guenter

maintainer
#3 lore raw
Quoted 43 lines · George Cherian
Quoted 36 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, February 8, 2023 8:41 PM
To: George Cherian <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

----------------------------------------------------------------------

Quoted 3 lines · George Cherian

Make sure to honour the max_hw_heartbeat_ms while programming the timeout value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to make sure the programmed value is within

the permissible range.

Quoted 10 lines
Fixes abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
---
  drivers/watchdog/sbsa_gwdt.c | 1 +
  1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1

100644

drivers/watchdog/sbsa_gwdt.c static int sbsa_gwdt_set_timeout(struct

Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c +0 -0
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct

watchdog_device *wdd,

Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c +0 -0
  {
  	struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
 
Quoted 7 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c +1 -0
+	timeout = clamp_t(unsigned int, timeout, 1, wdd-

max_hw_heartbeat_ms
+/ 1000);
wdd->timeout = timeout;

Wrong order. wdd->timeout should still contain the requested timeout.

Quoted 2 lines

But then the requested timeout is not being set in HW. Isn't that a disconnect?

No. The driver is supposed to set a timeout no larger than max_hw_heartbeat_ms. The watchdog core then takes care of differences between ->timeout (as seen by the user) and max_hw_heartbeat_ms and pings the watchdog as needed.

Guenter

#4 lore raw
Quoted 60 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, February 8, 2023 11:26 PM
To: George Cherian <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

----------------------------------------------------------------------

Quoted 4 lines · George Cherian
Quoted 4 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter

Roeck

Quoted 11 lines
Quoted 11 lines

Sent: Wednesday, February 8, 2023 8:41 PM
To: George Cherian <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

--------------------------------------------------------------------

Quoted 1 line · George Cherian

Make sure to honour the max_hw_heartbeat_ms while programming

the

Quoted 30 lines
Quoted 30 lines
Quoted 3 lines

timeout value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to make sure the programmed value is within

the permissible range.

Quoted 11 lines
Fixes abd3ac7902fb ("watchdog: sbsa: Support architecture version

1")

---
  drivers/watchdog/sbsa_gwdt.c | 1 +
  1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1

100644

drivers/watchdog/sbsa_gwdt.c static int sbsa_gwdt_set_timeout(struct

Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c +0 -0
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct

watchdog_device *wdd,

Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c +1 -0
  {
  	struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
 
+	timeout = clamp_t(unsigned int, timeout, 1, wdd-

max_hw_heartbeat_ms
+/ 1000);
wdd->timeout = timeout;

Wrong order. wdd->timeout should still contain the requested timeout.

Quoted 7 lines
Quoted 2 lines

But then the requested timeout is not being set in HW. Isn't that a disconnect?

No. The driver is supposed to set a timeout no larger than max_hw_heartbeat_ms. The watchdog core then takes care of differences between ->timeout (as seen by the user) and max_hw_heartbeat_ms and pings the watchdog as needed.

Thanks for the explanation. Will post v3.

-George

Quoted 2 lines

Guenter