Skip to content

Commit dad92ce

Browse files
committed
watchdog/perf: properly initialize the turbo mode timestamp and rearm counter
JIRA: https://issues.redhat.com/browse/RHEL-103375 Conflicts: kernel/watchdog_perf.c doesn't exist in RHEL at this time, so this commit is applied to kernel/watchdog_hld.c commit f944ffc Author: Thomas Gleixner <tglx@linutronix.de> Date: Thu Jul 11 22:25:21 2024 +0200 watchdog/perf: properly initialize the turbo mode timestamp and rearm counter For systems on which the performance counter can expire early due to turbo modes the watchdog handler has a safety net in place which validates that since the last watchdog event there has at least 4/5th of the watchdog period elapsed. This works reliably only after the first watchdog event because the per CPU variable which holds the timestamp of the last event is never initialized. So a first spurious event will validate against a timestamp of 0 which results in a delta which is likely to be way over the 4/5 threshold of the period. As this might happen before the first watchdog hrtimer event increments the watchdog counter, this can lead to false positives. Fix this by initializing the timestamp before enabling the hardware event. Reset the rearm counter as well, as that might be non zero after the watchdog was disabled and reenabled. Link: https://lkml.kernel.org/r/87frsfu15a.ffs@tglx Fixes: 7edaeb6 ("kernel/watchdog: Prevent false positives with turbo modes") Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent c9f71b9 commit dad92ce

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kernel/watchdog_hld.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ static bool watchdog_check_timestamp(void)
9191
__this_cpu_write(last_timestamp, now);
9292
return true;
9393
}
94-
#else
95-
static inline bool watchdog_check_timestamp(void)
94+
95+
static void watchdog_init_timestamp(void)
9696
{
97-
return true;
97+
__this_cpu_write(nmi_rearmed, 0);
98+
__this_cpu_write(last_timestamp, ktime_get_mono_fast_ns());
9899
}
100+
#else
101+
static inline bool watchdog_check_timestamp(void) { return true; }
102+
static inline void watchdog_init_timestamp(void) { }
99103
#endif
100104

101105
static struct perf_event_attr wd_hw_attr = {
@@ -196,6 +200,7 @@ void hardlockup_detector_perf_enable(void)
196200
if (!atomic_fetch_inc(&watchdog_cpus))
197201
pr_info("Enabled. Permanently consumes one hw-PMU counter.\n");
198202

203+
watchdog_init_timestamp();
199204
perf_event_enable(this_cpu_read(watchdog_ev));
200205
}
201206

0 commit comments

Comments
 (0)