linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] watchdog: at91sam9_wdt: various fixes and improvements
@ 2013-11-03 17:52 Boris BREZILLON
  2013-11-03 17:52 ` [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks Boris BREZILLON
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Boris BREZILLON @ 2013-11-03 17:52 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog, Boris BREZILLON

Hello,

This patch series fix the secs_to_ticks macro in case 0 is passed as an
argument.

It also rework the heartbeat calculation to increase the security margin of the
watchdog reset timer, and use the min_heartbeat value instead of the calculated
heartbeat value for the first watchdog reset (to avoid spurious watchdog
reset).

Best Regards,

Boris

Boris BREZILLON (3):
  watchdog: at91sam9_wdt: fix secs_to_ticks
  watchdog: at91sam9_wdt: avoid spurious watchdog reset during init
  watchdog: at91sam9_wdt: increase security margin on watchdog counter
    reset

 drivers/watchdog/at91sam9_wdt.c |   38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks
  2013-11-03 17:52 [PATCH 0/3] watchdog: at91sam9_wdt: various fixes and improvements Boris BREZILLON
@ 2013-11-03 17:52 ` Boris BREZILLON
  2013-11-03 18:06   ` Guenter Roeck
  2013-11-03 17:52 ` [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init Boris BREZILLON
  2013-11-03 17:52 ` [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset Boris BREZILLON
  2 siblings, 1 reply; 7+ messages in thread
From: Boris BREZILLON @ 2013-11-03 17:52 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog, Boris BREZILLON

Fix the secs_to_ticks macro in case 0 is passed as an argument.

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
---
 drivers/watchdog/at91sam9_wdt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 9bd089e..65f4691 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -51,7 +51,7 @@
 #define ticks_to_hz_rounddown(t)	((((t) + 1) * HZ) >> 8)
 #define ticks_to_hz_roundup(t)		(((((t) + 1) * HZ) + 255) >> 8)
 #define ticks_to_secs(t)		(((t) + 1) >> 8)
-#define secs_to_ticks(s)		(((s) << 8) - 1)
+#define secs_to_ticks(s)		((s) ? (((s) << 8) - 1) : 0)
 
 #define WDT_MR_RESET	0x3FFF2FFF
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init
  2013-11-03 17:52 [PATCH 0/3] watchdog: at91sam9_wdt: various fixes and improvements Boris BREZILLON
  2013-11-03 17:52 ` [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks Boris BREZILLON
@ 2013-11-03 17:52 ` Boris BREZILLON
  2013-11-03 18:09   ` Guenter Roeck
  2013-11-03 17:52 ` [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset Boris BREZILLON
  2 siblings, 1 reply; 7+ messages in thread
From: Boris BREZILLON @ 2013-11-03 17:52 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog, Boris BREZILLON

Use the min_heartbeat value instead of the calculated heartbeat value for
the first watchdog reset to avoid spurious watchdog reset.

Resetting the watchdog counter during init might lead to a watchdog fault
reset because the watchdog counter has to be running for at least
min_heartbeat.

Resetting the watchdog counter after heartbeat might lead to a watchdog
timeout reset because the watchdog counter is running for more than
max_heartbeat time.

Using min_heartbeat instead of heartbeat does not guarantee that the
watchdog won't trigger a reset, but at least it reduces the chances to be
in such a case.

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
---
 drivers/watchdog/at91sam9_wdt.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 65f4691..ab0c4e0 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -213,7 +213,15 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 			 tmp & wdt->mr_mask, wdt->mr & wdt->mr_mask);
 
 	setup_timer(&wdt->timer, at91_ping, (unsigned long)wdt);
-	mod_timer(&wdt->timer, jiffies + wdt->heartbeat);
+
+	/*
+	 * Use min_heartbeat the first time to avoid spurious watchdog reset:
+	 * we don't know for how long the watchdog counter is running, and
+	 *  - resetting it right now might trigger a watchdog fault reset
+	 *  - waiting for heartbeat time might lead to a watchdog timeout
+	 *    reset
+	 */
+	mod_timer(&wdt->timer, jiffies + min_heartbeat);
 
 	/* Try to set timeout from device tree first */
 	if (watchdog_init_timeout(&wdt->wdd, 0, dev))
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset
  2013-11-03 17:52 [PATCH 0/3] watchdog: at91sam9_wdt: various fixes and improvements Boris BREZILLON
  2013-11-03 17:52 ` [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks Boris BREZILLON
  2013-11-03 17:52 ` [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init Boris BREZILLON
@ 2013-11-03 17:52 ` Boris BREZILLON
  2013-11-03 18:32   ` Guenter Roeck
  2 siblings, 1 reply; 7+ messages in thread
From: Boris BREZILLON @ 2013-11-03 17:52 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog, Boris BREZILLON

Try to reset the watchdog counter 4 or 2 times more often than actually
requested, to avoid spurious watchdog reset.
If this is not possible because of the min_heartbeat value, reset it at
the min_heartbeat period.

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
---
 drivers/watchdog/at91sam9_wdt.c |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index ab0c4e0..489729b 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -158,6 +158,7 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 	int err;
 	u32 mask = wdt->mr_mask;
 	unsigned long min_heartbeat = 1;
+	unsigned long max_heartbeat;
 	struct device *dev = &pdev->dev;
 
 	tmp = wdt_read(wdt, AT91_WDT_MR);
@@ -181,23 +182,29 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 	if (delta < value)
 		min_heartbeat = ticks_to_hz_roundup(value - delta);
 
-	wdt->heartbeat = ticks_to_hz_rounddown(value);
-	if (!wdt->heartbeat) {
+	max_heartbeat = ticks_to_hz_rounddown(value);
+	if (!max_heartbeat) {
 		dev_err(dev,
 			"heartbeat is too small for the system to handle it correctly\n");
 		return -EINVAL;
 	}
 
-	if (wdt->heartbeat < min_heartbeat + 4) {
+	/*
+	 * Try to reset the watchdog counter 4 or 2 times more often than
+	 * actually requested, to avoid spurious watchdog reset.
+	 * If this is not possible because of the min_heartbeat value, reset
+	 * it at the min_heartbeat period.
+	 */
+	if ((max_heartbeat / 4) >= min_heartbeat)
+		wdt->heartbeat = max_heartbeat / 4;
+	else if ((max_heartbeat / 2) >= min_heartbeat)
+		wdt->heartbeat = max_heartbeat / 2;
+	else
 		wdt->heartbeat = min_heartbeat;
+
+	if (max_heartbeat < min_heartbeat + 4)
 		dev_warn(dev,
 			 "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n");
-		if (wdt->heartbeat < 4)
-			dev_warn(dev,
-				 "heartbeat might be too small for the system to handle it correctly\n");
-	} else {
-		wdt->heartbeat -= 4;
-	}
 
 	if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) {
 		err = request_irq(wdt->irq, wdt_interrupt,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks
  2013-11-03 17:52 ` [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks Boris BREZILLON
@ 2013-11-03 18:06   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2013-11-03 18:06 UTC (permalink / raw)
  To: Boris BREZILLON, Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog

On 11/03/2013 09:52 AM, Boris BREZILLON wrote:
> Fix the secs_to_ticks macro in case 0 is passed as an argument.
>
> Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init
  2013-11-03 17:52 ` [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init Boris BREZILLON
@ 2013-11-03 18:09   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2013-11-03 18:09 UTC (permalink / raw)
  To: Boris BREZILLON, Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog

On 11/03/2013 09:52 AM, Boris BREZILLON wrote:
> Use the min_heartbeat value instead of the calculated heartbeat value for
> the first watchdog reset to avoid spurious watchdog reset.
>
> Resetting the watchdog counter during init might lead to a watchdog fault
> reset because the watchdog counter has to be running for at least
> min_heartbeat.
>
> Resetting the watchdog counter after heartbeat might lead to a watchdog
> timeout reset because the watchdog counter is running for more than
> max_heartbeat time.
>
> Using min_heartbeat instead of heartbeat does not guarantee that the
> watchdog won't trigger a reset, but at least it reduces the chances to be
> in such a case.
>
> Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset
  2013-11-03 17:52 ` [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset Boris BREZILLON
@ 2013-11-03 18:32   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2013-11-03 18:32 UTC (permalink / raw)
  To: Boris BREZILLON, Wim Van Sebroeck
  Cc: Fabio Porcedda, Nicolas Ferre, Guenter Roeck, Yang Wenyou,
	linux-kernel, linux-arm-kernel, linux-watchdog

On 11/03/2013 09:52 AM, Boris BREZILLON wrote:
> Try to reset the watchdog counter 4 or 2 times more often than actually
> requested, to avoid spurious watchdog reset.
> If this is not possible because of the min_heartbeat value, reset it at
> the min_heartbeat period.
>
> Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-03 18:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-03 17:52 [PATCH 0/3] watchdog: at91sam9_wdt: various fixes and improvements Boris BREZILLON
2013-11-03 17:52 ` [PATCH 1/3] watchdog: at91sam9_wdt: fix secs_to_ticks Boris BREZILLON
2013-11-03 18:06   ` Guenter Roeck
2013-11-03 17:52 ` [PATCH 2/3] watchdog: at91sam9_wdt: avoid spurious watchdog reset during init Boris BREZILLON
2013-11-03 18:09   ` Guenter Roeck
2013-11-03 17:52 ` [PATCH 3/3] watchdog: at91sam9_wdt: increase security margin on watchdog counter reset Boris BREZILLON
2013-11-03 18:32   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).