Skip to content

Commit c90399f

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/cpu: Ensure that CPU info updates are propagated on UP
The boot sequence evaluates CPUID information twice: 1) During early boot 2) When finalizing the early setup right before mitigations are selected and alternatives are patched. In both cases the evaluation is stored in boot_cpu_data, but on UP the copying of boot_cpu_data to the per CPU info of the boot CPU happens between #1 and #2. So any update which happens in #2 is never propagated to the per CPU info instance. Consolidate the whole logic and copy boot_cpu_data right before applying alternatives as that's the point where boot_cpu_data is in it's final state and not supposed to change anymore. This also removes the voodoo mb() from smp_prepare_cpus_common() which had absolutely no purpose. Fixes: 71eb489 ("x86/percpu: Cure per CPU madness on UP") Reported-by: Guenter Roeck <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4e51653 commit c90399f

File tree

3 files changed

+14
-37
lines changed

3 files changed

+14
-37
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,8 @@ void arch_smt_update(void)
23072307

23082308
void __init arch_cpu_finalize_init(void)
23092309
{
2310+
struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info);
2311+
23102312
identify_boot_cpu();
23112313

23122314
select_idle_routine();
@@ -2345,6 +2347,13 @@ void __init arch_cpu_finalize_init(void)
23452347
fpu__init_system();
23462348
fpu__init_cpu();
23472349

2350+
/*
2351+
* Ensure that access to the per CPU representation has the initial
2352+
* boot CPU configuration.
2353+
*/
2354+
*c = boot_cpu_data;
2355+
c->initialized = true;
2356+
23482357
alternative_instructions();
23492358

23502359
if (IS_ENABLED(CONFIG_X86_64)) {

arch/x86/kernel/setup.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,16 +1206,6 @@ void __init i386_reserve_resources(void)
12061206

12071207
#endif /* CONFIG_X86_32 */
12081208

1209-
#ifndef CONFIG_SMP
1210-
void __init smp_prepare_boot_cpu(void)
1211-
{
1212-
struct cpuinfo_x86 *c = &cpu_data(0);
1213-
1214-
*c = boot_cpu_data;
1215-
c->initialized = true;
1216-
}
1217-
#endif
1218-
12191209
static struct notifier_block kernel_offset_notifier = {
12201210
.notifier_call = dump_kernel_offset
12211211
};

arch/x86/kernel/smpboot.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,6 @@ static void notrace start_secondary(void *unused)
313313
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
314314
}
315315

316-
static void __init smp_store_boot_cpu_info(void)
317-
{
318-
struct cpuinfo_x86 *c = &cpu_data(0);
319-
320-
*c = boot_cpu_data;
321-
c->initialized = true;
322-
}
323-
324316
/*
325317
* The bootstrap kernel entry code has set these up. Save them for
326318
* a given CPU
@@ -1039,29 +1031,15 @@ static __init void disable_smp(void)
10391031
cpumask_set_cpu(0, topology_die_cpumask(0));
10401032
}
10411033

1042-
static void __init smp_cpu_index_default(void)
1043-
{
1044-
int i;
1045-
struct cpuinfo_x86 *c;
1046-
1047-
for_each_possible_cpu(i) {
1048-
c = &cpu_data(i);
1049-
/* mark all to hotplug */
1050-
c->cpu_index = nr_cpu_ids;
1051-
}
1052-
}
1053-
10541034
void __init smp_prepare_cpus_common(void)
10551035
{
10561036
unsigned int i;
10571037

1058-
smp_cpu_index_default();
1059-
1060-
/*
1061-
* Setup boot CPU information
1062-
*/
1063-
smp_store_boot_cpu_info(); /* Final full version of the data */
1064-
mb();
1038+
/* Mark all except the boot CPU as hotpluggable */
1039+
for_each_possible_cpu(i) {
1040+
if (i)
1041+
per_cpu(cpu_info.cpu_index, i) = nr_cpu_ids;
1042+
}
10651043

10661044
for_each_possible_cpu(i) {
10671045
zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);

0 commit comments

Comments
 (0)