From d551516f521e449db114cffb4d5ad426edf5eea2 Mon Sep 17 00:00:00 2001
From: Kairui Song <kasong@redhat.com>
Date: Thu, 19 Nov 2020 22:07:09 +0800
Subject: [PATCH] Set watchdog's pretimeout to zero in kdump kernel

Most watchdogs have a parameter pretimeout, if set to non-zero, it means
before the watchdog really reset the system, it will try to panic the
kernel first, so kdump could kick in, or, just print a panic stacktrace
and then kernel should reset it self.

If we are already in kdump kernel, this is not really helpful, only
increase kernel hanging chance. And it also make thing become complex
as some watchdog triggers the kernel panic in NMI context, which
could also hang the kernel in strange ways, and fail the watchdog it
self. So just disable this parameter.

Also for hpwdt, it have another parameter kdumptimeout, which is
just designed for first kernel. The default behaviour is the watchdog
will simply stop working if timeouted, trigger a panic, and leave the
kernel to kdump. Again, if we are already in kdump this is not helpful.
So also disable that.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Lianbo Jiang <lijiang@redhat.com>
---
 kdump-lib.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kdump-lib.sh b/kdump-lib.sh
index 6475f52..98ff27c 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -797,5 +797,21 @@ prepare_cmdline()
     if [ ! -z ${id} ] ; then
         cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id})
     fi
+
+    # If any watchdog is used, set it's pretimeout to 0. pretimeout let
+    # watchdog panic the kernel first, and reset the system after the
+    # panic. If the system is already in kdump, panic is not helpful
+    # and only increase the chance of watchdog failure.
+    for i in $(get_watchdog_drvs); do
+        cmdline+=" $i.pretimeout=0"
+
+        if [[ $i == hpwdt ]]; then
+            # hpwdt have a special parameter kdumptimeout, is's only suppose
+            # to be set to non-zero in first kernel. In kdump, non-zero
+            # value could prevent the watchdog from resetting the system.
+            cmdline+=" $i.kdumptimeout=0"
+        fi
+    done
+
     echo ${cmdline}
 }