Skip to contentSkip to conversation

watchdog: wdat_wdt: Set the min and max timeout values properly

PATCH Superseded Jean Delvare 2 participants 3 messages Aug 6, 2022 – Aug 23, 2022 Watchdog device drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 watchdog: wdat_wdt: Set the min and max timeout values properly

The wdat_wdt driver is misusing the min_hw_heartbeat_ms field. This field should only be used when the hardware watchdog device should not be pinged more frequently than a specific period. The ACPI WDAT "Minimum Count" field, on the other hand, specifies the minimum timeout value that can be set. This corresponds to the min_timeout field in Linux's watchdog infrastructure.

Setting min_hw_heartbeat_ms instead can cause pings to the hardware to be delayed when there is no reason for that, eventually leading to unexpected firing of the watchdog timer (and thus unexpected reboot).

I'm also changing max_hw_heartbeat_ms to max_timeout for symmetry, although the use of this one isn't fundamentally wrong, but there is also no reason to enable the software-driven ping mechanism for the wdat_wdt driver.

Fixes 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")

Reviewed-by! Mika Westerberg <[email protected]>
Cc: Wim Van Sebroeck <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
---
Changes since v1:
* Fix a stupid typo which broke the build. Apparently I shouldn't be sending out patches after midnight, sorry.

 drivers/watchdog/wdat_wdt.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/watchdog/wdat_wdt.c +4 -4
@@ -342,8 +342,8 @@ static int wdat_wdt_probe(struct platfor
 		return -EINVAL;
 
 	wdat->period = tbl->timer_period;
-	wdat->wdd.min_hw_heartbeat_ms = wdat->period * tbl->min_count;
-	wdat->wdd.max_hw_heartbeat_ms = wdat->period * tbl->max_count;
+	wdat->wdd.min_timeout = DIV_ROUND_UP(wdat->period * tbl->min_count, 1000);
+	wdat->wdd.max_timeout = wdat->period * tbl->max_count / 1000;
 	wdat->stopped_in_sleep = tbl->flags & ACPI_WDAT_STOPPED;
 	wdat->wdd.info = &wdat_wdt_info;
 	wdat->wdd.ops = &wdat_wdt_ops;
@@ -450,8 +450,8 @@ static int wdat_wdt_probe(struct platfor
 	 * watchdog properly after it has opened the device. In some cases
 	 * the BIOS default is too short and causes immediate reboot.
 	 */
-	if (timeout * 1000 < wdat->wdd.min_hw_heartbeat_ms ||
-	    timeout * 1000 > wdat->wdd.max_hw_heartbeat_ms) {
+	if (timeout < wdat->wdd.min_timeout ||
+	    timeout > wdat->wdd.max_timeout) {
 		dev_warn(dev, "Invalid timeout %d given, using %d\n",
 			 timeout, WDAT_DEFAULT_TIMEOUT);
 		timeout = WDAT_DEFAULT_TIMEOUT;
Signature · 2 lines
Jean Delvare
SUSE L3 Support
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Jean Delvare

The wdat_wdt driver is misusing the min_hw_heartbeat_ms field. This field should only be used when the hardware watchdog device should not be pinged more frequently than a specific period. The ACPI WDAT "Minimum Count" field, on the other hand, specifies the minimum timeout value that can be set. This corresponds to the min_timeout field in Linux's watchdog infrastructure.

Quoted 9 lines

Setting min_hw_heartbeat_ms instead can cause pings to the hardware to be delayed when there is no reason for that, eventually leading to unexpected firing of the watchdog timer (and thus unexpected reboot).

I'm also changing max_hw_heartbeat_ms to max_timeout for symmetry, although the use of this one isn't fundamentally wrong, but there is also no reason to enable the software-driven ping mechanism for the wdat_wdt driver.

I dislike this part because it changes behavior and is unrelated to the problem at hand, but I assume Mike knows the actual hardware limits and understands the implications (ie that there is indeed no need to enable the software-driven ping mechanism).

Quoted 6 lines
Fixes 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")

Reviewed-by! Mika Westerberg <[email protected]>
Cc: Wim Van Sebroeck <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>

Quoted 34 lines

---
Changes since v1:
* Fix a stupid typo which broke the build. Apparently I shouldn't be sending out patches after midnight, sorry.

  drivers/watchdog/wdat_wdt.c |    8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/watchdog/wdat_wdt.c +4 -4
@@ -342,8 +342,8 @@ static int wdat_wdt_probe(struct platfor
  		return -EINVAL;
 
  	wdat->period = tbl->timer_period;
-	wdat->wdd.min_hw_heartbeat_ms = wdat->period * tbl->min_count;
-	wdat->wdd.max_hw_heartbeat_ms = wdat->period * tbl->max_count;
+	wdat->wdd.min_timeout = DIV_ROUND_UP(wdat->period * tbl->min_count, 1000);
+	wdat->wdd.max_timeout = wdat->period * tbl->max_count / 1000;
  	wdat->stopped_in_sleep = tbl->flags & ACPI_WDAT_STOPPED;
  	wdat->wdd.info = &wdat_wdt_info;
  	wdat->wdd.ops = &wdat_wdt_ops;
@@ -450,8 +450,8 @@ static int wdat_wdt_probe(struct platfor
  	 * watchdog properly after it has opened the device. In some cases
  	 * the BIOS default is too short and causes immediate reboot.
  	 */
-	if (timeout * 1000 < wdat->wdd.min_hw_heartbeat_ms ||
-	    timeout * 1000 > wdat->wdd.max_hw_heartbeat_ms) {
+	if (timeout < wdat->wdd.min_timeout ||
+	    timeout > wdat->wdd.max_timeout) {
  		dev_warn(dev, "Invalid timeout %d given, using %d\n",
  			 timeout, WDAT_DEFAULT_TIMEOUT);
  		timeout = WDAT_DEFAULT_TIMEOUT;
#2 lore raw
In reply to Jean Delvare

Hi all,

Quoted 11 lines · Jean Delvare

The wdat_wdt driver is misusing the min_hw_heartbeat_ms field. This field should only be used when the hardware watchdog device should not be pinged more frequently than a specific period. The ACPI WDAT "Minimum Count" field, on the other hand, specifies the minimum timeout value that can be set. This corresponds to the min_timeout field in Linux's watchdog infrastructure.

Setting min_hw_heartbeat_ms instead can cause pings to the hardware to be delayed when there is no reason for that, eventually leading to unexpected firing of the watchdog timer (and thus unexpected reboot). (...)

This patch no longer applies as it conflicts with:

commit 6d72c7ac9fbe26a77800676507da980436b40b2f

Author: Liu Xinpeng
Date:   Tue Apr 26 22:53:28 2022 +0800

which made it into kernel v5.19.

Having reviewed the commit mentioned above, I must say I'm skeptical. I can't see how setting min_timeout to 1 arbitrarily has been considered a good thing. This allows setting timeout values lower than the ACPI WDAT "Minimum Count" field, while presumably the hardware does not support such short timeouts.

Furthermore, calling watchdog_timeout_invalid() to validate the timeout value is a good idea in principle, however, given that min_timeout is now 1 and max_hw_heartbeat_ms is defined, the function is no longer checking much.

My understanding is that the original code was checking the right limits (from the WDAT table's perspective) using the wrong fields (from the watchdog core's perspective). This fix from Liu is not really fixing the problem (min_hw_heartbeat_ms and max_hw_heartbeat_ms are still set, which enables watchdog core facilities that the driver doesn't need IMHO) and is adding a new problem (the timeout limits defined in the ACPI WDAT table are no longer checked).

I will rebase my patch on top and address both problems.

Signature · 2 lines
Jean Delvare
SUSE L3 Support