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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-05-03 09:02:48 +00:00
|
|
|
#include <linux/init_task.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/mqueue.h>
|
|
|
|
#include <linux/sched.h>
|
2013-02-07 15:46:59 +00:00
|
|
|
#include <linux/sched/sysctl.h>
|
2013-02-07 15:47:07 +00:00
|
|
|
#include <linux/sched/rt.h>
|
2017-02-04 00:20:53 +00:00
|
|
|
#include <linux/sched/task.h>
|
2012-05-03 09:02:48 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2018-05-13 01:58:19 +00:00
|
|
|
#include <linux/audit.h>
|
2019-03-05 23:42:58 +00:00
|
|
|
#include <linux/numa.h>
|
2020-04-27 16:00:07 +00:00
|
|
|
#include <linux/scs.h>
|
2023-12-11 18:12:49 +00:00
|
|
|
#include <linux/plist.h>
|
2012-05-03 09:02:48 +00:00
|
|
|
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2012-05-03 09:02:48 +00:00
|
|
|
|
2018-01-02 15:12:01 +00:00
|
|
|
static struct signal_struct init_signals = {
|
|
|
|
.nr_threads = 1,
|
|
|
|
.thread_head = LIST_HEAD_INIT(init_task.thread_node),
|
|
|
|
.wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
|
|
|
|
.shared_pending = {
|
|
|
|
.list = LIST_HEAD_INIT(init_signals.shared_pending.list),
|
|
|
|
.signal = {{0}}
|
|
|
|
},
|
2018-07-23 20:20:37 +00:00
|
|
|
.multiprocess = HLIST_HEAD_INIT,
|
2018-01-02 15:12:01 +00:00
|
|
|
.rlim = INIT_RLIMITS,
|
|
|
|
.cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
|
2020-12-03 20:12:00 +00:00
|
|
|
.exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_POSIX_TIMERS
|
2024-06-10 16:42:28 +00:00
|
|
|
.posix_timers = HLIST_HEAD_INIT,
|
2018-01-02 15:12:01 +00:00
|
|
|
.cputimer = {
|
|
|
|
.cputime_atomic = INIT_CPUTIME_ATOMIC,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
INIT_CPU_TIMERS(init_signals)
|
2017-09-26 18:06:43 +00:00
|
|
|
.pids = {
|
|
|
|
[PIDTYPE_PID] = &init_struct_pid,
|
2017-06-04 09:32:13 +00:00
|
|
|
[PIDTYPE_TGID] = &init_struct_pid,
|
2017-09-26 18:06:43 +00:00
|
|
|
[PIDTYPE_PGID] = &init_struct_pid,
|
|
|
|
[PIDTYPE_SID] = &init_struct_pid,
|
|
|
|
},
|
2018-01-02 15:12:01 +00:00
|
|
|
INIT_PREV_CPUTIME(init_signals)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sighand_struct init_sighand = {
|
2019-01-18 12:27:27 +00:00
|
|
|
.count = REFCOUNT_INIT(1),
|
2018-01-02 15:12:01 +00:00
|
|
|
.action = { { { .sa_handler = SIG_DFL, } }, },
|
|
|
|
.siglock = __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
|
|
|
|
.signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
|
|
|
|
};
|
2012-05-03 09:02:48 +00:00
|
|
|
|
2020-04-27 16:00:07 +00:00
|
|
|
#ifdef CONFIG_SHADOW_CALL_STACK
|
2023-11-16 13:36:38 +00:00
|
|
|
unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)] = {
|
2020-04-27 16:00:07 +00:00
|
|
|
[(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-01-02 15:12:01 +00:00
|
|
|
/*
|
|
|
|
* Set up the first task table, touch at your own risk!. Base=0,
|
|
|
|
* limit=0x1fffff (=2MB)
|
|
|
|
*/
|
2023-11-16 13:36:38 +00:00
|
|
|
struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_THREAD_INFO_IN_TASK
|
|
|
|
.thread_info = INIT_THREAD_INFO(init_task),
|
2019-01-18 12:27:30 +00:00
|
|
|
.stack_refcount = REFCOUNT_INIT(1),
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
2021-06-11 08:28:17 +00:00
|
|
|
.__state = 0,
|
2018-01-02 15:12:01 +00:00
|
|
|
.stack = init_stack,
|
2019-01-18 12:27:29 +00:00
|
|
|
.usage = REFCOUNT_INIT(2),
|
2018-01-02 15:12:01 +00:00
|
|
|
.flags = PF_KTHREAD,
|
2018-01-02 15:12:01 +00:00
|
|
|
.prio = MAX_PRIO - 20,
|
|
|
|
.static_prio = MAX_PRIO - 20,
|
|
|
|
.normal_prio = MAX_PRIO - 20,
|
2018-01-02 15:12:01 +00:00
|
|
|
.policy = SCHED_NORMAL,
|
2019-04-23 14:26:36 +00:00
|
|
|
.cpus_ptr = &init_task.cpus_mask,
|
2021-07-30 11:24:33 +00:00
|
|
|
.user_cpus_ptr = NULL,
|
2019-04-23 14:26:36 +00:00
|
|
|
.cpus_mask = CPU_MASK_ALL,
|
2024-03-24 00:45:50 +00:00
|
|
|
.max_allowed_capacity = SCHED_CAPACITY_SCALE,
|
2018-01-02 15:12:01 +00:00
|
|
|
.nr_cpus_allowed= NR_CPUS,
|
|
|
|
.mm = NULL,
|
|
|
|
.active_mm = &init_mm,
|
sched: Add task_struct->faults_disabled_mapping
There has been a long standing page cache coherence bug with direct IO.
This provides part of a mechanism to fix it, currently just used by
bcachefs but potentially worth promoting to the VFS.
Direct IO evicts the range of the pagecache being read or written to.
For reads, we need dirty pages to be written to disk, so that the read
doesn't return stale data. For writes, we need to evict that range of
the pagecache so that it's not stale after the write completes.
However, without a locking mechanism to prevent those pages from being
re-added to the pagecache - by a buffered read or page fault - page
cache inconsistency is still possible.
This isn't necessarily just an issue for userspace when they're playing
games; filesystems may hang arbitrary state off the pagecache, and so
page cache inconsistency may cause real filesystem bugs, depending on
the filesystem. This is less of an issue for iomap based filesystems,
but e.g. buffer heads caches disk block mappings (!) and attaches them
to the pagecache, and bcachefs attaches disk reservations to pagecache
pages.
This issue has been hard to fix, because
- we need to add a lock (henceforth called pagecache_add_lock), which
would be held for the duration of the direct IO
- page faults add pages to the page cache, thus need to take the same
lock
- dio -> gup -> page fault thus can deadlock
And we cannot enforce a lock ordering with this lock, since userspace
will be controlling the lock ordering (via the fd and buffer arguments
to direct IOs), so we need a different method of deadlock avoidance.
We need to tell the page fault handler that we're already holding a
pagecache_add_lock, and since plumbing it through the entire gup() path
would be highly impractical this adds a field to task_struct.
Then the full method is:
- in the dio path, when we first take the pagecache_add_lock, note the
mapping in the current task_struct
- in the page fault handler, if faults_disabled_mapping is set, we
check if it's the same mapping as the one we're taking a page fault
for, and if so return an error.
Then we check lock ordering: if there's a lock ordering violation and
trylock fails, we'll have to cycle the locks and return an error that
tells the DIO path to retry: faults_disabled_mapping is also used for
signalling "locks were dropped, please retry".
Also relevant to this patch: mapping->invalidate_lock.
mapping->invalidate_lock provides most of the required semantics - it's
used by truncate/fallocate to block pages being added to the pagecache.
However, since it's a rwsem, direct IOs would need to take the write
side in order to block page cache adds, and would then be exclusive with
each other - we'll need a new type of lock to pair with this approach.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Jan Kara <jack@suse.cz>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: linux-fsdevel@vger.kernel.org
Cc: Andreas Grünbacher <andreas.gruenbacher@gmail.com>
2019-10-16 19:03:50 +00:00
|
|
|
.faults_disabled_mapping = NULL,
|
2018-01-02 15:12:01 +00:00
|
|
|
.restart_block = {
|
2018-01-02 15:12:01 +00:00
|
|
|
.fn = do_no_restart_syscall,
|
|
|
|
},
|
|
|
|
.se = {
|
|
|
|
.group_node = LIST_HEAD_INIT(init_task.se.group_node),
|
|
|
|
},
|
|
|
|
.rt = {
|
|
|
|
.run_list = LIST_HEAD_INIT(init_task.rt.run_list),
|
|
|
|
.time_slice = RR_TIMESLICE,
|
|
|
|
},
|
|
|
|
.tasks = LIST_HEAD_INIT(init_task.tasks),
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.pushable_tasks = PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CGROUP_SCHED
|
|
|
|
.sched_task_group = &root_task_group,
|
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
.ptraced = LIST_HEAD_INIT(init_task.ptraced),
|
|
|
|
.ptrace_entry = LIST_HEAD_INIT(init_task.ptrace_entry),
|
|
|
|
.real_parent = &init_task,
|
|
|
|
.parent = &init_task,
|
|
|
|
.children = LIST_HEAD_INIT(init_task.children),
|
|
|
|
.sibling = LIST_HEAD_INIT(init_task.sibling),
|
|
|
|
.group_leader = &init_task,
|
|
|
|
RCU_POINTER_INITIALIZER(real_cred, &init_cred),
|
|
|
|
RCU_POINTER_INITIALIZER(cred, &init_cred),
|
|
|
|
.comm = INIT_TASK_COMM,
|
|
|
|
.thread = INIT_THREAD,
|
|
|
|
.fs = &init_fs,
|
|
|
|
.files = &init_files,
|
2020-09-13 19:09:39 +00:00
|
|
|
#ifdef CONFIG_IO_URING
|
|
|
|
.io_uring = NULL,
|
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
.signal = &init_signals,
|
|
|
|
.sighand = &init_sighand,
|
|
|
|
.nsproxy = &init_nsproxy,
|
|
|
|
.pending = {
|
|
|
|
.list = LIST_HEAD_INIT(init_task.pending.list),
|
|
|
|
.signal = {{0}}
|
|
|
|
},
|
|
|
|
.blocked = {{0}},
|
|
|
|
.alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
|
|
|
|
.journal_info = NULL,
|
|
|
|
INIT_CPU_TIMERS(init_task)
|
|
|
|
.pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
|
|
|
|
.timer_slack_ns = 50000, /* 50 usec default slack */
|
2017-09-26 18:06:43 +00:00
|
|
|
.thread_pid = &init_struct_pid,
|
2018-01-02 15:12:01 +00:00
|
|
|
.thread_node = LIST_HEAD_INIT(init_signals.thread_head),
|
2019-01-22 22:06:39 +00:00
|
|
|
#ifdef CONFIG_AUDIT
|
2018-01-02 15:12:01 +00:00
|
|
|
.loginuid = INVALID_UID,
|
2018-05-13 01:58:19 +00:00
|
|
|
.sessionid = AUDIT_SID_UNSET,
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PERF_EVENTS
|
|
|
|
.perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
|
|
|
|
.perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PREEMPT_RCU
|
|
|
|
.rcu_read_lock_nesting = 0,
|
|
|
|
.rcu_read_unlock_special.s = 0,
|
|
|
|
.rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
|
|
|
|
.rcu_blocked_node = NULL,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TASKS_RCU
|
|
|
|
.rcu_tasks_holdout = false,
|
|
|
|
.rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
|
|
|
|
.rcu_tasks_idle_cpu = -1,
|
2024-02-05 21:10:19 +00:00
|
|
|
.rcu_tasks_exit_list = LIST_HEAD_INIT(init_task.rcu_tasks_exit_list),
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
rcu-tasks: Add an RCU Tasks Trace to simplify protection of tracing hooks
Because RCU does not watch exception early-entry/late-exit, idle-loop,
or CPU-hotplug execution, protection of tracing and BPF operations is
needlessly complicated. This commit therefore adds a variant of
Tasks RCU that:
o Has explicit read-side markers to allow finite grace periods in
the face of in-kernel loops for PREEMPT=n builds. These markers
are rcu_read_lock_trace() and rcu_read_unlock_trace().
o Protects code in the idle loop, exception entry/exit, and
CPU-hotplug code paths. In this respect, RCU-tasks trace is
similar to SRCU, but with lighter-weight readers.
o Avoids expensive read-side instruction, having overhead similar
to that of Preemptible RCU.
There are of course downsides:
o The grace-period code can send IPIs to CPUs, even when those
CPUs are in the idle loop or in nohz_full userspace. This is
mitigated by later commits.
o It is necessary to scan the full tasklist, much as for Tasks RCU.
o There is a single callback queue guarded by a single lock,
again, much as for Tasks RCU. However, those early use cases
that request multiple grace periods in quick succession are
expected to do so from a single task, which makes the single
lock almost irrelevant. If needed, multiple callback queues
can be provided using any number of schemes.
Perhaps most important, this variant of RCU does not affect the vanilla
flavors, rcu_preempt and rcu_sched. The fact that RCU Tasks Trace
readers can operate from idle, offline, and exception entry/exit in no
way enables rcu_preempt and rcu_sched readers to do so.
The memory ordering was outlined here:
https://lore.kernel.org/lkml/20200319034030.GX3199@paulmck-ThinkPad-P72/
This effort benefited greatly from off-list discussions of BPF
requirements with Alexei Starovoitov and Andrii Nakryiko. At least
some of the on-list discussions are captured in the Link: tags below.
In addition, KCSAN was quite helpful in finding some early bugs.
Link: https://lore.kernel.org/lkml/20200219150744.428764577@infradead.org/
Link: https://lore.kernel.org/lkml/87mu8p797b.fsf@nanos.tec.linutronix.de/
Link: https://lore.kernel.org/lkml/20200225221305.605144982@linutronix.de/
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andriin@fb.com>
[ paulmck: Apply feedback from Steve Rostedt and Joel Fernandes. ]
[ paulmck: Decrement trc_n_readers_need_end upon IPI failure. ]
[ paulmck: Fix locking issue reported by rcutorture. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2020-03-10 02:56:53 +00:00
|
|
|
#ifdef CONFIG_TASKS_TRACE_RCU
|
|
|
|
.trc_reader_nesting = 0,
|
2020-03-17 23:02:06 +00:00
|
|
|
.trc_reader_special.s = 0,
|
rcu-tasks: Add an RCU Tasks Trace to simplify protection of tracing hooks
Because RCU does not watch exception early-entry/late-exit, idle-loop,
or CPU-hotplug execution, protection of tracing and BPF operations is
needlessly complicated. This commit therefore adds a variant of
Tasks RCU that:
o Has explicit read-side markers to allow finite grace periods in
the face of in-kernel loops for PREEMPT=n builds. These markers
are rcu_read_lock_trace() and rcu_read_unlock_trace().
o Protects code in the idle loop, exception entry/exit, and
CPU-hotplug code paths. In this respect, RCU-tasks trace is
similar to SRCU, but with lighter-weight readers.
o Avoids expensive read-side instruction, having overhead similar
to that of Preemptible RCU.
There are of course downsides:
o The grace-period code can send IPIs to CPUs, even when those
CPUs are in the idle loop or in nohz_full userspace. This is
mitigated by later commits.
o It is necessary to scan the full tasklist, much as for Tasks RCU.
o There is a single callback queue guarded by a single lock,
again, much as for Tasks RCU. However, those early use cases
that request multiple grace periods in quick succession are
expected to do so from a single task, which makes the single
lock almost irrelevant. If needed, multiple callback queues
can be provided using any number of schemes.
Perhaps most important, this variant of RCU does not affect the vanilla
flavors, rcu_preempt and rcu_sched. The fact that RCU Tasks Trace
readers can operate from idle, offline, and exception entry/exit in no
way enables rcu_preempt and rcu_sched readers to do so.
The memory ordering was outlined here:
https://lore.kernel.org/lkml/20200319034030.GX3199@paulmck-ThinkPad-P72/
This effort benefited greatly from off-list discussions of BPF
requirements with Alexei Starovoitov and Andrii Nakryiko. At least
some of the on-list discussions are captured in the Link: tags below.
In addition, KCSAN was quite helpful in finding some early bugs.
Link: https://lore.kernel.org/lkml/20200219150744.428764577@infradead.org/
Link: https://lore.kernel.org/lkml/87mu8p797b.fsf@nanos.tec.linutronix.de/
Link: https://lore.kernel.org/lkml/20200225221305.605144982@linutronix.de/
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andriin@fb.com>
[ paulmck: Apply feedback from Steve Rostedt and Joel Fernandes. ]
[ paulmck: Decrement trc_n_readers_need_end upon IPI failure. ]
[ paulmck: Fix locking issue reported by rcutorture. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2020-03-10 02:56:53 +00:00
|
|
|
.trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
|
2022-05-17 00:56:16 +00:00
|
|
|
.trc_blkd_node = LIST_HEAD_INIT(init_task.trc_blkd_node),
|
rcu-tasks: Add an RCU Tasks Trace to simplify protection of tracing hooks
Because RCU does not watch exception early-entry/late-exit, idle-loop,
or CPU-hotplug execution, protection of tracing and BPF operations is
needlessly complicated. This commit therefore adds a variant of
Tasks RCU that:
o Has explicit read-side markers to allow finite grace periods in
the face of in-kernel loops for PREEMPT=n builds. These markers
are rcu_read_lock_trace() and rcu_read_unlock_trace().
o Protects code in the idle loop, exception entry/exit, and
CPU-hotplug code paths. In this respect, RCU-tasks trace is
similar to SRCU, but with lighter-weight readers.
o Avoids expensive read-side instruction, having overhead similar
to that of Preemptible RCU.
There are of course downsides:
o The grace-period code can send IPIs to CPUs, even when those
CPUs are in the idle loop or in nohz_full userspace. This is
mitigated by later commits.
o It is necessary to scan the full tasklist, much as for Tasks RCU.
o There is a single callback queue guarded by a single lock,
again, much as for Tasks RCU. However, those early use cases
that request multiple grace periods in quick succession are
expected to do so from a single task, which makes the single
lock almost irrelevant. If needed, multiple callback queues
can be provided using any number of schemes.
Perhaps most important, this variant of RCU does not affect the vanilla
flavors, rcu_preempt and rcu_sched. The fact that RCU Tasks Trace
readers can operate from idle, offline, and exception entry/exit in no
way enables rcu_preempt and rcu_sched readers to do so.
The memory ordering was outlined here:
https://lore.kernel.org/lkml/20200319034030.GX3199@paulmck-ThinkPad-P72/
This effort benefited greatly from off-list discussions of BPF
requirements with Alexei Starovoitov and Andrii Nakryiko. At least
some of the on-list discussions are captured in the Link: tags below.
In addition, KCSAN was quite helpful in finding some early bugs.
Link: https://lore.kernel.org/lkml/20200219150744.428764577@infradead.org/
Link: https://lore.kernel.org/lkml/87mu8p797b.fsf@nanos.tec.linutronix.de/
Link: https://lore.kernel.org/lkml/20200225221305.605144982@linutronix.de/
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andriin@fb.com>
[ paulmck: Apply feedback from Steve Rostedt and Joel Fernandes. ]
[ paulmck: Decrement trc_n_readers_need_end upon IPI failure. ]
[ paulmck: Fix locking issue reported by rcutorture. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2020-03-10 02:56:53 +00:00
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_CPUSETS
|
2020-07-20 15:55:19 +00:00
|
|
|
.mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
|
|
|
|
&init_task.alloc_lock),
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_RT_MUTEXES
|
|
|
|
.pi_waiters = RB_ROOT_CACHED,
|
|
|
|
.pi_top_task = NULL,
|
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
INIT_PREV_CPUTIME(init_task)
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
|
|
|
|
.vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount),
|
|
|
|
.vtime.starttime = 0,
|
|
|
|
.vtime.state = VTIME_SYS,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NUMA_BALANCING
|
2019-03-05 23:42:58 +00:00
|
|
|
.numa_preferred_nid = NUMA_NO_NODE,
|
2018-01-02 15:12:01 +00:00
|
|
|
.numa_group = NULL,
|
|
|
|
.numa_faults = NULL,
|
|
|
|
#endif
|
2020-12-22 20:00:56 +00:00
|
|
|
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
|
2018-01-02 15:12:01 +00:00
|
|
|
.kasan_depth = 1,
|
|
|
|
#endif
|
2019-11-14 18:02:54 +00:00
|
|
|
#ifdef CONFIG_KCSAN
|
|
|
|
.kcsan_ctx = {
|
kcsan: Add support for scoped accesses
This adds support for scoped accesses, where the memory range is checked
for the duration of the scope. The feature is implemented by inserting
the relevant access information into a list of scoped accesses for
the current execution context, which are then checked (until removed)
on every call (through instrumentation) into the KCSAN runtime.
An alternative, more complex, implementation could set up a watchpoint for
the scoped access, and keep the watchpoint set up. This, however, would
require first exposing a handle to the watchpoint, as well as dealing
with cases such as accesses by the same thread while the watchpoint is
still set up (and several more cases). It is also doubtful if this would
provide any benefit, since the majority of delay where the watchpoint
is set up is likely due to the injected delays by KCSAN. Therefore,
the implementation in this patch is simpler and avoids hurting KCSAN's
main use-case (normal data race detection); it also implicitly increases
scoped-access race-detection-ability due to increased probability of
setting up watchpoints by repeatedly calling __kcsan_check_access()
throughout the scope of the access.
The implementation required adding an additional conditional branch to
the fast-path. However, the microbenchmark showed a *speedup* of ~5%
on the fast-path. This appears to be due to subtly improved codegen by
GCC from moving get_ctx() and associated load of preempt_count earlier.
Suggested-by: Boqun Feng <boqun.feng@gmail.com>
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2020-03-25 16:41:56 +00:00
|
|
|
.scoped_accesses = {LIST_POISON1, NULL},
|
2019-11-14 18:02:54 +00:00
|
|
|
},
|
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
.softirqs_enabled = 1,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
2019-05-06 08:19:23 +00:00
|
|
|
.lockdep_depth = 0, /* no locks held yet */
|
2019-05-06 08:19:24 +00:00
|
|
|
.curr_chain_key = INITIAL_CHAIN_KEY,
|
2018-01-02 15:12:01 +00:00
|
|
|
.lockdep_recursion = 0,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
2021-01-29 15:13:53 +00:00
|
|
|
.ret_stack = NULL,
|
|
|
|
.tracing_graph_pause = ATOMIC_INIT(0),
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
2019-07-26 21:19:37 +00:00
|
|
|
#if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
|
2018-01-02 15:12:01 +00:00
|
|
|
.trace_recursion = 0,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_LIVEPATCH
|
2024-05-07 05:01:11 +00:00
|
|
|
.patch_state = KLP_TRANSITION_IDLE,
|
2018-01-02 15:12:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SECURITY
|
|
|
|
.security = NULL,
|
|
|
|
#endif
|
2021-03-21 15:52:19 +00:00
|
|
|
#ifdef CONFIG_SECCOMP_FILTER
|
2020-05-13 21:11:26 +00:00
|
|
|
.seccomp = { .filter_count = ATOMIC_INIT(0) },
|
|
|
|
#endif
|
2018-01-02 15:12:01 +00:00
|
|
|
};
|
2012-05-03 09:02:48 +00:00
|
|
|
EXPORT_SYMBOL(init_task);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initial thread structure. Alignment of this is handled by a special
|
|
|
|
* linker map entry.
|
|
|
|
*/
|
2016-09-13 21:29:24 +00:00
|
|
|
#ifndef CONFIG_THREAD_INFO_IN_TASK
|
2018-01-02 15:12:01 +00:00
|
|
|
struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
|
2016-09-13 21:29:24 +00:00
|
|
|
#endif
|