Skip to content

Commit 7c7077a

Browse files
committed
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
1 parent 7725aca commit 7c7077a

File tree

5 files changed

+56
-52
lines changed

5 files changed

+56
-52
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ config X86
7171
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
7272
select ARCH_HAS_CACHE_LINE_SIZE
7373
select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
74+
select ARCH_HAS_CPU_FINALIZE_INIT
7475
select ARCH_HAS_CURRENT_STACK_POINTER
7576
select ARCH_HAS_DEBUG_VIRTUAL
7677
select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE

arch/x86/include/asm/bugs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include <asm/processor.h>
66

7-
extern void check_bugs(void);
8-
97
#if defined(CONFIG_CPU_SUP_INTEL) && defined(CONFIG_X86_32)
108
int ppro_with_ram_bug(void);
119
#else

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* - Andrew D. Balsa (code cleanup).
1010
*/
1111
#include <linux/init.h>
12-
#include <linux/utsname.h>
1312
#include <linux/cpu.h>
1413
#include <linux/module.h>
1514
#include <linux/nospec.h>
@@ -27,8 +26,6 @@
2726
#include <asm/msr.h>
2827
#include <asm/vmx.h>
2928
#include <asm/paravirt.h>
30-
#include <asm/alternative.h>
31-
#include <asm/set_memory.h>
3229
#include <asm/intel-family.h>
3330
#include <asm/e820/api.h>
3431
#include <asm/hypervisor.h>
@@ -125,21 +122,8 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
125122
DEFINE_STATIC_KEY_FALSE(mmio_stale_data_clear);
126123
EXPORT_SYMBOL_GPL(mmio_stale_data_clear);
127124

128-
void __init check_bugs(void)
125+
void __init cpu_select_mitigations(void)
129126
{
130-
identify_boot_cpu();
131-
132-
/*
133-
* identify_boot_cpu() initialized SMT support information, let the
134-
* core code know.
135-
*/
136-
cpu_smt_check_topology();
137-
138-
if (!IS_ENABLED(CONFIG_SMP)) {
139-
pr_info("CPU: ");
140-
print_cpu_info(&boot_cpu_data);
141-
}
142-
143127
/*
144128
* Read the SPEC_CTRL MSR to account for reserved bits which may
145129
* have unknown values. AMD64_LS_CFG MSR is cached in the early AMD
@@ -176,39 +160,6 @@ void __init check_bugs(void)
176160
md_clear_select_mitigation();
177161
srbds_select_mitigation();
178162
l1d_flush_select_mitigation();
179-
180-
arch_smt_update();
181-
182-
#ifdef CONFIG_X86_32
183-
/*
184-
* Check whether we are able to run this kernel safely on SMP.
185-
*
186-
* - i386 is no longer supported.
187-
* - In order to run on anything without a TSC, we need to be
188-
* compiled for a i486.
189-
*/
190-
if (boot_cpu_data.x86 < 4)
191-
panic("Kernel requires i486+ for 'invlpg' and other features");
192-
193-
init_utsname()->machine[1] =
194-
'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
195-
alternative_instructions();
196-
197-
fpu__init_check_bugs();
198-
#else /* CONFIG_X86_64 */
199-
alternative_instructions();
200-
201-
/*
202-
* Make sure the first 2MB area is not mapped by huge pages
203-
* There are typically fixed size MTRRs in there and overlapping
204-
* MTRRs into large pages causes slow downs.
205-
*
206-
* Right now we don't do that with gbpages because there seems
207-
* very little benefit for that case.
208-
*/
209-
if (!direct_gbpages)
210-
set_memory_4k((unsigned long)__va(0), 1);
211-
#endif
212163
}
213164

214165
/*

arch/x86/kernel/cpu/common.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
#include <linux/kprobes.h>
2020
#include <linux/kgdb.h>
2121
#include <linux/smp.h>
22+
#include <linux/cpu.h>
2223
#include <linux/io.h>
2324
#include <linux/syscore_ops.h>
2425
#include <linux/pgtable.h>
2526
#include <linux/stackprotector.h>
27+
#include <linux/utsname.h>
2628

29+
#include <asm/alternative.h>
2730
#include <asm/cmdline.h>
2831
#include <asm/perf_event.h>
2932
#include <asm/mmu_context.h>
@@ -59,6 +62,7 @@
5962
#include <asm/intel-family.h>
6063
#include <asm/cpu_device_id.h>
6164
#include <asm/uv/uv.h>
65+
#include <asm/set_memory.h>
6266
#include <asm/sigframe.h>
6367
#include <asm/traps.h>
6468
#include <asm/sev.h>
@@ -2362,3 +2366,52 @@ void arch_smt_update(void)
23622366
/* Check whether IPI broadcasting can be enabled */
23632367
apic_smt_update();
23642368
}
2369+
2370+
void __init arch_cpu_finalize_init(void)
2371+
{
2372+
identify_boot_cpu();
2373+
2374+
/*
2375+
* identify_boot_cpu() initialized SMT support information, let the
2376+
* core code know.
2377+
*/
2378+
cpu_smt_check_topology();
2379+
2380+
if (!IS_ENABLED(CONFIG_SMP)) {
2381+
pr_info("CPU: ");
2382+
print_cpu_info(&boot_cpu_data);
2383+
}
2384+
2385+
cpu_select_mitigations();
2386+
2387+
arch_smt_update();
2388+
2389+
if (IS_ENABLED(CONFIG_X86_32)) {
2390+
/*
2391+
* Check whether this is a real i386 which is not longer
2392+
* supported and fixup the utsname.
2393+
*/
2394+
if (boot_cpu_data.x86 < 4)
2395+
panic("Kernel requires i486+ for 'invlpg' and other features");
2396+
2397+
init_utsname()->machine[1] =
2398+
'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
2399+
}
2400+
2401+
alternative_instructions();
2402+
2403+
if (IS_ENABLED(CONFIG_X86_64)) {
2404+
/*
2405+
* Make sure the first 2MB area is not mapped by huge pages
2406+
* There are typically fixed size MTRRs in there and overlapping
2407+
* MTRRs into large pages causes slow downs.
2408+
*
2409+
* Right now we don't do that with gbpages because there seems
2410+
* very little benefit for that case.
2411+
*/
2412+
if (!direct_gbpages)
2413+
set_memory_4k((unsigned long)__va(0), 1);
2414+
} else {
2415+
fpu__init_check_bugs();
2416+
}
2417+
}

arch/x86/kernel/cpu/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ extern void detect_ht(struct cpuinfo_x86 *c);
7979
extern void check_null_seg_clears_base(struct cpuinfo_x86 *c);
8080

8181
unsigned int aperfmperf_get_khz(int cpu);
82+
void cpu_select_mitigations(void);
8283

8384
extern void x86_spec_ctrl_setup_ap(void);
8485
extern void update_srbds_msr(void);

0 commit comments

Comments
 (0)