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 21:07:57 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* include/linux/cpu.h - generic cpu definition
|
|
|
|
*
|
|
|
|
* This is mainly for topological representation. We define the
|
|
|
|
* basic 'struct cpu' here, which can be embedded in per-arch
|
|
|
|
* definitions of processors.
|
|
|
|
*
|
|
|
|
* Basic handling of the devices is done in drivers/base/cpu.c
|
|
|
|
*
|
2013-05-03 17:45:48 +07:00
|
|
|
* CPUs are exported via sysfs in the devices/system/cpu
|
2005-04-17 05:20:36 +07:00
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_CPU_H_
|
|
|
|
#define _LINUX_CPU_H_
|
|
|
|
|
|
|
|
#include <linux/node.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/cpumask.h>
|
2016-02-27 01:43:28 +07:00
|
|
|
#include <linux/cpuhotplug.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-01-30 23:46:54 +07:00
|
|
|
struct device;
|
2013-10-04 04:24:51 +07:00
|
|
|
struct device_node;
|
2014-09-30 20:48:24 +07:00
|
|
|
struct attribute_group;
|
2012-01-30 23:46:54 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct cpu {
|
|
|
|
int node_id; /* The node which contains the CPU */
|
2006-12-07 08:14:10 +07:00
|
|
|
int hotpluggable; /* creates sysfs control file if hotpluggable */
|
2011-12-22 05:29:42 +07:00
|
|
|
struct device dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2016-02-27 01:43:28 +07:00
|
|
|
extern void boot_cpu_init(void);
|
init: rename and re-order boot_cpu_state_init()
This is purely a preparatory patch for upcoming changes during the 4.19
merge window.
We have a function called "boot_cpu_state_init()" that isn't really
about the bootup cpu state: that is done much earlier by the similarly
named "boot_cpu_init()" (note lack of "state" in name).
This function initializes some hotplug CPU state, and needs to run after
the percpu data has been properly initialized. It even has a comment to
that effect.
Except it _doesn't_ actually run after the percpu data has been properly
initialized. On x86 it happens to do that, but on at least arm and
arm64, the percpu base pointers are initialized by the arch-specific
'smp_prepare_boot_cpu()' hook, which ran _after_ boot_cpu_state_init().
This had some unexpected results, and in particular we have a patch
pending for the merge window that did the obvious cleanup of using
'this_cpu_write()' in the cpu hotplug init code:
- per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE;
+ this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
which is obviously the right thing to do. Except because of the
ordering issue, it actually failed miserably and unexpectedly on arm64.
So this just fixes the ordering, and changes the name of the function to
be 'boot_cpu_hotplug_init()' to make it obvious that it's about cpu
hotplug state, because the core CPU state was supposed to have already
been done earlier.
Marked for stable, since the (not yet merged) patch that will show this
problem is marked for stable.
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Reported-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-13 02:19:42 +07:00
|
|
|
extern void boot_cpu_hotplug_init(void);
|
2017-02-05 20:47:12 +07:00
|
|
|
extern void cpu_init(void);
|
|
|
|
extern void trap_init(void);
|
2016-02-27 01:43:28 +07:00
|
|
|
|
[PATCH] node hotplug: register cpu: remove node struct
With Goto-san's patch, we can add new pgdat/node at runtime. I'm now
considering node-hot-add with cpu + memory on ACPI.
I found acpi container, which describes node, could evaluate cpu before
memory. This means cpu-hot-add occurs before memory hot add.
In most part, cpu-hot-add doesn't depend on node hot add. But register_cpu(),
which creates symbolic link from node to cpu, requires that node should be
onlined before register_cpu(). When a node is onlined, its pgdat should be
there.
This patch-set holds off creating symbolic link from node to cpu
until node is onlined.
This removes node arguments from register_cpu().
Now, register_cpu() requires 'struct node' as its argument. But the array of
struct node is now unified in driver/base/node.c now (By Goto's node hotplug
patch). We can get struct node in generic way. So, this argument is not
necessary now.
This patch also guarantees add cpu under node only when node is onlined. It
is necessary for node-hot-add vs. cpu-hot-add patch following this.
Moreover, register_cpu calculates cpu->node_id by cpu_to_node() without regard
to its 'struct node *root' argument. This patch removes it.
Also modify callers of register_cpu()/unregister_cpu, whose args are changed
by register-cpu-remove-node-struct patch.
[Brice.Goglin@ens-lyon.org: fix it]
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Brice Goglin <Brice.Goglin@ens-lyon.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-27 16:53:41 +07:00
|
|
|
extern int register_cpu(struct cpu *cpu, int num);
|
2011-12-22 05:29:42 +07:00
|
|
|
extern struct device *get_cpu_device(unsigned cpu);
|
2011-12-04 04:06:50 +07:00
|
|
|
extern bool cpu_is_hotpluggable(unsigned cpu);
|
2013-08-15 20:01:40 +07:00
|
|
|
extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
|
2013-10-04 04:24:51 +07:00
|
|
|
extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
|
|
|
|
int cpu, unsigned int *thread);
|
2006-10-24 23:31:24 +07:00
|
|
|
|
2011-12-22 05:29:42 +07:00
|
|
|
extern int cpu_add_dev_attr(struct device_attribute *attr);
|
|
|
|
extern void cpu_remove_dev_attr(struct device_attribute *attr);
|
2006-10-24 23:31:24 +07:00
|
|
|
|
2011-12-22 05:29:42 +07:00
|
|
|
extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
|
|
|
|
extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
|
2006-10-24 23:31:24 +07:00
|
|
|
|
2018-01-08 04:48:00 +07:00
|
|
|
extern ssize_t cpu_show_meltdown(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
|
|
|
extern ssize_t cpu_show_spectre_v1(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
|
|
|
extern ssize_t cpu_show_spectre_v2(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
2018-04-26 09:04:20 +07:00
|
|
|
extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
2018-06-14 05:48:26 +07:00
|
|
|
extern ssize_t cpu_show_l1tf(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
2019-02-19 04:51:43 +07:00
|
|
|
extern ssize_t cpu_show_mds(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
2019-10-23 17:19:51 +07:00
|
|
|
extern ssize_t cpu_show_tsx_async_abort(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf);
|
2019-11-04 18:22:01 +07:00
|
|
|
extern ssize_t cpu_show_itlb_multihit(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf);
|
2020-06-17 21:14:10 +07:00
|
|
|
extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
|
2018-01-08 04:48:00 +07:00
|
|
|
|
2015-07-18 06:23:42 +07:00
|
|
|
extern __printf(4, 5)
|
|
|
|
struct device *cpu_device_create(struct device *parent, void *drvdata,
|
|
|
|
const struct attribute_group **groups,
|
|
|
|
const char *fmt, ...);
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
[PATCH] node hotplug: register cpu: remove node struct
With Goto-san's patch, we can add new pgdat/node at runtime. I'm now
considering node-hot-add with cpu + memory on ACPI.
I found acpi container, which describes node, could evaluate cpu before
memory. This means cpu-hot-add occurs before memory hot add.
In most part, cpu-hot-add doesn't depend on node hot add. But register_cpu(),
which creates symbolic link from node to cpu, requires that node should be
onlined before register_cpu(). When a node is onlined, its pgdat should be
there.
This patch-set holds off creating symbolic link from node to cpu
until node is onlined.
This removes node arguments from register_cpu().
Now, register_cpu() requires 'struct node' as its argument. But the array of
struct node is now unified in driver/base/node.c now (By Goto's node hotplug
patch). We can get struct node in generic way. So, this argument is not
necessary now.
This patch also guarantees add cpu under node only when node is onlined. It
is necessary for node-hot-add vs. cpu-hot-add patch following this.
Moreover, register_cpu calculates cpu->node_id by cpu_to_node() without regard
to its 'struct node *root' argument. This patch removes it.
Also modify callers of register_cpu()/unregister_cpu, whose args are changed
by register-cpu-remove-node-struct patch.
[Brice.Goglin@ens-lyon.org: fix it]
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Brice Goglin <Brice.Goglin@ens-lyon.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-27 16:53:41 +07:00
|
|
|
extern void unregister_cpu(struct cpu *cpu);
|
2009-11-26 00:23:25 +07:00
|
|
|
extern ssize_t arch_cpu_probe(const char *, size_t);
|
|
|
|
extern ssize_t arch_cpu_release(const char *, size_t);
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
|
2017-11-13 15:39:01 +07:00
|
|
|
/*
|
|
|
|
* These states are not related to the core CPU hotplug mechanism. They are
|
|
|
|
* used by various (sub)architectures to track internal state
|
2011-07-26 07:13:08 +07:00
|
|
|
*/
|
2017-11-13 15:39:01 +07:00
|
|
|
#define CPU_ONLINE 0x0002 /* CPU is up */
|
|
|
|
#define CPU_UP_PREPARE 0x0003 /* CPU coming up */
|
|
|
|
#define CPU_DEAD 0x0007 /* CPU dead */
|
|
|
|
#define CPU_DEAD_FROZEN 0x0008 /* CPU timed out on unplug */
|
|
|
|
#define CPU_POST_DEAD 0x0009 /* CPU successfully unplugged */
|
|
|
|
#define CPU_BROKEN 0x000B /* CPU did not die properly */
|
2011-07-26 07:13:08 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-27 01:43:23 +07:00
|
|
|
extern bool cpuhp_tasks_frozen;
|
2020-03-23 20:50:54 +07:00
|
|
|
int add_cpu(unsigned int cpu);
|
2020-03-23 20:51:10 +07:00
|
|
|
int cpu_device_up(struct device *dev);
|
2008-09-07 21:57:22 +07:00
|
|
|
void notify_cpu_starting(unsigned int cpu);
|
2008-07-25 15:47:50 +07:00
|
|
|
extern void cpu_maps_update_begin(void);
|
|
|
|
extern void cpu_maps_update_done(void);
|
2020-03-23 20:51:01 +07:00
|
|
|
int bringup_hibernate_cpu(unsigned int sleep_cpu);
|
2020-03-23 20:51:09 +07:00
|
|
|
void bringup_nonboot_cpus(unsigned int setup_max_cpus);
|
2008-01-26 03:08:02 +07:00
|
|
|
|
2008-07-25 15:47:50 +07:00
|
|
|
#else /* CONFIG_SMP */
|
2016-02-27 01:43:23 +07:00
|
|
|
#define cpuhp_tasks_frozen 0
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-07-25 15:47:50 +07:00
|
|
|
static inline void cpu_maps_update_begin(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cpu_maps_update_done(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* CONFIG_SMP */
|
2011-12-22 05:29:42 +07:00
|
|
|
extern struct bus_type cpu_subsys;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2017-05-24 15:15:12 +07:00
|
|
|
extern void cpus_write_lock(void);
|
|
|
|
extern void cpus_write_unlock(void);
|
|
|
|
extern void cpus_read_lock(void);
|
|
|
|
extern void cpus_read_unlock(void);
|
2018-07-25 01:26:04 +07:00
|
|
|
extern int cpus_read_trylock(void);
|
2017-05-24 15:15:40 +07:00
|
|
|
extern void lockdep_assert_cpus_held(void);
|
2013-06-13 04:04:36 +07:00
|
|
|
extern void cpu_hotplug_disable(void);
|
|
|
|
extern void cpu_hotplug_enable(void);
|
cpu: introduce clear_tasks_mm_cpumask() helper
Many architectures clear tasks' mm_cpumask like this:
read_lock(&tasklist_lock);
for_each_process(p) {
if (p->mm)
cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
}
read_unlock(&tasklist_lock);
Depending on the context, the code above may have several problems,
such as:
1. Working with task->mm w/o getting mm or grabing the task lock is
dangerous as ->mm might disappear (exit_mm() assigns NULL under
task_lock(), so tasklist lock is not enough).
2. Checking for process->mm is not enough because process' main
thread may exit or detach its mm via use_mm(), but other threads
may still have a valid mm.
This patch implements a small helper function that does things
correctly, i.e.:
1. We take the task's lock while whe handle its mm (we can't use
get_task_mm()/mmput() pair as mmput() might sleep);
2. To catch exited main thread case, we use find_lock_task_mm(),
which walks up all threads and returns an appropriate task
(with task lock held).
Also, Per Peter Zijlstra's idea, now we don't grab tasklist_lock in
the new helper, instead we take the rcu read lock. We can do this
because the function is called after the cpu is taken down and marked
offline, so no new tasks will get this cpu set in their mm mask.
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Cc: Richard Weinberger <richard@nod.at>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 06:26:22 +07:00
|
|
|
void clear_tasks_mm_cpumask(int cpu);
|
2020-03-23 20:50:54 +07:00
|
|
|
int remove_cpu(unsigned int cpu);
|
2020-03-23 20:51:10 +07:00
|
|
|
int cpu_device_down(struct device *dev);
|
2020-03-23 20:50:55 +07:00
|
|
|
extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
|
2006-12-07 11:38:58 +07:00
|
|
|
|
2017-05-24 15:15:12 +07:00
|
|
|
#else /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
|
|
|
static inline void cpus_write_lock(void) { }
|
|
|
|
static inline void cpus_write_unlock(void) { }
|
|
|
|
static inline void cpus_read_lock(void) { }
|
|
|
|
static inline void cpus_read_unlock(void) { }
|
2018-07-25 01:26:04 +07:00
|
|
|
static inline int cpus_read_trylock(void) { return true; }
|
2017-05-24 15:15:13 +07:00
|
|
|
static inline void lockdep_assert_cpus_held(void) { }
|
2017-05-24 15:15:12 +07:00
|
|
|
static inline void cpu_hotplug_disable(void) { }
|
|
|
|
static inline void cpu_hotplug_enable(void) { }
|
2020-03-23 20:50:55 +07:00
|
|
|
static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
|
2017-05-24 15:15:12 +07:00
|
|
|
#endif /* !CONFIG_HOTPLUG_CPU */
|
|
|
|
|
|
|
|
/* Wrappers which go away once all code is converted */
|
|
|
|
static inline void cpu_hotplug_begin(void) { cpus_write_lock(); }
|
|
|
|
static inline void cpu_hotplug_done(void) { cpus_write_unlock(); }
|
|
|
|
static inline void get_online_cpus(void) { cpus_read_lock(); }
|
|
|
|
static inline void put_online_cpus(void) { cpus_read_unlock(); }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-08-31 13:56:29 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP_SMP
|
2020-04-30 18:40:04 +07:00
|
|
|
extern int freeze_secondary_cpus(int primary);
|
2020-04-30 18:40:03 +07:00
|
|
|
extern void thaw_secondary_cpus(void);
|
2019-04-11 10:34:45 +07:00
|
|
|
|
|
|
|
static inline int suspend_disable_secondary_cpus(void)
|
|
|
|
{
|
2019-04-11 10:34:46 +07:00
|
|
|
int cpu = 0;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU))
|
|
|
|
cpu = -1;
|
|
|
|
|
|
|
|
return freeze_secondary_cpus(cpu);
|
2019-04-11 10:34:45 +07:00
|
|
|
}
|
|
|
|
static inline void suspend_enable_secondary_cpus(void)
|
|
|
|
{
|
2020-04-30 18:40:03 +07:00
|
|
|
return thaw_secondary_cpus();
|
2019-04-11 10:34:45 +07:00
|
|
|
}
|
|
|
|
|
2007-08-31 13:56:29 +07:00
|
|
|
#else /* !CONFIG_PM_SLEEP_SMP */
|
2020-04-30 18:40:03 +07:00
|
|
|
static inline void thaw_secondary_cpus(void) {}
|
2019-04-11 10:34:45 +07:00
|
|
|
static inline int suspend_disable_secondary_cpus(void) { return 0; }
|
|
|
|
static inline void suspend_enable_secondary_cpus(void) { }
|
2007-08-31 13:56:29 +07:00
|
|
|
#endif /* !CONFIG_PM_SLEEP_SMP */
|
2006-09-26 13:32:48 +07:00
|
|
|
|
2013-03-22 04:49:34 +07:00
|
|
|
void cpu_startup_entry(enum cpuhp_state state);
|
|
|
|
|
2013-03-22 04:49:35 +07:00
|
|
|
void cpu_idle_poll_ctrl(bool enable);
|
|
|
|
|
2016-10-08 07:02:55 +07:00
|
|
|
/* Attach to any functions which should be considered cpuidle. */
|
|
|
|
#define __cpuidle __attribute__((__section__(".cpuidle.text")))
|
|
|
|
|
|
|
|
bool cpu_in_idle(unsigned long pc);
|
|
|
|
|
2013-03-22 04:49:35 +07:00
|
|
|
void arch_cpu_idle(void);
|
|
|
|
void arch_cpu_idle_prepare(void);
|
|
|
|
void arch_cpu_idle_enter(void);
|
|
|
|
void arch_cpu_idle_exit(void);
|
|
|
|
void arch_cpu_idle_dead(void);
|
|
|
|
|
smpboot: Add common code for notification from dying CPU
RCU ignores offlined CPUs, so they cannot safely run RCU read-side code.
(They -can- use SRCU, but not RCU.) This means that any use of RCU
during or after the call to arch_cpu_idle_dead(). Unfortunately,
commit 2ed53c0d6cc99 added a complete() call, which will contain RCU
read-side critical sections if there is a task waiting to be awakened.
Which, as it turns out, there almost never is. In my qemu/KVM testing,
the to-be-awakened task is not yet asleep more than 99.5% of the time.
In current mainline, failure is even harder to reproduce, requiring a
virtualized environment that delays the outgoing CPU by at least three
jiffies between the time it exits its stop_machine() task at CPU_DYING
time and the time it calls arch_cpu_idle_dead() from the idle loop.
However, this problem really can occur, especially in virtualized
environments, and therefore really does need to be fixed
This suggests moving back to the polling loop, but using a much shorter
wait, with gentle exponential backoff instead of the old 100-millisecond
wait. Most of the time, the loop will exit without waiting at all,
and almost all of the remaining uses will wait only five microseconds.
If the outgoing CPU is preempted, a loop will wait one jiffy, then
increase the wait by a factor of 11/10ths, rounding up. As before, there
is a five-second timeout.
This commit therefore provides common-code infrastructure to do the
dying-to-surviving CPU handoff in a safe manner. This code also
provides an indication at CPU-online of whether the CPU to be onlined
previously timed out on offline. The new cpu_check_up_prepare() function
returns -EBUSY if this CPU previously took more than five seconds to
go offline, or -EAGAIN if it has not yet managed to go offline. The
rationale for -EAGAIN is that it might still be preempted, so an additional
wait might well find it correctly offlined. Architecture-specific code
can decide how to handle these conditions. Systems in which CPUs take
themselves completely offline might respond to an -EBUSY return as if
it was a zero (success) return. Systems in which the surviving CPU must
take some action might take it at this time, or might simply mark the
other CPU as unusable.
Note that architectures that take the easy way out and simply pass the
-EBUSY and -EAGAIN upwards will change the sysfs API.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: <linux-api@vger.kernel.org>
Cc: <linux-arch@vger.kernel.org>
[ paulmck: Fixed state machine for architectures that don't check earlier
CPU-hotplug results as suggested by James Hogan. ]
2015-02-26 01:34:39 +07:00
|
|
|
int cpu_report_state(int cpu);
|
|
|
|
int cpu_check_up_prepare(int cpu);
|
|
|
|
void cpu_set_state_online(int cpu);
|
cpuidle: Allow idle injection to apply exit latency limit
In some cases it may be useful to specify an exit latency limit for
the idle state to be used during CPU idle time injection.
Instead of duplicating the information in struct cpuidle_device
or propagating the latency limit in the call stack, replace the
use_deepest_state field with forced_latency_limit_ns to represent
that limit, so that the deepest idle state with exit latency within
that limit is forced (i.e. no governors) when it is set.
A zero exit latency limit for forced idle means to use governors in
the usual way (analogous to use_deepest_state equal to "false" before
this change).
Additionally, add play_idle_precise() taking two arguments, the
duration of forced idle and the idle state exit latency limit, both
in nanoseconds, and redefine play_idle() as a wrapper around that
new function.
This change is preparatory, no functional impact is expected.
Suggested-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
[ rjw: Subject, changelog, cpuidle_use_deepest_state() kerneldoc, whitespace ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2019-11-16 20:16:12 +07:00
|
|
|
void play_idle_precise(u64 duration_ns, u64 latency_ns);
|
|
|
|
|
|
|
|
static inline void play_idle(unsigned long duration_us)
|
|
|
|
{
|
|
|
|
play_idle_precise(duration_us * NSEC_PER_USEC, U64_MAX);
|
|
|
|
}
|
2016-11-29 14:03:05 +07:00
|
|
|
|
smpboot: Add common code for notification from dying CPU
RCU ignores offlined CPUs, so they cannot safely run RCU read-side code.
(They -can- use SRCU, but not RCU.) This means that any use of RCU
during or after the call to arch_cpu_idle_dead(). Unfortunately,
commit 2ed53c0d6cc99 added a complete() call, which will contain RCU
read-side critical sections if there is a task waiting to be awakened.
Which, as it turns out, there almost never is. In my qemu/KVM testing,
the to-be-awakened task is not yet asleep more than 99.5% of the time.
In current mainline, failure is even harder to reproduce, requiring a
virtualized environment that delays the outgoing CPU by at least three
jiffies between the time it exits its stop_machine() task at CPU_DYING
time and the time it calls arch_cpu_idle_dead() from the idle loop.
However, this problem really can occur, especially in virtualized
environments, and therefore really does need to be fixed
This suggests moving back to the polling loop, but using a much shorter
wait, with gentle exponential backoff instead of the old 100-millisecond
wait. Most of the time, the loop will exit without waiting at all,
and almost all of the remaining uses will wait only five microseconds.
If the outgoing CPU is preempted, a loop will wait one jiffy, then
increase the wait by a factor of 11/10ths, rounding up. As before, there
is a five-second timeout.
This commit therefore provides common-code infrastructure to do the
dying-to-surviving CPU handoff in a safe manner. This code also
provides an indication at CPU-online of whether the CPU to be onlined
previously timed out on offline. The new cpu_check_up_prepare() function
returns -EBUSY if this CPU previously took more than five seconds to
go offline, or -EAGAIN if it has not yet managed to go offline. The
rationale for -EAGAIN is that it might still be preempted, so an additional
wait might well find it correctly offlined. Architecture-specific code
can decide how to handle these conditions. Systems in which CPUs take
themselves completely offline might respond to an -EBUSY return as if
it was a zero (success) return. Systems in which the surviving CPU must
take some action might take it at this time, or might simply mark the
other CPU as unusable.
Note that architectures that take the easy way out and simply pass the
-EBUSY and -EAGAIN upwards will change the sysfs API.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: <linux-api@vger.kernel.org>
Cc: <linux-arch@vger.kernel.org>
[ paulmck: Fixed state machine for architectures that don't check earlier
CPU-hotplug results as suggested by James Hogan. ]
2015-02-26 01:34:39 +07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
bool cpu_wait_death(unsigned int cpu, int seconds);
|
|
|
|
bool cpu_report_death(void);
|
2016-02-27 01:43:43 +07:00
|
|
|
void cpuhp_report_idle_dead(void);
|
|
|
|
#else
|
|
|
|
static inline void cpuhp_report_idle_dead(void) { }
|
smpboot: Add common code for notification from dying CPU
RCU ignores offlined CPUs, so they cannot safely run RCU read-side code.
(They -can- use SRCU, but not RCU.) This means that any use of RCU
during or after the call to arch_cpu_idle_dead(). Unfortunately,
commit 2ed53c0d6cc99 added a complete() call, which will contain RCU
read-side critical sections if there is a task waiting to be awakened.
Which, as it turns out, there almost never is. In my qemu/KVM testing,
the to-be-awakened task is not yet asleep more than 99.5% of the time.
In current mainline, failure is even harder to reproduce, requiring a
virtualized environment that delays the outgoing CPU by at least three
jiffies between the time it exits its stop_machine() task at CPU_DYING
time and the time it calls arch_cpu_idle_dead() from the idle loop.
However, this problem really can occur, especially in virtualized
environments, and therefore really does need to be fixed
This suggests moving back to the polling loop, but using a much shorter
wait, with gentle exponential backoff instead of the old 100-millisecond
wait. Most of the time, the loop will exit without waiting at all,
and almost all of the remaining uses will wait only five microseconds.
If the outgoing CPU is preempted, a loop will wait one jiffy, then
increase the wait by a factor of 11/10ths, rounding up. As before, there
is a five-second timeout.
This commit therefore provides common-code infrastructure to do the
dying-to-surviving CPU handoff in a safe manner. This code also
provides an indication at CPU-online of whether the CPU to be onlined
previously timed out on offline. The new cpu_check_up_prepare() function
returns -EBUSY if this CPU previously took more than five seconds to
go offline, or -EAGAIN if it has not yet managed to go offline. The
rationale for -EAGAIN is that it might still be preempted, so an additional
wait might well find it correctly offlined. Architecture-specific code
can decide how to handle these conditions. Systems in which CPUs take
themselves completely offline might respond to an -EBUSY return as if
it was a zero (success) return. Systems in which the surviving CPU must
take some action might take it at this time, or might simply mark the
other CPU as unusable.
Note that architectures that take the easy way out and simply pass the
-EBUSY and -EAGAIN upwards will change the sysfs API.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: <linux-api@vger.kernel.org>
Cc: <linux-arch@vger.kernel.org>
[ paulmck: Fixed state machine for architectures that don't check earlier
CPU-hotplug results as suggested by James Hogan. ]
2015-02-26 01:34:39 +07:00
|
|
|
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2018-05-29 22:48:27 +07:00
|
|
|
enum cpuhp_smt_control {
|
|
|
|
CPU_SMT_ENABLED,
|
|
|
|
CPU_SMT_DISABLED,
|
|
|
|
CPU_SMT_FORCE_DISABLED,
|
|
|
|
CPU_SMT_NOT_SUPPORTED,
|
2019-03-27 19:00:29 +07:00
|
|
|
CPU_SMT_NOT_IMPLEMENTED,
|
2018-05-29 22:48:27 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
|
|
|
|
extern enum cpuhp_smt_control cpu_smt_control;
|
2018-07-13 21:23:23 +07:00
|
|
|
extern void cpu_smt_disable(bool force);
|
2018-07-13 21:23:24 +07:00
|
|
|
extern void cpu_smt_check_topology(void);
|
2019-09-16 23:22:56 +07:00
|
|
|
extern bool cpu_smt_possible(void);
|
x86/power: Fix 'nosmt' vs hibernation triple fault during resume
As explained in
0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once")
we always, no matter what, have to bring up x86 HT siblings during boot at
least once in order to avoid first MCE bringing the system to its knees.
That means that whenever 'nosmt' is supplied on the kernel command-line,
all the HT siblings are as a result sitting in mwait or cpudile after
going through the online-offline cycle at least once.
This causes a serious issue though when a kernel, which saw 'nosmt' on its
commandline, is going to perform resume from hibernation: if the resume
from the hibernated image is successful, cr3 is flipped in order to point
to the address space of the kernel that is being resumed, which in turn
means that all the HT siblings are all of a sudden mwaiting on address
which is no longer valid.
That results in triple fault shortly after cr3 is switched, and machine
reboots.
Fix this by always waking up all the SMT siblings before initiating the
'restore from hibernation' process; this guarantees that all the HT
siblings will be properly carried over to the resumed kernel waiting in
resume_play_dead(), and acted upon accordingly afterwards, based on the
target kernel configuration.
Symmetricaly, the resumed kernel has to push the SMT siblings to mwait
again in case it has SMT disabled; this means it has to online all
the siblings when resuming (so that they come out of hlt) and offline
them again to let them reach mwait.
Cc: 4.19+ <stable@vger.kernel.org> # v4.19+
Debugged-by: Thomas Gleixner <tglx@linutronix.de>
Fixes: 0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once")
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2019-05-30 05:09:39 +07:00
|
|
|
extern int cpuhp_smt_enable(void);
|
|
|
|
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
|
2018-05-29 22:48:27 +07:00
|
|
|
#else
|
2019-03-27 19:00:29 +07:00
|
|
|
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
|
2018-07-13 21:23:23 +07:00
|
|
|
static inline void cpu_smt_disable(bool force) { }
|
2018-07-13 21:23:24 +07:00
|
|
|
static inline void cpu_smt_check_topology(void) { }
|
2019-09-16 23:22:56 +07:00
|
|
|
static inline bool cpu_smt_possible(void) { return false; }
|
x86/power: Fix 'nosmt' vs hibernation triple fault during resume
As explained in
0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once")
we always, no matter what, have to bring up x86 HT siblings during boot at
least once in order to avoid first MCE bringing the system to its knees.
That means that whenever 'nosmt' is supplied on the kernel command-line,
all the HT siblings are as a result sitting in mwait or cpudile after
going through the online-offline cycle at least once.
This causes a serious issue though when a kernel, which saw 'nosmt' on its
commandline, is going to perform resume from hibernation: if the resume
from the hibernated image is successful, cr3 is flipped in order to point
to the address space of the kernel that is being resumed, which in turn
means that all the HT siblings are all of a sudden mwaiting on address
which is no longer valid.
That results in triple fault shortly after cr3 is switched, and machine
reboots.
Fix this by always waking up all the SMT siblings before initiating the
'restore from hibernation' process; this guarantees that all the HT
siblings will be properly carried over to the resumed kernel waiting in
resume_play_dead(), and acted upon accordingly afterwards, based on the
target kernel configuration.
Symmetricaly, the resumed kernel has to push the SMT siblings to mwait
again in case it has SMT disabled; this means it has to online all
the siblings when resuming (so that they come out of hlt) and offline
them again to let them reach mwait.
Cc: 4.19+ <stable@vger.kernel.org> # v4.19+
Debugged-by: Thomas Gleixner <tglx@linutronix.de>
Fixes: 0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once")
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2019-05-30 05:09:39 +07:00
|
|
|
static inline int cpuhp_smt_enable(void) { return 0; }
|
|
|
|
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
|
2018-05-29 22:48:27 +07:00
|
|
|
#endif
|
|
|
|
|
2019-11-04 18:22:02 +07:00
|
|
|
extern bool cpu_mitigations_off(void);
|
|
|
|
extern bool cpu_mitigations_auto_nosmt(void);
|
2019-04-13 03:39:28 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* _LINUX_CPU_H_ */
|