1f0fc4affSYinghai Lu #include <linux/bootmem.h> 29766cdbcSJaswinder Singh Rajput #include <linux/linkage.h> 3f0fc4affSYinghai Lu #include <linux/bitops.h> 49766cdbcSJaswinder Singh Rajput #include <linux/kernel.h> 5f0fc4affSYinghai Lu #include <linux/module.h> 6f7627e25SThomas Gleixner #include <linux/percpu.h> 79766cdbcSJaswinder Singh Rajput #include <linux/string.h> 89766cdbcSJaswinder Singh Rajput #include <linux/delay.h> 99766cdbcSJaswinder Singh Rajput #include <linux/sched.h> 109766cdbcSJaswinder Singh Rajput #include <linux/init.h> 110f46efebSMasami Hiramatsu #include <linux/kprobes.h> 129766cdbcSJaswinder Singh Rajput #include <linux/kgdb.h> 139766cdbcSJaswinder Singh Rajput #include <linux/smp.h> 149766cdbcSJaswinder Singh Rajput #include <linux/io.h> 159766cdbcSJaswinder Singh Rajput 169766cdbcSJaswinder Singh Rajput #include <asm/stackprotector.h> 17cdd6c482SIngo Molnar #include <asm/perf_event.h> 18f7627e25SThomas Gleixner #include <asm/mmu_context.h> 1949d859d7SH. Peter Anvin #include <asm/archrandom.h> 209766cdbcSJaswinder Singh Rajput #include <asm/hypervisor.h> 219766cdbcSJaswinder Singh Rajput #include <asm/processor.h> 221e02ce4cSAndy Lutomirski #include <asm/tlbflush.h> 23f649e938SPaul Gortmaker #include <asm/debugreg.h> 249766cdbcSJaswinder Singh Rajput #include <asm/sections.h> 25f40c3300SAndy Lutomirski #include <asm/vsyscall.h> 268bdbd962SAlan Cox #include <linux/topology.h> 278bdbd962SAlan Cox #include <linux/cpumask.h> 289766cdbcSJaswinder Singh Rajput #include <asm/pgtable.h> 2960063497SArun Sharma #include <linux/atomic.h> 309766cdbcSJaswinder Singh Rajput #include <asm/proto.h> 319766cdbcSJaswinder Singh Rajput #include <asm/setup.h> 32f7627e25SThomas Gleixner #include <asm/apic.h> 339766cdbcSJaswinder Singh Rajput #include <asm/desc.h> 349766cdbcSJaswinder Singh Rajput #include <asm/i387.h> 351361b83aSLinus Torvalds #include <asm/fpu-internal.h> 369766cdbcSJaswinder Singh Rajput #include <asm/mtrr.h> 378bdbd962SAlan Cox #include <linux/numa.h> 389766cdbcSJaswinder Singh Rajput #include <asm/asm.h> 399766cdbcSJaswinder Singh Rajput #include <asm/cpu.h> 409766cdbcSJaswinder Singh Rajput #include <asm/mce.h> 419766cdbcSJaswinder Singh Rajput #include <asm/msr.h> 429766cdbcSJaswinder Singh Rajput #include <asm/pat.h> 43d288e1cfSFenghua Yu #include <asm/microcode.h> 44d288e1cfSFenghua Yu #include <asm/microcode_intel.h> 45e641f5f5SIngo Molnar 46f7627e25SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC 47bdbcdd48STejun Heo #include <asm/uv/uv.h> 48f7627e25SThomas Gleixner #endif 49f7627e25SThomas Gleixner 50f7627e25SThomas Gleixner #include "cpu.h" 51f7627e25SThomas Gleixner 52c2d1cec1SMike Travis /* all of these masks are initialized in setup_cpu_local_masks() */ 53c2d1cec1SMike Travis cpumask_var_t cpu_initialized_mask; 549766cdbcSJaswinder Singh Rajput cpumask_var_t cpu_callout_mask; 559766cdbcSJaswinder Singh Rajput cpumask_var_t cpu_callin_mask; 56c2d1cec1SMike Travis 57c2d1cec1SMike Travis /* representing cpus for which sibling maps can be computed */ 58c2d1cec1SMike Travis cpumask_var_t cpu_sibling_setup_mask; 59c2d1cec1SMike Travis 602f2f52baSBrian Gerst /* correctly size the local cpu masks */ 614369f1fbSIngo Molnar void __init setup_cpu_local_masks(void) 622f2f52baSBrian Gerst { 632f2f52baSBrian Gerst alloc_bootmem_cpumask_var(&cpu_initialized_mask); 642f2f52baSBrian Gerst alloc_bootmem_cpumask_var(&cpu_callin_mask); 652f2f52baSBrian Gerst alloc_bootmem_cpumask_var(&cpu_callout_mask); 662f2f52baSBrian Gerst alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask); 672f2f52baSBrian Gerst } 682f2f52baSBrian Gerst 69148f9bb8SPaul Gortmaker static void default_init(struct cpuinfo_x86 *c) 70e8055139SOndrej Zary { 71e8055139SOndrej Zary #ifdef CONFIG_X86_64 7227c13eceSBorislav Petkov cpu_detect_cache_sizes(c); 73e8055139SOndrej Zary #else 74e8055139SOndrej Zary /* Not much we can do here... */ 75e8055139SOndrej Zary /* Check if at least it has cpuid */ 76e8055139SOndrej Zary if (c->cpuid_level == -1) { 77e8055139SOndrej Zary /* No cpuid. It must be an ancient CPU */ 78e8055139SOndrej Zary if (c->x86 == 4) 79e8055139SOndrej Zary strcpy(c->x86_model_id, "486"); 80e8055139SOndrej Zary else if (c->x86 == 3) 81e8055139SOndrej Zary strcpy(c->x86_model_id, "386"); 82e8055139SOndrej Zary } 83e8055139SOndrej Zary #endif 84e8055139SOndrej Zary } 85e8055139SOndrej Zary 86148f9bb8SPaul Gortmaker static const struct cpu_dev default_cpu = { 87e8055139SOndrej Zary .c_init = default_init, 88e8055139SOndrej Zary .c_vendor = "Unknown", 89e8055139SOndrej Zary .c_x86_vendor = X86_VENDOR_UNKNOWN, 90e8055139SOndrej Zary }; 91e8055139SOndrej Zary 92148f9bb8SPaul Gortmaker static const struct cpu_dev *this_cpu = &default_cpu; 930a488a53SYinghai Lu 9406deef89SBrian Gerst DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = { 95950ad7ffSYinghai Lu #ifdef CONFIG_X86_64 9606deef89SBrian Gerst /* 9706deef89SBrian Gerst * We need valid kernel segments for data and code in long mode too 98950ad7ffSYinghai Lu * IRET will check the segment types kkeil 2000/10/28 99950ad7ffSYinghai Lu * Also sysret mandates a special GDT layout 10006deef89SBrian Gerst * 1019766cdbcSJaswinder Singh Rajput * TLS descriptors are currently at a different place compared to i386. 10206deef89SBrian Gerst * Hopefully nobody expects them at a fixed place (Wine?) 103950ad7ffSYinghai Lu */ 1041e5de182SAkinobu Mita [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff), 1051e5de182SAkinobu Mita [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff), 1061e5de182SAkinobu Mita [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff), 1071e5de182SAkinobu Mita [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff), 1081e5de182SAkinobu Mita [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff), 1091e5de182SAkinobu Mita [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff), 110950ad7ffSYinghai Lu #else 1111e5de182SAkinobu Mita [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff), 1121e5de182SAkinobu Mita [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff), 1131e5de182SAkinobu Mita [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff), 1141e5de182SAkinobu Mita [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff), 115f7627e25SThomas Gleixner /* 116f7627e25SThomas Gleixner * Segments used for calling PnP BIOS have byte granularity. 117f7627e25SThomas Gleixner * They code segments and data segments have fixed 64k limits, 118f7627e25SThomas Gleixner * the transfer segment sizes are set at run time. 119f7627e25SThomas Gleixner */ 1206842ef0eSGlauber de Oliveira Costa /* 32-bit code */ 1211e5de182SAkinobu Mita [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff), 1226842ef0eSGlauber de Oliveira Costa /* 16-bit code */ 1231e5de182SAkinobu Mita [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff), 1246842ef0eSGlauber de Oliveira Costa /* 16-bit data */ 1251e5de182SAkinobu Mita [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff), 1266842ef0eSGlauber de Oliveira Costa /* 16-bit data */ 1271e5de182SAkinobu Mita [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0), 1286842ef0eSGlauber de Oliveira Costa /* 16-bit data */ 1291e5de182SAkinobu Mita [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0), 130f7627e25SThomas Gleixner /* 131f7627e25SThomas Gleixner * The APM segments have byte granularity and their bases 132f7627e25SThomas Gleixner * are set at run time. All have 64k limits. 133f7627e25SThomas Gleixner */ 1346842ef0eSGlauber de Oliveira Costa /* 32-bit code */ 1351e5de182SAkinobu Mita [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff), 136f7627e25SThomas Gleixner /* 16-bit code */ 1371e5de182SAkinobu Mita [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff), 1386842ef0eSGlauber de Oliveira Costa /* data */ 13972c4d853SIngo Molnar [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff), 140f7627e25SThomas Gleixner 1411e5de182SAkinobu Mita [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff), 1421e5de182SAkinobu Mita [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff), 14360a5317fSTejun Heo GDT_STACK_CANARY_INIT 144950ad7ffSYinghai Lu #endif 14506deef89SBrian Gerst } }; 146f7627e25SThomas Gleixner EXPORT_PER_CPU_SYMBOL_GPL(gdt_page); 147f7627e25SThomas Gleixner 1480c752a93SSuresh Siddha static int __init x86_xsave_setup(char *s) 1490c752a93SSuresh Siddha { 1502cd3949fSDave Hansen if (strlen(s)) 1512cd3949fSDave Hansen return 0; 1520c752a93SSuresh Siddha setup_clear_cpu_cap(X86_FEATURE_XSAVE); 1536bad06b7SSuresh Siddha setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); 154b6f42a4aSFenghua Yu setup_clear_cpu_cap(X86_FEATURE_XSAVES); 155c6fd893dSSuresh Siddha setup_clear_cpu_cap(X86_FEATURE_AVX); 156c6fd893dSSuresh Siddha setup_clear_cpu_cap(X86_FEATURE_AVX2); 1570c752a93SSuresh Siddha return 1; 1580c752a93SSuresh Siddha } 1590c752a93SSuresh Siddha __setup("noxsave", x86_xsave_setup); 1600c752a93SSuresh Siddha 1616bad06b7SSuresh Siddha static int __init x86_xsaveopt_setup(char *s) 1626bad06b7SSuresh Siddha { 1636bad06b7SSuresh Siddha setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); 1646bad06b7SSuresh Siddha return 1; 1656bad06b7SSuresh Siddha } 1666bad06b7SSuresh Siddha __setup("noxsaveopt", x86_xsaveopt_setup); 1676bad06b7SSuresh Siddha 168b6f42a4aSFenghua Yu static int __init x86_xsaves_setup(char *s) 169b6f42a4aSFenghua Yu { 170b6f42a4aSFenghua Yu setup_clear_cpu_cap(X86_FEATURE_XSAVES); 171b6f42a4aSFenghua Yu return 1; 172b6f42a4aSFenghua Yu } 173b6f42a4aSFenghua Yu __setup("noxsaves", x86_xsaves_setup); 174b6f42a4aSFenghua Yu 175ba51dcedSYinghai Lu #ifdef CONFIG_X86_32 176148f9bb8SPaul Gortmaker static int cachesize_override = -1; 177148f9bb8SPaul Gortmaker static int disable_x86_serial_nr = 1; 178f7627e25SThomas Gleixner 179f7627e25SThomas Gleixner static int __init cachesize_setup(char *str) 180f7627e25SThomas Gleixner { 181f7627e25SThomas Gleixner get_option(&str, &cachesize_override); 182f7627e25SThomas Gleixner return 1; 183f7627e25SThomas Gleixner } 184f7627e25SThomas Gleixner __setup("cachesize=", cachesize_setup); 185f7627e25SThomas Gleixner 186f7627e25SThomas Gleixner static int __init x86_fxsr_setup(char *s) 187f7627e25SThomas Gleixner { 18813530257SAndi Kleen setup_clear_cpu_cap(X86_FEATURE_FXSR); 18913530257SAndi Kleen setup_clear_cpu_cap(X86_FEATURE_XMM); 190f7627e25SThomas Gleixner return 1; 191f7627e25SThomas Gleixner } 192f7627e25SThomas Gleixner __setup("nofxsr", x86_fxsr_setup); 193f7627e25SThomas Gleixner 194f7627e25SThomas Gleixner static int __init x86_sep_setup(char *s) 195f7627e25SThomas Gleixner { 19613530257SAndi Kleen setup_clear_cpu_cap(X86_FEATURE_SEP); 197f7627e25SThomas Gleixner return 1; 198f7627e25SThomas Gleixner } 199f7627e25SThomas Gleixner __setup("nosep", x86_sep_setup); 200f7627e25SThomas Gleixner 201f7627e25SThomas Gleixner /* Standard macro to see if a specific flag is changeable */ 202f7627e25SThomas Gleixner static inline int flag_is_changeable_p(u32 flag) 203f7627e25SThomas Gleixner { 204f7627e25SThomas Gleixner u32 f1, f2; 205f7627e25SThomas Gleixner 20694f6bac1SKrzysztof Helt /* 20794f6bac1SKrzysztof Helt * Cyrix and IDT cpus allow disabling of CPUID 20894f6bac1SKrzysztof Helt * so the code below may return different results 20994f6bac1SKrzysztof Helt * when it is executed before and after enabling 21094f6bac1SKrzysztof Helt * the CPUID. Add "volatile" to not allow gcc to 21194f6bac1SKrzysztof Helt * optimize the subsequent calls to this function. 21294f6bac1SKrzysztof Helt */ 21394f6bac1SKrzysztof Helt asm volatile ("pushfl \n\t" 214f7627e25SThomas Gleixner "pushfl \n\t" 215f7627e25SThomas Gleixner "popl %0 \n\t" 216f7627e25SThomas Gleixner "movl %0, %1 \n\t" 217f7627e25SThomas Gleixner "xorl %2, %0 \n\t" 218f7627e25SThomas Gleixner "pushl %0 \n\t" 219f7627e25SThomas Gleixner "popfl \n\t" 220f7627e25SThomas Gleixner "pushfl \n\t" 221f7627e25SThomas Gleixner "popl %0 \n\t" 222f7627e25SThomas Gleixner "popfl \n\t" 2230f3fa48aSIngo Molnar 224f7627e25SThomas Gleixner : "=&r" (f1), "=&r" (f2) 225f7627e25SThomas Gleixner : "ir" (flag)); 226f7627e25SThomas Gleixner 227f7627e25SThomas Gleixner return ((f1^f2) & flag) != 0; 228f7627e25SThomas Gleixner } 229f7627e25SThomas Gleixner 230f7627e25SThomas Gleixner /* Probe for the CPUID instruction */ 231148f9bb8SPaul Gortmaker int have_cpuid_p(void) 232f7627e25SThomas Gleixner { 233f7627e25SThomas Gleixner return flag_is_changeable_p(X86_EFLAGS_ID); 234f7627e25SThomas Gleixner } 235f7627e25SThomas Gleixner 236148f9bb8SPaul Gortmaker static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) 2370a488a53SYinghai Lu { 2380a488a53SYinghai Lu unsigned long lo, hi; 2390f3fa48aSIngo Molnar 2400f3fa48aSIngo Molnar if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr) 2410f3fa48aSIngo Molnar return; 2420f3fa48aSIngo Molnar 2430f3fa48aSIngo Molnar /* Disable processor serial number: */ 2440f3fa48aSIngo Molnar 2450a488a53SYinghai Lu rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi); 2460a488a53SYinghai Lu lo |= 0x200000; 2470a488a53SYinghai Lu wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi); 2480f3fa48aSIngo Molnar 2490a488a53SYinghai Lu printk(KERN_NOTICE "CPU serial number disabled.\n"); 2500a488a53SYinghai Lu clear_cpu_cap(c, X86_FEATURE_PN); 2510a488a53SYinghai Lu 2520a488a53SYinghai Lu /* Disabling the serial number may affect the cpuid level */ 2530a488a53SYinghai Lu c->cpuid_level = cpuid_eax(0); 2540a488a53SYinghai Lu } 2550a488a53SYinghai Lu 2560a488a53SYinghai Lu static int __init x86_serial_nr_setup(char *s) 2570a488a53SYinghai Lu { 2580a488a53SYinghai Lu disable_x86_serial_nr = 0; 2590a488a53SYinghai Lu return 1; 2600a488a53SYinghai Lu } 2610a488a53SYinghai Lu __setup("serialnumber", x86_serial_nr_setup); 262ba51dcedSYinghai Lu #else 263102bbe3aSYinghai Lu static inline int flag_is_changeable_p(u32 flag) 264102bbe3aSYinghai Lu { 265102bbe3aSYinghai Lu return 1; 266102bbe3aSYinghai Lu } 267102bbe3aSYinghai Lu static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) 268102bbe3aSYinghai Lu { 269102bbe3aSYinghai Lu } 270ba51dcedSYinghai Lu #endif 2710a488a53SYinghai Lu 272de5397adSFenghua Yu static __init int setup_disable_smep(char *arg) 273de5397adSFenghua Yu { 274b2cc2a07SH. Peter Anvin setup_clear_cpu_cap(X86_FEATURE_SMEP); 275de5397adSFenghua Yu return 1; 276de5397adSFenghua Yu } 277de5397adSFenghua Yu __setup("nosmep", setup_disable_smep); 278de5397adSFenghua Yu 279b2cc2a07SH. Peter Anvin static __always_inline void setup_smep(struct cpuinfo_x86 *c) 280de5397adSFenghua Yu { 281b2cc2a07SH. Peter Anvin if (cpu_has(c, X86_FEATURE_SMEP)) 282375074ccSAndy Lutomirski cr4_set_bits(X86_CR4_SMEP); 283de5397adSFenghua Yu } 284de5397adSFenghua Yu 28552b6179aSH. Peter Anvin static __init int setup_disable_smap(char *arg) 28652b6179aSH. Peter Anvin { 287b2cc2a07SH. Peter Anvin setup_clear_cpu_cap(X86_FEATURE_SMAP); 28852b6179aSH. Peter Anvin return 1; 28952b6179aSH. Peter Anvin } 29052b6179aSH. Peter Anvin __setup("nosmap", setup_disable_smap); 29152b6179aSH. Peter Anvin 292b2cc2a07SH. Peter Anvin static __always_inline void setup_smap(struct cpuinfo_x86 *c) 29352b6179aSH. Peter Anvin { 294b2cc2a07SH. Peter Anvin unsigned long eflags; 295b2cc2a07SH. Peter Anvin 296b2cc2a07SH. Peter Anvin /* This should have been cleared long ago */ 297b2cc2a07SH. Peter Anvin raw_local_save_flags(eflags); 298b2cc2a07SH. Peter Anvin BUG_ON(eflags & X86_EFLAGS_AC); 299b2cc2a07SH. Peter Anvin 30003bbd596SH. Peter Anvin if (cpu_has(c, X86_FEATURE_SMAP)) { 30103bbd596SH. Peter Anvin #ifdef CONFIG_X86_SMAP 302375074ccSAndy Lutomirski cr4_set_bits(X86_CR4_SMAP); 30303bbd596SH. Peter Anvin #else 304375074ccSAndy Lutomirski cr4_clear_bits(X86_CR4_SMAP); 30503bbd596SH. Peter Anvin #endif 30603bbd596SH. Peter Anvin } 307f7627e25SThomas Gleixner } 308f7627e25SThomas Gleixner 309f7627e25SThomas Gleixner /* 310b38b0665SH. Peter Anvin * Some CPU features depend on higher CPUID levels, which may not always 311b38b0665SH. Peter Anvin * be available due to CPUID level capping or broken virtualization 312b38b0665SH. Peter Anvin * software. Add those features to this table to auto-disable them. 313b38b0665SH. Peter Anvin */ 314b38b0665SH. Peter Anvin struct cpuid_dependent_feature { 315b38b0665SH. Peter Anvin u32 feature; 316b38b0665SH. Peter Anvin u32 level; 317b38b0665SH. Peter Anvin }; 3180f3fa48aSIngo Molnar 319148f9bb8SPaul Gortmaker static const struct cpuid_dependent_feature 320b38b0665SH. Peter Anvin cpuid_dependent_features[] = { 321b38b0665SH. Peter Anvin { X86_FEATURE_MWAIT, 0x00000005 }, 322b38b0665SH. Peter Anvin { X86_FEATURE_DCA, 0x00000009 }, 323b38b0665SH. Peter Anvin { X86_FEATURE_XSAVE, 0x0000000d }, 324b38b0665SH. Peter Anvin { 0, 0 } 325b38b0665SH. Peter Anvin }; 326b38b0665SH. Peter Anvin 327148f9bb8SPaul Gortmaker static void filter_cpuid_features(struct cpuinfo_x86 *c, bool warn) 328b38b0665SH. Peter Anvin { 329b38b0665SH. Peter Anvin const struct cpuid_dependent_feature *df; 3309766cdbcSJaswinder Singh Rajput 331b38b0665SH. Peter Anvin for (df = cpuid_dependent_features; df->feature; df++) { 3320f3fa48aSIngo Molnar 3330f3fa48aSIngo Molnar if (!cpu_has(c, df->feature)) 3340f3fa48aSIngo Molnar continue; 335b38b0665SH. Peter Anvin /* 336b38b0665SH. Peter Anvin * Note: cpuid_level is set to -1 if unavailable, but 337b38b0665SH. Peter Anvin * extended_extended_level is set to 0 if unavailable 338b38b0665SH. Peter Anvin * and the legitimate extended levels are all negative 339b38b0665SH. Peter Anvin * when signed; hence the weird messing around with 340b38b0665SH. Peter Anvin * signs here... 341b38b0665SH. Peter Anvin */ 3420f3fa48aSIngo Molnar if (!((s32)df->level < 0 ? 343f6db44dfSYinghai Lu (u32)df->level > (u32)c->extended_cpuid_level : 3440f3fa48aSIngo Molnar (s32)df->level > (s32)c->cpuid_level)) 3450f3fa48aSIngo Molnar continue; 3460f3fa48aSIngo Molnar 347b38b0665SH. Peter Anvin clear_cpu_cap(c, df->feature); 3480f3fa48aSIngo Molnar if (!warn) 3490f3fa48aSIngo Molnar continue; 3500f3fa48aSIngo Molnar 351b38b0665SH. Peter Anvin printk(KERN_WARNING 3529def39beSJosh Triplett "CPU: CPU feature " X86_CAP_FMT " disabled, no CPUID level 0x%x\n", 3539def39beSJosh Triplett x86_cap_flag(df->feature), df->level); 354b38b0665SH. Peter Anvin } 355b38b0665SH. Peter Anvin } 356b38b0665SH. Peter Anvin 357b38b0665SH. Peter Anvin /* 358f7627e25SThomas Gleixner * Naming convention should be: <Name> [(<Codename>)] 359f7627e25SThomas Gleixner * This table only is used unless init_<vendor>() below doesn't set it; 3600f3fa48aSIngo Molnar * in particular, if CPUID levels 0x80000002..4 are supported, this 3610f3fa48aSIngo Molnar * isn't used 362f7627e25SThomas Gleixner */ 363f7627e25SThomas Gleixner 364f7627e25SThomas Gleixner /* Look up CPU names by table lookup. */ 365148f9bb8SPaul Gortmaker static const char *table_lookup_model(struct cpuinfo_x86 *c) 366f7627e25SThomas Gleixner { 36709dc68d9SJan Beulich #ifdef CONFIG_X86_32 36809dc68d9SJan Beulich const struct legacy_cpu_model_info *info; 369f7627e25SThomas Gleixner 370f7627e25SThomas Gleixner if (c->x86_model >= 16) 371f7627e25SThomas Gleixner return NULL; /* Range check */ 372f7627e25SThomas Gleixner 373f7627e25SThomas Gleixner if (!this_cpu) 374f7627e25SThomas Gleixner return NULL; 375f7627e25SThomas Gleixner 37609dc68d9SJan Beulich info = this_cpu->legacy_models; 377f7627e25SThomas Gleixner 37809dc68d9SJan Beulich while (info->family) { 379f7627e25SThomas Gleixner if (info->family == c->x86) 380f7627e25SThomas Gleixner return info->model_names[c->x86_model]; 381f7627e25SThomas Gleixner info++; 382f7627e25SThomas Gleixner } 38309dc68d9SJan Beulich #endif 384f7627e25SThomas Gleixner return NULL; /* Not found */ 385f7627e25SThomas Gleixner } 386f7627e25SThomas Gleixner 387148f9bb8SPaul Gortmaker __u32 cpu_caps_cleared[NCAPINTS]; 388148f9bb8SPaul Gortmaker __u32 cpu_caps_set[NCAPINTS]; 389f7627e25SThomas Gleixner 39011e3a840SJeremy Fitzhardinge void load_percpu_segment(int cpu) 3919d31d35bSYinghai Lu { 392fab334c1SYinghai Lu #ifdef CONFIG_X86_32 3932697fbd5SBrian Gerst loadsegment(fs, __KERNEL_PERCPU); 3942697fbd5SBrian Gerst #else 3952697fbd5SBrian Gerst loadsegment(gs, 0); 3962697fbd5SBrian Gerst wrmsrl(MSR_GS_BASE, (unsigned long)per_cpu(irq_stack_union.gs_base, cpu)); 397fab334c1SYinghai Lu #endif 39860a5317fSTejun Heo load_stack_canary_segment(); 3999d31d35bSYinghai Lu } 4009d31d35bSYinghai Lu 4010f3fa48aSIngo Molnar /* 4020f3fa48aSIngo Molnar * Current gdt points %fs at the "master" per-cpu area: after this, 4030f3fa48aSIngo Molnar * it's on the real one. 4040f3fa48aSIngo Molnar */ 405552be871SBrian Gerst void switch_to_new_gdt(int cpu) 406f7627e25SThomas Gleixner { 407f7627e25SThomas Gleixner struct desc_ptr gdt_descr; 408f7627e25SThomas Gleixner 409f7627e25SThomas Gleixner gdt_descr.address = (long)get_cpu_gdt_table(cpu); 410f7627e25SThomas Gleixner gdt_descr.size = GDT_SIZE - 1; 411f7627e25SThomas Gleixner load_gdt(&gdt_descr); 412f7627e25SThomas Gleixner /* Reload the per-cpu base */ 41311e3a840SJeremy Fitzhardinge 41411e3a840SJeremy Fitzhardinge load_percpu_segment(cpu); 415f7627e25SThomas Gleixner } 416f7627e25SThomas Gleixner 417148f9bb8SPaul Gortmaker static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; 418f7627e25SThomas Gleixner 419148f9bb8SPaul Gortmaker static void get_model_name(struct cpuinfo_x86 *c) 420f7627e25SThomas Gleixner { 421f7627e25SThomas Gleixner unsigned int *v; 422f7627e25SThomas Gleixner char *p, *q; 423f7627e25SThomas Gleixner 4243da99c97SYinghai Lu if (c->extended_cpuid_level < 0x80000004) 4251b05d60dSYinghai Lu return; 426f7627e25SThomas Gleixner 427f7627e25SThomas Gleixner v = (unsigned int *)c->x86_model_id; 428f7627e25SThomas Gleixner cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); 429f7627e25SThomas Gleixner cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]); 430f7627e25SThomas Gleixner cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]); 431f7627e25SThomas Gleixner c->x86_model_id[48] = 0; 432f7627e25SThomas Gleixner 4330f3fa48aSIngo Molnar /* 4340f3fa48aSIngo Molnar * Intel chips right-justify this string for some dumb reason; 4350f3fa48aSIngo Molnar * undo that brain damage: 4360f3fa48aSIngo Molnar */ 437f7627e25SThomas Gleixner p = q = &c->x86_model_id[0]; 438f7627e25SThomas Gleixner while (*p == ' ') 439f7627e25SThomas Gleixner p++; 440f7627e25SThomas Gleixner if (p != q) { 441f7627e25SThomas Gleixner while (*p) 442f7627e25SThomas Gleixner *q++ = *p++; 443f7627e25SThomas Gleixner while (q <= &c->x86_model_id[48]) 444f7627e25SThomas Gleixner *q++ = '\0'; /* Zero-pad the rest */ 445f7627e25SThomas Gleixner } 446f7627e25SThomas Gleixner } 447f7627e25SThomas Gleixner 448148f9bb8SPaul Gortmaker void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) 449f7627e25SThomas Gleixner { 4509d31d35bSYinghai Lu unsigned int n, dummy, ebx, ecx, edx, l2size; 451f7627e25SThomas Gleixner 4523da99c97SYinghai Lu n = c->extended_cpuid_level; 453f7627e25SThomas Gleixner 454f7627e25SThomas Gleixner if (n >= 0x80000005) { 4559d31d35bSYinghai Lu cpuid(0x80000005, &dummy, &ebx, &ecx, &edx); 456f7627e25SThomas Gleixner c->x86_cache_size = (ecx>>24) + (edx>>24); 457140fc727SYinghai Lu #ifdef CONFIG_X86_64 458140fc727SYinghai Lu /* On K8 L1 TLB is inclusive, so don't count it */ 459140fc727SYinghai Lu c->x86_tlbsize = 0; 460140fc727SYinghai Lu #endif 461f7627e25SThomas Gleixner } 462f7627e25SThomas Gleixner 463f7627e25SThomas Gleixner if (n < 0x80000006) /* Some chips just has a large L1. */ 464f7627e25SThomas Gleixner return; 465f7627e25SThomas Gleixner 4660a488a53SYinghai Lu cpuid(0x80000006, &dummy, &ebx, &ecx, &edx); 467f7627e25SThomas Gleixner l2size = ecx >> 16; 468f7627e25SThomas Gleixner 469140fc727SYinghai Lu #ifdef CONFIG_X86_64 470140fc727SYinghai Lu c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff); 471140fc727SYinghai Lu #else 472f7627e25SThomas Gleixner /* do processor-specific cache resizing */ 47309dc68d9SJan Beulich if (this_cpu->legacy_cache_size) 47409dc68d9SJan Beulich l2size = this_cpu->legacy_cache_size(c, l2size); 475f7627e25SThomas Gleixner 476f7627e25SThomas Gleixner /* Allow user to override all this if necessary. */ 477f7627e25SThomas Gleixner if (cachesize_override != -1) 478f7627e25SThomas Gleixner l2size = cachesize_override; 479f7627e25SThomas Gleixner 480f7627e25SThomas Gleixner if (l2size == 0) 481f7627e25SThomas Gleixner return; /* Again, no L2 cache is possible */ 482140fc727SYinghai Lu #endif 483f7627e25SThomas Gleixner 484f7627e25SThomas Gleixner c->x86_cache_size = l2size; 485f7627e25SThomas Gleixner } 486f7627e25SThomas Gleixner 487e0ba94f1SAlex Shi u16 __read_mostly tlb_lli_4k[NR_INFO]; 488e0ba94f1SAlex Shi u16 __read_mostly tlb_lli_2m[NR_INFO]; 489e0ba94f1SAlex Shi u16 __read_mostly tlb_lli_4m[NR_INFO]; 490e0ba94f1SAlex Shi u16 __read_mostly tlb_lld_4k[NR_INFO]; 491e0ba94f1SAlex Shi u16 __read_mostly tlb_lld_2m[NR_INFO]; 492e0ba94f1SAlex Shi u16 __read_mostly tlb_lld_4m[NR_INFO]; 493dd360393SKirill A. Shutemov u16 __read_mostly tlb_lld_1g[NR_INFO]; 494e0ba94f1SAlex Shi 495f94fe119SSteven Honeyman static void cpu_detect_tlb(struct cpuinfo_x86 *c) 496e0ba94f1SAlex Shi { 497e0ba94f1SAlex Shi if (this_cpu->c_detect_tlb) 498e0ba94f1SAlex Shi this_cpu->c_detect_tlb(c); 499e0ba94f1SAlex Shi 500f94fe119SSteven Honeyman pr_info("Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n", 501e0ba94f1SAlex Shi tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES], 502f94fe119SSteven Honeyman tlb_lli_4m[ENTRIES]); 503f94fe119SSteven Honeyman 504f94fe119SSteven Honeyman pr_info("Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d, 1GB %d\n", 505f94fe119SSteven Honeyman tlb_lld_4k[ENTRIES], tlb_lld_2m[ENTRIES], 506f94fe119SSteven Honeyman tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); 507e0ba94f1SAlex Shi } 508e0ba94f1SAlex Shi 509148f9bb8SPaul Gortmaker void detect_ht(struct cpuinfo_x86 *c) 5109d31d35bSYinghai Lu { 51197e4db7cSYinghai Lu #ifdef CONFIG_X86_HT 5129d31d35bSYinghai Lu u32 eax, ebx, ecx, edx; 5139d31d35bSYinghai Lu int index_msb, core_bits; 5142eaad1fdSMike Travis static bool printed; 5159d31d35bSYinghai Lu 5160a488a53SYinghai Lu if (!cpu_has(c, X86_FEATURE_HT)) 5179d31d35bSYinghai Lu return; 5189d31d35bSYinghai Lu 5190a488a53SYinghai Lu if (cpu_has(c, X86_FEATURE_CMP_LEGACY)) 5200a488a53SYinghai Lu goto out; 5210a488a53SYinghai Lu 5221cd78776SYinghai Lu if (cpu_has(c, X86_FEATURE_XTOPOLOGY)) 5231cd78776SYinghai Lu return; 5241cd78776SYinghai Lu 5250a488a53SYinghai Lu cpuid(1, &eax, &ebx, &ecx, &edx); 5260a488a53SYinghai Lu 5279d31d35bSYinghai Lu smp_num_siblings = (ebx & 0xff0000) >> 16; 5289d31d35bSYinghai Lu 5299d31d35bSYinghai Lu if (smp_num_siblings == 1) { 5302eaad1fdSMike Travis printk_once(KERN_INFO "CPU0: Hyper-Threading is disabled\n"); 5310f3fa48aSIngo Molnar goto out; 5320f3fa48aSIngo Molnar } 5330f3fa48aSIngo Molnar 5340f3fa48aSIngo Molnar if (smp_num_siblings <= 1) 5350f3fa48aSIngo Molnar goto out; 5369d31d35bSYinghai Lu 5379d31d35bSYinghai Lu index_msb = get_count_order(smp_num_siblings); 538cb8cc442SIngo Molnar c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb); 5399d31d35bSYinghai Lu 5409d31d35bSYinghai Lu smp_num_siblings = smp_num_siblings / c->x86_max_cores; 5419d31d35bSYinghai Lu 5429d31d35bSYinghai Lu index_msb = get_count_order(smp_num_siblings); 5439d31d35bSYinghai Lu 5449d31d35bSYinghai Lu core_bits = get_count_order(c->x86_max_cores); 5459d31d35bSYinghai Lu 546cb8cc442SIngo Molnar c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) & 5471cd78776SYinghai Lu ((1 << core_bits) - 1); 5489d31d35bSYinghai Lu 5490a488a53SYinghai Lu out: 5502eaad1fdSMike Travis if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) { 5510a488a53SYinghai Lu printk(KERN_INFO "CPU: Physical Processor ID: %d\n", 5520a488a53SYinghai Lu c->phys_proc_id); 5539d31d35bSYinghai Lu printk(KERN_INFO "CPU: Processor Core ID: %d\n", 5549d31d35bSYinghai Lu c->cpu_core_id); 5552eaad1fdSMike Travis printed = 1; 5569d31d35bSYinghai Lu } 5579d31d35bSYinghai Lu #endif 55897e4db7cSYinghai Lu } 559f7627e25SThomas Gleixner 560148f9bb8SPaul Gortmaker static void get_cpu_vendor(struct cpuinfo_x86 *c) 561f7627e25SThomas Gleixner { 562f7627e25SThomas Gleixner char *v = c->x86_vendor_id; 5630f3fa48aSIngo Molnar int i; 564f7627e25SThomas Gleixner 565f7627e25SThomas Gleixner for (i = 0; i < X86_VENDOR_NUM; i++) { 56610a434fcSYinghai Lu if (!cpu_devs[i]) 56710a434fcSYinghai Lu break; 56810a434fcSYinghai Lu 569f7627e25SThomas Gleixner if (!strcmp(v, cpu_devs[i]->c_ident[0]) || 570f7627e25SThomas Gleixner (cpu_devs[i]->c_ident[1] && 571f7627e25SThomas Gleixner !strcmp(v, cpu_devs[i]->c_ident[1]))) { 5720f3fa48aSIngo Molnar 573f7627e25SThomas Gleixner this_cpu = cpu_devs[i]; 57410a434fcSYinghai Lu c->x86_vendor = this_cpu->c_x86_vendor; 575f7627e25SThomas Gleixner return; 576f7627e25SThomas Gleixner } 577f7627e25SThomas Gleixner } 57810a434fcSYinghai Lu 579a9c56953SMinchan Kim printk_once(KERN_ERR 580a9c56953SMinchan Kim "CPU: vendor_id '%s' unknown, using generic init.\n" \ 581a9c56953SMinchan Kim "CPU: Your system may be unstable.\n", v); 58210a434fcSYinghai Lu 583f7627e25SThomas Gleixner c->x86_vendor = X86_VENDOR_UNKNOWN; 584f7627e25SThomas Gleixner this_cpu = &default_cpu; 585f7627e25SThomas Gleixner } 586f7627e25SThomas Gleixner 587148f9bb8SPaul Gortmaker void cpu_detect(struct cpuinfo_x86 *c) 588f7627e25SThomas Gleixner { 589f7627e25SThomas Gleixner /* Get vendor name */ 5904a148513SHarvey Harrison cpuid(0x00000000, (unsigned int *)&c->cpuid_level, 5914a148513SHarvey Harrison (unsigned int *)&c->x86_vendor_id[0], 5924a148513SHarvey Harrison (unsigned int *)&c->x86_vendor_id[8], 5934a148513SHarvey Harrison (unsigned int *)&c->x86_vendor_id[4]); 594f7627e25SThomas Gleixner 595f7627e25SThomas Gleixner c->x86 = 4; 5969d31d35bSYinghai Lu /* Intel-defined flags: level 0x00000001 */ 597f7627e25SThomas Gleixner if (c->cpuid_level >= 0x00000001) { 598f7627e25SThomas Gleixner u32 junk, tfms, cap0, misc; 5990f3fa48aSIngo Molnar 600f7627e25SThomas Gleixner cpuid(0x00000001, &tfms, &misc, &junk, &cap0); 6019d31d35bSYinghai Lu c->x86 = (tfms >> 8) & 0xf; 6029d31d35bSYinghai Lu c->x86_model = (tfms >> 4) & 0xf; 6039d31d35bSYinghai Lu c->x86_mask = tfms & 0xf; 6040f3fa48aSIngo Molnar 605f7627e25SThomas Gleixner if (c->x86 == 0xf) 606f7627e25SThomas Gleixner c->x86 += (tfms >> 20) & 0xff; 607f7627e25SThomas Gleixner if (c->x86 >= 0x6) 6089d31d35bSYinghai Lu c->x86_model += ((tfms >> 16) & 0xf) << 4; 6090f3fa48aSIngo Molnar 610d4387bd3SHuang, Ying if (cap0 & (1<<19)) { 611d4387bd3SHuang, Ying c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; 6129d31d35bSYinghai Lu c->x86_cache_alignment = c->x86_clflush_size; 613d4387bd3SHuang, Ying } 614f7627e25SThomas Gleixner } 615f7627e25SThomas Gleixner } 6163da99c97SYinghai Lu 617148f9bb8SPaul Gortmaker void get_cpu_cap(struct cpuinfo_x86 *c) 618093af8d7SYinghai Lu { 619093af8d7SYinghai Lu u32 tfms, xlvl; 6203da99c97SYinghai Lu u32 ebx; 621093af8d7SYinghai Lu 622093af8d7SYinghai Lu /* Intel-defined flags: level 0x00000001 */ 623093af8d7SYinghai Lu if (c->cpuid_level >= 0x00000001) { 624093af8d7SYinghai Lu u32 capability, excap; 6250f3fa48aSIngo Molnar 626093af8d7SYinghai Lu cpuid(0x00000001, &tfms, &ebx, &excap, &capability); 627093af8d7SYinghai Lu c->x86_capability[0] = capability; 628093af8d7SYinghai Lu c->x86_capability[4] = excap; 629093af8d7SYinghai Lu } 630093af8d7SYinghai Lu 631bdc802dcSH. Peter Anvin /* Additional Intel-defined flags: level 0x00000007 */ 632bdc802dcSH. Peter Anvin if (c->cpuid_level >= 0x00000007) { 633bdc802dcSH. Peter Anvin u32 eax, ebx, ecx, edx; 634bdc802dcSH. Peter Anvin 635bdc802dcSH. Peter Anvin cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); 636bdc802dcSH. Peter Anvin 637bdc802dcSH. Peter Anvin c->x86_capability[9] = ebx; 638bdc802dcSH. Peter Anvin } 639bdc802dcSH. Peter Anvin 6406229ad27SFenghua Yu /* Extended state features: level 0x0000000d */ 6416229ad27SFenghua Yu if (c->cpuid_level >= 0x0000000d) { 6426229ad27SFenghua Yu u32 eax, ebx, ecx, edx; 6436229ad27SFenghua Yu 6446229ad27SFenghua Yu cpuid_count(0x0000000d, 1, &eax, &ebx, &ecx, &edx); 6456229ad27SFenghua Yu 6466229ad27SFenghua Yu c->x86_capability[10] = eax; 6476229ad27SFenghua Yu } 6486229ad27SFenghua Yu 649093af8d7SYinghai Lu /* AMD-defined flags: level 0x80000001 */ 650093af8d7SYinghai Lu xlvl = cpuid_eax(0x80000000); 6513da99c97SYinghai Lu c->extended_cpuid_level = xlvl; 6520f3fa48aSIngo Molnar 653093af8d7SYinghai Lu if ((xlvl & 0xffff0000) == 0x80000000) { 654093af8d7SYinghai Lu if (xlvl >= 0x80000001) { 655093af8d7SYinghai Lu c->x86_capability[1] = cpuid_edx(0x80000001); 656093af8d7SYinghai Lu c->x86_capability[6] = cpuid_ecx(0x80000001); 657093af8d7SYinghai Lu } 658093af8d7SYinghai Lu } 659093af8d7SYinghai Lu 6605122c890SYinghai Lu if (c->extended_cpuid_level >= 0x80000008) { 6615122c890SYinghai Lu u32 eax = cpuid_eax(0x80000008); 6625122c890SYinghai Lu 6635122c890SYinghai Lu c->x86_virt_bits = (eax >> 8) & 0xff; 6645122c890SYinghai Lu c->x86_phys_bits = eax & 0xff; 6655122c890SYinghai Lu } 66613c6c532SJan Beulich #ifdef CONFIG_X86_32 66713c6c532SJan Beulich else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) 66813c6c532SJan Beulich c->x86_phys_bits = 36; 6695122c890SYinghai Lu #endif 670e3224234SYinghai Lu 671e3224234SYinghai Lu if (c->extended_cpuid_level >= 0x80000007) 672e3224234SYinghai Lu c->x86_power = cpuid_edx(0x80000007); 673e3224234SYinghai Lu 6741dedefd1SJacob Pan init_scattered_cpuid_features(c); 675093af8d7SYinghai Lu } 676093af8d7SYinghai Lu 677148f9bb8SPaul Gortmaker static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) 678aef93c8bSYinghai Lu { 679aef93c8bSYinghai Lu #ifdef CONFIG_X86_32 680aef93c8bSYinghai Lu int i; 681aef93c8bSYinghai Lu 682aef93c8bSYinghai Lu /* 683aef93c8bSYinghai Lu * First of all, decide if this is a 486 or higher 684aef93c8bSYinghai Lu * It's a 486 if we can modify the AC flag 685aef93c8bSYinghai Lu */ 686aef93c8bSYinghai Lu if (flag_is_changeable_p(X86_EFLAGS_AC)) 687aef93c8bSYinghai Lu c->x86 = 4; 688aef93c8bSYinghai Lu else 689aef93c8bSYinghai Lu c->x86 = 3; 690aef93c8bSYinghai Lu 691aef93c8bSYinghai Lu for (i = 0; i < X86_VENDOR_NUM; i++) 692aef93c8bSYinghai Lu if (cpu_devs[i] && cpu_devs[i]->c_identify) { 693aef93c8bSYinghai Lu c->x86_vendor_id[0] = 0; 694aef93c8bSYinghai Lu cpu_devs[i]->c_identify(c); 695aef93c8bSYinghai Lu if (c->x86_vendor_id[0]) { 696aef93c8bSYinghai Lu get_cpu_vendor(c); 697aef93c8bSYinghai Lu break; 698aef93c8bSYinghai Lu } 699aef93c8bSYinghai Lu } 700aef93c8bSYinghai Lu #endif 701093af8d7SYinghai Lu } 702f7627e25SThomas Gleixner 70334048c9eSPaolo Ciarrocchi /* 70434048c9eSPaolo Ciarrocchi * Do minimum CPU detection early. 70534048c9eSPaolo Ciarrocchi * Fields really needed: vendor, cpuid_level, family, model, mask, 70634048c9eSPaolo Ciarrocchi * cache alignment. 70734048c9eSPaolo Ciarrocchi * The others are not touched to avoid unwanted side effects. 70834048c9eSPaolo Ciarrocchi * 70934048c9eSPaolo Ciarrocchi * WARNING: this function is only called on the BP. Don't add code here 71034048c9eSPaolo Ciarrocchi * that is supposed to run on all CPUs. 71134048c9eSPaolo Ciarrocchi */ 7123da99c97SYinghai Lu static void __init early_identify_cpu(struct cpuinfo_x86 *c) 713f7627e25SThomas Gleixner { 7146627d242SYinghai Lu #ifdef CONFIG_X86_64 7156627d242SYinghai Lu c->x86_clflush_size = 64; 71613c6c532SJan Beulich c->x86_phys_bits = 36; 71713c6c532SJan Beulich c->x86_virt_bits = 48; 7186627d242SYinghai Lu #else 719d4387bd3SHuang, Ying c->x86_clflush_size = 32; 72013c6c532SJan Beulich c->x86_phys_bits = 32; 72113c6c532SJan Beulich c->x86_virt_bits = 32; 7226627d242SYinghai Lu #endif 7230a488a53SYinghai Lu c->x86_cache_alignment = c->x86_clflush_size; 724f7627e25SThomas Gleixner 7253da99c97SYinghai Lu memset(&c->x86_capability, 0, sizeof c->x86_capability); 7260a488a53SYinghai Lu c->extended_cpuid_level = 0; 7270a488a53SYinghai Lu 728aef93c8bSYinghai Lu if (!have_cpuid_p()) 729aef93c8bSYinghai Lu identify_cpu_without_cpuid(c); 730aef93c8bSYinghai Lu 731aef93c8bSYinghai Lu /* cyrix could have cpuid enabled via c_identify()*/ 732f7627e25SThomas Gleixner if (!have_cpuid_p()) 733f7627e25SThomas Gleixner return; 734f7627e25SThomas Gleixner 735f7627e25SThomas Gleixner cpu_detect(c); 7363da99c97SYinghai Lu get_cpu_vendor(c); 7373da99c97SYinghai Lu get_cpu_cap(c); 73860e019ebSH. Peter Anvin fpu_detect(c); 73912cf105cSKrzysztof Helt 74010a434fcSYinghai Lu if (this_cpu->c_early_init) 74110a434fcSYinghai Lu this_cpu->c_early_init(c); 7423da99c97SYinghai Lu 743f6e9456cSRobert Richter c->cpu_index = 0; 744b38b0665SH. Peter Anvin filter_cpuid_features(c, false); 745de5397adSFenghua Yu 746a110b5ecSBorislav Petkov if (this_cpu->c_bsp_init) 747a110b5ecSBorislav Petkov this_cpu->c_bsp_init(c); 748c3b83598SBorislav Petkov 749c3b83598SBorislav Petkov setup_force_cpu_cap(X86_FEATURE_ALWAYS); 750f7627e25SThomas Gleixner } 751f7627e25SThomas Gleixner 7529d31d35bSYinghai Lu void __init early_cpu_init(void) 7539d31d35bSYinghai Lu { 75402dde8b4SJan Beulich const struct cpu_dev *const *cdev; 75510a434fcSYinghai Lu int count = 0; 7569d31d35bSYinghai Lu 757ac23f253SJan Beulich #ifdef CONFIG_PROCESSOR_SELECT 7589766cdbcSJaswinder Singh Rajput printk(KERN_INFO "KERNEL supported cpus:\n"); 75931c997caSIngo Molnar #endif 76031c997caSIngo Molnar 76110a434fcSYinghai Lu for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) { 76202dde8b4SJan Beulich const struct cpu_dev *cpudev = *cdev; 7639d31d35bSYinghai Lu 76410a434fcSYinghai Lu if (count >= X86_VENDOR_NUM) 76510a434fcSYinghai Lu break; 76610a434fcSYinghai Lu cpu_devs[count] = cpudev; 76710a434fcSYinghai Lu count++; 76810a434fcSYinghai Lu 769ac23f253SJan Beulich #ifdef CONFIG_PROCESSOR_SELECT 77031c997caSIngo Molnar { 77131c997caSIngo Molnar unsigned int j; 77231c997caSIngo Molnar 77310a434fcSYinghai Lu for (j = 0; j < 2; j++) { 77410a434fcSYinghai Lu if (!cpudev->c_ident[j]) 77510a434fcSYinghai Lu continue; 7769766cdbcSJaswinder Singh Rajput printk(KERN_INFO " %s %s\n", cpudev->c_vendor, 77710a434fcSYinghai Lu cpudev->c_ident[j]); 77810a434fcSYinghai Lu } 77910a434fcSYinghai Lu } 7800388423dSDave Jones #endif 78131c997caSIngo Molnar } 7829d31d35bSYinghai Lu early_identify_cpu(&boot_cpu_data); 783f7627e25SThomas Gleixner } 784f7627e25SThomas Gleixner 785b6734c35SH. Peter Anvin /* 786366d4a43SBorislav Petkov * The NOPL instruction is supposed to exist on all CPUs of family >= 6; 787366d4a43SBorislav Petkov * unfortunately, that's not true in practice because of early VIA 788366d4a43SBorislav Petkov * chips and (more importantly) broken virtualizers that are not easy 789366d4a43SBorislav Petkov * to detect. In the latter case it doesn't even *fail* reliably, so 790366d4a43SBorislav Petkov * probing for it doesn't even work. Disable it completely on 32-bit 791ba0593bfSH. Peter Anvin * unless we can find a reliable way to detect all the broken cases. 792366d4a43SBorislav Petkov * Enable it explicitly on 64-bit for non-constant inputs of cpu_has(). 793b6734c35SH. Peter Anvin */ 794148f9bb8SPaul Gortmaker static void detect_nopl(struct cpuinfo_x86 *c) 795b6734c35SH. Peter Anvin { 796366d4a43SBorislav Petkov #ifdef CONFIG_X86_32 797b6734c35SH. Peter Anvin clear_cpu_cap(c, X86_FEATURE_NOPL); 798366d4a43SBorislav Petkov #else 799366d4a43SBorislav Petkov set_cpu_cap(c, X86_FEATURE_NOPL); 800366d4a43SBorislav Petkov #endif 801f7627e25SThomas Gleixner } 802f7627e25SThomas Gleixner 803148f9bb8SPaul Gortmaker static void generic_identify(struct cpuinfo_x86 *c) 804f7627e25SThomas Gleixner { 8053da99c97SYinghai Lu c->extended_cpuid_level = 0; 806f7627e25SThomas Gleixner 807aef93c8bSYinghai Lu if (!have_cpuid_p()) 808aef93c8bSYinghai Lu identify_cpu_without_cpuid(c); 809f7627e25SThomas Gleixner 810aef93c8bSYinghai Lu /* cyrix could have cpuid enabled via c_identify()*/ 811a9853dd6SIngo Molnar if (!have_cpuid_p()) 812aef93c8bSYinghai Lu return; 813aef93c8bSYinghai Lu 8143da99c97SYinghai Lu cpu_detect(c); 8153da99c97SYinghai Lu 8163da99c97SYinghai Lu get_cpu_vendor(c); 8173da99c97SYinghai Lu 8183da99c97SYinghai Lu get_cpu_cap(c); 8193da99c97SYinghai Lu 820f7627e25SThomas Gleixner if (c->cpuid_level >= 0x00000001) { 8213da99c97SYinghai Lu c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; 822b89d3b3eSYinghai Lu #ifdef CONFIG_X86_32 823f7627e25SThomas Gleixner # ifdef CONFIG_X86_HT 824cb8cc442SIngo Molnar c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); 825f7627e25SThomas Gleixner # else 82601aaea1aSYinghai Lu c->apicid = c->initial_apicid; 827f7627e25SThomas Gleixner # endif 828b89d3b3eSYinghai Lu #endif 829b89d3b3eSYinghai Lu c->phys_proc_id = c->initial_apicid; 830f7627e25SThomas Gleixner } 831f7627e25SThomas Gleixner 832f7627e25SThomas Gleixner get_model_name(c); /* Default name */ 833f7627e25SThomas Gleixner 834b6734c35SH. Peter Anvin detect_nopl(c); 835f7627e25SThomas Gleixner } 836f7627e25SThomas Gleixner 837f7627e25SThomas Gleixner /* 838f7627e25SThomas Gleixner * This does the hard work of actually picking apart the CPU stuff... 839f7627e25SThomas Gleixner */ 840148f9bb8SPaul Gortmaker static void identify_cpu(struct cpuinfo_x86 *c) 841f7627e25SThomas Gleixner { 842f7627e25SThomas Gleixner int i; 843f7627e25SThomas Gleixner 844f7627e25SThomas Gleixner c->loops_per_jiffy = loops_per_jiffy; 845f7627e25SThomas Gleixner c->x86_cache_size = -1; 846f7627e25SThomas Gleixner c->x86_vendor = X86_VENDOR_UNKNOWN; 847f7627e25SThomas Gleixner c->x86_model = c->x86_mask = 0; /* So far unknown... */ 848f7627e25SThomas Gleixner c->x86_vendor_id[0] = '\0'; /* Unset */ 849f7627e25SThomas Gleixner c->x86_model_id[0] = '\0'; /* Unset */ 850f7627e25SThomas Gleixner c->x86_max_cores = 1; 851102bbe3aSYinghai Lu c->x86_coreid_bits = 0; 85211fdd252SYinghai Lu #ifdef CONFIG_X86_64 853102bbe3aSYinghai Lu c->x86_clflush_size = 64; 85413c6c532SJan Beulich c->x86_phys_bits = 36; 85513c6c532SJan Beulich c->x86_virt_bits = 48; 856102bbe3aSYinghai Lu #else 857102bbe3aSYinghai Lu c->cpuid_level = -1; /* CPUID not detected */ 858f7627e25SThomas Gleixner c->x86_clflush_size = 32; 85913c6c532SJan Beulich c->x86_phys_bits = 32; 86013c6c532SJan Beulich c->x86_virt_bits = 32; 861102bbe3aSYinghai Lu #endif 862102bbe3aSYinghai Lu c->x86_cache_alignment = c->x86_clflush_size; 863f7627e25SThomas Gleixner memset(&c->x86_capability, 0, sizeof c->x86_capability); 864f7627e25SThomas Gleixner 865f7627e25SThomas Gleixner generic_identify(c); 866f7627e25SThomas Gleixner 8673898534dSAndi Kleen if (this_cpu->c_identify) 868f7627e25SThomas Gleixner this_cpu->c_identify(c); 869f7627e25SThomas Gleixner 8702759c328SYinghai Lu /* Clear/Set all flags overriden by options, after probe */ 8712759c328SYinghai Lu for (i = 0; i < NCAPINTS; i++) { 8722759c328SYinghai Lu c->x86_capability[i] &= ~cpu_caps_cleared[i]; 8732759c328SYinghai Lu c->x86_capability[i] |= cpu_caps_set[i]; 8742759c328SYinghai Lu } 8752759c328SYinghai Lu 876102bbe3aSYinghai Lu #ifdef CONFIG_X86_64 877cb8cc442SIngo Molnar c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); 878102bbe3aSYinghai Lu #endif 879102bbe3aSYinghai Lu 880f7627e25SThomas Gleixner /* 881f7627e25SThomas Gleixner * Vendor-specific initialization. In this section we 882f7627e25SThomas Gleixner * canonicalize the feature flags, meaning if there are 883f7627e25SThomas Gleixner * features a certain CPU supports which CPUID doesn't 884f7627e25SThomas Gleixner * tell us, CPUID claiming incorrect flags, or other bugs, 885f7627e25SThomas Gleixner * we handle them here. 886f7627e25SThomas Gleixner * 887f7627e25SThomas Gleixner * At the end of this section, c->x86_capability better 888f7627e25SThomas Gleixner * indicate the features this CPU genuinely supports! 889f7627e25SThomas Gleixner */ 890f7627e25SThomas Gleixner if (this_cpu->c_init) 891f7627e25SThomas Gleixner this_cpu->c_init(c); 892f7627e25SThomas Gleixner 893f7627e25SThomas Gleixner /* Disable the PN if appropriate */ 894f7627e25SThomas Gleixner squash_the_stupid_serial_number(c); 895f7627e25SThomas Gleixner 896b2cc2a07SH. Peter Anvin /* Set up SMEP/SMAP */ 897b2cc2a07SH. Peter Anvin setup_smep(c); 898b2cc2a07SH. Peter Anvin setup_smap(c); 899b2cc2a07SH. Peter Anvin 900f7627e25SThomas Gleixner /* 9010f3fa48aSIngo Molnar * The vendor-specific functions might have changed features. 9020f3fa48aSIngo Molnar * Now we do "generic changes." 903f7627e25SThomas Gleixner */ 904f7627e25SThomas Gleixner 905b38b0665SH. Peter Anvin /* Filter out anything that depends on CPUID levels we don't have */ 906b38b0665SH. Peter Anvin filter_cpuid_features(c, true); 907b38b0665SH. Peter Anvin 908f7627e25SThomas Gleixner /* If the model name is still unset, do table lookup. */ 909f7627e25SThomas Gleixner if (!c->x86_model_id[0]) { 91002dde8b4SJan Beulich const char *p; 911f7627e25SThomas Gleixner p = table_lookup_model(c); 912f7627e25SThomas Gleixner if (p) 913f7627e25SThomas Gleixner strcpy(c->x86_model_id, p); 914f7627e25SThomas Gleixner else 915f7627e25SThomas Gleixner /* Last resort... */ 916f7627e25SThomas Gleixner sprintf(c->x86_model_id, "%02x/%02x", 917f7627e25SThomas Gleixner c->x86, c->x86_model); 918f7627e25SThomas Gleixner } 919f7627e25SThomas Gleixner 920102bbe3aSYinghai Lu #ifdef CONFIG_X86_64 921102bbe3aSYinghai Lu detect_ht(c); 922102bbe3aSYinghai Lu #endif 923102bbe3aSYinghai Lu 92488b094fbSAlok Kataria init_hypervisor(c); 92549d859d7SH. Peter Anvin x86_init_rdrand(c); 9263e0c3737SYinghai Lu 9273e0c3737SYinghai Lu /* 9283e0c3737SYinghai Lu * Clear/Set all flags overriden by options, need do it 9293e0c3737SYinghai Lu * before following smp all cpus cap AND. 9303e0c3737SYinghai Lu */ 9313e0c3737SYinghai Lu for (i = 0; i < NCAPINTS; i++) { 9323e0c3737SYinghai Lu c->x86_capability[i] &= ~cpu_caps_cleared[i]; 9333e0c3737SYinghai Lu c->x86_capability[i] |= cpu_caps_set[i]; 9343e0c3737SYinghai Lu } 9353e0c3737SYinghai Lu 936f7627e25SThomas Gleixner /* 937f7627e25SThomas Gleixner * On SMP, boot_cpu_data holds the common feature set between 938f7627e25SThomas Gleixner * all CPUs; so make sure that we indicate which features are 939f7627e25SThomas Gleixner * common between the CPUs. The first time this routine gets 940f7627e25SThomas Gleixner * executed, c == &boot_cpu_data. 941f7627e25SThomas Gleixner */ 942f7627e25SThomas Gleixner if (c != &boot_cpu_data) { 943f7627e25SThomas Gleixner /* AND the already accumulated flags with these */ 944f7627e25SThomas Gleixner for (i = 0; i < NCAPINTS; i++) 945f7627e25SThomas Gleixner boot_cpu_data.x86_capability[i] &= c->x86_capability[i]; 94665fc985bSBorislav Petkov 94765fc985bSBorislav Petkov /* OR, i.e. replicate the bug flags */ 94865fc985bSBorislav Petkov for (i = NCAPINTS; i < NCAPINTS + NBUGINTS; i++) 94965fc985bSBorislav Petkov c->x86_capability[i] |= boot_cpu_data.x86_capability[i]; 950f7627e25SThomas Gleixner } 951f7627e25SThomas Gleixner 952f7627e25SThomas Gleixner /* Init Machine Check Exception if available. */ 9535e09954aSBorislav Petkov mcheck_cpu_init(c); 95430d432dfSAndi Kleen 95530d432dfSAndi Kleen select_idle_routine(c); 956102bbe3aSYinghai Lu 957de2d9445STejun Heo #ifdef CONFIG_NUMA 958102bbe3aSYinghai Lu numa_add_cpu(smp_processor_id()); 959102bbe3aSYinghai Lu #endif 960f7627e25SThomas Gleixner } 961f7627e25SThomas Gleixner 962e04d645fSGlauber Costa #ifdef CONFIG_X86_64 963e48510f4SAndrew Morton # ifdef CONFIG_IA32_EMULATION 964cfda7bb9SAndy Lutomirski /* May not be __init: called during resume */ 965cfda7bb9SAndy Lutomirski static void syscall32_cpu_init(void) 966cfda7bb9SAndy Lutomirski { 967*8b6c0ab1SIngo Molnar /* 968*8b6c0ab1SIngo Molnar * Always load these, in case some future 64-bit CPU supports 969*8b6c0ab1SIngo Molnar * SYSENTER from compat mode too: 970*8b6c0ab1SIngo Molnar */ 971cfda7bb9SAndy Lutomirski wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS); 972cfda7bb9SAndy Lutomirski wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL); 973cfda7bb9SAndy Lutomirski wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target); 974cfda7bb9SAndy Lutomirski 975cfda7bb9SAndy Lutomirski wrmsrl(MSR_CSTAR, ia32_cstar_target); 976cfda7bb9SAndy Lutomirski } 977*8b6c0ab1SIngo Molnar # endif 978*8b6c0ab1SIngo Molnar #endif 979cfda7bb9SAndy Lutomirski 980*8b6c0ab1SIngo Molnar /* 981*8b6c0ab1SIngo Molnar * Set up the CPU state needed to execute SYSENTER/SYSEXIT instructions 982*8b6c0ab1SIngo Molnar * on 32-bit kernels: 983*8b6c0ab1SIngo Molnar */ 984cfda7bb9SAndy Lutomirski #ifdef CONFIG_X86_32 985cfda7bb9SAndy Lutomirski void enable_sep_cpu(void) 986cfda7bb9SAndy Lutomirski { 987*8b6c0ab1SIngo Molnar struct tss_struct *tss; 988*8b6c0ab1SIngo Molnar int cpu; 989cfda7bb9SAndy Lutomirski 990*8b6c0ab1SIngo Molnar cpu = get_cpu(); 991*8b6c0ab1SIngo Molnar tss = &per_cpu(cpu_tss, cpu); 992*8b6c0ab1SIngo Molnar 993*8b6c0ab1SIngo Molnar if (!boot_cpu_has(X86_FEATURE_SEP)) 994*8b6c0ab1SIngo Molnar goto out; 995*8b6c0ab1SIngo Molnar 996*8b6c0ab1SIngo Molnar /* 997*8b6c0ab1SIngo Molnar * The struct::SS1 and tss_struct::SP1 fields are not used by the hardware, 998*8b6c0ab1SIngo Molnar * we cache the SYSENTER CS and ESP values there for easy access: 999*8b6c0ab1SIngo Molnar */ 1000cfda7bb9SAndy Lutomirski 1001cfda7bb9SAndy Lutomirski tss->x86_tss.ss1 = __KERNEL_CS; 1002*8b6c0ab1SIngo Molnar wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0); 1003*8b6c0ab1SIngo Molnar 1004d828c71fSDenys Vlasenko tss->x86_tss.sp1 = (unsigned long)tss + offsetofend(struct tss_struct, SYSENTER_stack); 1005cfda7bb9SAndy Lutomirski wrmsr(MSR_IA32_SYSENTER_ESP, tss->x86_tss.sp1, 0); 1006*8b6c0ab1SIngo Molnar 1007cfda7bb9SAndy Lutomirski wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)ia32_sysenter_target, 0); 1008*8b6c0ab1SIngo Molnar 1009*8b6c0ab1SIngo Molnar out: 1010cfda7bb9SAndy Lutomirski put_cpu(); 1011cfda7bb9SAndy Lutomirski } 1012e04d645fSGlauber Costa #endif 1013e04d645fSGlauber Costa 1014f7627e25SThomas Gleixner void __init identify_boot_cpu(void) 1015f7627e25SThomas Gleixner { 1016f7627e25SThomas Gleixner identify_cpu(&boot_cpu_data); 101702c68a02SLen Brown init_amd_e400_c1e_mask(); 1018102bbe3aSYinghai Lu #ifdef CONFIG_X86_32 1019f7627e25SThomas Gleixner sysenter_setup(); 1020f7627e25SThomas Gleixner enable_sep_cpu(); 1021102bbe3aSYinghai Lu #endif 1022e0ba94f1SAlex Shi cpu_detect_tlb(&boot_cpu_data); 1023f7627e25SThomas Gleixner } 1024f7627e25SThomas Gleixner 1025148f9bb8SPaul Gortmaker void identify_secondary_cpu(struct cpuinfo_x86 *c) 1026f7627e25SThomas Gleixner { 1027f7627e25SThomas Gleixner BUG_ON(c == &boot_cpu_data); 1028f7627e25SThomas Gleixner identify_cpu(c); 1029102bbe3aSYinghai Lu #ifdef CONFIG_X86_32 1030f7627e25SThomas Gleixner enable_sep_cpu(); 1031102bbe3aSYinghai Lu #endif 1032f7627e25SThomas Gleixner mtrr_ap_init(); 1033f7627e25SThomas Gleixner } 1034f7627e25SThomas Gleixner 1035a0854a46SYinghai Lu struct msr_range { 1036a0854a46SYinghai Lu unsigned min; 1037a0854a46SYinghai Lu unsigned max; 1038a0854a46SYinghai Lu }; 1039a0854a46SYinghai Lu 1040148f9bb8SPaul Gortmaker static const struct msr_range msr_range_array[] = { 1041a0854a46SYinghai Lu { 0x00000000, 0x00000418}, 1042a0854a46SYinghai Lu { 0xc0000000, 0xc000040b}, 1043a0854a46SYinghai Lu { 0xc0010000, 0xc0010142}, 1044a0854a46SYinghai Lu { 0xc0011000, 0xc001103b}, 1045a0854a46SYinghai Lu }; 1046a0854a46SYinghai Lu 1047148f9bb8SPaul Gortmaker static void __print_cpu_msr(void) 1048f7627e25SThomas Gleixner { 10490f3fa48aSIngo Molnar unsigned index_min, index_max; 1050a0854a46SYinghai Lu unsigned index; 1051a0854a46SYinghai Lu u64 val; 1052a0854a46SYinghai Lu int i; 1053f7627e25SThomas Gleixner 1054a0854a46SYinghai Lu for (i = 0; i < ARRAY_SIZE(msr_range_array); i++) { 1055a0854a46SYinghai Lu index_min = msr_range_array[i].min; 1056a0854a46SYinghai Lu index_max = msr_range_array[i].max; 10570f3fa48aSIngo Molnar 1058a0854a46SYinghai Lu for (index = index_min; index < index_max; index++) { 1059ecd431d9SBorislav Petkov if (rdmsrl_safe(index, &val)) 1060a0854a46SYinghai Lu continue; 1061a0854a46SYinghai Lu printk(KERN_INFO " MSR%08x: %016llx\n", index, val); 1062f7627e25SThomas Gleixner } 1063f7627e25SThomas Gleixner } 1064a0854a46SYinghai Lu } 1065a0854a46SYinghai Lu 1066148f9bb8SPaul Gortmaker static int show_msr; 10670f3fa48aSIngo Molnar 1068a0854a46SYinghai Lu static __init int setup_show_msr(char *arg) 1069a0854a46SYinghai Lu { 1070a0854a46SYinghai Lu int num; 1071a0854a46SYinghai Lu 1072a0854a46SYinghai Lu get_option(&arg, &num); 1073a0854a46SYinghai Lu 1074a0854a46SYinghai Lu if (num > 0) 1075a0854a46SYinghai Lu show_msr = num; 1076a0854a46SYinghai Lu return 1; 1077a0854a46SYinghai Lu } 1078a0854a46SYinghai Lu __setup("show_msr=", setup_show_msr); 1079f7627e25SThomas Gleixner 1080191679fdSAndi Kleen static __init int setup_noclflush(char *arg) 1081191679fdSAndi Kleen { 1082840d2830SH. Peter Anvin setup_clear_cpu_cap(X86_FEATURE_CLFLUSH); 1083da4aaa7dSH. Peter Anvin setup_clear_cpu_cap(X86_FEATURE_CLFLUSHOPT); 1084191679fdSAndi Kleen return 1; 1085191679fdSAndi Kleen } 1086191679fdSAndi Kleen __setup("noclflush", setup_noclflush); 1087191679fdSAndi Kleen 1088148f9bb8SPaul Gortmaker void print_cpu_info(struct cpuinfo_x86 *c) 1089f7627e25SThomas Gleixner { 109002dde8b4SJan Beulich const char *vendor = NULL; 1091f7627e25SThomas Gleixner 10920f3fa48aSIngo Molnar if (c->x86_vendor < X86_VENDOR_NUM) { 1093f7627e25SThomas Gleixner vendor = this_cpu->c_vendor; 10940f3fa48aSIngo Molnar } else { 10950f3fa48aSIngo Molnar if (c->cpuid_level >= 0) 1096f7627e25SThomas Gleixner vendor = c->x86_vendor_id; 10970f3fa48aSIngo Molnar } 1098f7627e25SThomas Gleixner 1099bd32a8cfSYinghai Lu if (vendor && !strstr(c->x86_model_id, vendor)) 11009d31d35bSYinghai Lu printk(KERN_CONT "%s ", vendor); 1101f7627e25SThomas Gleixner 11029d31d35bSYinghai Lu if (c->x86_model_id[0]) 1103924e101aSBorislav Petkov printk(KERN_CONT "%s", strim(c->x86_model_id)); 1104f7627e25SThomas Gleixner else 11059d31d35bSYinghai Lu printk(KERN_CONT "%d86", c->x86); 1106f7627e25SThomas Gleixner 1107924e101aSBorislav Petkov printk(KERN_CONT " (fam: %02x, model: %02x", c->x86, c->x86_model); 1108924e101aSBorislav Petkov 1109f7627e25SThomas Gleixner if (c->x86_mask || c->cpuid_level >= 0) 1110924e101aSBorislav Petkov printk(KERN_CONT ", stepping: %02x)\n", c->x86_mask); 1111f7627e25SThomas Gleixner else 1112924e101aSBorislav Petkov printk(KERN_CONT ")\n"); 1113a0854a46SYinghai Lu 11140b8b8078SYinghai Lu print_cpu_msr(c); 111521c3fcf3SYinghai Lu } 111621c3fcf3SYinghai Lu 1117148f9bb8SPaul Gortmaker void print_cpu_msr(struct cpuinfo_x86 *c) 111821c3fcf3SYinghai Lu { 1119a0854a46SYinghai Lu if (c->cpu_index < show_msr) 112021c3fcf3SYinghai Lu __print_cpu_msr(); 1121f7627e25SThomas Gleixner } 1122f7627e25SThomas Gleixner 1123ac72e788SAndi Kleen static __init int setup_disablecpuid(char *arg) 1124ac72e788SAndi Kleen { 1125ac72e788SAndi Kleen int bit; 11260f3fa48aSIngo Molnar 1127ac72e788SAndi Kleen if (get_option(&arg, &bit) && bit < NCAPINTS*32) 1128ac72e788SAndi Kleen setup_clear_cpu_cap(bit); 1129ac72e788SAndi Kleen else 1130ac72e788SAndi Kleen return 0; 11310f3fa48aSIngo Molnar 1132ac72e788SAndi Kleen return 1; 1133ac72e788SAndi Kleen } 1134ac72e788SAndi Kleen __setup("clearcpuid=", setup_disablecpuid); 1135ac72e788SAndi Kleen 1136198d208dSSteven Rostedt DEFINE_PER_CPU(unsigned long, kernel_stack) = 1137198d208dSSteven Rostedt (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE; 1138198d208dSSteven Rostedt EXPORT_PER_CPU_SYMBOL(kernel_stack); 1139198d208dSSteven Rostedt 1140d5494d4fSYinghai Lu #ifdef CONFIG_X86_64 11419ff80942SCyrill Gorcunov struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table }; 1142629f4f9dSSeiji Aguchi struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, 1143629f4f9dSSeiji Aguchi (unsigned long) debug_idt_table }; 1144d5494d4fSYinghai Lu 1145947e76cdSBrian Gerst DEFINE_PER_CPU_FIRST(union irq_stack_union, 1146277d5b40SAndi Kleen irq_stack_union) __aligned(PAGE_SIZE) __visible; 11470f3fa48aSIngo Molnar 1148bdf977b3STejun Heo /* 1149a7fcf28dSAndy Lutomirski * The following percpu variables are hot. Align current_task to 1150a7fcf28dSAndy Lutomirski * cacheline size such that they fall in the same cacheline. 1151bdf977b3STejun Heo */ 1152bdf977b3STejun Heo DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned = 1153bdf977b3STejun Heo &init_task; 1154bdf977b3STejun Heo EXPORT_PER_CPU_SYMBOL(current_task); 1155d5494d4fSYinghai Lu 1156bdf977b3STejun Heo DEFINE_PER_CPU(char *, irq_stack_ptr) = 1157bdf977b3STejun Heo init_per_cpu_var(irq_stack_union.irq_stack) + IRQ_STACK_SIZE - 64; 1158bdf977b3STejun Heo 1159277d5b40SAndi Kleen DEFINE_PER_CPU(unsigned int, irq_count) __visible = -1; 1160d5494d4fSYinghai Lu 1161c2daa3beSPeter Zijlstra DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT; 1162c2daa3beSPeter Zijlstra EXPORT_PER_CPU_SYMBOL(__preempt_count); 1163c2daa3beSPeter Zijlstra 11647e16838dSLinus Torvalds DEFINE_PER_CPU(struct task_struct *, fpu_owner_task); 11657e16838dSLinus Torvalds 11660f3fa48aSIngo Molnar /* 11670f3fa48aSIngo Molnar * Special IST stacks which the CPU switches to when it calls 11680f3fa48aSIngo Molnar * an IST-marked descriptor entry. Up to 7 stacks (hardware 11690f3fa48aSIngo Molnar * limit), all of them are 4K, except the debug stack which 11700f3fa48aSIngo Molnar * is 8K. 11710f3fa48aSIngo Molnar */ 11720f3fa48aSIngo Molnar static const unsigned int exception_stack_sizes[N_EXCEPTION_STACKS] = { 11730f3fa48aSIngo Molnar [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ, 11740f3fa48aSIngo Molnar [DEBUG_STACK - 1] = DEBUG_STKSZ 11750f3fa48aSIngo Molnar }; 11760f3fa48aSIngo Molnar 117792d65b23SBrian Gerst static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks 11783e352aa8STejun Heo [(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]); 1179d5494d4fSYinghai Lu 1180d5494d4fSYinghai Lu /* May not be marked __init: used by software suspend */ 1181d5494d4fSYinghai Lu void syscall_init(void) 1182d5494d4fSYinghai Lu { 1183d5494d4fSYinghai Lu /* 1184d5494d4fSYinghai Lu * LSTAR and STAR live in a bit strange symbiosis. 1185d5494d4fSYinghai Lu * They both write to the same internal register. STAR allows to 1186d5494d4fSYinghai Lu * set CS/DS but only a 32bit target. LSTAR sets the 64bit rip. 1187d5494d4fSYinghai Lu */ 1188d5494d4fSYinghai Lu wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32); 1189d5494d4fSYinghai Lu wrmsrl(MSR_LSTAR, system_call); 1190d5494d4fSYinghai Lu wrmsrl(MSR_CSTAR, ignore_sysret); 1191d5494d4fSYinghai Lu 1192d5494d4fSYinghai Lu #ifdef CONFIG_IA32_EMULATION 1193d5494d4fSYinghai Lu syscall32_cpu_init(); 1194d5494d4fSYinghai Lu #endif 1195d5494d4fSYinghai Lu 1196d5494d4fSYinghai Lu /* Flags to clear on syscall */ 1197d5494d4fSYinghai Lu wrmsrl(MSR_SYSCALL_MASK, 119863bcff2aSH. Peter Anvin X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF| 11998c7aa698SAndy Lutomirski X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT); 1200d5494d4fSYinghai Lu } 1201d5494d4fSYinghai Lu 1202d5494d4fSYinghai Lu /* 1203d5494d4fSYinghai Lu * Copies of the original ist values from the tss are only accessed during 1204d5494d4fSYinghai Lu * debugging, no special alignment required. 1205d5494d4fSYinghai Lu */ 1206d5494d4fSYinghai Lu DEFINE_PER_CPU(struct orig_ist, orig_ist); 1207d5494d4fSYinghai Lu 1208228bdaa9SSteven Rostedt static DEFINE_PER_CPU(unsigned long, debug_stack_addr); 120942181186SSteven Rostedt DEFINE_PER_CPU(int, debug_stack_usage); 1210228bdaa9SSteven Rostedt 1211228bdaa9SSteven Rostedt int is_debug_stack(unsigned long addr) 1212228bdaa9SSteven Rostedt { 121389cbc767SChristoph Lameter return __this_cpu_read(debug_stack_usage) || 121489cbc767SChristoph Lameter (addr <= __this_cpu_read(debug_stack_addr) && 121589cbc767SChristoph Lameter addr > (__this_cpu_read(debug_stack_addr) - DEBUG_STKSZ)); 1216228bdaa9SSteven Rostedt } 12170f46efebSMasami Hiramatsu NOKPROBE_SYMBOL(is_debug_stack); 1218228bdaa9SSteven Rostedt 1219629f4f9dSSeiji Aguchi DEFINE_PER_CPU(u32, debug_idt_ctr); 1220f8988175SSteven Rostedt 1221228bdaa9SSteven Rostedt void debug_stack_set_zero(void) 1222228bdaa9SSteven Rostedt { 1223629f4f9dSSeiji Aguchi this_cpu_inc(debug_idt_ctr); 1224629f4f9dSSeiji Aguchi load_current_idt(); 1225228bdaa9SSteven Rostedt } 12260f46efebSMasami Hiramatsu NOKPROBE_SYMBOL(debug_stack_set_zero); 1227228bdaa9SSteven Rostedt 1228228bdaa9SSteven Rostedt void debug_stack_reset(void) 1229228bdaa9SSteven Rostedt { 1230629f4f9dSSeiji Aguchi if (WARN_ON(!this_cpu_read(debug_idt_ctr))) 1231f8988175SSteven Rostedt return; 1232629f4f9dSSeiji Aguchi if (this_cpu_dec_return(debug_idt_ctr) == 0) 1233629f4f9dSSeiji Aguchi load_current_idt(); 1234228bdaa9SSteven Rostedt } 12350f46efebSMasami Hiramatsu NOKPROBE_SYMBOL(debug_stack_reset); 1236228bdaa9SSteven Rostedt 12370f3fa48aSIngo Molnar #else /* CONFIG_X86_64 */ 1238d5494d4fSYinghai Lu 1239bdf977b3STejun Heo DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task; 1240bdf977b3STejun Heo EXPORT_PER_CPU_SYMBOL(current_task); 1241c2daa3beSPeter Zijlstra DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT; 1242c2daa3beSPeter Zijlstra EXPORT_PER_CPU_SYMBOL(__preempt_count); 124327e74da9SLinus Torvalds DEFINE_PER_CPU(struct task_struct *, fpu_owner_task); 1244bdf977b3STejun Heo 1245a7fcf28dSAndy Lutomirski /* 1246a7fcf28dSAndy Lutomirski * On x86_32, vm86 modifies tss.sp0, so sp0 isn't a reliable way to find 1247a7fcf28dSAndy Lutomirski * the top of the kernel stack. Use an extra percpu variable to track the 1248a7fcf28dSAndy Lutomirski * top of the kernel stack directly. 1249a7fcf28dSAndy Lutomirski */ 1250a7fcf28dSAndy Lutomirski DEFINE_PER_CPU(unsigned long, cpu_current_top_of_stack) = 1251a7fcf28dSAndy Lutomirski (unsigned long)&init_thread_union + THREAD_SIZE; 1252a7fcf28dSAndy Lutomirski EXPORT_PER_CPU_SYMBOL(cpu_current_top_of_stack); 1253a7fcf28dSAndy Lutomirski 125460a5317fSTejun Heo #ifdef CONFIG_CC_STACKPROTECTOR 125553f82452SJeremy Fitzhardinge DEFINE_PER_CPU_ALIGNED(struct stack_canary, stack_canary); 125660a5317fSTejun Heo #endif 125760a5317fSTejun Heo 12580f3fa48aSIngo Molnar #endif /* CONFIG_X86_64 */ 1259f7627e25SThomas Gleixner 1260f7627e25SThomas Gleixner /* 12619766cdbcSJaswinder Singh Rajput * Clear all 6 debug registers: 12629766cdbcSJaswinder Singh Rajput */ 12639766cdbcSJaswinder Singh Rajput static void clear_all_debug_regs(void) 12649766cdbcSJaswinder Singh Rajput { 12659766cdbcSJaswinder Singh Rajput int i; 12669766cdbcSJaswinder Singh Rajput 12679766cdbcSJaswinder Singh Rajput for (i = 0; i < 8; i++) { 12689766cdbcSJaswinder Singh Rajput /* Ignore db4, db5 */ 12699766cdbcSJaswinder Singh Rajput if ((i == 4) || (i == 5)) 12709766cdbcSJaswinder Singh Rajput continue; 12719766cdbcSJaswinder Singh Rajput 12729766cdbcSJaswinder Singh Rajput set_debugreg(0, i); 12739766cdbcSJaswinder Singh Rajput } 12749766cdbcSJaswinder Singh Rajput } 1275f7627e25SThomas Gleixner 12760bb9fef9SJason Wessel #ifdef CONFIG_KGDB 12770bb9fef9SJason Wessel /* 12780bb9fef9SJason Wessel * Restore debug regs if using kgdbwait and you have a kernel debugger 12790bb9fef9SJason Wessel * connection established. 12800bb9fef9SJason Wessel */ 12810bb9fef9SJason Wessel static void dbg_restore_debug_regs(void) 12820bb9fef9SJason Wessel { 12830bb9fef9SJason Wessel if (unlikely(kgdb_connected && arch_kgdb_ops.correct_hw_break)) 12840bb9fef9SJason Wessel arch_kgdb_ops.correct_hw_break(); 12850bb9fef9SJason Wessel } 12860bb9fef9SJason Wessel #else /* ! CONFIG_KGDB */ 12870bb9fef9SJason Wessel #define dbg_restore_debug_regs() 12880bb9fef9SJason Wessel #endif /* ! CONFIG_KGDB */ 12890bb9fef9SJason Wessel 1290ce4b1b16SIgor Mammedov static void wait_for_master_cpu(int cpu) 1291ce4b1b16SIgor Mammedov { 1292ce4b1b16SIgor Mammedov #ifdef CONFIG_SMP 1293ce4b1b16SIgor Mammedov /* 1294ce4b1b16SIgor Mammedov * wait for ACK from master CPU before continuing 1295ce4b1b16SIgor Mammedov * with AP initialization 1296ce4b1b16SIgor Mammedov */ 1297ce4b1b16SIgor Mammedov WARN_ON(cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)); 1298ce4b1b16SIgor Mammedov while (!cpumask_test_cpu(cpu, cpu_callout_mask)) 1299ce4b1b16SIgor Mammedov cpu_relax(); 1300ce4b1b16SIgor Mammedov #endif 1301ce4b1b16SIgor Mammedov } 1302ce4b1b16SIgor Mammedov 1303f7627e25SThomas Gleixner /* 1304f7627e25SThomas Gleixner * cpu_init() initializes state that is per-CPU. Some data is already 1305f7627e25SThomas Gleixner * initialized (naturally) in the bootstrap process, such as the GDT 1306f7627e25SThomas Gleixner * and IDT. We reload them nevertheless, this function acts as a 1307f7627e25SThomas Gleixner * 'CPU state barrier', nothing should get across. 13081ba76586SYinghai Lu * A lot of state is already set up in PDA init for 64 bit 1309f7627e25SThomas Gleixner */ 13101ba76586SYinghai Lu #ifdef CONFIG_X86_64 13110f3fa48aSIngo Molnar 1312148f9bb8SPaul Gortmaker void cpu_init(void) 13131ba76586SYinghai Lu { 13140fe1e009STejun Heo struct orig_ist *oist; 13151ba76586SYinghai Lu struct task_struct *me; 13160f3fa48aSIngo Molnar struct tss_struct *t; 13170f3fa48aSIngo Molnar unsigned long v; 1318ce4b1b16SIgor Mammedov int cpu = stack_smp_processor_id(); 13191ba76586SYinghai Lu int i; 13201ba76586SYinghai Lu 1321ce4b1b16SIgor Mammedov wait_for_master_cpu(cpu); 1322ce4b1b16SIgor Mammedov 1323e6ebf5deSFenghua Yu /* 13241e02ce4cSAndy Lutomirski * Initialize the CR4 shadow before doing anything that could 13251e02ce4cSAndy Lutomirski * try to read it. 13261e02ce4cSAndy Lutomirski */ 13271e02ce4cSAndy Lutomirski cr4_init_shadow(); 13281e02ce4cSAndy Lutomirski 13291e02ce4cSAndy Lutomirski /* 1330e6ebf5deSFenghua Yu * Load microcode on this cpu if a valid microcode is available. 1331e6ebf5deSFenghua Yu * This is early microcode loading procedure. 1332e6ebf5deSFenghua Yu */ 1333e6ebf5deSFenghua Yu load_ucode_ap(); 1334e6ebf5deSFenghua Yu 133524933b82SAndy Lutomirski t = &per_cpu(cpu_tss, cpu); 13360fe1e009STejun Heo oist = &per_cpu(orig_ist, cpu); 13370f3fa48aSIngo Molnar 1338e7a22c1eSBrian Gerst #ifdef CONFIG_NUMA 133927fd185fSFenghua Yu if (this_cpu_read(numa_node) == 0 && 1340e534c7c5SLee Schermerhorn early_cpu_to_node(cpu) != NUMA_NO_NODE) 1341e534c7c5SLee Schermerhorn set_numa_node(early_cpu_to_node(cpu)); 1342e7a22c1eSBrian Gerst #endif 13431ba76586SYinghai Lu 13441ba76586SYinghai Lu me = current; 13451ba76586SYinghai Lu 13462eaad1fdSMike Travis pr_debug("Initializing CPU#%d\n", cpu); 13471ba76586SYinghai Lu 1348375074ccSAndy Lutomirski cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); 13491ba76586SYinghai Lu 13501ba76586SYinghai Lu /* 13511ba76586SYinghai Lu * Initialize the per-CPU GDT with the boot GDT, 13521ba76586SYinghai Lu * and set up the GDT descriptor: 13531ba76586SYinghai Lu */ 13541ba76586SYinghai Lu 1355552be871SBrian Gerst switch_to_new_gdt(cpu); 13562697fbd5SBrian Gerst loadsegment(fs, 0); 13572697fbd5SBrian Gerst 1358cf910e83SSeiji Aguchi load_current_idt(); 13591ba76586SYinghai Lu 13601ba76586SYinghai Lu memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8); 13611ba76586SYinghai Lu syscall_init(); 13621ba76586SYinghai Lu 13631ba76586SYinghai Lu wrmsrl(MSR_FS_BASE, 0); 13641ba76586SYinghai Lu wrmsrl(MSR_KERNEL_GS_BASE, 0); 13651ba76586SYinghai Lu barrier(); 13661ba76586SYinghai Lu 13674763ed4dSH. Peter Anvin x86_configure_nx(); 1368659006bfSThomas Gleixner x2apic_setup(); 13691ba76586SYinghai Lu 13701ba76586SYinghai Lu /* 13711ba76586SYinghai Lu * set up and load the per-CPU TSS 13721ba76586SYinghai Lu */ 13730fe1e009STejun Heo if (!oist->ist[0]) { 137492d65b23SBrian Gerst char *estacks = per_cpu(exception_stacks, cpu); 13750f3fa48aSIngo Molnar 13761ba76586SYinghai Lu for (v = 0; v < N_EXCEPTION_STACKS; v++) { 13770f3fa48aSIngo Molnar estacks += exception_stack_sizes[v]; 13780fe1e009STejun Heo oist->ist[v] = t->x86_tss.ist[v] = 13791ba76586SYinghai Lu (unsigned long)estacks; 1380228bdaa9SSteven Rostedt if (v == DEBUG_STACK-1) 1381228bdaa9SSteven Rostedt per_cpu(debug_stack_addr, cpu) = (unsigned long)estacks; 13821ba76586SYinghai Lu } 13831ba76586SYinghai Lu } 13841ba76586SYinghai Lu 13851ba76586SYinghai Lu t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap); 13860f3fa48aSIngo Molnar 13871ba76586SYinghai Lu /* 13881ba76586SYinghai Lu * <= is required because the CPU will access up to 13891ba76586SYinghai Lu * 8 bits beyond the end of the IO permission bitmap. 13901ba76586SYinghai Lu */ 13911ba76586SYinghai Lu for (i = 0; i <= IO_BITMAP_LONGS; i++) 13921ba76586SYinghai Lu t->io_bitmap[i] = ~0UL; 13931ba76586SYinghai Lu 13941ba76586SYinghai Lu atomic_inc(&init_mm.mm_count); 13951ba76586SYinghai Lu me->active_mm = &init_mm; 13968c5dfd25SStoyan Gaydarov BUG_ON(me->mm); 13971ba76586SYinghai Lu enter_lazy_tlb(&init_mm, me); 13981ba76586SYinghai Lu 13991ba76586SYinghai Lu load_sp0(t, ¤t->thread); 14001ba76586SYinghai Lu set_tss_desc(cpu, t); 14011ba76586SYinghai Lu load_TR_desc(); 14021ba76586SYinghai Lu load_LDT(&init_mm.context); 14031ba76586SYinghai Lu 14049766cdbcSJaswinder Singh Rajput clear_all_debug_regs(); 14050bb9fef9SJason Wessel dbg_restore_debug_regs(); 14061ba76586SYinghai Lu 14071ba76586SYinghai Lu fpu_init(); 14081ba76586SYinghai Lu 14091ba76586SYinghai Lu if (is_uv_system()) 14101ba76586SYinghai Lu uv_cpu_init(); 14111ba76586SYinghai Lu } 14121ba76586SYinghai Lu 14131ba76586SYinghai Lu #else 14141ba76586SYinghai Lu 1415148f9bb8SPaul Gortmaker void cpu_init(void) 1416f7627e25SThomas Gleixner { 1417f7627e25SThomas Gleixner int cpu = smp_processor_id(); 1418f7627e25SThomas Gleixner struct task_struct *curr = current; 141924933b82SAndy Lutomirski struct tss_struct *t = &per_cpu(cpu_tss, cpu); 1420f7627e25SThomas Gleixner struct thread_struct *thread = &curr->thread; 1421f7627e25SThomas Gleixner 1422ce4b1b16SIgor Mammedov wait_for_master_cpu(cpu); 1423e6ebf5deSFenghua Yu 14245b2bdbc8SSteven Rostedt /* 14255b2bdbc8SSteven Rostedt * Initialize the CR4 shadow before doing anything that could 14265b2bdbc8SSteven Rostedt * try to read it. 14275b2bdbc8SSteven Rostedt */ 14285b2bdbc8SSteven Rostedt cr4_init_shadow(); 14295b2bdbc8SSteven Rostedt 1430ce4b1b16SIgor Mammedov show_ucode_info_early(); 1431f7627e25SThomas Gleixner 1432f7627e25SThomas Gleixner printk(KERN_INFO "Initializing CPU#%d\n", cpu); 1433f7627e25SThomas Gleixner 14349298b815SDave Hansen if (cpu_feature_enabled(X86_FEATURE_VME) || cpu_has_tsc || cpu_has_de) 1435375074ccSAndy Lutomirski cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); 1436f7627e25SThomas Gleixner 1437cf910e83SSeiji Aguchi load_current_idt(); 1438552be871SBrian Gerst switch_to_new_gdt(cpu); 1439f7627e25SThomas Gleixner 1440f7627e25SThomas Gleixner /* 1441f7627e25SThomas Gleixner * Set up and load the per-CPU TSS and LDT 1442f7627e25SThomas Gleixner */ 1443f7627e25SThomas Gleixner atomic_inc(&init_mm.mm_count); 1444f7627e25SThomas Gleixner curr->active_mm = &init_mm; 14458c5dfd25SStoyan Gaydarov BUG_ON(curr->mm); 1446f7627e25SThomas Gleixner enter_lazy_tlb(&init_mm, curr); 1447f7627e25SThomas Gleixner 1448faca6227SH. Peter Anvin load_sp0(t, thread); 1449f7627e25SThomas Gleixner set_tss_desc(cpu, t); 1450f7627e25SThomas Gleixner load_TR_desc(); 1451f7627e25SThomas Gleixner load_LDT(&init_mm.context); 1452f7627e25SThomas Gleixner 1453f9a196b8SThomas Gleixner t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap); 1454f9a196b8SThomas Gleixner 1455f7627e25SThomas Gleixner #ifdef CONFIG_DOUBLEFAULT 1456f7627e25SThomas Gleixner /* Set up doublefault TSS pointer in the GDT */ 1457f7627e25SThomas Gleixner __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss); 1458f7627e25SThomas Gleixner #endif 1459f7627e25SThomas Gleixner 14609766cdbcSJaswinder Singh Rajput clear_all_debug_regs(); 14610bb9fef9SJason Wessel dbg_restore_debug_regs(); 1462f7627e25SThomas Gleixner 14630e49bf66SRobert Richter fpu_init(); 1464f7627e25SThomas Gleixner } 14651ba76586SYinghai Lu #endif 14665700f743SBorislav Petkov 14675700f743SBorislav Petkov #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS 14685700f743SBorislav Petkov void warn_pre_alternatives(void) 14695700f743SBorislav Petkov { 14705700f743SBorislav Petkov WARN(1, "You're using static_cpu_has before alternatives have run!\n"); 14715700f743SBorislav Petkov } 14725700f743SBorislav Petkov EXPORT_SYMBOL_GPL(warn_pre_alternatives); 14735700f743SBorislav Petkov #endif 14744a90a99cSBorislav Petkov 14754a90a99cSBorislav Petkov inline bool __static_cpu_has_safe(u16 bit) 14764a90a99cSBorislav Petkov { 14774a90a99cSBorislav Petkov return boot_cpu_has(bit); 14784a90a99cSBorislav Petkov } 14794a90a99cSBorislav Petkov EXPORT_SYMBOL_GPL(__static_cpu_has_safe); 1480