Skip to contentSkip to conversation

powerpc/64s: SMP hardlockup watchdog

RFC PATCH New Nicholas Piggin 1 participant 1 message Apr 13, 2017

Subsystems (4)
lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

RFC PATCH 1/1 powerpc/64s: SMP hardlockup watchdog

Implement a new SMP based watchdog rather than use the perf based hardlockup detector. The new watchdog uses all SMP threads to watch each other for lockups, by pinging a shared cpumask.

This has nothing really to do with NMIs at the moment, but it looks into a couple of kernel options and APIs that have NMI in the name.

In the interests of size and simplicity, I have avoided grabbing the pseudo-NMI from underneath the soft IRQ masking code. One issue there is I want to avoid reusing process stacks when Linux irqs are disabled.

This will become most useful with NMI IPIs to crash stuck CPUs with. Probably needs some small build fixes on other archs which do their own watchdogs like sparc, but it works on powerpc.

---
 arch/powerpc/Kconfig           |   1 +
 arch/powerpc/include/asm/nmi.h |   2 +
 arch/powerpc/kernel/Makefile   |   1 +
 arch/powerpc/kernel/kvm.c      |   6 +
 arch/powerpc/kernel/setup_64.c |  18 ---
 arch/powerpc/kernel/watchdog.c | 282 +++++++++++++++++++++++++++++++++++++++++
 include/linux/nmi.h            |   2 +-
 kernel/sysctl.c                |   2 +-
 kernel/watchdog.c              |  50 +++++++-
 lib/Kconfig.debug              |   4 +-
 10 files changed, 340 insertions(+), 28 deletions(-)
 create mode 100644 arch/powerpc/kernel/watchdog.c
arch/powerpc/Kconfig +1 -0
index c4804cd65b9a..66f23c700233 100644
@@ -148,6 +148,7 @@ config PPC
 	select HAVE_MEMBLOCK_NODE_MAP
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI				if PERF_EVENTS
+	select HAVE_NMI_WATCHDOG		if PPC64 && PPC_BOOK3S && SMP
 	select HAVE_OPROFILE
 	select HAVE_OPTPROBES			if PPC64
 	select HAVE_PERF_EVENTS
arch/powerpc/include/asm/nmi.h +2 -0
index ff1ccb375e60..df8e058d94d4 100644
@@ -1,4 +1,6 @@
 #ifndef _ASM_NMI_H
 #define _ASM_NMI_H
 
+void touch_nmi_watchdog(void);
+
 #endif /* _ASM_NMI_H */
arch/powerpc/kernel/Makefile +1 -0
index 9b264ebe6ac1..691a5713cc3a 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_PPC64)		+= setup_64.o sys_ppc32.o \
 				   signal_64.o ptrace32.o \
 				   paca.o nvram_64.o firmware.o
 obj-$(CONFIG_VDSO32)		+= vdso32/
+obj-$(CONFIG_HAVE_NMI_WATCHDOG)	+= watchdog.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT)	+= hw_breakpoint.o
 obj-$(CONFIG_PPC_BOOK3S_64)	+= cpu_setup_ppc970.o cpu_setup_pa6t.o
 obj-$(CONFIG_PPC_BOOK3S_64)	+= cpu_setup_power.o
arch/powerpc/kernel/kvm.c +6 -0
index 9ad37f827a97..dee51a1373e9 100644
@@ -718,6 +718,12 @@ static __init void kvm_free_tmp(void)
 
 static int __init kvm_guest_init(void)
 {
+	/*
+	 * The hardlockup detector is likely to get false positives in
+	 * KVM guests, so disable it by default.
+	 */
+	hardlockup_detector_disable();
+
 	if (!kvm_para_available())
 		goto free_tmp;
 
arch/powerpc/kernel/setup_64.c +0 -18
index f3e65de63ce8..5a8c57396947 100644
@@ -729,21 +729,3 @@ struct ppc_pci_io ppc_pci_io;
 EXPORT_SYMBOL(ppc_pci_io);
 #endif
 
-#ifdef CONFIG_HARDLOCKUP_DETECTOR
-u64 hw_nmi_get_sample_period(int watchdog_thresh)
-{
-	return ppc_proc_freq * watchdog_thresh;
-}
-
-/*
- * The hardlockup detector breaks PMU event based branches and is likely
- * to get false positives in KVM guests, so disable it by default.
- */
-static int __init disable_hardlockup_detector(void)
-{
-	hardlockup_detector_disable();
-
-	return 0;
-}
-early_initcall(disable_hardlockup_detector);
-#endif
arch/powerpc/kernel/watchdog.c new file +282 -0

282 lines not on this page · raw message

include/linux/nmi.h +1 -1
index aa3cd0878270..793d05d29140 100644
@@ -78,7 +78,7 @@ static inline void touch_nmi_watchdog(void)
 }
 #endif
 
-#if defined(CONFIG_HARDLOCKUP_DETECTOR)
+#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
 extern void hardlockup_detector_disable(void);
 #else
 static inline void hardlockup_detector_disable(void) {}
kernel/sysctl.c +1 -1
index 8c8714fcb53c..dae648322bb9 100644
@@ -904,7 +904,7 @@ static struct ctl_table kern_table[] = {
 		.extra1		= &zero,
 		.extra2		= &one,
 	},
-#ifdef CONFIG_HARDLOCKUP_DETECTOR
+#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
 	{
 		.procname	= "hardlockup_panic",
 		.data		= &hardlockup_panic,
kernel/watchdog.c +44 -6

78 lines not on this page · raw message

lib/Kconfig.debug +2 -2
index 97d62c2da6c2..bc10e69a3a8a 100644
@@ -807,7 +807,7 @@ config HARDLOCKUP_DETECTOR
 
 config BOOTPARAM_HARDLOCKUP_PANIC
 	bool "Panic (Reboot) On Hard Lockups"
-	depends on HARDLOCKUP_DETECTOR
+	depends on HARDLOCKUP_DETECTOR || HAVE_NMI_WATCHDOG
 	help
 	  Say Y here to enable the kernel to panic on "hard lockups",
 	  which are bugs that cause the kernel to loop in kernel
@@ -818,7 +818,7 @@ config BOOTPARAM_HARDLOCKUP_PANIC
 
 config BOOTPARAM_HARDLOCKUP_PANIC_VALUE
 	int
-	depends on HARDLOCKUP_DETECTOR
+	depends on HARDLOCKUP_DETECTOR || HAVE_NMI_WATCHDOG
 	range 0 1
 	default 0 if !BOOTPARAM_HARDLOCKUP_PANIC
 	default 1 if BOOTPARAM_HARDLOCKUP_PANIC
Signature · 1 line
2.11.0