* mark python sqlite DEP opt and update .cache
[t2sde.git] / package / kernel / linux / hotfix-i686-detect-nopl.patch
blob4d8239ef743136de417e2b5c8fe491d50168c033
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/linux/hotfix-i686-detect-nopl.patch
3 # Copyright (C) 2024 The T2 SDE Project
4 #
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7 #
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 While removed upstream, we do not really care about decade old
15 broken commercial virtualizers. Check for real hw and potentially
16 use it.
18 --- linux-6.8/arch/x86/kernel/cpu/common.c.vanilla 2024-03-26 20:38:26.748240700 +0100
19 +++ linux-6.8/arch/x86/kernel/cpu/common.c 2024-03-26 20:43:34.183225214 +0100
20 @@ -1488,16 +1488,30 @@
22 * The NOPL instruction is supposed to exist on all CPUs of family >= 6;
23 * unfortunately, that's not true in practice because of early VIA
24 - * chips and (more importantly) broken virtualizers that are not easy
25 - * to detect. In the latter case it doesn't even *fail* reliably, so
26 - * probing for it doesn't even work. Disable it completely on 32-bit
27 - * unless we can find a reliable way to detect all the broken cases.
28 - * Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
29 + * chips and broken virtualizers. Instead, probe for NOPL directly by
30 + * executing a NOPL instruction and see if we get #UD.
32 static void detect_nopl(void)
34 #ifdef CONFIG_X86_32
35 - setup_clear_cpu_cap(X86_FEATURE_NOPL);
36 + const u32 nopl_signature = 0x888c53b1; /* Random number */
37 + u32 has_nopl = nopl_signature;
39 + setup_clear_cpu_cap(X86_FEATURE_NOPL);
40 + if (boot_cpu_data.x86 >= 6) {
41 + asm volatile("\n"
42 + "1: .byte 0x0f,0x1f,0xc0\n" /* nopl %eax */
43 + "2:\n"
44 + " .section .fixup,\"ax\"\n"
45 + "3: xor %0,%0\n"
46 + " jmp 2b\n"
47 + " .previous\n"
48 + _ASM_EXTABLE(1b,3b)
49 + : "+a" (has_nopl));
51 + if (has_nopl == nopl_signature)
52 + setup_force_cpu_cap(X86_FEATURE_NOPL);
53 + }
54 #else
55 setup_force_cpu_cap(X86_FEATURE_NOPL);
56 #endif