9dd7462461
by cherry-picking the relevant commits from launchpad/lunar [0]. (relevant commits are based on k.o/stable commits for this) minimally tested by booting my (ryzen) machine with this kernel and skimming through dmesg after boot. [0] git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/lunar Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
236 lines
6.9 KiB
Diff
236 lines
6.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Thomas Gleixner <tglx@linutronix.de>
|
|
Date: Wed, 14 Jun 2023 01:39:24 +0200
|
|
Subject: [PATCH] x86/cpu: Switch to arch_cpu_finalize_init()
|
|
|
|
check_bugs() is a dumping ground for finalizing the CPU bringup. Only parts of
|
|
it has to do with actual CPU bugs.
|
|
|
|
Split it apart into arch_cpu_finalize_init() and cpu_select_mitigations().
|
|
|
|
Fixup the bogus 32bit comments while at it.
|
|
|
|
No functional change.
|
|
|
|
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
|
|
Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
|
|
Link: https://lore.kernel.org/r/20230613224545.019583869@linutronix.de
|
|
|
|
(cherry picked from commit 7c7077a72674402654f3291354720cd73cdf649e)
|
|
CVE-2022-40982
|
|
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
|
|
Acked-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
|
|
Acked-by: Stefan Bader <stefan.bader@canonical.com>
|
|
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
|
|
(cherry picked from commit d839524be6ba339640b7729353ff14156fad42a7)
|
|
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
|
|
---
|
|
arch/x86/Kconfig | 1 +
|
|
arch/x86/include/asm/bugs.h | 2 --
|
|
arch/x86/kernel/cpu/bugs.c | 51 +---------------------------------
|
|
arch/x86/kernel/cpu/common.c | 53 ++++++++++++++++++++++++++++++++++++
|
|
arch/x86/kernel/cpu/cpu.h | 1 +
|
|
5 files changed, 56 insertions(+), 52 deletions(-)
|
|
|
|
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
|
|
index df9e15bcf6d1..598a303819da 100644
|
|
--- a/arch/x86/Kconfig
|
|
+++ b/arch/x86/Kconfig
|
|
@@ -70,6 +70,7 @@ config X86
|
|
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
|
|
select ARCH_HAS_CACHE_LINE_SIZE
|
|
select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|
|
+ select ARCH_HAS_CPU_FINALIZE_INIT
|
|
select ARCH_HAS_CURRENT_STACK_POINTER
|
|
select ARCH_HAS_DEBUG_VIRTUAL
|
|
select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE
|
|
diff --git a/arch/x86/include/asm/bugs.h b/arch/x86/include/asm/bugs.h
|
|
index 92ae28389940..f25ca2d709d4 100644
|
|
--- a/arch/x86/include/asm/bugs.h
|
|
+++ b/arch/x86/include/asm/bugs.h
|
|
@@ -4,8 +4,6 @@
|
|
|
|
#include <asm/processor.h>
|
|
|
|
-extern void check_bugs(void);
|
|
-
|
|
#if defined(CONFIG_CPU_SUP_INTEL) && defined(CONFIG_X86_32)
|
|
int ppro_with_ram_bug(void);
|
|
#else
|
|
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
|
|
index daad10e7665b..edb670b77294 100644
|
|
--- a/arch/x86/kernel/cpu/bugs.c
|
|
+++ b/arch/x86/kernel/cpu/bugs.c
|
|
@@ -9,7 +9,6 @@
|
|
* - Andrew D. Balsa (code cleanup).
|
|
*/
|
|
#include <linux/init.h>
|
|
-#include <linux/utsname.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/module.h>
|
|
#include <linux/nospec.h>
|
|
@@ -27,8 +26,6 @@
|
|
#include <asm/msr.h>
|
|
#include <asm/vmx.h>
|
|
#include <asm/paravirt.h>
|
|
-#include <asm/alternative.h>
|
|
-#include <asm/set_memory.h>
|
|
#include <asm/intel-family.h>
|
|
#include <asm/e820/api.h>
|
|
#include <asm/hypervisor.h>
|
|
@@ -124,21 +121,8 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
|
|
DEFINE_STATIC_KEY_FALSE(mmio_stale_data_clear);
|
|
EXPORT_SYMBOL_GPL(mmio_stale_data_clear);
|
|
|
|
-void __init check_bugs(void)
|
|
+void __init cpu_select_mitigations(void)
|
|
{
|
|
- identify_boot_cpu();
|
|
-
|
|
- /*
|
|
- * identify_boot_cpu() initialized SMT support information, let the
|
|
- * core code know.
|
|
- */
|
|
- cpu_smt_check_topology();
|
|
-
|
|
- if (!IS_ENABLED(CONFIG_SMP)) {
|
|
- pr_info("CPU: ");
|
|
- print_cpu_info(&boot_cpu_data);
|
|
- }
|
|
-
|
|
/*
|
|
* Read the SPEC_CTRL MSR to account for reserved bits which may
|
|
* have unknown values. AMD64_LS_CFG MSR is cached in the early AMD
|
|
@@ -175,39 +159,6 @@ void __init check_bugs(void)
|
|
md_clear_select_mitigation();
|
|
srbds_select_mitigation();
|
|
l1d_flush_select_mitigation();
|
|
-
|
|
- arch_smt_update();
|
|
-
|
|
-#ifdef CONFIG_X86_32
|
|
- /*
|
|
- * Check whether we are able to run this kernel safely on SMP.
|
|
- *
|
|
- * - i386 is no longer supported.
|
|
- * - In order to run on anything without a TSC, we need to be
|
|
- * compiled for a i486.
|
|
- */
|
|
- if (boot_cpu_data.x86 < 4)
|
|
- panic("Kernel requires i486+ for 'invlpg' and other features");
|
|
-
|
|
- init_utsname()->machine[1] =
|
|
- '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
|
|
- alternative_instructions();
|
|
-
|
|
- fpu__init_check_bugs();
|
|
-#else /* CONFIG_X86_64 */
|
|
- alternative_instructions();
|
|
-
|
|
- /*
|
|
- * Make sure the first 2MB area is not mapped by huge pages
|
|
- * There are typically fixed size MTRRs in there and overlapping
|
|
- * MTRRs into large pages causes slow downs.
|
|
- *
|
|
- * Right now we don't do that with gbpages because there seems
|
|
- * very little benefit for that case.
|
|
- */
|
|
- if (!direct_gbpages)
|
|
- set_memory_4k((unsigned long)__va(0), 1);
|
|
-#endif
|
|
}
|
|
|
|
/*
|
|
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
|
|
index 2ac8ceae0ed1..0f32ecfbdeb1 100644
|
|
--- a/arch/x86/kernel/cpu/common.c
|
|
+++ b/arch/x86/kernel/cpu/common.c
|
|
@@ -19,11 +19,14 @@
|
|
#include <linux/kprobes.h>
|
|
#include <linux/kgdb.h>
|
|
#include <linux/smp.h>
|
|
+#include <linux/cpu.h>
|
|
#include <linux/io.h>
|
|
#include <linux/syscore_ops.h>
|
|
#include <linux/pgtable.h>
|
|
#include <linux/stackprotector.h>
|
|
+#include <linux/utsname.h>
|
|
|
|
+#include <asm/alternative.h>
|
|
#include <asm/cmdline.h>
|
|
#include <asm/perf_event.h>
|
|
#include <asm/mmu_context.h>
|
|
@@ -59,6 +62,7 @@
|
|
#include <asm/intel-family.h>
|
|
#include <asm/cpu_device_id.h>
|
|
#include <asm/uv/uv.h>
|
|
+#include <asm/set_memory.h>
|
|
#include <asm/sigframe.h>
|
|
#include <asm/traps.h>
|
|
#include <asm/sev.h>
|
|
@@ -2360,3 +2364,52 @@ void arch_smt_update(void)
|
|
/* Check whether IPI broadcasting can be enabled */
|
|
apic_smt_update();
|
|
}
|
|
+
|
|
+void __init arch_cpu_finalize_init(void)
|
|
+{
|
|
+ identify_boot_cpu();
|
|
+
|
|
+ /*
|
|
+ * identify_boot_cpu() initialized SMT support information, let the
|
|
+ * core code know.
|
|
+ */
|
|
+ cpu_smt_check_topology();
|
|
+
|
|
+ if (!IS_ENABLED(CONFIG_SMP)) {
|
|
+ pr_info("CPU: ");
|
|
+ print_cpu_info(&boot_cpu_data);
|
|
+ }
|
|
+
|
|
+ cpu_select_mitigations();
|
|
+
|
|
+ arch_smt_update();
|
|
+
|
|
+ if (IS_ENABLED(CONFIG_X86_32)) {
|
|
+ /*
|
|
+ * Check whether this is a real i386 which is not longer
|
|
+ * supported and fixup the utsname.
|
|
+ */
|
|
+ if (boot_cpu_data.x86 < 4)
|
|
+ panic("Kernel requires i486+ for 'invlpg' and other features");
|
|
+
|
|
+ init_utsname()->machine[1] =
|
|
+ '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
|
|
+ }
|
|
+
|
|
+ alternative_instructions();
|
|
+
|
|
+ if (IS_ENABLED(CONFIG_X86_64)) {
|
|
+ /*
|
|
+ * Make sure the first 2MB area is not mapped by huge pages
|
|
+ * There are typically fixed size MTRRs in there and overlapping
|
|
+ * MTRRs into large pages causes slow downs.
|
|
+ *
|
|
+ * Right now we don't do that with gbpages because there seems
|
|
+ * very little benefit for that case.
|
|
+ */
|
|
+ if (!direct_gbpages)
|
|
+ set_memory_4k((unsigned long)__va(0), 1);
|
|
+ } else {
|
|
+ fpu__init_check_bugs();
|
|
+ }
|
|
+}
|
|
diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h
|
|
index 7c9b5893c30a..61dbb9b216e6 100644
|
|
--- a/arch/x86/kernel/cpu/cpu.h
|
|
+++ b/arch/x86/kernel/cpu/cpu.h
|
|
@@ -79,6 +79,7 @@ extern void detect_ht(struct cpuinfo_x86 *c);
|
|
extern void check_null_seg_clears_base(struct cpuinfo_x86 *c);
|
|
|
|
unsigned int aperfmperf_get_khz(int cpu);
|
|
+void cpu_select_mitigations(void);
|
|
|
|
extern void x86_spec_ctrl_setup_ap(void);
|
|
extern void update_srbds_msr(void);
|