Skip to content

Commit 71eb489

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/percpu: Cure per CPU madness on UP
On UP builds Sparse complains rightfully about accesses to cpu_info with per CPU accessors: cacheinfo.c:282:30: sparse: warning: incorrect type in initializer (different address spaces) cacheinfo.c:282:30: sparse: expected void const [noderef] __percpu *__vpp_verify cacheinfo.c:282:30: sparse: got unsigned int * The reason is that on UP builds cpu_info which is a per CPU variable on SMP is mapped to boot_cpu_info which is a regular variable. There is a hideous accessor cpu_data() which tries to hide this, but it's not sufficient as some places require raw accessors and generates worse code than the regular per CPU accessors. Waste sizeof(struct x86_cpuinfo) memory on UP and provide the per CPU cpu_info unconditionally. This requires to update the CPU info on the boot CPU as SMP does. (Ab)use the weakly defined smp_prepare_boot_cpu() function and implement exactly that. This allows to use regular per CPU accessors uncoditionally and paves the way to remove the cpu_data() hackery. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7126107 commit 71eb489

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,8 @@ extern struct cpuinfo_x86 new_cpu_data;
185185
extern __u32 cpu_caps_cleared[NCAPINTS + NBUGINTS];
186186
extern __u32 cpu_caps_set[NCAPINTS + NBUGINTS];
187187

188-
#ifdef CONFIG_SMP
189188
DECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
190189
#define cpu_data(cpu) per_cpu(cpu_info, cpu)
191-
#else
192-
#define cpu_info boot_cpu_data
193-
#define cpu_data(cpu) boot_cpu_data
194-
#endif
195190

196191
extern const struct seq_operations cpuinfo_op;
197192

arch/x86/kernel/cpu/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070

7171
#include "cpu.h"
7272

73+
DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
74+
EXPORT_PER_CPU_SYMBOL(cpu_info);
75+
7376
u32 elf_hwcap2 __read_mostly;
7477

7578
/* Number of siblings per CPU package */

arch/x86/kernel/setup.c

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

12121212
#endif /* CONFIG_X86_32 */
12131213

1214+
#ifndef CONFIG_SMP
1215+
void __init smp_prepare_boot_cpu(void)
1216+
{
1217+
struct cpuinfo_x86 *c = &cpu_data(0);
1218+
1219+
*c = boot_cpu_data;
1220+
c->initialized = true;
1221+
}
1222+
#endif
1223+
12141224
static struct notifier_block kernel_offset_notifier = {
12151225
.notifier_call = dump_kernel_offset
12161226
};

arch/x86/kernel/smpboot.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_core_map);
101101
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
102102
EXPORT_PER_CPU_SYMBOL(cpu_die_map);
103103

104-
/* Per CPU bogomips and other parameters */
105-
DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
106-
EXPORT_PER_CPU_SYMBOL(cpu_info);
107-
108104
/* CPUs which are the primary SMT threads */
109105
struct cpumask __cpu_primary_thread_mask __read_mostly;
110106

0 commit comments

Comments
 (0)