]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/x86/kernel/cpu/bugs.c
x86/retpoline: Add initial retpoline support
[mirror_ubuntu-jammy-kernel.git] / arch / x86 / kernel / cpu / bugs.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1353ebb4 2/*
1353ebb4
JF
3 * Copyright (C) 1994 Linus Torvalds
4 *
5 * Cyrix stuff, June 1998 by:
6 * - Rafael R. Reilova (moved everything from head.S),
7 * <rreilova@ececs.uc.edu>
8 * - Channing Corn (tests & fixes),
9 * - Andrew D. Balsa (code cleanup).
10 */
11#include <linux/init.h>
12#include <linux/utsname.h>
61dc0f55 13#include <linux/cpu.h>
91eb1b79 14#include <asm/bugs.h>
1353ebb4 15#include <asm/processor.h>
7ebad705 16#include <asm/processor-flags.h>
952f07ec 17#include <asm/fpu/internal.h>
1353ebb4
JF
18#include <asm/msr.h>
19#include <asm/paravirt.h>
20#include <asm/alternative.h>
62a67e12 21#include <asm/pgtable.h>
d1163651 22#include <asm/set_memory.h>
1353ebb4 23
1353ebb4
JF
24void __init check_bugs(void)
25{
26 identify_boot_cpu();
55a36b65 27
62a67e12
BP
28 if (!IS_ENABLED(CONFIG_SMP)) {
29 pr_info("CPU: ");
30 print_cpu_info(&boot_cpu_data);
31 }
32
33#ifdef CONFIG_X86_32
55a36b65
BP
34 /*
35 * Check whether we are able to run this kernel safely on SMP.
36 *
37 * - i386 is no longer supported.
38 * - In order to run on anything without a TSC, we need to be
39 * compiled for a i486.
40 */
41 if (boot_cpu_data.x86 < 4)
42 panic("Kernel requires i486+ for 'invlpg' and other features");
43
bfe4bb15
MV
44 init_utsname()->machine[1] =
45 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
1353ebb4 46 alternative_instructions();
304bceda 47
4d164092 48 fpu__init_check_bugs();
62a67e12
BP
49#else /* CONFIG_X86_64 */
50 alternative_instructions();
51
52 /*
53 * Make sure the first 2MB area is not mapped by huge pages
54 * There are typically fixed size MTRRs in there and overlapping
55 * MTRRs into large pages causes slow downs.
56 *
57 * Right now we don't do that with gbpages because there seems
58 * very little benefit for that case.
59 */
60 if (!direct_gbpages)
61 set_memory_4k((unsigned long)__va(0), 1);
62#endif
1353ebb4 63}
61dc0f55
TG
64
65#ifdef CONFIG_SYSFS
66ssize_t cpu_show_meltdown(struct device *dev,
67 struct device_attribute *attr, char *buf)
68{
69 if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
70 return sprintf(buf, "Not affected\n");
71 if (boot_cpu_has(X86_FEATURE_PTI))
72 return sprintf(buf, "Mitigation: PTI\n");
73 return sprintf(buf, "Vulnerable\n");
74}
75
76ssize_t cpu_show_spectre_v1(struct device *dev,
77 struct device_attribute *attr, char *buf)
78{
79 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1))
80 return sprintf(buf, "Not affected\n");
81 return sprintf(buf, "Vulnerable\n");
82}
83
84ssize_t cpu_show_spectre_v2(struct device *dev,
85 struct device_attribute *attr, char *buf)
86{
87 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
88 return sprintf(buf, "Not affected\n");
89 return sprintf(buf, "Vulnerable\n");
90}
91#endif