Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Watchdog support on powerpc systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2017, IBM Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This uses code from arch/sparc/kernel/nmi.c and kernel/watchdog.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) "watchdog: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/hardirq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/paca.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * The powerpc watchdog ensures that each CPU is able to service timers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * The watchdog sets up a simple timer on each CPU to run once per timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * period, and updates a per-cpu timestamp and a "pending" cpumask. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * the heartbeat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Then there are two systems to check that the heartbeat is still running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * The local soft-NMI, and the SMP checker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * The soft-NMI checker can detect lockups on the local CPU. When interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * are disabled with local_irq_disable(), platforms that use soft-masking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * can leave hardware interrupts enabled and handle them with a masked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * interrupt handler. The masked handler can send the timer interrupt to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * watchdog's soft_nmi_interrupt(), which appears to Linux as an NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * interrupt, and can be used to detect CPUs stuck with IRQs disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * The soft-NMI checker will compare the heartbeat timestamp for this CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * with the current time, and take action if the difference exceeds the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * watchdog threshold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * The limitation of the soft-NMI watchdog is that it does not work when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * interrupts are hard disabled or otherwise not being serviced. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * solved by also having a SMP watchdog where all CPUs check all other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * CPUs heartbeat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * The SMP checker can detect lockups on other CPUs. A gobal "pending"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * cpumask is kept, containing all CPUs which enable the watchdog. Each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * CPU clears their pending bit in their heartbeat timer. When the bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * becomes empty, the last CPU to clear its pending bit updates a global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * timestamp and refills the pending bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * In the heartbeat timer, if any CPU notices that the global timestamp has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * not been updated for a period exceeding the watchdog threshold, then it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * means the CPU(s) with their bit still set in the pending mask have had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * their heartbeat stop, and action is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * Some platforms implement true NMI IPIs, which can be used by the SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * watchdog to detect an unresponsive CPU and pull it out of its stuck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * state with the NMI IPI, to get crash/debug data from it. This way the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * SMP watchdog can detect hardware interrupts off lockups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static cpumask_t wd_cpus_enabled __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static u64 wd_panic_timeout_tb __read_mostly; /* timebase ticks until panic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static u64 wd_smp_panic_timeout_tb __read_mostly; /* panic other CPUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static u64 wd_timer_period_ms __read_mostly;  /* interval between heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static DEFINE_PER_CPU(struct hrtimer, wd_hrtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static DEFINE_PER_CPU(u64, wd_timer_tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /* SMP checker bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static unsigned long __wd_smp_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static cpumask_t wd_smp_cpus_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static cpumask_t wd_smp_cpus_stuck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static u64 wd_smp_last_reset_tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static inline void wd_smp_lock(unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * Avoid locking layers if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * This may be called from low level interrupt handlers at some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * point in future.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	raw_local_irq_save(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	hard_irq_disable(); /* Make it soft-NMI safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	while (unlikely(test_and_set_bit_lock(0, &__wd_smp_lock))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		raw_local_irq_restore(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		spin_until_cond(!test_bit(0, &__wd_smp_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		raw_local_irq_save(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		hard_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static inline void wd_smp_unlock(unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	clear_bit_unlock(0, &__wd_smp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	raw_local_irq_restore(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void wd_lockup_ipi(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u64 tb = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	pr_emerg("CPU %d Hard LOCKUP\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	pr_emerg("CPU %d TB:%lld, last heartbeat TB:%lld (%lldms ago)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 cpu, tb, per_cpu(wd_timer_tb, cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 tb_to_ns(tb - per_cpu(wd_timer_tb, cpu)) / 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	print_modules();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	print_irqtrace_events(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* Do not panic from here because that can recurse into NMI IPI layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void set_cpumask_stuck(const struct cpumask *cpumask, u64 tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	cpumask_or(&wd_smp_cpus_stuck, &wd_smp_cpus_stuck, cpumask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	cpumask_andnot(&wd_smp_cpus_pending, &wd_smp_cpus_pending, cpumask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * See wd_smp_clear_cpu_pending()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (cpumask_empty(&wd_smp_cpus_pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		wd_smp_last_reset_tb = tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		cpumask_andnot(&wd_smp_cpus_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				&wd_cpus_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				&wd_smp_cpus_stuck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static void set_cpu_stuck(int cpu, u64 tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	set_cpumask_stuck(cpumask_of(cpu), tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void watchdog_smp_panic(int cpu, u64 tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Double check some things under lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if ((s64)(tb - wd_smp_last_reset_tb) < (s64)wd_smp_panic_timeout_tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (cpumask_test_cpu(cpu, &wd_smp_cpus_pending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (cpumask_weight(&wd_smp_cpus_pending) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	pr_emerg("CPU %d detected hard LOCKUP on other CPUs %*pbl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		 cpu, cpumask_pr_args(&wd_smp_cpus_pending));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	pr_emerg("CPU %d TB:%lld, last SMP heartbeat TB:%lld (%lldms ago)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		 cpu, tb, wd_smp_last_reset_tb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		 tb_to_ns(tb - wd_smp_last_reset_tb) / 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!sysctl_hardlockup_all_cpu_backtrace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		 * Try to trigger the stuck CPUs, unless we are going to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		 * get a backtrace on all of them anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		for_each_cpu(c, &wd_smp_cpus_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			if (c == cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			smp_send_nmi_ipi(c, wd_lockup_ipi, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* Take the stuck CPUs out of the watch group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	set_cpumask_stuck(&wd_smp_cpus_pending, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	printk_safe_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * printk_safe_flush() seems to require another print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * before anything actually goes out to console.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (sysctl_hardlockup_all_cpu_backtrace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		trigger_allbutself_cpu_backtrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (hardlockup_panic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		nmi_panic(NULL, "Hard LOCKUP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void wd_smp_clear_cpu_pending(int cpu, u64 tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!cpumask_test_cpu(cpu, &wd_smp_cpus_pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (unlikely(cpumask_test_cpu(cpu, &wd_smp_cpus_stuck))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			struct pt_regs *regs = get_irq_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			pr_emerg("CPU %d became unstuck TB:%lld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				 cpu, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			print_irqtrace_events(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			cpumask_clear_cpu(cpu, &wd_smp_cpus_stuck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			 * The last CPU to clear pending should have reset the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			 * watchdog so we generally should not find it empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			 * here if our CPU was clear. However it could happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			 * due to a rare race with another CPU taking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			 * last CPU out of the mask concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			 * We can't add a warning for it. But just in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			 * there is a problem with the watchdog that is causing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			 * the mask to not be reset, try to kick it along here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			if (unlikely(cpumask_empty(&wd_smp_cpus_pending)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				goto none_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	cpumask_clear_cpu(cpu, &wd_smp_cpus_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * Order the store to clear pending with the load(s) to check all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * words in the pending mask to check they are all empty. This orders
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * with the same barrier on another CPU. This prevents two CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * clearing the last 2 pending bits, but neither seeing the other's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * store when checking if the mask is empty, and missing an empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * mask, which ends with a false positive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (cpumask_empty(&wd_smp_cpus_pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) none_pending:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		 * Double check under lock because more than one CPU could see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		 * a clear mask with the lockless check after clearing their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		 * pending bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (cpumask_empty(&wd_smp_cpus_pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			wd_smp_last_reset_tb = tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			cpumask_andnot(&wd_smp_cpus_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 					&wd_cpus_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 					&wd_smp_cpus_stuck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static void watchdog_timer_interrupt(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	u64 tb = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	per_cpu(wd_timer_tb, cpu) = tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	wd_smp_clear_cpu_pending(cpu, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if ((s64)(tb - wd_smp_last_reset_tb) >= (s64)wd_smp_panic_timeout_tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		watchdog_smp_panic(cpu, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) void soft_nmi_interrupt(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	u64 tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (!cpumask_test_cpu(cpu, &wd_cpus_enabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	nmi_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	__this_cpu_inc(irq_stat.soft_nmi_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	tb = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (tb - per_cpu(wd_timer_tb, cpu) >= wd_panic_timeout_tb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		if (cpumask_test_cpu(cpu, &wd_smp_cpus_stuck)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		set_cpu_stuck(cpu, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		pr_emerg("CPU %d self-detected hard LOCKUP @ %pS\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			 cpu, (void *)regs->nip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		pr_emerg("CPU %d TB:%lld, last heartbeat TB:%lld (%lldms ago)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			 cpu, tb, per_cpu(wd_timer_tb, cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			 tb_to_ns(tb - per_cpu(wd_timer_tb, cpu)) / 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		print_modules();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		print_irqtrace_events(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (sysctl_hardlockup_all_cpu_backtrace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			trigger_allbutself_cpu_backtrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		if (hardlockup_panic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			nmi_panic(regs, "Hard LOCKUP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (wd_panic_timeout_tb < 0x7fffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		mtspr(SPRN_DEC, wd_panic_timeout_tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	nmi_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	watchdog_timer_interrupt(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	hrtimer_forward_now(hrtimer, ms_to_ktime(wd_timer_period_ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return HRTIMER_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void arch_touch_nmi_watchdog(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	u64 tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	tb = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (tb - per_cpu(wd_timer_tb, cpu) >= ticks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		per_cpu(wd_timer_tb, cpu) = tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		wd_smp_clear_cpu_pending(cpu, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) EXPORT_SYMBOL(arch_touch_nmi_watchdog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static void start_watchdog(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (cpumask_test_cpu(cpu, &wd_cpus_enabled)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	cpumask_set_cpu(cpu, &wd_cpus_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (cpumask_weight(&wd_cpus_enabled) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		cpumask_set_cpu(cpu, &wd_smp_cpus_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		wd_smp_last_reset_tb = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	*this_cpu_ptr(&wd_timer_tb) = get_tb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	hrtimer->function = watchdog_timer_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	hrtimer_start(hrtimer, ms_to_ktime(wd_timer_period_ms),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		      HRTIMER_MODE_REL_PINNED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int start_watchdog_on_cpu(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return smp_call_function_single(cpu, start_watchdog, NULL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static void stop_watchdog(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (!cpumask_test_cpu(cpu, &wd_cpus_enabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return; /* Can happen in CPU unplug case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	hrtimer_cancel(hrtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	wd_smp_lock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	cpumask_clear_cpu(cpu, &wd_cpus_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	wd_smp_unlock(&flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	wd_smp_clear_cpu_pending(cpu, get_tb());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static int stop_watchdog_on_cpu(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return smp_call_function_single(cpu, stop_watchdog, NULL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static void watchdog_calc_timeouts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	wd_panic_timeout_tb = watchdog_thresh * ppc_tb_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	/* Have the SMP detector trigger a bit later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	wd_smp_panic_timeout_tb = wd_panic_timeout_tb * 3 / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	/* 2/5 is the factor that the perf based detector uses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	wd_timer_period_ms = watchdog_thresh * 1000 * 2 / 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) void watchdog_nmi_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	for_each_cpu(cpu, &wd_cpus_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		stop_watchdog_on_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) void watchdog_nmi_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	watchdog_calc_timeouts();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	for_each_cpu_and(cpu, cpu_online_mask, &watchdog_cpumask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		start_watchdog_on_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  * Invoked from core watchdog init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int __init watchdog_nmi_probe(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	err = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 					"powerpc/watchdog:online",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 					start_watchdog_on_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 					stop_watchdog_on_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		pr_warn("could not be initialized");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }