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 */
|
2008-10-23 05:26:29 +00:00
|
|
|
#ifndef _ASM_X86_CPUFEATURE_H
|
|
|
|
#define _ASM_X86_CPUFEATURE_H
|
2008-01-30 12:30:07 +00:00
|
|
|
|
2018-10-05 20:27:17 +00:00
|
|
|
#include <asm/processor.h>
|
2018-12-19 10:20:30 +00:00
|
|
|
|
|
|
|
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
|
|
|
|
|
2010-05-12 00:47:07 +00:00
|
|
|
#include <asm/asm.h>
|
2008-02-04 15:48:00 +00:00
|
|
|
#include <linux/bitops.h>
|
2021-03-11 14:23:12 +00:00
|
|
|
#include <asm/alternative.h>
|
2008-02-04 15:48:00 +00:00
|
|
|
|
2015-12-07 09:39:40 +00:00
|
|
|
enum cpuid_leafs
|
|
|
|
{
|
|
|
|
CPUID_1_EDX = 0,
|
|
|
|
CPUID_8000_0001_EDX,
|
|
|
|
CPUID_8086_0001_EDX,
|
|
|
|
CPUID_LNX_1,
|
|
|
|
CPUID_1_ECX,
|
|
|
|
CPUID_C000_0001_EDX,
|
|
|
|
CPUID_8000_0001_ECX,
|
|
|
|
CPUID_LNX_2,
|
|
|
|
CPUID_LNX_3,
|
|
|
|
CPUID_7_0_EBX,
|
|
|
|
CPUID_D_1_EAX,
|
2019-06-19 16:51:09 +00:00
|
|
|
CPUID_LNX_4,
|
2019-06-17 18:00:16 +00:00
|
|
|
CPUID_7_1_EAX,
|
2015-12-07 09:39:40 +00:00
|
|
|
CPUID_8000_0008_EBX,
|
|
|
|
CPUID_6_EAX,
|
|
|
|
CPUID_8000_000A_EDX,
|
x86/cpufeature, x86/mm/pkeys: Add protection keys related CPUID definitions
There are two CPUID bits for protection keys. One is for whether
the CPU contains the feature, and the other will appear set once
the OS enables protection keys. Specifically:
Bit 04: OSPKE. If 1, OS has set CR4.PKE to enable
Protection keys (and the RDPKRU/WRPKRU instructions)
This is because userspace can not see CR4 contents, but it can
see CPUID contents.
X86_FEATURE_PKU is referred to as "PKU" in the hardware documentation:
CPUID.(EAX=07H,ECX=0H):ECX.PKU [bit 3]
X86_FEATURE_OSPKE is "OSPKU":
CPUID.(EAX=07H,ECX=0H):ECX.OSPKE [bit 4]
These are the first CPU features which need to look at the
ECX word in CPUID leaf 0x7, so this patch also includes
fetching that word in to the cpuinfo->x86_capability[] array.
Add it to the disabled-features mask when its config option is
off. Even though we are not using it here, we also extend the
REQUIRED_MASK_BIT_SET() macro to keep it mirroring the
DISABLED_MASK_BIT_SET() version.
This means that in almost all code, you should use:
cpu_has(c, X86_FEATURE_PKU)
and *not* the CONFIG option.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20160212210201.7714C250@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-12 21:02:01 +00:00
|
|
|
CPUID_7_ECX,
|
2016-05-11 12:58:26 +00:00
|
|
|
CPUID_8000_0007_EBX,
|
2018-01-25 16:14:09 +00:00
|
|
|
CPUID_7_EDX,
|
2021-01-22 20:40:46 +00:00
|
|
|
CPUID_8000_001F_EAX,
|
2015-12-07 09:39:40 +00:00
|
|
|
};
|
|
|
|
|
2013-10-30 15:09:45 +00:00
|
|
|
#ifdef CONFIG_X86_FEATURE_NAMES
|
2008-02-04 15:48:00 +00:00
|
|
|
extern const char * const x86_cap_flags[NCAPINTS*32];
|
|
|
|
extern const char * const x86_power_flags[32];
|
2013-10-30 15:09:45 +00:00
|
|
|
#define X86_CAP_FMT "%s"
|
|
|
|
#define x86_cap_flag(flag) x86_cap_flags[flag]
|
|
|
|
#else
|
|
|
|
#define X86_CAP_FMT "%d:%d"
|
|
|
|
#define x86_cap_flag(flag) ((flag) >> 5), ((flag) & 31)
|
|
|
|
#endif
|
2008-02-04 15:48:00 +00:00
|
|
|
|
2014-06-24 11:25:03 +00:00
|
|
|
/*
|
|
|
|
* In order to save room, we index into this array by doing
|
|
|
|
* X86_BUG_<name> - NCAPINTS*32.
|
|
|
|
*/
|
|
|
|
extern const char * const x86_bug_flags[NBUGINTS*32];
|
|
|
|
|
2008-02-26 07:34:21 +00:00
|
|
|
#define test_cpu_cap(c, bit) \
|
|
|
|
test_bit(bit, (unsigned long *)((c)->x86_capability))
|
|
|
|
|
2016-06-29 20:01:10 +00:00
|
|
|
/*
|
|
|
|
* There are 32 bits/features in each mask word. The high bits
|
|
|
|
* (selected with (bit>>5) give us the word number and the low 5
|
|
|
|
* bits give us the bit/feature number inside the word.
|
|
|
|
* (1UL<<((bit)&31) gives us a mask for the feature_bit so we can
|
|
|
|
* see if it is set in the mask word.
|
|
|
|
*/
|
|
|
|
#define CHECK_BIT_IN_MASK_WORD(maskname, word, bit) \
|
|
|
|
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
|
|
|
|
|
2019-08-28 06:11:00 +00:00
|
|
|
/*
|
|
|
|
* {REQUIRED,DISABLED}_MASK_CHECK below may seem duplicated with the
|
|
|
|
* following BUILD_BUG_ON_ZERO() check but when NCAPINTS gets changed, all
|
|
|
|
* header macros which use NCAPINTS need to be changed. The duplicated macro
|
|
|
|
* use causes the compiler to issue errors for all headers so that all usage
|
|
|
|
* sites can be corrected.
|
|
|
|
*/
|
2016-06-29 20:01:10 +00:00
|
|
|
#define REQUIRED_MASK_BIT_SET(feature_bit) \
|
|
|
|
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 4, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 5, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 6, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 7, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 8, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 9, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 10, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 11, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 12, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 13, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 14, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 15, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \
|
2018-01-25 16:14:09 +00:00
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \
|
2021-01-22 20:40:46 +00:00
|
|
|
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \
|
2016-06-29 20:01:10 +00:00
|
|
|
REQUIRED_MASK_CHECK || \
|
2021-01-22 20:40:46 +00:00
|
|
|
BUILD_BUG_ON_ZERO(NCAPINTS != 20))
|
2011-03-12 11:50:10 +00:00
|
|
|
|
2016-06-29 20:01:10 +00:00
|
|
|
#define DISABLED_MASK_BIT_SET(feature_bit) \
|
|
|
|
( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 1, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 2, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 3, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 4, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 5, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 6, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 7, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 8, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 9, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 10, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 11, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 12, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 13, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 14, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 15, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) || \
|
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \
|
2018-01-25 16:14:09 +00:00
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \
|
2021-01-22 20:40:46 +00:00
|
|
|
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \
|
2016-06-29 20:01:10 +00:00
|
|
|
DISABLED_MASK_CHECK || \
|
2021-01-22 20:40:46 +00:00
|
|
|
BUILD_BUG_ON_ZERO(NCAPINTS != 20))
|
x86: Introduce disabled-features
I believe the REQUIRED_MASK aproach was taken so that it was
easier to consult in assembly (arch/x86/kernel/verify_cpu.S).
DISABLED_MASK does not have the same restriction, but I
implemented it the same way for consistency.
We have a REQUIRED_MASK... which does two things:
1. Keeps a list of cpuid bits to check in very early boot and
refuse to boot if those are not present.
2. Consulted during cpu_has() checks, which allows us to
optimize out things at compile-time. In other words, if we
*KNOW* we will not boot with the feature off, then we can
safely assume that it will be present forever.
But, we don't have a similar mechanism for CPU features which
may be present but that we know we will not use. We simply
use our existing mechanisms to repeatedly check the status of
the bit at runtime (well, the alternatives patching helps here
but it does not provide compile-time optimization).
Adding a feature to disabled-features.h allows the bit to be
checked via a new macro: cpu_feature_enabled(). Note that
for features in DISABLED_MASK, checks with this macro have
all of the benefits of an #ifdef. Before, we would have done
this in a header:
#ifdef CONFIG_X86_INTEL_MPX
#define cpu_has_mpx cpu_has(X86_FEATURE_MPX)
#else
#define cpu_has_mpx 0
#endif
and this in the code:
if (cpu_has_mpx)
do_some_mpx_thing();
Now, just add your feature to DISABLED_MASK and you can do this
everywhere, and get the same benefits you would have from
#ifdefs:
if (cpu_feature_enabled(X86_FEATURE_MPX))
do_some_mpx_thing();
We need a new function and *not* a modification to cpu_has()
because there are cases where we actually need to check the CPU
itself, despite what features the kernel supports. The best
example of this is a hypervisor which has no control over what
features its guests are using and where the guest does not depend
on the host for support.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: http://lkml.kernel.org/r/20140911211513.9E35E931@viggo.jf.intel.com
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-09-11 21:15:13 +00:00
|
|
|
|
2011-03-12 11:50:10 +00:00
|
|
|
#define cpu_has(c, bit) \
|
|
|
|
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
|
2008-02-26 07:34:21 +00:00
|
|
|
test_cpu_cap(c, bit))
|
|
|
|
|
2011-03-12 11:50:10 +00:00
|
|
|
#define this_cpu_has(bit) \
|
2019-03-28 15:49:48 +00:00
|
|
|
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
|
|
|
|
x86_this_cpu_test_bit(bit, \
|
|
|
|
(unsigned long __percpu *)&cpu_info.x86_capability))
|
2011-03-12 11:50:10 +00:00
|
|
|
|
x86: Introduce disabled-features
I believe the REQUIRED_MASK aproach was taken so that it was
easier to consult in assembly (arch/x86/kernel/verify_cpu.S).
DISABLED_MASK does not have the same restriction, but I
implemented it the same way for consistency.
We have a REQUIRED_MASK... which does two things:
1. Keeps a list of cpuid bits to check in very early boot and
refuse to boot if those are not present.
2. Consulted during cpu_has() checks, which allows us to
optimize out things at compile-time. In other words, if we
*KNOW* we will not boot with the feature off, then we can
safely assume that it will be present forever.
But, we don't have a similar mechanism for CPU features which
may be present but that we know we will not use. We simply
use our existing mechanisms to repeatedly check the status of
the bit at runtime (well, the alternatives patching helps here
but it does not provide compile-time optimization).
Adding a feature to disabled-features.h allows the bit to be
checked via a new macro: cpu_feature_enabled(). Note that
for features in DISABLED_MASK, checks with this macro have
all of the benefits of an #ifdef. Before, we would have done
this in a header:
#ifdef CONFIG_X86_INTEL_MPX
#define cpu_has_mpx cpu_has(X86_FEATURE_MPX)
#else
#define cpu_has_mpx 0
#endif
and this in the code:
if (cpu_has_mpx)
do_some_mpx_thing();
Now, just add your feature to DISABLED_MASK and you can do this
everywhere, and get the same benefits you would have from
#ifdefs:
if (cpu_feature_enabled(X86_FEATURE_MPX))
do_some_mpx_thing();
We need a new function and *not* a modification to cpu_has()
because there are cases where we actually need to check the CPU
itself, despite what features the kernel supports. The best
example of this is a hypervisor which has no control over what
features its guests are using and where the guest does not depend
on the host for support.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: http://lkml.kernel.org/r/20140911211513.9E35E931@viggo.jf.intel.com
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-09-11 21:15:13 +00:00
|
|
|
/*
|
|
|
|
* This macro is for detection of features which need kernel
|
|
|
|
* infrastructure to be used. It may *not* directly test the CPU
|
|
|
|
* itself. Use the cpu_has() family if you want true runtime
|
|
|
|
* testing of CPU features, like in hypervisor code where you are
|
|
|
|
* supporting a possible guest feature where host support for it
|
|
|
|
* is not relevant.
|
|
|
|
*/
|
|
|
|
#define cpu_feature_enabled(bit) \
|
2016-02-15 23:19:18 +00:00
|
|
|
(__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : static_cpu_has(bit))
|
x86: Introduce disabled-features
I believe the REQUIRED_MASK aproach was taken so that it was
easier to consult in assembly (arch/x86/kernel/verify_cpu.S).
DISABLED_MASK does not have the same restriction, but I
implemented it the same way for consistency.
We have a REQUIRED_MASK... which does two things:
1. Keeps a list of cpuid bits to check in very early boot and
refuse to boot if those are not present.
2. Consulted during cpu_has() checks, which allows us to
optimize out things at compile-time. In other words, if we
*KNOW* we will not boot with the feature off, then we can
safely assume that it will be present forever.
But, we don't have a similar mechanism for CPU features which
may be present but that we know we will not use. We simply
use our existing mechanisms to repeatedly check the status of
the bit at runtime (well, the alternatives patching helps here
but it does not provide compile-time optimization).
Adding a feature to disabled-features.h allows the bit to be
checked via a new macro: cpu_feature_enabled(). Note that
for features in DISABLED_MASK, checks with this macro have
all of the benefits of an #ifdef. Before, we would have done
this in a header:
#ifdef CONFIG_X86_INTEL_MPX
#define cpu_has_mpx cpu_has(X86_FEATURE_MPX)
#else
#define cpu_has_mpx 0
#endif
and this in the code:
if (cpu_has_mpx)
do_some_mpx_thing();
Now, just add your feature to DISABLED_MASK and you can do this
everywhere, and get the same benefits you would have from
#ifdefs:
if (cpu_feature_enabled(X86_FEATURE_MPX))
do_some_mpx_thing();
We need a new function and *not* a modification to cpu_has()
because there are cases where we actually need to check the CPU
itself, despite what features the kernel supports. The best
example of this is a hypervisor which has no control over what
features its guests are using and where the guest does not depend
on the host for support.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: http://lkml.kernel.org/r/20140911211513.9E35E931@viggo.jf.intel.com
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-09-11 21:15:13 +00:00
|
|
|
|
2008-01-30 12:30:07 +00:00
|
|
|
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
|
|
|
|
|
2008-01-30 12:30:55 +00:00
|
|
|
#define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability))
|
2017-10-13 21:56:42 +00:00
|
|
|
|
|
|
|
extern void setup_clear_cpu_cap(unsigned int bit);
|
|
|
|
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
|
|
|
|
|
2008-01-30 12:33:20 +00:00
|
|
|
#define setup_force_cpu_cap(bit) do { \
|
|
|
|
set_cpu_cap(&boot_cpu_data, bit); \
|
2009-05-10 06:47:42 +00:00
|
|
|
set_bit(bit, (unsigned long *)cpu_caps_set); \
|
2008-01-30 12:33:20 +00:00
|
|
|
} while (0)
|
2008-01-30 12:30:55 +00:00
|
|
|
|
2017-12-04 14:07:32 +00:00
|
|
|
#define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)
|
|
|
|
|
2018-12-30 15:14:15 +00:00
|
|
|
#if defined(__clang__) && !defined(CONFIG_CC_HAS_ASM_GOTO)
|
2018-05-13 19:32:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Workaround for the sake of BPF compilation which utilizes kernel
|
|
|
|
* headers, but clang does not support ASM GOTO and fails the build.
|
|
|
|
*/
|
|
|
|
#ifndef __BPF_TRACING__
|
|
|
|
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define static_cpu_has(bit) boot_cpu_has(bit)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-05-12 00:47:07 +00:00
|
|
|
/*
|
2019-03-29 18:35:24 +00:00
|
|
|
* Static testing of CPU features. Used the same as boot_cpu_has(). It
|
|
|
|
* statically patches the target code for additional performance. Use
|
|
|
|
* static_cpu_has() only in fast paths, where every cycle counts. Which
|
|
|
|
* means that the boot_cpu_has() variant is already fast enough for the
|
|
|
|
* majority of cases and you should stick to using it as it is generally
|
|
|
|
* only two instructions: a RIP-relative MOV and a TEST.
|
2010-05-12 00:47:07 +00:00
|
|
|
*/
|
2019-03-07 14:54:51 +00:00
|
|
|
static __always_inline bool _static_cpu_has(u16 bit)
|
2013-06-09 10:07:33 +00:00
|
|
|
{
|
2021-03-11 14:23:12 +00:00
|
|
|
asm_volatile_goto(
|
|
|
|
ALTERNATIVE_TERNARY("jmp 6f", %P[feature], "", "jmp %l[t_no]")
|
|
|
|
".section .altinstr_aux,\"ax\"\n"
|
|
|
|
"6:\n"
|
|
|
|
" testb %[bitnum],%[cap_byte]\n"
|
|
|
|
" jnz %l[t_yes]\n"
|
|
|
|
" jmp %l[t_no]\n"
|
|
|
|
".previous\n"
|
2018-01-16 08:34:01 +00:00
|
|
|
: : [feature] "i" (bit),
|
|
|
|
[bitnum] "i" (1 << (bit & 7)),
|
2018-01-15 16:21:48 +00:00
|
|
|
[cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
|
|
|
|
: : t_yes, t_no);
|
|
|
|
t_yes:
|
|
|
|
return true;
|
|
|
|
t_no:
|
|
|
|
return false;
|
2013-06-09 10:07:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 21:12:05 +00:00
|
|
|
#define static_cpu_has(bit) \
|
2013-06-09 10:07:33 +00:00
|
|
|
( \
|
|
|
|
__builtin_constant_p(boot_cpu_has(bit)) ? \
|
|
|
|
boot_cpu_has(bit) : \
|
2016-01-26 21:12:05 +00:00
|
|
|
_static_cpu_has(bit) \
|
2013-06-09 10:07:33 +00:00
|
|
|
)
|
2018-05-13 19:32:22 +00:00
|
|
|
#endif
|
2010-05-12 00:47:07 +00:00
|
|
|
|
2014-06-17 22:06:23 +00:00
|
|
|
#define cpu_has_bug(c, bit) cpu_has(c, (bit))
|
|
|
|
#define set_cpu_bug(c, bit) set_cpu_cap(c, (bit))
|
|
|
|
#define clear_cpu_bug(c, bit) clear_cpu_cap(c, (bit))
|
2013-03-20 14:07:23 +00:00
|
|
|
|
2014-06-17 22:06:23 +00:00
|
|
|
#define static_cpu_has_bug(bit) static_cpu_has((bit))
|
|
|
|
#define boot_cpu_has_bug(bit) cpu_has_bug(&boot_cpu_data, (bit))
|
2016-12-09 18:29:08 +00:00
|
|
|
#define boot_cpu_set_bug(bit) set_cpu_cap(&boot_cpu_data, (bit))
|
2013-03-20 14:07:23 +00:00
|
|
|
|
2014-06-17 22:06:23 +00:00
|
|
|
#define MAX_CPU_FEATURES (NCAPINTS * 32)
|
|
|
|
#define cpu_have_feature boot_cpu_has
|
2014-02-08 12:34:10 +00:00
|
|
|
|
2014-06-17 22:06:23 +00:00
|
|
|
#define CPU_FEATURE_TYPEFMT "x86,ven%04Xfam%04Xmod%04X"
|
|
|
|
#define CPU_FEATURE_TYPEVAL boot_cpu_data.x86_vendor, boot_cpu_data.x86, \
|
|
|
|
boot_cpu_data.x86_model
|
2014-02-08 12:34:10 +00:00
|
|
|
|
2018-12-19 10:20:30 +00:00
|
|
|
#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
|
2008-10-23 05:26:29 +00:00
|
|
|
#endif /* _ASM_X86_CPUFEATURE_H */
|