License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-07-13 05:35:52 +08:00
|
|
|
/*
|
|
|
|
* Watchdog support on powerpc systems.
|
|
|
|
*
|
|
|
|
* Copyright 2017, IBM Corporation.
|
|
|
|
*
|
|
|
|
* This uses code from arch/sparc/kernel/nmi.c and kernel/watchdog.c
|
|
|
|
*/
|
2017-10-12 12:44:32 +08:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) "watchdog: " fmt
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/param.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/nmi.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/kprobes.h>
|
|
|
|
#include <linux/hardirq.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/sched/debug.h>
|
|
|
|
#include <linux/delay.h>
|
2021-06-12 03:10:58 +08:00
|
|
|
#include <linux/processor.h>
|
2017-07-13 05:35:52 +08:00
|
|
|
#include <linux/smp.h>
|
|
|
|
|
2021-01-30 21:08:38 +08:00
|
|
|
#include <asm/interrupt.h>
|
2017-07-13 05:35:52 +08:00
|
|
|
#include <asm/paca.h>
|
2021-01-04 22:32:00 +08:00
|
|
|
#include <asm/nmi.h>
|
2017-07-13 05:35:52 +08:00
|
|
|
|
|
|
|
/*
|
2017-11-01 08:27:33 +08:00
|
|
|
* The powerpc watchdog ensures that each CPU is able to service timers.
|
|
|
|
* The watchdog sets up a simple timer on each CPU to run once per timer
|
|
|
|
* period, and updates a per-cpu timestamp and a "pending" cpumask. This is
|
|
|
|
* the heartbeat.
|
2017-07-13 05:35:52 +08:00
|
|
|
*
|
2017-11-01 08:27:33 +08:00
|
|
|
* Then there are two systems to check that the heartbeat is still running.
|
|
|
|
* The local soft-NMI, and the SMP checker.
|
2017-07-13 05:35:52 +08:00
|
|
|
*
|
2017-11-01 08:27:33 +08:00
|
|
|
* The soft-NMI checker can detect lockups on the local CPU. When interrupts
|
|
|
|
* are disabled with local_irq_disable(), platforms that use soft-masking
|
|
|
|
* can leave hardware interrupts enabled and handle them with a masked
|
|
|
|
* interrupt handler. The masked handler can send the timer interrupt to the
|
|
|
|
* watchdog's soft_nmi_interrupt(), which appears to Linux as an NMI
|
|
|
|
* interrupt, and can be used to detect CPUs stuck with IRQs disabled.
|
|
|
|
*
|
|
|
|
* The soft-NMI checker will compare the heartbeat timestamp for this CPU
|
|
|
|
* with the current time, and take action if the difference exceeds the
|
|
|
|
* watchdog threshold.
|
|
|
|
*
|
|
|
|
* The limitation of the soft-NMI watchdog is that it does not work when
|
|
|
|
* interrupts are hard disabled or otherwise not being serviced. This is
|
|
|
|
* solved by also having a SMP watchdog where all CPUs check all other
|
|
|
|
* CPUs heartbeat.
|
|
|
|
*
|
2022-05-01 02:56:54 +08:00
|
|
|
* The SMP checker can detect lockups on other CPUs. A global "pending"
|
2017-11-01 08:27:33 +08:00
|
|
|
* cpumask is kept, containing all CPUs which enable the watchdog. Each
|
|
|
|
* CPU clears their pending bit in their heartbeat timer. When the bitmask
|
|
|
|
* becomes empty, the last CPU to clear its pending bit updates a global
|
|
|
|
* timestamp and refills the pending bitmask.
|
|
|
|
*
|
|
|
|
* In the heartbeat timer, if any CPU notices that the global timestamp has
|
|
|
|
* not been updated for a period exceeding the watchdog threshold, then it
|
|
|
|
* means the CPU(s) with their bit still set in the pending mask have had
|
|
|
|
* their heartbeat stop, and action is taken.
|
|
|
|
*
|
2018-05-06 19:23:46 +08:00
|
|
|
* Some platforms implement true NMI IPIs, which can be used by the SMP
|
2017-11-01 08:27:33 +08:00
|
|
|
* watchdog to detect an unresponsive CPU and pull it out of its stuck
|
|
|
|
* state with the NMI IPI, to get crash/debug data from it. This way the
|
|
|
|
* SMP watchdog can detect hardware interrupts off lockups.
|
2017-07-13 05:35:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static cpumask_t wd_cpus_enabled __read_mostly;
|
|
|
|
|
|
|
|
static u64 wd_panic_timeout_tb __read_mostly; /* timebase ticks until panic */
|
|
|
|
static u64 wd_smp_panic_timeout_tb __read_mostly; /* panic other CPUs */
|
|
|
|
|
|
|
|
static u64 wd_timer_period_ms __read_mostly; /* interval between heartbeat */
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
static DEFINE_PER_CPU(struct hrtimer, wd_hrtimer);
|
2017-07-13 05:35:52 +08:00
|
|
|
static DEFINE_PER_CPU(u64, wd_timer_tb);
|
|
|
|
|
2017-11-01 08:27:33 +08:00
|
|
|
/* SMP checker bits */
|
2017-07-13 05:35:52 +08:00
|
|
|
static unsigned long __wd_smp_lock;
|
2021-11-10 10:50:55 +08:00
|
|
|
static unsigned long __wd_reporting;
|
2021-11-19 19:31:46 +08:00
|
|
|
static unsigned long __wd_nmi_output;
|
2017-07-13 05:35:52 +08:00
|
|
|
static cpumask_t wd_smp_cpus_pending;
|
|
|
|
static cpumask_t wd_smp_cpus_stuck;
|
|
|
|
static u64 wd_smp_last_reset_tb;
|
|
|
|
|
2022-07-13 23:47:28 +08:00
|
|
|
#ifdef CONFIG_PPC_PSERIES
|
|
|
|
static u64 wd_timeout_pct;
|
|
|
|
#endif
|
|
|
|
|
2021-11-10 10:50:55 +08:00
|
|
|
/*
|
|
|
|
* Try to take the exclusive watchdog action / NMI IPI / printing lock.
|
|
|
|
* wd_smp_lock must be held. If this fails, we should return and wait
|
|
|
|
* for the watchdog to kick in again (or another CPU to trigger it).
|
|
|
|
*
|
|
|
|
* Importantly, if hardlockup_panic is set, wd_try_report failure should
|
|
|
|
* not delay the panic, because whichever other CPU is reporting will
|
|
|
|
* call panic.
|
|
|
|
*/
|
|
|
|
static bool wd_try_report(void)
|
|
|
|
{
|
|
|
|
if (__wd_reporting)
|
|
|
|
return false;
|
|
|
|
__wd_reporting = 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End printing after successful wd_try_report. wd_smp_lock not required. */
|
|
|
|
static void wd_end_reporting(void)
|
|
|
|
{
|
|
|
|
smp_mb(); /* End printing "critical section" */
|
|
|
|
WARN_ON_ONCE(__wd_reporting == 0);
|
|
|
|
WRITE_ONCE(__wd_reporting, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
static inline void wd_smp_lock(unsigned long *flags)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Avoid locking layers if possible.
|
|
|
|
* This may be called from low level interrupt handlers at some
|
|
|
|
* point in future.
|
|
|
|
*/
|
2017-08-09 20:41:22 +08:00
|
|
|
raw_local_irq_save(*flags);
|
|
|
|
hard_irq_disable(); /* Make it soft-NMI safe */
|
|
|
|
while (unlikely(test_and_set_bit_lock(0, &__wd_smp_lock))) {
|
|
|
|
raw_local_irq_restore(*flags);
|
|
|
|
spin_until_cond(!test_bit(0, &__wd_smp_lock));
|
|
|
|
raw_local_irq_save(*flags);
|
|
|
|
hard_irq_disable();
|
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wd_smp_unlock(unsigned long *flags)
|
|
|
|
{
|
|
|
|
clear_bit_unlock(0, &__wd_smp_lock);
|
2017-08-09 20:41:22 +08:00
|
|
|
raw_local_irq_restore(*flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wd_lockup_ipi(struct pt_regs *regs)
|
|
|
|
{
|
2018-05-05 15:26:00 +08:00
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
u64 tb = get_tb();
|
|
|
|
|
|
|
|
pr_emerg("CPU %d Hard LOCKUP\n", cpu);
|
|
|
|
pr_emerg("CPU %d TB:%lld, last heartbeat TB:%lld (%lldms ago)\n",
|
|
|
|
cpu, tb, per_cpu(wd_timer_tb, cpu),
|
|
|
|
tb_to_ns(tb - per_cpu(wd_timer_tb, cpu)) / 1000000);
|
2017-07-13 05:35:52 +08:00
|
|
|
print_modules();
|
|
|
|
print_irqtrace_events(current);
|
|
|
|
if (regs)
|
|
|
|
show_regs(regs);
|
|
|
|
else
|
|
|
|
dump_stack();
|
|
|
|
|
2021-11-19 19:31:46 +08:00
|
|
|
/*
|
|
|
|
* __wd_nmi_output must be set after we printk from NMI context.
|
|
|
|
*
|
|
|
|
* printk from NMI context defers printing to the console to irq_work.
|
|
|
|
* If that NMI was taken in some code that is hard-locked, then irqs
|
|
|
|
* are disabled so irq_work will never fire. That can result in the
|
|
|
|
* hard lockup messages being delayed (indefinitely, until something
|
|
|
|
* else kicks the console drivers).
|
|
|
|
*
|
|
|
|
* Setting __wd_nmi_output will cause another CPU to notice and kick
|
|
|
|
* the console drivers for us.
|
|
|
|
*
|
|
|
|
* xchg is not needed here (it could be a smp_mb and store), but xchg
|
|
|
|
* gives the memory ordering and atomicity required.
|
|
|
|
*/
|
|
|
|
xchg(&__wd_nmi_output, 1);
|
|
|
|
|
2017-09-29 11:29:37 +08:00
|
|
|
/* Do not panic from here because that can recurse into NMI IPI layer */
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
static bool set_cpu_stuck(int cpu)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
2021-11-10 10:50:54 +08:00
|
|
|
cpumask_set_cpu(cpu, &wd_smp_cpus_stuck);
|
|
|
|
cpumask_clear_cpu(cpu, &wd_smp_cpus_pending);
|
2021-11-10 10:50:53 +08:00
|
|
|
/*
|
|
|
|
* See wd_smp_clear_cpu_pending()
|
|
|
|
*/
|
|
|
|
smp_mb();
|
2017-07-13 05:35:52 +08:00
|
|
|
if (cpumask_empty(&wd_smp_cpus_pending)) {
|
2021-11-10 10:50:56 +08:00
|
|
|
wd_smp_last_reset_tb = get_tb();
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_andnot(&wd_smp_cpus_pending,
|
|
|
|
&wd_cpus_enabled,
|
|
|
|
&wd_smp_cpus_stuck);
|
2021-11-10 10:50:54 +08:00
|
|
|
return true;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
2021-11-10 10:50:54 +08:00
|
|
|
return false;
|
2017-08-09 20:41:25 +08:00
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
static void watchdog_smp_panic(int cpu)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
2021-11-10 10:50:55 +08:00
|
|
|
static cpumask_t wd_smp_cpus_ipi; // protected by reporting
|
2017-07-13 05:35:52 +08:00
|
|
|
unsigned long flags;
|
2021-11-25 18:33:46 +08:00
|
|
|
u64 tb, last_reset;
|
2017-07-13 05:35:52 +08:00
|
|
|
int c;
|
|
|
|
|
|
|
|
wd_smp_lock(&flags);
|
|
|
|
/* Double check some things under lock */
|
2021-11-10 10:50:56 +08:00
|
|
|
tb = get_tb();
|
2021-11-25 18:33:46 +08:00
|
|
|
last_reset = wd_smp_last_reset_tb;
|
|
|
|
if ((s64)(tb - last_reset) < (s64)wd_smp_panic_timeout_tb)
|
2017-07-13 05:35:52 +08:00
|
|
|
goto out;
|
|
|
|
if (cpumask_test_cpu(cpu, &wd_smp_cpus_pending))
|
|
|
|
goto out;
|
2021-11-10 10:50:55 +08:00
|
|
|
if (!wd_try_report())
|
2017-07-13 05:35:52 +08:00
|
|
|
goto out;
|
2021-11-10 10:50:55 +08:00
|
|
|
for_each_online_cpu(c) {
|
|
|
|
if (!cpumask_test_cpu(c, &wd_smp_cpus_pending))
|
|
|
|
continue;
|
|
|
|
if (c == cpu)
|
|
|
|
continue; // should not happen
|
|
|
|
|
|
|
|
__cpumask_set_cpu(c, &wd_smp_cpus_ipi);
|
2021-11-10 10:50:56 +08:00
|
|
|
if (set_cpu_stuck(c))
|
2021-11-10 10:50:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cpumask_empty(&wd_smp_cpus_ipi)) {
|
|
|
|
wd_end_reporting();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wd_smp_unlock(&flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2017-10-12 12:44:32 +08:00
|
|
|
pr_emerg("CPU %d detected hard LOCKUP on other CPUs %*pbl\n",
|
2021-11-10 10:50:55 +08:00
|
|
|
cpu, cpumask_pr_args(&wd_smp_cpus_ipi));
|
2018-05-05 15:26:00 +08:00
|
|
|
pr_emerg("CPU %d TB:%lld, last SMP heartbeat TB:%lld (%lldms ago)\n",
|
2021-11-25 18:33:46 +08:00
|
|
|
cpu, tb, last_reset, tb_to_ns(tb - last_reset) / 1000000);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2017-09-29 11:29:38 +08:00
|
|
|
if (!sysctl_hardlockup_all_cpu_backtrace) {
|
|
|
|
/*
|
|
|
|
* Try to trigger the stuck CPUs, unless we are going to
|
|
|
|
* get a backtrace on all of them anyway.
|
|
|
|
*/
|
2021-11-10 10:50:55 +08:00
|
|
|
for_each_cpu(c, &wd_smp_cpus_ipi) {
|
2017-09-29 11:29:38 +08:00
|
|
|
smp_send_nmi_ipi(c, wd_lockup_ipi, 1000000);
|
2021-11-10 10:50:55 +08:00
|
|
|
__cpumask_clear_cpu(c, &wd_smp_cpus_ipi);
|
2017-09-29 11:29:38 +08:00
|
|
|
}
|
2021-11-10 10:50:55 +08:00
|
|
|
} else {
|
2017-07-13 05:35:52 +08:00
|
|
|
trigger_allbutself_cpu_backtrace();
|
2021-11-10 10:50:55 +08:00
|
|
|
cpumask_clear(&wd_smp_cpus_ipi);
|
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
|
|
|
|
if (hardlockup_panic)
|
|
|
|
nmi_panic(NULL, "Hard LOCKUP");
|
2017-08-09 20:41:24 +08:00
|
|
|
|
2021-11-10 10:50:55 +08:00
|
|
|
wd_end_reporting();
|
|
|
|
|
2017-08-09 20:41:24 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
|
|
|
wd_smp_unlock(&flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
static void wd_smp_clear_cpu_pending(int cpu)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
|
|
|
if (!cpumask_test_cpu(cpu, &wd_smp_cpus_pending)) {
|
|
|
|
if (unlikely(cpumask_test_cpu(cpu, &wd_smp_cpus_stuck))) {
|
2018-05-05 15:26:00 +08:00
|
|
|
struct pt_regs *regs = get_irq_regs();
|
2017-07-13 05:35:52 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2018-05-05 15:26:00 +08:00
|
|
|
pr_emerg("CPU %d became unstuck TB:%lld\n",
|
2021-11-10 10:50:56 +08:00
|
|
|
cpu, get_tb());
|
2018-05-05 15:26:00 +08:00
|
|
|
print_irqtrace_events(current);
|
|
|
|
if (regs)
|
|
|
|
show_regs(regs);
|
|
|
|
else
|
|
|
|
dump_stack();
|
|
|
|
|
2021-11-10 10:50:55 +08:00
|
|
|
wd_smp_lock(&flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_clear_cpu(cpu, &wd_smp_cpus_stuck);
|
|
|
|
wd_smp_unlock(&flags);
|
2021-11-10 10:50:53 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The last CPU to clear pending should have reset the
|
|
|
|
* watchdog so we generally should not find it empty
|
|
|
|
* here if our CPU was clear. However it could happen
|
|
|
|
* due to a rare race with another CPU taking the
|
|
|
|
* last CPU out of the mask concurrently.
|
|
|
|
*
|
|
|
|
* We can't add a warning for it. But just in case
|
|
|
|
* there is a problem with the watchdog that is causing
|
|
|
|
* the mask to not be reset, try to kick it along here.
|
|
|
|
*/
|
|
|
|
if (unlikely(cpumask_empty(&wd_smp_cpus_pending)))
|
|
|
|
goto none_pending;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-11-10 10:50:53 +08:00
|
|
|
|
2021-11-10 10:50:54 +08:00
|
|
|
/*
|
|
|
|
* All other updates to wd_smp_cpus_pending are performed under
|
|
|
|
* wd_smp_lock. All of them are atomic except the case where the
|
|
|
|
* mask becomes empty and is reset. This will not happen here because
|
|
|
|
* cpu was tested to be in the bitmap (above), and a CPU only clears
|
|
|
|
* its own bit. _Except_ in the case where another CPU has detected a
|
|
|
|
* hard lockup on our CPU and takes us out of the pending mask. So in
|
|
|
|
* normal operation there will be no race here, no problem.
|
|
|
|
*
|
|
|
|
* In the lockup case, this atomic clear-bit vs a store that refills
|
|
|
|
* other bits in the accessed word wll not be a problem. The bit clear
|
|
|
|
* is atomic so it will not cause the store to get lost, and the store
|
|
|
|
* will never set this bit so it will not overwrite the bit clear. The
|
|
|
|
* only way for a stuck CPU to return to the pending bitmap is to
|
|
|
|
* become unstuck itself.
|
|
|
|
*/
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_clear_cpu(cpu, &wd_smp_cpus_pending);
|
2021-11-10 10:50:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Order the store to clear pending with the load(s) to check all
|
|
|
|
* words in the pending mask to check they are all empty. This orders
|
|
|
|
* with the same barrier on another CPU. This prevents two CPUs
|
|
|
|
* clearing the last 2 pending bits, but neither seeing the other's
|
|
|
|
* store when checking if the mask is empty, and missing an empty
|
|
|
|
* mask, which ends with a false positive.
|
|
|
|
*/
|
|
|
|
smp_mb();
|
2017-07-13 05:35:52 +08:00
|
|
|
if (cpumask_empty(&wd_smp_cpus_pending)) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
2021-11-10 10:50:53 +08:00
|
|
|
none_pending:
|
|
|
|
/*
|
|
|
|
* Double check under lock because more than one CPU could see
|
|
|
|
* a clear mask with the lockless check after clearing their
|
|
|
|
* pending bits.
|
|
|
|
*/
|
2017-07-13 05:35:52 +08:00
|
|
|
wd_smp_lock(&flags);
|
|
|
|
if (cpumask_empty(&wd_smp_cpus_pending)) {
|
2021-11-10 10:50:56 +08:00
|
|
|
wd_smp_last_reset_tb = get_tb();
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_andnot(&wd_smp_cpus_pending,
|
|
|
|
&wd_cpus_enabled,
|
|
|
|
&wd_smp_cpus_stuck);
|
|
|
|
}
|
|
|
|
wd_smp_unlock(&flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void watchdog_timer_interrupt(int cpu)
|
|
|
|
{
|
|
|
|
u64 tb = get_tb();
|
|
|
|
|
|
|
|
per_cpu(wd_timer_tb, cpu) = tb;
|
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
wd_smp_clear_cpu_pending(cpu);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
|
|
|
if ((s64)(tb - wd_smp_last_reset_tb) >= (s64)wd_smp_panic_timeout_tb)
|
2021-11-10 10:50:56 +08:00
|
|
|
watchdog_smp_panic(cpu);
|
2021-11-19 19:31:46 +08:00
|
|
|
|
|
|
|
if (__wd_nmi_output && xchg(&__wd_nmi_output, 0)) {
|
|
|
|
/*
|
|
|
|
* Something has called printk from NMI context. It might be
|
2022-07-18 17:51:58 +08:00
|
|
|
* stuck, so this triggers a flush that will get that
|
2021-11-19 19:31:46 +08:00
|
|
|
* printk output to the console.
|
|
|
|
*
|
|
|
|
* See wd_lockup_ipi.
|
|
|
|
*/
|
|
|
|
printk_trigger_flush();
|
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 21:08:38 +08:00
|
|
|
DEFINE_INTERRUPT_HANDLER_NMI(soft_nmi_interrupt)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
u64 tb;
|
|
|
|
|
2021-01-30 21:08:49 +08:00
|
|
|
/* should only arrive from kernel, with irqs disabled */
|
|
|
|
WARN_ON_ONCE(!arch_irq_disabled_regs(regs));
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
if (!cpumask_test_cpu(cpu, &wd_cpus_enabled))
|
2021-01-30 21:08:38 +08:00
|
|
|
return 0;
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2017-08-01 20:00:54 +08:00
|
|
|
__this_cpu_inc(irq_stat.soft_nmi_irqs);
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
tb = get_tb();
|
|
|
|
if (tb - per_cpu(wd_timer_tb, cpu) >= wd_panic_timeout_tb) {
|
2021-11-10 10:50:55 +08:00
|
|
|
/*
|
|
|
|
* Taking wd_smp_lock here means it is a soft-NMI lock, which
|
|
|
|
* means we can't take any regular or irqsafe spin locks while
|
|
|
|
* holding this lock. This is why timers can't printk while
|
|
|
|
* holding the lock.
|
|
|
|
*/
|
2017-07-13 05:35:52 +08:00
|
|
|
wd_smp_lock(&flags);
|
|
|
|
if (cpumask_test_cpu(cpu, &wd_smp_cpus_stuck)) {
|
|
|
|
wd_smp_unlock(&flags);
|
2021-01-30 21:08:49 +08:00
|
|
|
return 0;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
2021-11-10 10:50:55 +08:00
|
|
|
if (!wd_try_report()) {
|
|
|
|
wd_smp_unlock(&flags);
|
|
|
|
/* Couldn't report, try again in 100ms */
|
|
|
|
mtspr(SPRN_DEC, 100 * tb_ticks_per_usec * 1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
set_cpu_stuck(cpu);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2021-11-10 10:50:55 +08:00
|
|
|
wd_smp_unlock(&flags);
|
|
|
|
|
2018-05-05 15:26:00 +08:00
|
|
|
pr_emerg("CPU %d self-detected hard LOCKUP @ %pS\n",
|
|
|
|
cpu, (void *)regs->nip);
|
|
|
|
pr_emerg("CPU %d TB:%lld, last heartbeat TB:%lld (%lldms ago)\n",
|
|
|
|
cpu, tb, per_cpu(wd_timer_tb, cpu),
|
|
|
|
tb_to_ns(tb - per_cpu(wd_timer_tb, cpu)) / 1000000);
|
2017-07-13 05:35:52 +08:00
|
|
|
print_modules();
|
|
|
|
print_irqtrace_events(current);
|
2017-10-12 12:44:33 +08:00
|
|
|
show_regs(regs);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2021-11-19 19:31:46 +08:00
|
|
|
xchg(&__wd_nmi_output, 1); // see wd_lockup_ipi
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
if (sysctl_hardlockup_all_cpu_backtrace)
|
|
|
|
trigger_allbutself_cpu_backtrace();
|
|
|
|
|
|
|
|
if (hardlockup_panic)
|
|
|
|
nmi_panic(regs, "Hard LOCKUP");
|
2021-11-10 10:50:55 +08:00
|
|
|
|
|
|
|
wd_end_reporting();
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
2021-11-10 10:50:55 +08:00
|
|
|
/*
|
|
|
|
* We are okay to change DEC in soft_nmi_interrupt because the masked
|
|
|
|
* handler has marked a DEC as pending, so the timer interrupt will be
|
|
|
|
* replayed as soon as local irqs are enabled again.
|
|
|
|
*/
|
2017-07-13 05:35:52 +08:00
|
|
|
if (wd_panic_timeout_tb < 0x7fffffff)
|
|
|
|
mtspr(SPRN_DEC, wd_panic_timeout_tb);
|
|
|
|
|
2021-01-30 21:08:38 +08:00
|
|
|
return 0;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
2023-05-20 01:18:36 +08:00
|
|
|
if (!(watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED))
|
2019-04-09 12:40:05 +08:00
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
|
|
|
|
if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
|
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
watchdog_timer_interrupt(cpu);
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
hrtimer_forward_now(hrtimer, ms_to_ktime(wd_timer_period_ms));
|
|
|
|
|
|
|
|
return HRTIMER_RESTART;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_touch_nmi_watchdog(void)
|
|
|
|
{
|
2017-08-09 20:41:23 +08:00
|
|
|
unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000;
|
2017-07-13 05:35:52 +08:00
|
|
|
int cpu = smp_processor_id();
|
2021-11-10 10:50:53 +08:00
|
|
|
u64 tb;
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2021-11-10 10:50:53 +08:00
|
|
|
if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tb = get_tb();
|
2017-09-29 11:29:39 +08:00
|
|
|
if (tb - per_cpu(wd_timer_tb, cpu) >= ticks) {
|
|
|
|
per_cpu(wd_timer_tb, cpu) = tb;
|
2021-11-10 10:50:56 +08:00
|
|
|
wd_smp_clear_cpu_pending(cpu);
|
2017-09-29 11:29:39 +08:00
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(arch_touch_nmi_watchdog);
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
static void start_watchdog(void *arg)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
2019-04-09 12:40:05 +08:00
|
|
|
struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
|
|
|
|
int cpu = smp_processor_id();
|
2017-08-09 20:41:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
if (cpumask_test_cpu(cpu, &wd_cpus_enabled)) {
|
|
|
|
WARN_ON(1);
|
2019-04-09 12:40:05 +08:00
|
|
|
return;
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2023-05-20 01:18:36 +08:00
|
|
|
if (!(watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED))
|
2019-04-09 12:40:05 +08:00
|
|
|
return;
|
2017-07-13 05:35:52 +08:00
|
|
|
|
|
|
|
if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
|
2019-04-09 12:40:05 +08:00
|
|
|
return;
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2017-08-09 20:41:26 +08:00
|
|
|
wd_smp_lock(&flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_set_cpu(cpu, &wd_cpus_enabled);
|
|
|
|
if (cpumask_weight(&wd_cpus_enabled) == 1) {
|
|
|
|
cpumask_set_cpu(cpu, &wd_smp_cpus_pending);
|
|
|
|
wd_smp_last_reset_tb = get_tb();
|
|
|
|
}
|
2017-08-09 20:41:26 +08:00
|
|
|
wd_smp_unlock(&flags);
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
*this_cpu_ptr(&wd_timer_tb) = get_tb();
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
hrtimer->function = watchdog_timer_fn;
|
|
|
|
hrtimer_start(hrtimer, ms_to_ktime(wd_timer_period_ms),
|
|
|
|
HRTIMER_MODE_REL_PINNED);
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
static int start_watchdog_on_cpu(unsigned int cpu)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
2019-04-09 12:40:05 +08:00
|
|
|
return smp_call_function_single(cpu, start_watchdog, NULL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stop_watchdog(void *arg)
|
|
|
|
{
|
|
|
|
struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
|
|
|
|
int cpu = smp_processor_id();
|
2017-08-09 20:41:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2017-07-13 05:35:52 +08:00
|
|
|
if (!cpumask_test_cpu(cpu, &wd_cpus_enabled))
|
2019-04-09 12:40:05 +08:00
|
|
|
return; /* Can happen in CPU unplug case */
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
hrtimer_cancel(hrtimer);
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2017-08-09 20:41:26 +08:00
|
|
|
wd_smp_lock(&flags);
|
2017-07-13 05:35:52 +08:00
|
|
|
cpumask_clear_cpu(cpu, &wd_cpus_enabled);
|
2017-08-09 20:41:26 +08:00
|
|
|
wd_smp_unlock(&flags);
|
|
|
|
|
2021-11-10 10:50:56 +08:00
|
|
|
wd_smp_clear_cpu_pending(cpu);
|
2019-04-09 12:40:05 +08:00
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
|
2019-04-09 12:40:05 +08:00
|
|
|
static int stop_watchdog_on_cpu(unsigned int cpu)
|
|
|
|
{
|
|
|
|
return smp_call_function_single(cpu, stop_watchdog, NULL, true);
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void watchdog_calc_timeouts(void)
|
|
|
|
{
|
2022-07-13 23:47:28 +08:00
|
|
|
u64 threshold = watchdog_thresh;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC_PSERIES
|
|
|
|
threshold += (READ_ONCE(wd_timeout_pct) * threshold) / 100;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wd_panic_timeout_tb = threshold * ppc_tb_freq;
|
2017-07-13 05:35:52 +08:00
|
|
|
|
|
|
|
/* Have the SMP detector trigger a bit later */
|
|
|
|
wd_smp_panic_timeout_tb = wd_panic_timeout_tb * 3 / 2;
|
|
|
|
|
|
|
|
/* 2/5 is the factor that the perf based detector uses */
|
|
|
|
wd_timer_period_ms = watchdog_thresh * 1000 * 2 / 5;
|
|
|
|
}
|
|
|
|
|
2023-05-20 01:18:36 +08:00
|
|
|
void watchdog_hardlockup_stop(void)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2017-10-02 18:34:50 +08:00
|
|
|
for_each_cpu(cpu, &wd_cpus_enabled)
|
2019-04-09 12:40:05 +08:00
|
|
|
stop_watchdog_on_cpu(cpu);
|
2017-10-02 18:34:50 +08:00
|
|
|
}
|
|
|
|
|
2023-05-20 01:18:36 +08:00
|
|
|
void watchdog_hardlockup_start(void)
|
2017-10-02 18:34:50 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
watchdog_calc_timeouts();
|
|
|
|
for_each_cpu_and(cpu, cpu_online_mask, &watchdog_cpumask)
|
2019-04-09 12:40:05 +08:00
|
|
|
start_watchdog_on_cpu(cpu);
|
2017-07-13 05:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-10-03 22:39:02 +08:00
|
|
|
* Invoked from core watchdog init.
|
2017-07-13 05:35:52 +08:00
|
|
|
*/
|
2023-05-20 01:18:36 +08:00
|
|
|
int __init watchdog_hardlockup_probe(void)
|
2017-07-13 05:35:52 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2017-10-03 22:39:02 +08:00
|
|
|
err = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
|
|
|
|
"powerpc/watchdog:online",
|
2019-04-09 12:40:05 +08:00
|
|
|
start_watchdog_on_cpu,
|
|
|
|
stop_watchdog_on_cpu);
|
2017-10-03 22:39:02 +08:00
|
|
|
if (err < 0) {
|
2017-10-12 12:44:32 +08:00
|
|
|
pr_warn("could not be initialized");
|
2017-10-03 22:39:02 +08:00
|
|
|
return err;
|
|
|
|
}
|
2017-07-13 05:35:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-13 23:47:28 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PPC_PSERIES
|
2023-05-20 01:18:36 +08:00
|
|
|
void watchdog_hardlockup_set_timeout_pct(u64 pct)
|
2022-07-13 23:47:28 +08:00
|
|
|
{
|
|
|
|
pr_info("Set the NMI watchdog timeout factor to %llu%%\n", pct);
|
|
|
|
WRITE_ONCE(wd_timeout_pct, pct);
|
|
|
|
lockup_detector_reconfigure();
|
|
|
|
}
|
|
|
|
#endif
|