2 #include <linux/linkage.h>
3 #include <linux/bitops.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
7 #include <linux/string.h>
9 #include <linux/sched.h>
15 #include <asm/stackprotector.h>
16 #include <asm/perf_event.h>
17 #include <asm/mmu_context.h>
19 #include <asm/hypervisor.h>
20 #include <asm/processor.h>
22 #include <asm/sections.h>
25 #include <asm/pgtable.h>
28 #include <asm/setup.h>
41 #ifdef CONFIG_X86_LOCAL_APIC
42 #include <asm/uv/uv.h>
82 .c_init = default_init,
83 .c_vendor =
"Unknown",
143 static int __init x86_xsave_setup(
char *
s)
151 __setup(
"noxsave", x86_xsave_setup);
153 static int __init x86_xsaveopt_setup(
char *
s)
158 __setup(
"noxsaveopt", x86_xsaveopt_setup);
161 static int cachesize_override __cpuinitdata = -1;
162 static int disable_x86_serial_nr __cpuinitdata = 1;
164 static int __init cachesize_setup(
char *
str)
169 __setup(
"cachesize=", cachesize_setup);
171 static int __init x86_fxsr_setup(
char *
s)
177 __setup(
"nofxsr", x86_fxsr_setup);
179 static int __init x86_sep_setup(
char *
s)
184 __setup(
"nosep", x86_sep_setup);
187 static inline int flag_is_changeable_p(
u32 flag)
198 asm volatile (
"pushfl \n\t"
209 :
"=&r" (
f1),
"=&r" (f2)
212 return ((f1^f2) &
flag) != 0;
223 unsigned long lo,
hi;
241 static int __init x86_serial_nr_setup(
char *
s)
243 disable_x86_serial_nr = 0;
246 __setup(
"serialnumber", x86_serial_nr_setup);
248 static inline int flag_is_changeable_p(
u32 flag)
253 static inline int have_cpuid_p(
void)
257 static inline void squash_the_stupid_serial_number(
struct cpuinfo_x86 *c)
262 static __init int setup_disable_smep(
char *
arg)
267 __setup(
"nosmep", setup_disable_smep);
275 static __init int setup_disable_smap(
char *
arg)
280 __setup(
"nosmap", setup_disable_smap);
305 cpuid_dependent_features[] = {
316 for (df = cpuid_dependent_features; df->
feature; df++) {
337 "CPU: CPU feature %s disabled, no CPUID level 0x%x\n",
360 info = this_cpu->c_models;
362 while (info && info->
family) {
376 loadsegment(
fs, __KERNEL_PERCPU);
381 load_stack_canary_segment();
411 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
412 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
413 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
437 if (n >= 0x80000005) {
438 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
449 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
453 c->
x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
456 if (this_cpu->c_size_cache)
457 l2size = this_cpu->c_size_cache(c, l2size);
460 if (cachesize_override != -1)
461 l2size = cachesize_override;
487 if (this_cpu->c_detect_tlb)
488 this_cpu->c_detect_tlb(c);
491 "Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \
492 "tlb_flushall_shift: %d\n",
493 tlb_lli_4k[
ENTRIES], tlb_lli_2m[ENTRIES],
494 tlb_lli_4m[ENTRIES], tlb_lld_4k[ENTRIES],
495 tlb_lld_2m[ENTRIES], tlb_lld_4m[ENTRIES],
503 int index_msb, core_bits;
515 cpuid(1, &eax, &ebx, &ecx, &edx);
537 ((1 << core_bits) - 1);
563 this_cpu = cpu_devs[
i];
570 "CPU: vendor_id '%s' unknown, using generic init.\n" \
571 "CPU: Your system may be unstable.\n", v);
574 this_cpu = &default_cpu;
590 cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
591 c->
x86 = (tfms >> 8) & 0xf;
596 c->
x86 += (tfms >> 20) & 0xff;
598 c->
x86_model += ((tfms >> 16) & 0xf) << 4;
600 if (cap0 & (1<<19)) {
616 cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
625 cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx);
631 xlvl = cpuid_eax(0x80000000);
634 if ((xlvl & 0xffff0000) == 0x80000000) {
635 if (xlvl >= 0x80000001) {
642 u32 eax = cpuid_eax(0x80000008);
675 cpu_devs[
i]->c_identify(c);
710 identify_cpu_without_cpuid(c);
722 if (this_cpu->c_early_init)
723 this_cpu->c_early_init(c);
726 filter_cpuid_features(c,
false);
728 if (this_cpu->c_bsp_init)
729 this_cpu->c_bsp_init(c);
737 #ifdef CONFIG_PROCESSOR_SELECT
744 if (count >= X86_VENDOR_NUM)
746 cpu_devs[
count] = cpudev;
749 #ifdef CONFIG_PROCESSOR_SELECT
753 for (j = 0; j < 2; j++) {
788 identify_cpu_without_cpuid(c);
803 # ifdef CONFIG_X86_HT
847 if (this_cpu->c_identify)
848 this_cpu->c_identify(c);
870 if (this_cpu->c_init)
874 squash_the_stupid_serial_number(c);
886 filter_cpuid_features(c,
true);
891 p = table_lookup_model(c);
939 static void vgetcpu_set_mode(
void)
942 vgetcpu_mode = VGETCPU_RDTSCP;
944 vgetcpu_mode = VGETCPU_LSL;
977 { 0x00000000, 0x00000418},
978 { 0xc0000000, 0xc000040b},
979 { 0xc0010000, 0xc0010142},
980 { 0xc0011000, 0xc001103b},
983 static void __cpuinit __print_cpu_msr(
void)
985 unsigned index_min, index_max;
990 for (i = 0; i <
ARRAY_SIZE(msr_range_array); i++) {
991 index_min = msr_range_array[
i].min;
992 index_max = msr_range_array[
i].max;
994 for (index = index_min; index < index_max; index++) {
995 if (rdmsrl_safe(index, &val))
1004 static __init int setup_show_msr(
char *
arg)
1014 __setup(
"show_msr=", setup_show_msr);
1016 static __init int setup_noclflush(
char *arg)
1021 __setup(
"noclflush", setup_noclflush);
1028 vendor = this_cpu->c_vendor;
1058 static __init int setup_disablecpuid(
char *arg)
1062 if (
get_option(&arg, &bit) && bit < NCAPINTS*32)
1063 setup_clear_cpu_cap(bit);
1069 __setup(
"clearcpuid=", setup_disablecpuid);
1071 #ifdef CONFIG_X86_64
1074 (
unsigned long) nmi_idt_table };
1124 #ifdef CONFIG_IA32_EMULATION
1143 int is_debug_stack(
unsigned long addr)
1152 void debug_stack_set_zero(
void)
1158 void debug_stack_reset(
void)
1172 #ifdef CONFIG_CC_STACKPROTECTOR
1180 regs->fs = __KERNEL_PERCPU;
1181 regs->gs = __KERNEL_STACK_CANARY;
1190 static void clear_all_debug_regs(
void)
1194 for (i = 0; i < 8; i++) {
1196 if ((i == 4) || (i == 5))
1214 #define dbg_restore_debug_regs()
1224 #ifdef CONFIG_X86_64
1248 panic(
"CPU#%d already initialized!\n", cpu);
1250 pr_debug(
"Initializing CPU#%d\n", cpu);
1278 if (!oist->
ist[0]) {
1279 char *estacks =
per_cpu(exception_stacks, cpu);
1282 estacks += exception_stack_sizes[
v];
1284 (
unsigned long)estacks;
1286 per_cpu(debug_stack_addr, cpu) = (
unsigned long)estacks;
1304 load_sp0(t, &
current->thread);
1309 clear_all_debug_regs();
1335 if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
1349 load_sp0(t, thread);
1356 #ifdef CONFIG_DOUBLEFAULT
1361 clear_all_debug_regs();