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 17:07:57 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-12-15 02:06:24 +03:00
|
|
|
/*
|
|
|
|
* Detect hard lockups on a system
|
|
|
|
*
|
|
|
|
* started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Note: Most of this code is borrowed heavily from the original softlockup
|
|
|
|
* detector, so thanks to Ingo for the initial implementation.
|
|
|
|
* Some chunks also taken from the old x86-specific nmi watchdog code, thanks
|
|
|
|
* to those contributors as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "NMI watchdog: " fmt
|
|
|
|
|
|
|
|
#include <linux/nmi.h>
|
2017-11-01 21:11:27 +03:00
|
|
|
#include <linux/atomic.h>
|
2016-12-15 02:06:24 +03:00
|
|
|
#include <linux/module.h>
|
2017-02-08 20:51:35 +03:00
|
|
|
#include <linux/sched/debug.h>
|
|
|
|
|
2016-12-15 02:06:24 +03:00
|
|
|
#include <asm/irq_regs.h>
|
|
|
|
#include <linux/perf_event.h>
|
|
|
|
|
|
|
|
static DEFINE_PER_CPU(bool, hard_watchdog_warn);
|
|
|
|
static DEFINE_PER_CPU(bool, watchdog_nmi_touch);
|
|
|
|
static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);
|
2017-11-01 00:32:00 +03:00
|
|
|
static DEFINE_PER_CPU(struct perf_event *, dead_event);
|
2017-09-12 22:37:04 +03:00
|
|
|
static struct cpumask dead_events_mask;
|
2016-12-15 02:06:24 +03:00
|
|
|
|
|
|
|
static unsigned long hardlockup_allcpu_dumped;
|
2017-11-01 21:11:27 +03:00
|
|
|
static atomic_t watchdog_cpus = ATOMIC_INIT(0);
|
2016-12-15 02:06:24 +03:00
|
|
|
|
2018-08-21 18:25:07 +03:00
|
|
|
notrace void arch_touch_nmi_watchdog(void)
|
2016-12-15 02:06:24 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Using __raw here because some code paths have
|
|
|
|
* preemption enabled. If preemption is enabled
|
|
|
|
* then interrupts should be enabled too, in which
|
|
|
|
* case we shouldn't have to worry about the watchdog
|
|
|
|
* going off.
|
|
|
|
*/
|
|
|
|
raw_cpu_write(watchdog_nmi_touch, true);
|
|
|
|
}
|
2017-07-13 00:35:43 +03:00
|
|
|
EXPORT_SYMBOL(arch_touch_nmi_watchdog);
|
2016-12-15 02:06:24 +03:00
|
|
|
|
2017-08-15 10:50:13 +03:00
|
|
|
#ifdef CONFIG_HARDLOCKUP_CHECK_TIMESTAMP
|
|
|
|
static DEFINE_PER_CPU(ktime_t, last_timestamp);
|
|
|
|
static DEFINE_PER_CPU(unsigned int, nmi_rearmed);
|
|
|
|
static ktime_t watchdog_hrtimer_sample_threshold __read_mostly;
|
|
|
|
|
|
|
|
void watchdog_update_hrtimer_threshold(u64 period)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The hrtimer runs with a period of (watchdog_threshold * 2) / 5
|
|
|
|
*
|
|
|
|
* So it runs effectively with 2.5 times the rate of the NMI
|
|
|
|
* watchdog. That means the hrtimer should fire 2-3 times before
|
|
|
|
* the NMI watchdog expires. The NMI watchdog on x86 is based on
|
|
|
|
* unhalted CPU cycles, so if Turbo-Mode is enabled the CPU cycles
|
|
|
|
* might run way faster than expected and the NMI fires in a
|
|
|
|
* smaller period than the one deduced from the nominal CPU
|
|
|
|
* frequency. Depending on the Turbo-Mode factor this might be fast
|
|
|
|
* enough to get the NMI period smaller than the hrtimer watchdog
|
|
|
|
* period and trigger false positives.
|
|
|
|
*
|
|
|
|
* The sample threshold is used to check in the NMI handler whether
|
|
|
|
* the minimum time between two NMI samples has elapsed. That
|
|
|
|
* prevents false positives.
|
|
|
|
*
|
|
|
|
* Set this to 4/5 of the actual watchdog threshold period so the
|
|
|
|
* hrtimer is guaranteed to fire at least once within the real
|
|
|
|
* watchdog threshold.
|
|
|
|
*/
|
|
|
|
watchdog_hrtimer_sample_threshold = period * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool watchdog_check_timestamp(void)
|
|
|
|
{
|
|
|
|
ktime_t delta, now = ktime_get_mono_fast_ns();
|
|
|
|
|
|
|
|
delta = now - __this_cpu_read(last_timestamp);
|
|
|
|
if (delta < watchdog_hrtimer_sample_threshold) {
|
|
|
|
/*
|
|
|
|
* If ktime is jiffies based, a stalled timer would prevent
|
|
|
|
* jiffies from being incremented and the filter would look
|
|
|
|
* at a stale timestamp and never trigger.
|
|
|
|
*/
|
|
|
|
if (__this_cpu_inc_return(nmi_rearmed) < 10)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
__this_cpu_write(nmi_rearmed, 0);
|
|
|
|
__this_cpu_write(last_timestamp, now);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline bool watchdog_check_timestamp(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-15 02:06:24 +03:00
|
|
|
static struct perf_event_attr wd_hw_attr = {
|
|
|
|
.type = PERF_TYPE_HARDWARE,
|
|
|
|
.config = PERF_COUNT_HW_CPU_CYCLES,
|
|
|
|
.size = sizeof(struct perf_event_attr),
|
|
|
|
.pinned = 1,
|
|
|
|
.disabled = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Callback function for perf event subsystem */
|
|
|
|
static void watchdog_overflow_callback(struct perf_event *event,
|
2017-09-12 22:37:05 +03:00
|
|
|
struct perf_sample_data *data,
|
|
|
|
struct pt_regs *regs)
|
2016-12-15 02:06:24 +03:00
|
|
|
{
|
|
|
|
/* Ensure the watchdog never gets throttled */
|
|
|
|
event->hw.interrupts = 0;
|
|
|
|
|
2023-05-19 20:18:26 +03:00
|
|
|
if (!watchdog_check_timestamp())
|
|
|
|
return;
|
|
|
|
|
2016-12-15 02:06:24 +03:00
|
|
|
if (__this_cpu_read(watchdog_nmi_touch) == true) {
|
|
|
|
__this_cpu_write(watchdog_nmi_touch, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for a hardlockup
|
|
|
|
* This is done by making sure our timer interrupt
|
|
|
|
* is incrementing. The timer interrupt should have
|
|
|
|
* fired multiple times before we overflow'd. If it hasn't
|
|
|
|
* then this is a good indication the cpu is stuck
|
|
|
|
*/
|
|
|
|
if (is_hardlockup()) {
|
|
|
|
int this_cpu = smp_processor_id();
|
|
|
|
|
|
|
|
/* only print hardlockups once */
|
|
|
|
if (__this_cpu_read(hard_watchdog_warn) == true)
|
|
|
|
return;
|
|
|
|
|
2019-04-19 03:50:41 +03:00
|
|
|
pr_emerg("Watchdog detected hard LOCKUP on cpu %d\n",
|
|
|
|
this_cpu);
|
2016-12-15 02:06:24 +03:00
|
|
|
print_modules();
|
|
|
|
print_irqtrace_events(current);
|
|
|
|
if (regs)
|
|
|
|
show_regs(regs);
|
|
|
|
else
|
|
|
|
dump_stack();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform all-CPU dump only once to avoid multiple hardlockups
|
|
|
|
* generating interleaving traces
|
|
|
|
*/
|
|
|
|
if (sysctl_hardlockup_all_cpu_backtrace &&
|
|
|
|
!test_and_set_bit(0, &hardlockup_allcpu_dumped))
|
|
|
|
trigger_allbutself_cpu_backtrace();
|
|
|
|
|
|
|
|
if (hardlockup_panic)
|
|
|
|
nmi_panic(regs, "Hard LOCKUP");
|
|
|
|
|
|
|
|
__this_cpu_write(hard_watchdog_warn, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__this_cpu_write(hard_watchdog_warn, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:37:18 +03:00
|
|
|
static int hardlockup_detector_event_create(void)
|
|
|
|
{
|
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
struct perf_event_attr *wd_attr;
|
|
|
|
struct perf_event *evt;
|
|
|
|
|
|
|
|
wd_attr = &wd_hw_attr;
|
|
|
|
wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
|
|
|
|
|
|
|
|
/* Try to register using hardware perf events */
|
|
|
|
evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
|
|
|
|
watchdog_overflow_callback, NULL);
|
|
|
|
if (IS_ERR(evt)) {
|
2018-08-03 09:09:41 +03:00
|
|
|
pr_debug("Perf event create on CPU %d failed with %ld\n", cpu,
|
|
|
|
PTR_ERR(evt));
|
2017-09-12 22:37:18 +03:00
|
|
|
return PTR_ERR(evt);
|
|
|
|
}
|
|
|
|
this_cpu_write(watchdog_ev, evt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:37:20 +03:00
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_enable - Enable the local event
|
|
|
|
*/
|
|
|
|
void hardlockup_detector_perf_enable(void)
|
|
|
|
{
|
|
|
|
if (hardlockup_detector_event_create())
|
|
|
|
return;
|
|
|
|
|
2017-11-01 21:11:27 +03:00
|
|
|
/* use original value for check */
|
|
|
|
if (!atomic_fetch_inc(&watchdog_cpus))
|
2017-09-12 22:37:21 +03:00
|
|
|
pr_info("Enabled. Permanently consumes one hw-PMU counter.\n");
|
|
|
|
|
2017-09-12 22:37:20 +03:00
|
|
|
perf_event_enable(this_cpu_read(watchdog_ev));
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:37:04 +03:00
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_disable - Disable the local event
|
|
|
|
*/
|
|
|
|
void hardlockup_detector_perf_disable(void)
|
2016-12-15 02:06:24 +03:00
|
|
|
{
|
2017-09-12 22:37:04 +03:00
|
|
|
struct perf_event *event = this_cpu_read(watchdog_ev);
|
2016-12-15 02:06:24 +03:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
perf_event_disable(event);
|
2017-11-01 00:32:00 +03:00
|
|
|
this_cpu_write(watchdog_ev, NULL);
|
|
|
|
this_cpu_write(dead_event, event);
|
2017-09-12 22:37:04 +03:00
|
|
|
cpumask_set_cpu(smp_processor_id(), &dead_events_mask);
|
2017-11-01 21:11:27 +03:00
|
|
|
atomic_dec(&watchdog_cpus);
|
2016-12-15 02:06:24 +03:00
|
|
|
}
|
|
|
|
}
|
2017-09-12 22:36:55 +03:00
|
|
|
|
2017-09-12 22:37:04 +03:00
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_cleanup - Cleanup disabled events and destroy them
|
|
|
|
*
|
|
|
|
* Called from lockup_detector_cleanup(). Serialized by the caller.
|
|
|
|
*/
|
|
|
|
void hardlockup_detector_perf_cleanup(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_cpu(cpu, &dead_events_mask) {
|
2017-11-01 00:32:00 +03:00
|
|
|
struct perf_event *event = per_cpu(dead_event, cpu);
|
2017-09-12 22:37:04 +03:00
|
|
|
|
2017-09-25 21:21:54 +03:00
|
|
|
/*
|
|
|
|
* Required because for_each_cpu() reports unconditionally
|
|
|
|
* CPU0 as set on UP kernels. Sigh.
|
|
|
|
*/
|
|
|
|
if (event)
|
|
|
|
perf_event_release_kernel(event);
|
2017-11-01 00:32:00 +03:00
|
|
|
per_cpu(dead_event, cpu) = NULL;
|
2017-09-12 22:37:04 +03:00
|
|
|
}
|
|
|
|
cpumask_clear(&dead_events_mask);
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:36:55 +03:00
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_stop - Globally stop watchdog events
|
|
|
|
*
|
|
|
|
* Special interface for x86 to handle the perf HT bug.
|
|
|
|
*/
|
|
|
|
void __init hardlockup_detector_perf_stop(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct perf_event *event = per_cpu(watchdog_ev, cpu);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
perf_event_disable(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_restart - Globally restart watchdog events
|
|
|
|
*
|
|
|
|
* Special interface for x86 to handle the perf HT bug.
|
|
|
|
*/
|
|
|
|
void __init hardlockup_detector_perf_restart(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
|
|
|
if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct perf_event *event = per_cpu(watchdog_ev, cpu);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
perf_event_enable(event);
|
|
|
|
}
|
|
|
|
}
|
2017-09-12 22:37:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hardlockup_detector_perf_init - Probe whether NMI event is available at all
|
|
|
|
*/
|
|
|
|
int __init hardlockup_detector_perf_init(void)
|
|
|
|
{
|
|
|
|
int ret = hardlockup_detector_event_create();
|
|
|
|
|
|
|
|
if (ret) {
|
2017-09-26 12:36:03 +03:00
|
|
|
pr_info("Perf NMI watchdog permanently disabled\n");
|
2017-09-12 22:37:18 +03:00
|
|
|
} else {
|
|
|
|
perf_event_release_kernel(this_cpu_read(watchdog_ev));
|
|
|
|
this_cpu_write(watchdog_ev, NULL);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|