forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/x86/include/asm/cpufeature.h
....@@ -8,6 +8,7 @@
88
99 #include <asm/asm.h>
1010 #include <linux/bitops.h>
11
+#include <asm/alternative.h>
1112
1213 enum cpuid_leafs
1314 {
....@@ -23,7 +24,7 @@
2324 CPUID_7_0_EBX,
2425 CPUID_D_1_EAX,
2526 CPUID_LNX_4,
26
- CPUID_DUMMY,
27
+ CPUID_7_1_EAX,
2728 CPUID_8000_0008_EBX,
2829 CPUID_6_EAX,
2930 CPUID_8000_000A_EDX,
....@@ -49,7 +50,7 @@
4950 extern const char * const x86_bug_flags[NBUGINTS*32];
5051
5152 #define test_cpu_cap(c, bit) \
52
- test_bit(bit, (unsigned long *)((c)->x86_capability))
53
+ arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
5354
5455 /*
5556 * There are 32 bits/features in each mask word. The high bits
....@@ -61,6 +62,13 @@
6162 #define CHECK_BIT_IN_MASK_WORD(maskname, word, bit) \
6263 (((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
6364
65
+/*
66
+ * {REQUIRED,DISABLED}_MASK_CHECK below may seem duplicated with the
67
+ * following BUILD_BUG_ON_ZERO() check but when NCAPINTS gets changed, all
68
+ * header macros which use NCAPINTS need to be changed. The duplicated macro
69
+ * use causes the compiler to issue errors for all headers so that all usage
70
+ * sites can be corrected.
71
+ */
6472 #define REQUIRED_MASK_BIT_SET(feature_bit) \
6573 ( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
6674 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
....@@ -112,8 +120,9 @@
112120 test_cpu_cap(c, bit))
113121
114122 #define this_cpu_has(bit) \
115
- (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
116
- x86_this_cpu_test_bit(bit, (unsigned long *)&cpu_info.x86_capability))
123
+ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
124
+ x86_this_cpu_test_bit(bit, \
125
+ (unsigned long __percpu *)&cpu_info.x86_capability))
117126
118127 /*
119128 * This macro is for detection of features which need kernel
....@@ -146,51 +155,33 @@
146155 * Workaround for the sake of BPF compilation which utilizes kernel
147156 * headers, but clang does not support ASM GOTO and fails the build.
148157 */
158
+#ifndef __BPF_TRACING__
159
+#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
160
+#endif
149161
150162 #define static_cpu_has(bit) boot_cpu_has(bit)
151163
152164 #else
153165
154166 /*
155
- * Static testing of CPU features. Used the same as boot_cpu_has().
156
- * These will statically patch the target code for additional
157
- * performance.
167
+ * Static testing of CPU features. Used the same as boot_cpu_has(). It
168
+ * statically patches the target code for additional performance. Use
169
+ * static_cpu_has() only in fast paths, where every cycle counts. Which
170
+ * means that the boot_cpu_has() variant is already fast enough for the
171
+ * majority of cases and you should stick to using it as it is generally
172
+ * only two instructions: a RIP-relative MOV and a TEST.
158173 */
159
-static __always_inline __pure bool _static_cpu_has(u16 bit)
174
+static __always_inline bool _static_cpu_has(u16 bit)
160175 {
161
- asm_volatile_goto("1: jmp 6f\n"
162
- "2:\n"
163
- ".skip -(((5f-4f) - (2b-1b)) > 0) * "
164
- "((5f-4f) - (2b-1b)),0x90\n"
165
- "3:\n"
166
- ".section .altinstructions,\"a\"\n"
167
- " .long 1b - .\n" /* src offset */
168
- " .long 4f - .\n" /* repl offset */
169
- " .word %P[always]\n" /* always replace */
170
- " .byte 3b - 1b\n" /* src len */
171
- " .byte 5f - 4f\n" /* repl len */
172
- " .byte 3b - 2b\n" /* pad len */
173
- ".previous\n"
174
- ".section .altinstr_replacement,\"ax\"\n"
175
- "4: jmp %l[t_no]\n"
176
- "5:\n"
177
- ".previous\n"
178
- ".section .altinstructions,\"a\"\n"
179
- " .long 1b - .\n" /* src offset */
180
- " .long 0\n" /* no replacement */
181
- " .word %P[feature]\n" /* feature bit */
182
- " .byte 3b - 1b\n" /* src len */
183
- " .byte 0\n" /* repl len */
184
- " .byte 0\n" /* pad len */
185
- ".previous\n"
186
- ".section .altinstr_aux,\"ax\"\n"
187
- "6:\n"
188
- " testb %[bitnum],%[cap_byte]\n"
189
- " jnz %l[t_yes]\n"
190
- " jmp %l[t_no]\n"
191
- ".previous\n"
176
+ asm_volatile_goto(
177
+ ALTERNATIVE_TERNARY("jmp 6f", %P[feature], "", "jmp %l[t_no]")
178
+ ".section .altinstr_aux,\"ax\"\n"
179
+ "6:\n"
180
+ " testb %[bitnum],%[cap_byte]\n"
181
+ " jnz %l[t_yes]\n"
182
+ " jmp %l[t_no]\n"
183
+ ".previous\n"
192184 : : [feature] "i" (bit),
193
- [always] "i" (X86_FEATURE_ALWAYS),
194185 [bitnum] "i" (1 << (bit & 7)),
195186 [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
196187 : : t_yes, t_no);