diff mbox series

[5/9] ipmi-watchdog: Add a flag to determine if we are still ticking

Message ID 20180524001335.15457-6-wak@google.com
State Accepted
Headers show
Series ipmi-watchdog: Fixes for error handling and general cleanups | expand

Commit Message

William Kennington May 24, 2018, 12:13 a.m. UTC
This makes it easier for future changes to ensure that the watchdog
stops ticking and doesn't requeue itself for execution in the
background. This way it is safe for resets to be performed after the
ticks are assumed to be stopped and it won't start the timer again.

Signed-off-by: William A. Kennington III <wak@google.com>
---
 hw/ipmi/ipmi-watchdog.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/hw/ipmi/ipmi-watchdog.c b/hw/ipmi/ipmi-watchdog.c
index b5cb5fee4..fc559c6da 100644
--- a/hw/ipmi/ipmi-watchdog.c
+++ b/hw/ipmi/ipmi-watchdog.c
@@ -46,11 +46,12 @@  more frequently than necessary. */
 #define WDT_MARGIN		300
 
 static struct timer wdt_timer;
-static bool wdt_stopped = false;
+static bool wdt_stopped;
+static bool wdt_ticking;
 
 static void ipmi_wdt_complete(struct ipmi_msg *msg)
 {
-	if (msg->cmd == IPMI_CMD(IPMI_RESET_WDT) && !msg->user_data)
+	if (msg->cmd == IPMI_CMD(IPMI_RESET_WDT) && wdt_ticking)
 		schedule_timer(&wdt_timer, msecs_to_tb(
 				       (WDT_TIMEOUT - WDT_MARGIN)*100));
 
@@ -121,11 +122,18 @@  void ipmi_wdt_stop(void)
 
 void ipmi_wdt_final_reset(void)
 {
+	/* We can safely stop the timer prior to setting up our final
+	 * watchdog timeout since we have enough margin before the
+	 * timeout. */
+	wdt_ticking = false;
+	cancel_timer(&wdt_timer);
+
+	/* Configure the watchdog and make sure it is still enabled */
 	set_wdt(WDT_RESET_ACTION | WDT_PRETIMEOUT_SMI, WDT_TIMEOUT,
 		WDT_MARGIN/10, true);
 	sync_reset_wdt();
+
 	ipmi_set_boot_count();
-	cancel_timer(&wdt_timer);
 }
 
 void ipmi_wdt_init(void)
@@ -136,6 +144,7 @@  void ipmi_wdt_init(void)
 	/* Start the WDT. We do it synchronously to make sure it has
 	 * started before skiboot continues booting. Otherwise we
 	 * could crash before the wdt has actually been started. */
+	wdt_ticking = true;
 	sync_reset_wdt();
 
 	return;