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 */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* thread_info.h: common low-level thread information accessors
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 David Howells (dhowells@redhat.com)
|
|
|
|
* - Incorporating suggestions made by Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_THREAD_INFO_H
|
|
|
|
#define _LINUX_THREAD_INFO_H
|
|
|
|
|
futex: fix for futex_wait signal stack corruption
David Holmes found a bug in the -rt tree with respect to
pthread_cond_timedwait. After trying his test program on the latest git
from mainline, I found the bug was there too. The bug he was seeing
that his test program showed, was that if one were to do a "Ctrl-Z" on a
process that was in the pthread_cond_timedwait, and then did a "bg" on
that process, it would return with a "-ETIMEDOUT" but early. That is,
the timer would go off early.
Looking into this, I found the source of the problem. And it is a rather
nasty bug at that.
Here's the relevant code from kernel/futex.c: (not in order in the file)
[...]
smlinkage long sys_futex(u32 __user *uaddr, int op, u32 val,
struct timespec __user *utime, u32 __user *uaddr2,
u32 val3)
{
struct timespec ts;
ktime_t t, *tp = NULL;
u32 val2 = 0;
int cmd = op & FUTEX_CMD_MASK;
if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI)) {
if (copy_from_user(&ts, utime, sizeof(ts)) != 0)
return -EFAULT;
if (!timespec_valid(&ts))
return -EINVAL;
t = timespec_to_ktime(ts);
if (cmd == FUTEX_WAIT)
t = ktime_add(ktime_get(), t);
tp = &t;
}
[...]
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
}
[...]
long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
u32 __user *uaddr2, u32 val2, u32 val3)
{
int ret;
int cmd = op & FUTEX_CMD_MASK;
struct rw_semaphore *fshared = NULL;
if (!(op & FUTEX_PRIVATE_FLAG))
fshared = ¤t->mm->mmap_sem;
switch (cmd) {
case FUTEX_WAIT:
ret = futex_wait(uaddr, fshared, val, timeout);
[...]
static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
u32 val, ktime_t *abs_time)
{
[...]
struct restart_block *restart;
restart = ¤t_thread_info()->restart_block;
restart->fn = futex_wait_restart;
restart->arg0 = (unsigned long)uaddr;
restart->arg1 = (unsigned long)val;
restart->arg2 = (unsigned long)abs_time;
restart->arg3 = 0;
if (fshared)
restart->arg3 |= ARG3_SHARED;
return -ERESTART_RESTARTBLOCK;
[...]
static long futex_wait_restart(struct restart_block *restart)
{
u32 __user *uaddr = (u32 __user *)restart->arg0;
u32 val = (u32)restart->arg1;
ktime_t *abs_time = (ktime_t *)restart->arg2;
struct rw_semaphore *fshared = NULL;
restart->fn = do_no_restart_syscall;
if (restart->arg3 & ARG3_SHARED)
fshared = ¤t->mm->mmap_sem;
return (long)futex_wait(uaddr, fshared, val, abs_time);
}
So when the futex_wait is interrupt by a signal we break out of the
hrtimer code and set up or return from signal. This code does not return
back to userspace, so we set up a RESTARTBLOCK. The bug here is that we
save the "abs_time" which is a pointer to the stack variable "ktime_t t"
from sys_futex.
This returns and unwinds the stack before we get to call our signal. On
return from the signal we go to futex_wait_restart, where we update all
the parameters for futex_wait and call it. But here we have a problem
where abs_time is no longer valid.
I verified this with print statements, and sure enough, what abs_time
was set to ends up being garbage when we get to futex_wait_restart.
The solution I did to solve this (with input from Linus Torvalds)
was to add unions to the restart_block to allow system calls to
use the restart with specific parameters. This way the futex code now
saves the time in a 64bit value in the restart block instead of storing
it on the stack.
Note: I'm a bit nervious to add "linux/types.h" and use u32 and u64
in thread_info.h, when there's a #ifdef __KERNEL__ just below that.
Not sure what that is there for. If this turns out to be a problem, I've
tested this with using "unsigned int" for u32 and "unsigned long long" for
u64 and it worked just the same. I'm using u32 and u64 just to be
consistent with what the futex code uses.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-12-05 22:46:09 +08:00
|
|
|
#include <linux/types.h>
|
2021-07-01 09:54:59 +08:00
|
|
|
#include <linux/limits.h>
|
2012-04-28 01:42:45 +08:00
|
|
|
#include <linux/bug.h>
|
2016-10-20 02:28:12 +08:00
|
|
|
#include <linux/restart_block.h>
|
2021-02-02 01:46:41 +08:00
|
|
|
#include <linux/errno.h>
|
2008-02-10 16:04:12 +08:00
|
|
|
|
2016-09-14 05:29:24 +08:00
|
|
|
#ifdef CONFIG_THREAD_INFO_IN_TASK
|
2016-10-20 02:28:13 +08:00
|
|
|
/*
|
|
|
|
* For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the
|
|
|
|
* definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels,
|
|
|
|
* including <asm/current.h> can cause a circular dependency on some platforms.
|
|
|
|
*/
|
|
|
|
#include <asm/current.h>
|
2016-09-14 05:29:24 +08:00
|
|
|
#define current_thread_info() ((struct thread_info *)current)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/bitops.h>
|
2017-02-17 02:29:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For per-arch arch_within_stack_frames() implementations, defined in
|
|
|
|
* asm/thread_info.h.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
BAD_STACK = -1,
|
|
|
|
NOT_STACK = 0,
|
|
|
|
GOOD_FRAME,
|
|
|
|
GOOD_STACK,
|
|
|
|
};
|
|
|
|
|
2020-11-23 23:54:58 +08:00
|
|
|
#ifdef CONFIG_GENERIC_ENTRY
|
2020-11-17 01:42:00 +08:00
|
|
|
enum syscall_work_bit {
|
|
|
|
SYSCALL_WORK_BIT_SECCOMP,
|
2020-11-17 01:42:01 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT,
|
2020-11-17 01:42:02 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_TRACE,
|
2020-11-17 01:42:03 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_EMU,
|
2020-11-17 01:42:04 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_AUDIT,
|
kernel: Implement selective syscall userspace redirection
Introduce a mechanism to quickly disable/enable syscall handling for a
specific process and redirect to userspace via SIGSYS. This is useful
for processes with parts that require syscall redirection and parts that
don't, but who need to perform this boundary crossing really fast,
without paying the cost of a system call to reconfigure syscall handling
on each boundary transition. This is particularly important for Windows
games running over Wine.
The proposed interface looks like this:
prctl(PR_SET_SYSCALL_USER_DISPATCH, <op>, <off>, <length>, [selector])
The range [<offset>,<offset>+<length>) is a part of the process memory
map that is allowed to by-pass the redirection code and dispatch
syscalls directly, such that in fast paths a process doesn't need to
disable the trap nor the kernel has to check the selector. This is
essential to return from SIGSYS to a blocked area without triggering
another SIGSYS from rt_sigreturn.
selector is an optional pointer to a char-sized userspace memory region
that has a key switch for the mechanism. This key switch is set to
either PR_SYS_DISPATCH_ON, PR_SYS_DISPATCH_OFF to enable and disable the
redirection without calling the kernel.
The feature is meant to be set per-thread and it is disabled on
fork/clone/execv.
Internally, this doesn't add overhead to the syscall hot path, and it
requires very little per-architecture support. I avoided using seccomp,
even though it duplicates some functionality, due to previous feedback
that maybe it shouldn't mix with seccomp since it is not a security
mechanism. And obviously, this should never be considered a security
mechanism, since any part of the program can by-pass it by using the
syscall dispatcher.
For the sysinfo benchmark, which measures the overhead added to
executing a native syscall that doesn't require interception, the
overhead using only the direct dispatcher region to issue syscalls is
pretty much irrelevant. The overhead of using the selector goes around
40ns for a native (unredirected) syscall in my system, and it is (as
expected) dominated by the supervisor-mode user-address access. In
fact, with SMAP off, the overhead is consistently less than 5ns on my
test box.
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201127193238.821364-4-krisman@collabora.com
2020-11-28 03:32:34 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH,
|
2021-02-04 02:00:48 +08:00
|
|
|
SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP,
|
2020-11-17 01:42:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP)
|
2020-11-17 01:42:01 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_TRACEPOINT BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)
|
2020-11-17 01:42:02 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_TRACE BIT(SYSCALL_WORK_BIT_SYSCALL_TRACE)
|
2020-11-17 01:42:03 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_EMU BIT(SYSCALL_WORK_BIT_SYSCALL_EMU)
|
2020-11-17 01:42:04 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_AUDIT BIT(SYSCALL_WORK_BIT_SYSCALL_AUDIT)
|
kernel: Implement selective syscall userspace redirection
Introduce a mechanism to quickly disable/enable syscall handling for a
specific process and redirect to userspace via SIGSYS. This is useful
for processes with parts that require syscall redirection and parts that
don't, but who need to perform this boundary crossing really fast,
without paying the cost of a system call to reconfigure syscall handling
on each boundary transition. This is particularly important for Windows
games running over Wine.
The proposed interface looks like this:
prctl(PR_SET_SYSCALL_USER_DISPATCH, <op>, <off>, <length>, [selector])
The range [<offset>,<offset>+<length>) is a part of the process memory
map that is allowed to by-pass the redirection code and dispatch
syscalls directly, such that in fast paths a process doesn't need to
disable the trap nor the kernel has to check the selector. This is
essential to return from SIGSYS to a blocked area without triggering
another SIGSYS from rt_sigreturn.
selector is an optional pointer to a char-sized userspace memory region
that has a key switch for the mechanism. This key switch is set to
either PR_SYS_DISPATCH_ON, PR_SYS_DISPATCH_OFF to enable and disable the
redirection without calling the kernel.
The feature is meant to be set per-thread and it is disabled on
fork/clone/execv.
Internally, this doesn't add overhead to the syscall hot path, and it
requires very little per-architecture support. I avoided using seccomp,
even though it duplicates some functionality, due to previous feedback
that maybe it shouldn't mix with seccomp since it is not a security
mechanism. And obviously, this should never be considered a security
mechanism, since any part of the program can by-pass it by using the
syscall dispatcher.
For the sysinfo benchmark, which measures the overhead added to
executing a native syscall that doesn't require interception, the
overhead using only the direct dispatcher region to issue syscalls is
pretty much irrelevant. The overhead of using the selector goes around
40ns for a native (unredirected) syscall in my system, and it is (as
expected) dominated by the supervisor-mode user-address access. In
fact, with SMAP off, the overhead is consistently less than 5ns on my
test box.
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201127193238.821364-4-krisman@collabora.com
2020-11-28 03:32:34 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_USER_DISPATCH BIT(SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH)
|
2021-02-04 02:00:48 +08:00
|
|
|
#define SYSCALL_WORK_SYSCALL_EXIT_TRAP BIT(SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP)
|
2020-11-23 23:54:58 +08:00
|
|
|
#endif
|
2020-11-17 01:42:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/thread_info.h>
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
2021-02-02 01:46:41 +08:00
|
|
|
#ifndef arch_set_restart_data
|
|
|
|
#define arch_set_restart_data(restart) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline long set_restart_fn(struct restart_block *restart,
|
|
|
|
long (*fn)(struct restart_block *))
|
|
|
|
{
|
|
|
|
restart->fn = fn;
|
|
|
|
arch_set_restart_data(restart);
|
|
|
|
return -ERESTART_RESTARTBLOCK;
|
|
|
|
}
|
|
|
|
|
2017-07-14 19:23:09 +08:00
|
|
|
#ifndef THREAD_ALIGN
|
|
|
|
#define THREAD_ALIGN THREAD_SIZE
|
|
|
|
#endif
|
|
|
|
|
2018-04-21 05:55:31 +08:00
|
|
|
#define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO)
|
2012-05-05 23:05:41 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* flag set/clear/test wrappers
|
|
|
|
* - pass TIF_xxxx constants to these functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
|
|
|
|
{
|
2008-01-30 20:30:55 +08:00
|
|
|
set_bit(flag, (unsigned long *)&ti->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
|
|
|
|
{
|
2008-01-30 20:30:55 +08:00
|
|
|
clear_bit(flag, (unsigned long *)&ti->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-04-12 00:54:20 +08:00
|
|
|
static inline void update_ti_thread_flag(struct thread_info *ti, int flag,
|
|
|
|
bool value)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
set_ti_thread_flag(ti, flag);
|
|
|
|
else
|
|
|
|
clear_ti_thread_flag(ti, flag);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
|
|
|
|
{
|
2008-01-30 20:30:55 +08:00
|
|
|
return test_and_set_bit(flag, (unsigned long *)&ti->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
|
|
|
|
{
|
2008-01-30 20:30:55 +08:00
|
|
|
return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
|
|
|
|
{
|
2008-01-30 20:30:55 +08:00
|
|
|
return test_bit(flag, (unsigned long *)&ti->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2021-11-29 21:06:43 +08:00
|
|
|
/*
|
|
|
|
* This may be used in noinstr code, and needs to be __always_inline to prevent
|
|
|
|
* inadvertent instrumentation.
|
|
|
|
*/
|
|
|
|
static __always_inline unsigned long read_ti_thread_flags(struct thread_info *ti)
|
|
|
|
{
|
|
|
|
return READ_ONCE(ti->flags);
|
|
|
|
}
|
|
|
|
|
2005-11-14 08:06:59 +08:00
|
|
|
#define set_thread_flag(flag) \
|
|
|
|
set_ti_thread_flag(current_thread_info(), flag)
|
|
|
|
#define clear_thread_flag(flag) \
|
|
|
|
clear_ti_thread_flag(current_thread_info(), flag)
|
2018-04-12 00:54:20 +08:00
|
|
|
#define update_thread_flag(flag, value) \
|
|
|
|
update_ti_thread_flag(current_thread_info(), flag, value)
|
2005-11-14 08:06:59 +08:00
|
|
|
#define test_and_set_thread_flag(flag) \
|
|
|
|
test_and_set_ti_thread_flag(current_thread_info(), flag)
|
|
|
|
#define test_and_clear_thread_flag(flag) \
|
|
|
|
test_and_clear_ti_thread_flag(current_thread_info(), flag)
|
|
|
|
#define test_thread_flag(flag) \
|
|
|
|
test_ti_thread_flag(current_thread_info(), flag)
|
2021-11-29 21:06:43 +08:00
|
|
|
#define read_thread_flags() \
|
|
|
|
read_ti_thread_flags(current_thread_info())
|
|
|
|
|
|
|
|
#define read_task_thread_flags(t) \
|
|
|
|
read_ti_thread_flags(task_thread_info(t))
|
2005-11-14 08:06:59 +08:00
|
|
|
|
2020-11-17 01:41:58 +08:00
|
|
|
#ifdef CONFIG_GENERIC_ENTRY
|
|
|
|
#define set_syscall_work(fl) \
|
|
|
|
set_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
|
|
|
|
#define test_syscall_work(fl) \
|
|
|
|
test_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
|
|
|
|
#define clear_syscall_work(fl) \
|
|
|
|
clear_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
|
|
|
|
|
|
|
|
#define set_task_syscall_work(t, fl) \
|
|
|
|
set_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
|
|
|
|
#define test_task_syscall_work(t, fl) \
|
|
|
|
test_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
|
|
|
|
#define clear_task_syscall_work(t, fl) \
|
|
|
|
clear_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
|
|
|
|
|
|
|
|
#else /* CONFIG_GENERIC_ENTRY */
|
|
|
|
|
|
|
|
#define set_syscall_work(fl) \
|
2020-11-23 23:54:58 +08:00
|
|
|
set_ti_thread_flag(current_thread_info(), TIF_##fl)
|
2020-11-17 01:41:58 +08:00
|
|
|
#define test_syscall_work(fl) \
|
2020-11-23 23:54:58 +08:00
|
|
|
test_ti_thread_flag(current_thread_info(), TIF_##fl)
|
2020-11-17 01:41:58 +08:00
|
|
|
#define clear_syscall_work(fl) \
|
2020-11-23 23:54:58 +08:00
|
|
|
clear_ti_thread_flag(current_thread_info(), TIF_##fl)
|
2020-11-17 01:41:58 +08:00
|
|
|
|
|
|
|
#define set_task_syscall_work(t, fl) \
|
|
|
|
set_ti_thread_flag(task_thread_info(t), TIF_##fl)
|
|
|
|
#define test_task_syscall_work(t, fl) \
|
|
|
|
test_ti_thread_flag(task_thread_info(t), TIF_##fl)
|
|
|
|
#define clear_task_syscall_work(t, fl) \
|
|
|
|
clear_ti_thread_flag(task_thread_info(t), TIF_##fl)
|
|
|
|
#endif /* !CONFIG_GENERIC_ENTRY */
|
|
|
|
|
2023-01-13 03:43:41 +08:00
|
|
|
#ifdef _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H
|
|
|
|
|
|
|
|
static __always_inline bool tif_need_resched(void)
|
|
|
|
{
|
|
|
|
return arch_test_bit(TIF_NEED_RESCHED,
|
|
|
|
(unsigned long *)(¤t_thread_info()->flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static __always_inline bool tif_need_resched(void)
|
|
|
|
{
|
|
|
|
return test_bit(TIF_NEED_RESCHED,
|
|
|
|
(unsigned long *)(¤t_thread_info()->flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
|
2013-09-11 18:43:13 +08:00
|
|
|
|
2016-07-13 07:19:48 +08:00
|
|
|
#ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
|
|
|
|
static inline int arch_within_stack_frames(const void * const stack,
|
|
|
|
const void * const stackend,
|
|
|
|
const void *obj, unsigned long len)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-08 02:05:33 +08:00
|
|
|
#ifdef CONFIG_HARDENED_USERCOPY
|
|
|
|
extern void __check_object_size(const void *ptr, unsigned long n,
|
|
|
|
bool to_user);
|
|
|
|
|
2016-09-08 00:39:32 +08:00
|
|
|
static __always_inline void check_object_size(const void *ptr, unsigned long n,
|
|
|
|
bool to_user)
|
2016-06-08 02:05:33 +08:00
|
|
|
{
|
2016-09-01 07:04:21 +08:00
|
|
|
if (!__builtin_constant_p(n))
|
|
|
|
__check_object_size(ptr, n, to_user);
|
2016-06-08 02:05:33 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void check_object_size(const void *ptr, unsigned long n,
|
|
|
|
bool to_user)
|
|
|
|
{ }
|
|
|
|
#endif /* CONFIG_HARDENED_USERCOPY */
|
|
|
|
|
2017-06-30 09:42:43 +08:00
|
|
|
extern void __compiletime_error("copy source size is too small")
|
|
|
|
__bad_copy_from(void);
|
|
|
|
extern void __compiletime_error("copy destination size is too small")
|
|
|
|
__bad_copy_to(void);
|
|
|
|
|
mm: uninline copy_overflow()
While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE, I ended
up with more than 50 times the following function in vmlinux because GCC
doesn't honor the 'inline' keyword:
c00243bc <copy_overflow>:
c00243bc: 94 21 ff f0 stwu r1,-16(r1)
c00243c0: 7c 85 23 78 mr r5,r4
c00243c4: 7c 64 1b 78 mr r4,r3
c00243c8: 3c 60 c0 62 lis r3,-16286
c00243cc: 7c 08 02 a6 mflr r0
c00243d0: 38 63 5e e5 addi r3,r3,24293
c00243d4: 90 01 00 14 stw r0,20(r1)
c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk>
c00243dc: 0f e0 00 00 twui r0,0
c00243e0: 80 01 00 14 lwz r0,20(r1)
c00243e4: 38 21 00 10 addi r1,r1,16
c00243e8: 7c 08 03 a6 mtlr r0
c00243ec: 4e 80 00 20 blr
With -Winline, GCC tells:
/include/linux/thread_info.h:212:20: warning: inlining failed in call to 'copy_overflow': call is unlikely and code size would grow [-Winline]
copy_overflow() is a non conditional warning called by check_copy_size()
on an error path.
check_copy_size() have to remain inlined in order to benefit from
constant folding, but copy_overflow() is not worth inlining.
Uninline the warning when CONFIG_BUG is selected.
When CONFIG_BUG is not selected, WARN() does nothing so skip it.
This reduces the size of vmlinux by almost 4kbytes.
Link: https://lkml.kernel.org/r/e1723b9cfa924bcefcd41f69d0025b38e4c9364e.1644819985.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-23 05:47:49 +08:00
|
|
|
void __copy_overflow(int size, unsigned long count);
|
|
|
|
|
2017-06-30 09:42:43 +08:00
|
|
|
static inline void copy_overflow(int size, unsigned long count)
|
|
|
|
{
|
mm: uninline copy_overflow()
While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE, I ended
up with more than 50 times the following function in vmlinux because GCC
doesn't honor the 'inline' keyword:
c00243bc <copy_overflow>:
c00243bc: 94 21 ff f0 stwu r1,-16(r1)
c00243c0: 7c 85 23 78 mr r5,r4
c00243c4: 7c 64 1b 78 mr r4,r3
c00243c8: 3c 60 c0 62 lis r3,-16286
c00243cc: 7c 08 02 a6 mflr r0
c00243d0: 38 63 5e e5 addi r3,r3,24293
c00243d4: 90 01 00 14 stw r0,20(r1)
c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk>
c00243dc: 0f e0 00 00 twui r0,0
c00243e0: 80 01 00 14 lwz r0,20(r1)
c00243e4: 38 21 00 10 addi r1,r1,16
c00243e8: 7c 08 03 a6 mtlr r0
c00243ec: 4e 80 00 20 blr
With -Winline, GCC tells:
/include/linux/thread_info.h:212:20: warning: inlining failed in call to 'copy_overflow': call is unlikely and code size would grow [-Winline]
copy_overflow() is a non conditional warning called by check_copy_size()
on an error path.
check_copy_size() have to remain inlined in order to benefit from
constant folding, but copy_overflow() is not worth inlining.
Uninline the warning when CONFIG_BUG is selected.
When CONFIG_BUG is not selected, WARN() does nothing so skip it.
This reduces the size of vmlinux by almost 4kbytes.
Link: https://lkml.kernel.org/r/e1723b9cfa924bcefcd41f69d0025b38e4c9364e.1644819985.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-23 05:47:49 +08:00
|
|
|
if (IS_ENABLED(CONFIG_BUG))
|
|
|
|
__copy_overflow(size, count);
|
2017-06-30 09:42:43 +08:00
|
|
|
}
|
|
|
|
|
2019-09-26 07:47:39 +08:00
|
|
|
static __always_inline __must_check bool
|
2017-06-30 09:42:43 +08:00
|
|
|
check_copy_size(const void *addr, size_t bytes, bool is_source)
|
|
|
|
{
|
2021-06-18 13:48:05 +08:00
|
|
|
int sz = __builtin_object_size(addr, 0);
|
2017-06-30 09:42:43 +08:00
|
|
|
if (unlikely(sz >= 0 && sz < bytes)) {
|
|
|
|
if (!__builtin_constant_p(bytes))
|
|
|
|
copy_overflow(sz, bytes);
|
|
|
|
else if (is_source)
|
|
|
|
__bad_copy_from();
|
|
|
|
else
|
|
|
|
__bad_copy_to();
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-05 08:52:40 +08:00
|
|
|
if (WARN_ON_ONCE(bytes > INT_MAX))
|
|
|
|
return false;
|
2017-06-30 09:42:43 +08:00
|
|
|
check_object_size(addr, bytes, is_source);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:16:26 +08:00
|
|
|
#ifndef arch_setup_new_exec
|
|
|
|
static inline void arch_setup_new_exec(void) { }
|
|
|
|
#endif
|
|
|
|
|
2023-05-17 21:11:01 +08:00
|
|
|
void arch_task_cache_init(void); /* for CONFIG_SH */
|
|
|
|
void arch_release_task_struct(struct task_struct *tsk);
|
|
|
|
int arch_dup_task_struct(struct task_struct *dst,
|
|
|
|
struct task_struct *src);
|
|
|
|
|
2008-04-30 15:53:06 +08:00
|
|
|
#endif /* __KERNEL__ */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* _LINUX_THREAD_INFO_H */
|