common.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. #include <linux/bootmem.h>
  2. #include <linux/linkage.h>
  3. #include <linux/bitops.h>
  4. #include <linux/kernel.h>
  5. #include <linux/export.h>
  6. #include <linux/percpu.h>
  7. #include <linux/string.h>
  8. #include <linux/ctype.h>
  9. #include <linux/delay.h>
  10. #include <linux/sched/mm.h>
  11. #include <linux/sched/clock.h>
  12. #include <linux/sched/task.h>
  13. #include <linux/init.h>
  14. #include <linux/kprobes.h>
  15. #include <linux/kgdb.h>
  16. #include <linux/smp.h>
  17. #include <linux/io.h>
  18. #include <linux/syscore_ops.h>
  19. #include <asm/stackprotector.h>
  20. #include <asm/perf_event.h>
  21. #include <asm/mmu_context.h>
  22. #include <asm/archrandom.h>
  23. #include <asm/hypervisor.h>
  24. #include <asm/processor.h>
  25. #include <asm/tlbflush.h>
  26. #include <asm/debugreg.h>
  27. #include <asm/sections.h>
  28. #include <asm/vsyscall.h>
  29. #include <linux/topology.h>
  30. #include <linux/cpumask.h>
  31. #include <asm/pgtable.h>
  32. #include <linux/atomic.h>
  33. #include <asm/proto.h>
  34. #include <asm/setup.h>
  35. #include <asm/apic.h>
  36. #include <asm/desc.h>
  37. #include <asm/fpu/internal.h>
  38. #include <asm/mtrr.h>
  39. #include <asm/hwcap2.h>
  40. #include <linux/numa.h>
  41. #include <asm/asm.h>
  42. #include <asm/bugs.h>
  43. #include <asm/cpu.h>
  44. #include <asm/mce.h>
  45. #include <asm/msr.h>
  46. #include <asm/pat.h>
  47. #include <asm/microcode.h>
  48. #include <asm/microcode_intel.h>
  49. #include <asm/intel-family.h>
  50. #include <asm/cpu_device_id.h>
  51. #ifdef CONFIG_X86_LOCAL_APIC
  52. #include <asm/uv/uv.h>
  53. #endif
  54. #include "cpu.h"
  55. u32 elf_hwcap2 __read_mostly;
  56. /* all of these masks are initialized in setup_cpu_local_masks() */
  57. cpumask_var_t cpu_initialized_mask;
  58. cpumask_var_t cpu_callout_mask;
  59. cpumask_var_t cpu_callin_mask;
  60. /* representing cpus for which sibling maps can be computed */
  61. cpumask_var_t cpu_sibling_setup_mask;
  62. /* correctly size the local cpu masks */
  63. void __init setup_cpu_local_masks(void)
  64. {
  65. alloc_bootmem_cpumask_var(&cpu_initialized_mask);
  66. alloc_bootmem_cpumask_var(&cpu_callin_mask);
  67. alloc_bootmem_cpumask_var(&cpu_callout_mask);
  68. alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
  69. }
  70. static void default_init(struct cpuinfo_x86 *c)
  71. {
  72. #ifdef CONFIG_X86_64
  73. cpu_detect_cache_sizes(c);
  74. #else
  75. /* Not much we can do here... */
  76. /* Check if at least it has cpuid */
  77. if (c->cpuid_level == -1) {
  78. /* No cpuid. It must be an ancient CPU */
  79. if (c->x86 == 4)
  80. strcpy(c->x86_model_id, "486");
  81. else if (c->x86 == 3)
  82. strcpy(c->x86_model_id, "386");
  83. }
  84. #endif
  85. }
  86. static const struct cpu_dev default_cpu = {
  87. .c_init = default_init,
  88. .c_vendor = "Unknown",
  89. .c_x86_vendor = X86_VENDOR_UNKNOWN,
  90. };
  91. static const struct cpu_dev *this_cpu = &default_cpu;
  92. DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
  93. #ifdef CONFIG_X86_64
  94. /*
  95. * We need valid kernel segments for data and code in long mode too
  96. * IRET will check the segment types kkeil 2000/10/28
  97. * Also sysret mandates a special GDT layout
  98. *
  99. * TLS descriptors are currently at a different place compared to i386.
  100. * Hopefully nobody expects them at a fixed place (Wine?)
  101. */
  102. [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
  103. [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
  104. [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
  105. [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
  106. [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
  107. [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
  108. #else
  109. [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
  110. [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  111. [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
  112. [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
  113. /*
  114. * Segments used for calling PnP BIOS have byte granularity.
  115. * They code segments and data segments have fixed 64k limits,
  116. * the transfer segment sizes are set at run time.
  117. */
  118. /* 32-bit code */
  119. [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
  120. /* 16-bit code */
  121. [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
  122. /* 16-bit data */
  123. [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
  124. /* 16-bit data */
  125. [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
  126. /* 16-bit data */
  127. [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
  128. /*
  129. * The APM segments have byte granularity and their bases
  130. * are set at run time. All have 64k limits.
  131. */
  132. /* 32-bit code */
  133. [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
  134. /* 16-bit code */
  135. [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
  136. /* data */
  137. [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
  138. [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  139. [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  140. GDT_STACK_CANARY_INIT
  141. #endif
  142. } };
  143. EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
  144. static int __init x86_mpx_setup(char *s)
  145. {
  146. /* require an exact match without trailing characters */
  147. if (strlen(s))
  148. return 0;
  149. /* do not emit a message if the feature is not present */
  150. if (!boot_cpu_has(X86_FEATURE_MPX))
  151. return 1;
  152. setup_clear_cpu_cap(X86_FEATURE_MPX);
  153. pr_info("nompx: Intel Memory Protection Extensions (MPX) disabled\n");
  154. return 1;
  155. }
  156. __setup("nompx", x86_mpx_setup);
  157. #ifdef CONFIG_X86_64
  158. static int __init x86_nopcid_setup(char *s)
  159. {
  160. /* nopcid doesn't accept parameters */
  161. if (s)
  162. return -EINVAL;
  163. /* do not emit a message if the feature is not present */
  164. if (!boot_cpu_has(X86_FEATURE_PCID))
  165. return 0;
  166. setup_clear_cpu_cap(X86_FEATURE_PCID);
  167. pr_info("nopcid: PCID feature disabled\n");
  168. return 0;
  169. }
  170. early_param("nopcid", x86_nopcid_setup);
  171. #endif
  172. static int __init x86_noinvpcid_setup(char *s)
  173. {
  174. /* noinvpcid doesn't accept parameters */
  175. if (s)
  176. return -EINVAL;
  177. /* do not emit a message if the feature is not present */
  178. if (!boot_cpu_has(X86_FEATURE_INVPCID))
  179. return 0;
  180. setup_clear_cpu_cap(X86_FEATURE_INVPCID);
  181. pr_info("noinvpcid: INVPCID feature disabled\n");
  182. return 0;
  183. }
  184. early_param("noinvpcid", x86_noinvpcid_setup);
  185. #ifdef CONFIG_X86_32
  186. static int cachesize_override = -1;
  187. static int disable_x86_serial_nr = 1;
  188. static int __init cachesize_setup(char *str)
  189. {
  190. get_option(&str, &cachesize_override);
  191. return 1;
  192. }
  193. __setup("cachesize=", cachesize_setup);
  194. static int __init x86_sep_setup(char *s)
  195. {
  196. setup_clear_cpu_cap(X86_FEATURE_SEP);
  197. return 1;
  198. }
  199. __setup("nosep", x86_sep_setup);
  200. /* Standard macro to see if a specific flag is changeable */
  201. static inline int flag_is_changeable_p(u32 flag)
  202. {
  203. u32 f1, f2;
  204. /*
  205. * Cyrix and IDT cpus allow disabling of CPUID
  206. * so the code below may return different results
  207. * when it is executed before and after enabling
  208. * the CPUID. Add "volatile" to not allow gcc to
  209. * optimize the subsequent calls to this function.
  210. */
  211. asm volatile ("pushfl \n\t"
  212. "pushfl \n\t"
  213. "popl %0 \n\t"
  214. "movl %0, %1 \n\t"
  215. "xorl %2, %0 \n\t"
  216. "pushl %0 \n\t"
  217. "popfl \n\t"
  218. "pushfl \n\t"
  219. "popl %0 \n\t"
  220. "popfl \n\t"
  221. : "=&r" (f1), "=&r" (f2)
  222. : "ir" (flag));
  223. return ((f1^f2) & flag) != 0;
  224. }
  225. /* Probe for the CPUID instruction */
  226. int have_cpuid_p(void)
  227. {
  228. return flag_is_changeable_p(X86_EFLAGS_ID);
  229. }
  230. static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
  231. {
  232. unsigned long lo, hi;
  233. if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr)
  234. return;
  235. /* Disable processor serial number: */
  236. rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
  237. lo |= 0x200000;
  238. wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
  239. pr_notice("CPU serial number disabled.\n");
  240. clear_cpu_cap(c, X86_FEATURE_PN);
  241. /* Disabling the serial number may affect the cpuid level */
  242. c->cpuid_level = cpuid_eax(0);
  243. }
  244. static int __init x86_serial_nr_setup(char *s)
  245. {
  246. disable_x86_serial_nr = 0;
  247. return 1;
  248. }
  249. __setup("serialnumber", x86_serial_nr_setup);
  250. #else
  251. static inline int flag_is_changeable_p(u32 flag)
  252. {
  253. return 1;
  254. }
  255. static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
  256. {
  257. }
  258. #endif
  259. static __init int setup_disable_smep(char *arg)
  260. {
  261. setup_clear_cpu_cap(X86_FEATURE_SMEP);
  262. /* Check for things that depend on SMEP being enabled: */
  263. check_mpx_erratum(&boot_cpu_data);
  264. return 1;
  265. }
  266. __setup("nosmep", setup_disable_smep);
  267. static __always_inline void setup_smep(struct cpuinfo_x86 *c)
  268. {
  269. if (cpu_has(c, X86_FEATURE_SMEP))
  270. cr4_set_bits(X86_CR4_SMEP);
  271. }
  272. static __init int setup_disable_smap(char *arg)
  273. {
  274. setup_clear_cpu_cap(X86_FEATURE_SMAP);
  275. return 1;
  276. }
  277. __setup("nosmap", setup_disable_smap);
  278. static __always_inline void setup_smap(struct cpuinfo_x86 *c)
  279. {
  280. unsigned long eflags = native_save_fl();
  281. /* This should have been cleared long ago */
  282. BUG_ON(eflags & X86_EFLAGS_AC);
  283. if (cpu_has(c, X86_FEATURE_SMAP)) {
  284. #ifdef CONFIG_X86_SMAP
  285. cr4_set_bits(X86_CR4_SMAP);
  286. #else
  287. cr4_clear_bits(X86_CR4_SMAP);
  288. #endif
  289. }
  290. }
  291. static __always_inline void setup_umip(struct cpuinfo_x86 *c)
  292. {
  293. /* Check the boot processor, plus build option for UMIP. */
  294. if (!cpu_feature_enabled(X86_FEATURE_UMIP))
  295. goto out;
  296. /* Check the current processor's cpuid bits. */
  297. if (!cpu_has(c, X86_FEATURE_UMIP))
  298. goto out;
  299. cr4_set_bits(X86_CR4_UMIP);
  300. pr_info("x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature\n");
  301. return;
  302. out:
  303. /*
  304. * Make sure UMIP is disabled in case it was enabled in a
  305. * previous boot (e.g., via kexec).
  306. */
  307. cr4_clear_bits(X86_CR4_UMIP);
  308. }
  309. /*
  310. * Protection Keys are not available in 32-bit mode.
  311. */
  312. static bool pku_disabled;
  313. static __always_inline void setup_pku(struct cpuinfo_x86 *c)
  314. {
  315. /* check the boot processor, plus compile options for PKU: */
  316. if (!cpu_feature_enabled(X86_FEATURE_PKU))
  317. return;
  318. /* checks the actual processor's cpuid bits: */
  319. if (!cpu_has(c, X86_FEATURE_PKU))
  320. return;
  321. if (pku_disabled)
  322. return;
  323. cr4_set_bits(X86_CR4_PKE);
  324. /*
  325. * Seting X86_CR4_PKE will cause the X86_FEATURE_OSPKE
  326. * cpuid bit to be set. We need to ensure that we
  327. * update that bit in this CPU's "cpu_info".
  328. */
  329. get_cpu_cap(c);
  330. }
  331. #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
  332. static __init int setup_disable_pku(char *arg)
  333. {
  334. /*
  335. * Do not clear the X86_FEATURE_PKU bit. All of the
  336. * runtime checks are against OSPKE so clearing the
  337. * bit does nothing.
  338. *
  339. * This way, we will see "pku" in cpuinfo, but not
  340. * "ospke", which is exactly what we want. It shows
  341. * that the CPU has PKU, but the OS has not enabled it.
  342. * This happens to be exactly how a system would look
  343. * if we disabled the config option.
  344. */
  345. pr_info("x86: 'nopku' specified, disabling Memory Protection Keys\n");
  346. pku_disabled = true;
  347. return 1;
  348. }
  349. __setup("nopku", setup_disable_pku);
  350. #endif /* CONFIG_X86_64 */
  351. /*
  352. * Some CPU features depend on higher CPUID levels, which may not always
  353. * be available due to CPUID level capping or broken virtualization
  354. * software. Add those features to this table to auto-disable them.
  355. */
  356. struct cpuid_dependent_feature {
  357. u32 feature;
  358. u32 level;
  359. };
  360. static const struct cpuid_dependent_feature
  361. cpuid_dependent_features[] = {
  362. { X86_FEATURE_MWAIT, 0x00000005 },
  363. { X86_FEATURE_DCA, 0x00000009 },
  364. { X86_FEATURE_XSAVE, 0x0000000d },
  365. { 0, 0 }
  366. };
  367. static void filter_cpuid_features(struct cpuinfo_x86 *c, bool warn)
  368. {
  369. const struct cpuid_dependent_feature *df;
  370. for (df = cpuid_dependent_features; df->feature; df++) {
  371. if (!cpu_has(c, df->feature))
  372. continue;
  373. /*
  374. * Note: cpuid_level is set to -1 if unavailable, but
  375. * extended_extended_level is set to 0 if unavailable
  376. * and the legitimate extended levels are all negative
  377. * when signed; hence the weird messing around with
  378. * signs here...
  379. */
  380. if (!((s32)df->level < 0 ?
  381. (u32)df->level > (u32)c->extended_cpuid_level :
  382. (s32)df->level > (s32)c->cpuid_level))
  383. continue;
  384. clear_cpu_cap(c, df->feature);
  385. if (!warn)
  386. continue;
  387. pr_warn("CPU: CPU feature " X86_CAP_FMT " disabled, no CPUID level 0x%x\n",
  388. x86_cap_flag(df->feature), df->level);
  389. }
  390. }
  391. /*
  392. * Naming convention should be: <Name> [(<Codename>)]
  393. * This table only is used unless init_<vendor>() below doesn't set it;
  394. * in particular, if CPUID levels 0x80000002..4 are supported, this
  395. * isn't used
  396. */
  397. /* Look up CPU names by table lookup. */
  398. static const char *table_lookup_model(struct cpuinfo_x86 *c)
  399. {
  400. #ifdef CONFIG_X86_32
  401. const struct legacy_cpu_model_info *info;
  402. if (c->x86_model >= 16)
  403. return NULL; /* Range check */
  404. if (!this_cpu)
  405. return NULL;
  406. info = this_cpu->legacy_models;
  407. while (info->family) {
  408. if (info->family == c->x86)
  409. return info->model_names[c->x86_model];
  410. info++;
  411. }
  412. #endif
  413. return NULL; /* Not found */
  414. }
  415. __u32 cpu_caps_cleared[NCAPINTS + NBUGINTS];
  416. __u32 cpu_caps_set[NCAPINTS + NBUGINTS];
  417. void load_percpu_segment(int cpu)
  418. {
  419. #ifdef CONFIG_X86_32
  420. loadsegment(fs, __KERNEL_PERCPU);
  421. #else
  422. __loadsegment_simple(gs, 0);
  423. wrmsrl(MSR_GS_BASE, (unsigned long)per_cpu(irq_stack_union.gs_base, cpu));
  424. #endif
  425. load_stack_canary_segment();
  426. }
  427. #ifdef CONFIG_X86_32
  428. /* The 32-bit entry code needs to find cpu_entry_area. */
  429. DEFINE_PER_CPU(struct cpu_entry_area *, cpu_entry_area);
  430. #endif
  431. #ifdef CONFIG_X86_64
  432. /*
  433. * Special IST stacks which the CPU switches to when it calls
  434. * an IST-marked descriptor entry. Up to 7 stacks (hardware
  435. * limit), all of them are 4K, except the debug stack which
  436. * is 8K.
  437. */
  438. static const unsigned int exception_stack_sizes[N_EXCEPTION_STACKS] = {
  439. [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ,
  440. [DEBUG_STACK - 1] = DEBUG_STKSZ
  441. };
  442. #endif
  443. /* Load the original GDT from the per-cpu structure */
  444. void load_direct_gdt(int cpu)
  445. {
  446. struct desc_ptr gdt_descr;
  447. gdt_descr.address = (long)get_cpu_gdt_rw(cpu);
  448. gdt_descr.size = GDT_SIZE - 1;
  449. load_gdt(&gdt_descr);
  450. }
  451. EXPORT_SYMBOL_GPL(load_direct_gdt);
  452. /* Load a fixmap remapping of the per-cpu GDT */
  453. void load_fixmap_gdt(int cpu)
  454. {
  455. struct desc_ptr gdt_descr;
  456. gdt_descr.address = (long)get_cpu_gdt_ro(cpu);
  457. gdt_descr.size = GDT_SIZE - 1;
  458. load_gdt(&gdt_descr);
  459. }
  460. EXPORT_SYMBOL_GPL(load_fixmap_gdt);
  461. /*
  462. * Current gdt points %fs at the "master" per-cpu area: after this,
  463. * it's on the real one.
  464. */
  465. void switch_to_new_gdt(int cpu)
  466. {
  467. /* Load the original GDT */
  468. load_direct_gdt(cpu);
  469. /* Reload the per-cpu base */
  470. load_percpu_segment(cpu);
  471. }
  472. static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
  473. static void get_model_name(struct cpuinfo_x86 *c)
  474. {
  475. unsigned int *v;
  476. char *p, *q, *s;
  477. if (c->extended_cpuid_level < 0x80000004)
  478. return;
  479. v = (unsigned int *)c->x86_model_id;
  480. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  481. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  482. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  483. c->x86_model_id[48] = 0;
  484. /* Trim whitespace */
  485. p = q = s = &c->x86_model_id[0];
  486. while (*p == ' ')
  487. p++;
  488. while (*p) {
  489. /* Note the last non-whitespace index */
  490. if (!isspace(*p))
  491. s = q;
  492. *q++ = *p++;
  493. }
  494. *(s + 1) = '\0';
  495. }
  496. void cpu_detect_cache_sizes(struct cpuinfo_x86 *c)
  497. {
  498. unsigned int n, dummy, ebx, ecx, edx, l2size;
  499. n = c->extended_cpuid_level;
  500. if (n >= 0x80000005) {
  501. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  502. c->x86_cache_size = (ecx>>24) + (edx>>24);
  503. #ifdef CONFIG_X86_64
  504. /* On K8 L1 TLB is inclusive, so don't count it */
  505. c->x86_tlbsize = 0;
  506. #endif
  507. }
  508. if (n < 0x80000006) /* Some chips just has a large L1. */
  509. return;
  510. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  511. l2size = ecx >> 16;
  512. #ifdef CONFIG_X86_64
  513. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  514. #else
  515. /* do processor-specific cache resizing */
  516. if (this_cpu->legacy_cache_size)
  517. l2size = this_cpu->legacy_cache_size(c, l2size);
  518. /* Allow user to override all this if necessary. */
  519. if (cachesize_override != -1)
  520. l2size = cachesize_override;
  521. if (l2size == 0)
  522. return; /* Again, no L2 cache is possible */
  523. #endif
  524. c->x86_cache_size = l2size;
  525. }
  526. u16 __read_mostly tlb_lli_4k[NR_INFO];
  527. u16 __read_mostly tlb_lli_2m[NR_INFO];
  528. u16 __read_mostly tlb_lli_4m[NR_INFO];
  529. u16 __read_mostly tlb_lld_4k[NR_INFO];
  530. u16 __read_mostly tlb_lld_2m[NR_INFO];
  531. u16 __read_mostly tlb_lld_4m[NR_INFO];
  532. u16 __read_mostly tlb_lld_1g[NR_INFO];
  533. static void cpu_detect_tlb(struct cpuinfo_x86 *c)
  534. {
  535. if (this_cpu->c_detect_tlb)
  536. this_cpu->c_detect_tlb(c);
  537. pr_info("Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n",
  538. tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES],
  539. tlb_lli_4m[ENTRIES]);
  540. pr_info("Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d, 1GB %d\n",
  541. tlb_lld_4k[ENTRIES], tlb_lld_2m[ENTRIES],
  542. tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]);
  543. }
  544. void detect_ht(struct cpuinfo_x86 *c)
  545. {
  546. #ifdef CONFIG_SMP
  547. u32 eax, ebx, ecx, edx;
  548. int index_msb, core_bits;
  549. static bool printed;
  550. if (!cpu_has(c, X86_FEATURE_HT))
  551. return;
  552. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  553. goto out;
  554. if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
  555. return;
  556. cpuid(1, &eax, &ebx, &ecx, &edx);
  557. smp_num_siblings = (ebx & 0xff0000) >> 16;
  558. if (smp_num_siblings == 1) {
  559. pr_info_once("CPU0: Hyper-Threading is disabled\n");
  560. goto out;
  561. }
  562. if (smp_num_siblings <= 1)
  563. goto out;
  564. index_msb = get_count_order(smp_num_siblings);
  565. c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb);
  566. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  567. index_msb = get_count_order(smp_num_siblings);
  568. core_bits = get_count_order(c->x86_max_cores);
  569. c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) &
  570. ((1 << core_bits) - 1);
  571. out:
  572. if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) {
  573. pr_info("CPU: Physical Processor ID: %d\n",
  574. c->phys_proc_id);
  575. pr_info("CPU: Processor Core ID: %d\n",
  576. c->cpu_core_id);
  577. printed = 1;
  578. }
  579. #endif
  580. }
  581. static void get_cpu_vendor(struct cpuinfo_x86 *c)
  582. {
  583. char *v = c->x86_vendor_id;
  584. int i;
  585. for (i = 0; i < X86_VENDOR_NUM; i++) {
  586. if (!cpu_devs[i])
  587. break;
  588. if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
  589. (cpu_devs[i]->c_ident[1] &&
  590. !strcmp(v, cpu_devs[i]->c_ident[1]))) {
  591. this_cpu = cpu_devs[i];
  592. c->x86_vendor = this_cpu->c_x86_vendor;
  593. return;
  594. }
  595. }
  596. pr_err_once("CPU: vendor_id '%s' unknown, using generic init.\n" \
  597. "CPU: Your system may be unstable.\n", v);
  598. c->x86_vendor = X86_VENDOR_UNKNOWN;
  599. this_cpu = &default_cpu;
  600. }
  601. void cpu_detect(struct cpuinfo_x86 *c)
  602. {
  603. /* Get vendor name */
  604. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  605. (unsigned int *)&c->x86_vendor_id[0],
  606. (unsigned int *)&c->x86_vendor_id[8],
  607. (unsigned int *)&c->x86_vendor_id[4]);
  608. c->x86 = 4;
  609. /* Intel-defined flags: level 0x00000001 */
  610. if (c->cpuid_level >= 0x00000001) {
  611. u32 junk, tfms, cap0, misc;
  612. cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  613. c->x86 = x86_family(tfms);
  614. c->x86_model = x86_model(tfms);
  615. c->x86_stepping = x86_stepping(tfms);
  616. if (cap0 & (1<<19)) {
  617. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  618. c->x86_cache_alignment = c->x86_clflush_size;
  619. }
  620. }
  621. }
  622. static void apply_forced_caps(struct cpuinfo_x86 *c)
  623. {
  624. int i;
  625. for (i = 0; i < NCAPINTS + NBUGINTS; i++) {
  626. c->x86_capability[i] &= ~cpu_caps_cleared[i];
  627. c->x86_capability[i] |= cpu_caps_set[i];
  628. }
  629. }
  630. static void init_speculation_control(struct cpuinfo_x86 *c)
  631. {
  632. /*
  633. * The Intel SPEC_CTRL CPUID bit implies IBRS and IBPB support,
  634. * and they also have a different bit for STIBP support. Also,
  635. * a hypervisor might have set the individual AMD bits even on
  636. * Intel CPUs, for finer-grained selection of what's available.
  637. *
  638. * We use the AMD bits in 0x8000_0008 EBX as the generic hardware
  639. * features, which are visible in /proc/cpuinfo and used by the
  640. * kernel. So set those accordingly from the Intel bits.
  641. */
  642. if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
  643. set_cpu_cap(c, X86_FEATURE_IBRS);
  644. set_cpu_cap(c, X86_FEATURE_IBPB);
  645. }
  646. if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
  647. set_cpu_cap(c, X86_FEATURE_STIBP);
  648. }
  649. void get_cpu_cap(struct cpuinfo_x86 *c)
  650. {
  651. u32 eax, ebx, ecx, edx;
  652. /* Intel-defined flags: level 0x00000001 */
  653. if (c->cpuid_level >= 0x00000001) {
  654. cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
  655. c->x86_capability[CPUID_1_ECX] = ecx;
  656. c->x86_capability[CPUID_1_EDX] = edx;
  657. }
  658. /* Thermal and Power Management Leaf: level 0x00000006 (eax) */
  659. if (c->cpuid_level >= 0x00000006)
  660. c->x86_capability[CPUID_6_EAX] = cpuid_eax(0x00000006);
  661. /* Additional Intel-defined flags: level 0x00000007 */
  662. if (c->cpuid_level >= 0x00000007) {
  663. cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx);
  664. c->x86_capability[CPUID_7_0_EBX] = ebx;
  665. c->x86_capability[CPUID_7_ECX] = ecx;
  666. c->x86_capability[CPUID_7_EDX] = edx;
  667. }
  668. /* Extended state features: level 0x0000000d */
  669. if (c->cpuid_level >= 0x0000000d) {
  670. cpuid_count(0x0000000d, 1, &eax, &ebx, &ecx, &edx);
  671. c->x86_capability[CPUID_D_1_EAX] = eax;
  672. }
  673. /* Additional Intel-defined flags: level 0x0000000F */
  674. if (c->cpuid_level >= 0x0000000F) {
  675. /* QoS sub-leaf, EAX=0Fh, ECX=0 */
  676. cpuid_count(0x0000000F, 0, &eax, &ebx, &ecx, &edx);
  677. c->x86_capability[CPUID_F_0_EDX] = edx;
  678. if (cpu_has(c, X86_FEATURE_CQM_LLC)) {
  679. /* will be overridden if occupancy monitoring exists */
  680. c->x86_cache_max_rmid = ebx;
  681. /* QoS sub-leaf, EAX=0Fh, ECX=1 */
  682. cpuid_count(0x0000000F, 1, &eax, &ebx, &ecx, &edx);
  683. c->x86_capability[CPUID_F_1_EDX] = edx;
  684. if ((cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC)) ||
  685. ((cpu_has(c, X86_FEATURE_CQM_MBM_TOTAL)) ||
  686. (cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL)))) {
  687. c->x86_cache_max_rmid = ecx;
  688. c->x86_cache_occ_scale = ebx;
  689. }
  690. } else {
  691. c->x86_cache_max_rmid = -1;
  692. c->x86_cache_occ_scale = -1;
  693. }
  694. }
  695. /* AMD-defined flags: level 0x80000001 */
  696. eax = cpuid_eax(0x80000000);
  697. c->extended_cpuid_level = eax;
  698. if ((eax & 0xffff0000) == 0x80000000) {
  699. if (eax >= 0x80000001) {
  700. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  701. c->x86_capability[CPUID_8000_0001_ECX] = ecx;
  702. c->x86_capability[CPUID_8000_0001_EDX] = edx;
  703. }
  704. }
  705. if (c->extended_cpuid_level >= 0x80000007) {
  706. cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
  707. c->x86_capability[CPUID_8000_0007_EBX] = ebx;
  708. c->x86_power = edx;
  709. }
  710. if (c->extended_cpuid_level >= 0x8000000a)
  711. c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a);
  712. init_scattered_cpuid_features(c);
  713. init_speculation_control(c);
  714. /*
  715. * Clear/Set all flags overridden by options, after probe.
  716. * This needs to happen each time we re-probe, which may happen
  717. * several times during CPU initialization.
  718. */
  719. apply_forced_caps(c);
  720. }
  721. static void get_cpu_address_sizes(struct cpuinfo_x86 *c)
  722. {
  723. u32 eax, ebx, ecx, edx;
  724. if (c->extended_cpuid_level >= 0x80000008) {
  725. cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
  726. c->x86_virt_bits = (eax >> 8) & 0xff;
  727. c->x86_phys_bits = eax & 0xff;
  728. c->x86_capability[CPUID_8000_0008_EBX] = ebx;
  729. }
  730. #ifdef CONFIG_X86_32
  731. else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
  732. c->x86_phys_bits = 36;
  733. #endif
  734. }
  735. static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
  736. {
  737. #ifdef CONFIG_X86_32
  738. int i;
  739. /*
  740. * First of all, decide if this is a 486 or higher
  741. * It's a 486 if we can modify the AC flag
  742. */
  743. if (flag_is_changeable_p(X86_EFLAGS_AC))
  744. c->x86 = 4;
  745. else
  746. c->x86 = 3;
  747. for (i = 0; i < X86_VENDOR_NUM; i++)
  748. if (cpu_devs[i] && cpu_devs[i]->c_identify) {
  749. c->x86_vendor_id[0] = 0;
  750. cpu_devs[i]->c_identify(c);
  751. if (c->x86_vendor_id[0]) {
  752. get_cpu_vendor(c);
  753. break;
  754. }
  755. }
  756. #endif
  757. }
  758. static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
  759. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW, X86_FEATURE_ANY },
  760. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW, X86_FEATURE_ANY },
  761. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT, X86_FEATURE_ANY },
  762. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL, X86_FEATURE_ANY },
  763. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW, X86_FEATURE_ANY },
  764. { X86_VENDOR_CENTAUR, 5 },
  765. { X86_VENDOR_INTEL, 5 },
  766. { X86_VENDOR_NSC, 5 },
  767. { X86_VENDOR_ANY, 4 },
  768. {}
  769. };
  770. static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
  771. { X86_VENDOR_AMD },
  772. {}
  773. };
  774. static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c)
  775. {
  776. u64 ia32_cap = 0;
  777. if (x86_match_cpu(cpu_no_meltdown))
  778. return false;
  779. if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
  780. rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
  781. /* Rogue Data Cache Load? No! */
  782. if (ia32_cap & ARCH_CAP_RDCL_NO)
  783. return false;
  784. return true;
  785. }
  786. /*
  787. * Do minimum CPU detection early.
  788. * Fields really needed: vendor, cpuid_level, family, model, mask,
  789. * cache alignment.
  790. * The others are not touched to avoid unwanted side effects.
  791. *
  792. * WARNING: this function is only called on the boot CPU. Don't add code
  793. * here that is supposed to run on all CPUs.
  794. */
  795. static void __init early_identify_cpu(struct cpuinfo_x86 *c)
  796. {
  797. #ifdef CONFIG_X86_64
  798. c->x86_clflush_size = 64;
  799. c->x86_phys_bits = 36;
  800. c->x86_virt_bits = 48;
  801. #else
  802. c->x86_clflush_size = 32;
  803. c->x86_phys_bits = 32;
  804. c->x86_virt_bits = 32;
  805. #endif
  806. c->x86_cache_alignment = c->x86_clflush_size;
  807. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  808. c->extended_cpuid_level = 0;
  809. /* cyrix could have cpuid enabled via c_identify()*/
  810. if (have_cpuid_p()) {
  811. cpu_detect(c);
  812. get_cpu_vendor(c);
  813. get_cpu_cap(c);
  814. get_cpu_address_sizes(c);
  815. setup_force_cpu_cap(X86_FEATURE_CPUID);
  816. if (this_cpu->c_early_init)
  817. this_cpu->c_early_init(c);
  818. c->cpu_index = 0;
  819. filter_cpuid_features(c, false);
  820. if (this_cpu->c_bsp_init)
  821. this_cpu->c_bsp_init(c);
  822. } else {
  823. identify_cpu_without_cpuid(c);
  824. setup_clear_cpu_cap(X86_FEATURE_CPUID);
  825. }
  826. setup_force_cpu_cap(X86_FEATURE_ALWAYS);
  827. if (!x86_match_cpu(cpu_no_speculation)) {
  828. if (cpu_vulnerable_to_meltdown(c))
  829. setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
  830. setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
  831. setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
  832. }
  833. fpu__init_system(c);
  834. #ifdef CONFIG_X86_32
  835. /*
  836. * Regardless of whether PCID is enumerated, the SDM says
  837. * that it can't be enabled in 32-bit mode.
  838. */
  839. setup_clear_cpu_cap(X86_FEATURE_PCID);
  840. #endif
  841. }
  842. void __init early_cpu_init(void)
  843. {
  844. const struct cpu_dev *const *cdev;
  845. int count = 0;
  846. #ifdef CONFIG_PROCESSOR_SELECT
  847. pr_info("KERNEL supported cpus:\n");
  848. #endif
  849. for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
  850. const struct cpu_dev *cpudev = *cdev;
  851. if (count >= X86_VENDOR_NUM)
  852. break;
  853. cpu_devs[count] = cpudev;
  854. count++;
  855. #ifdef CONFIG_PROCESSOR_SELECT
  856. {
  857. unsigned int j;
  858. for (j = 0; j < 2; j++) {
  859. if (!cpudev->c_ident[j])
  860. continue;
  861. pr_info(" %s %s\n", cpudev->c_vendor,
  862. cpudev->c_ident[j]);
  863. }
  864. }
  865. #endif
  866. }
  867. early_identify_cpu(&boot_cpu_data);
  868. }
  869. /*
  870. * The NOPL instruction is supposed to exist on all CPUs of family >= 6;
  871. * unfortunately, that's not true in practice because of early VIA
  872. * chips and (more importantly) broken virtualizers that are not easy
  873. * to detect. In the latter case it doesn't even *fail* reliably, so
  874. * probing for it doesn't even work. Disable it completely on 32-bit
  875. * unless we can find a reliable way to detect all the broken cases.
  876. * Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
  877. */
  878. static void detect_nopl(struct cpuinfo_x86 *c)
  879. {
  880. #ifdef CONFIG_X86_32
  881. clear_cpu_cap(c, X86_FEATURE_NOPL);
  882. #else
  883. set_cpu_cap(c, X86_FEATURE_NOPL);
  884. #endif
  885. }
  886. static void detect_null_seg_behavior(struct cpuinfo_x86 *c)
  887. {
  888. #ifdef CONFIG_X86_64
  889. /*
  890. * Empirically, writing zero to a segment selector on AMD does
  891. * not clear the base, whereas writing zero to a segment
  892. * selector on Intel does clear the base. Intel's behavior
  893. * allows slightly faster context switches in the common case
  894. * where GS is unused by the prev and next threads.
  895. *
  896. * Since neither vendor documents this anywhere that I can see,
  897. * detect it directly instead of hardcoding the choice by
  898. * vendor.
  899. *
  900. * I've designated AMD's behavior as the "bug" because it's
  901. * counterintuitive and less friendly.
  902. */
  903. unsigned long old_base, tmp;
  904. rdmsrl(MSR_FS_BASE, old_base);
  905. wrmsrl(MSR_FS_BASE, 1);
  906. loadsegment(fs, 0);
  907. rdmsrl(MSR_FS_BASE, tmp);
  908. if (tmp != 0)
  909. set_cpu_bug(c, X86_BUG_NULL_SEG);
  910. wrmsrl(MSR_FS_BASE, old_base);
  911. #endif
  912. }
  913. static void generic_identify(struct cpuinfo_x86 *c)
  914. {
  915. c->extended_cpuid_level = 0;
  916. if (!have_cpuid_p())
  917. identify_cpu_without_cpuid(c);
  918. /* cyrix could have cpuid enabled via c_identify()*/
  919. if (!have_cpuid_p())
  920. return;
  921. cpu_detect(c);
  922. get_cpu_vendor(c);
  923. get_cpu_cap(c);
  924. get_cpu_address_sizes(c);
  925. if (c->cpuid_level >= 0x00000001) {
  926. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
  927. #ifdef CONFIG_X86_32
  928. # ifdef CONFIG_SMP
  929. c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
  930. # else
  931. c->apicid = c->initial_apicid;
  932. # endif
  933. #endif
  934. c->phys_proc_id = c->initial_apicid;
  935. }
  936. get_model_name(c); /* Default name */
  937. detect_nopl(c);
  938. detect_null_seg_behavior(c);
  939. /*
  940. * ESPFIX is a strange bug. All real CPUs have it. Paravirt
  941. * systems that run Linux at CPL > 0 may or may not have the
  942. * issue, but, even if they have the issue, there's absolutely
  943. * nothing we can do about it because we can't use the real IRET
  944. * instruction.
  945. *
  946. * NB: For the time being, only 32-bit kernels support
  947. * X86_BUG_ESPFIX as such. 64-bit kernels directly choose
  948. * whether to apply espfix using paravirt hooks. If any
  949. * non-paravirt system ever shows up that does *not* have the
  950. * ESPFIX issue, we can change this.
  951. */
  952. #ifdef CONFIG_X86_32
  953. # ifdef CONFIG_PARAVIRT
  954. do {
  955. extern void native_iret(void);
  956. if (pv_cpu_ops.iret == native_iret)
  957. set_cpu_bug(c, X86_BUG_ESPFIX);
  958. } while (0);
  959. # else
  960. set_cpu_bug(c, X86_BUG_ESPFIX);
  961. # endif
  962. #endif
  963. }
  964. static void x86_init_cache_qos(struct cpuinfo_x86 *c)
  965. {
  966. /*
  967. * The heavy lifting of max_rmid and cache_occ_scale are handled
  968. * in get_cpu_cap(). Here we just set the max_rmid for the boot_cpu
  969. * in case CQM bits really aren't there in this CPU.
  970. */
  971. if (c != &boot_cpu_data) {
  972. boot_cpu_data.x86_cache_max_rmid =
  973. min(boot_cpu_data.x86_cache_max_rmid,
  974. c->x86_cache_max_rmid);
  975. }
  976. }
  977. /*
  978. * Validate that ACPI/mptables have the same information about the
  979. * effective APIC id and update the package map.
  980. */
  981. static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
  982. {
  983. #ifdef CONFIG_SMP
  984. unsigned int apicid, cpu = smp_processor_id();
  985. apicid = apic->cpu_present_to_apicid(cpu);
  986. if (apicid != c->apicid) {
  987. pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n",
  988. cpu, apicid, c->initial_apicid);
  989. }
  990. BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
  991. #else
  992. c->logical_proc_id = 0;
  993. #endif
  994. }
  995. /*
  996. * This does the hard work of actually picking apart the CPU stuff...
  997. */
  998. static void identify_cpu(struct cpuinfo_x86 *c)
  999. {
  1000. int i;
  1001. c->loops_per_jiffy = loops_per_jiffy;
  1002. c->x86_cache_size = 0;
  1003. c->x86_vendor = X86_VENDOR_UNKNOWN;
  1004. c->x86_model = c->x86_stepping = 0; /* So far unknown... */
  1005. c->x86_vendor_id[0] = '\0'; /* Unset */
  1006. c->x86_model_id[0] = '\0'; /* Unset */
  1007. c->x86_max_cores = 1;
  1008. c->x86_coreid_bits = 0;
  1009. c->cu_id = 0xff;
  1010. #ifdef CONFIG_X86_64
  1011. c->x86_clflush_size = 64;
  1012. c->x86_phys_bits = 36;
  1013. c->x86_virt_bits = 48;
  1014. #else
  1015. c->cpuid_level = -1; /* CPUID not detected */
  1016. c->x86_clflush_size = 32;
  1017. c->x86_phys_bits = 32;
  1018. c->x86_virt_bits = 32;
  1019. #endif
  1020. c->x86_cache_alignment = c->x86_clflush_size;
  1021. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  1022. generic_identify(c);
  1023. if (this_cpu->c_identify)
  1024. this_cpu->c_identify(c);
  1025. /* Clear/Set all flags overridden by options, after probe */
  1026. apply_forced_caps(c);
  1027. #ifdef CONFIG_X86_64
  1028. c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
  1029. #endif
  1030. /*
  1031. * Vendor-specific initialization. In this section we
  1032. * canonicalize the feature flags, meaning if there are
  1033. * features a certain CPU supports which CPUID doesn't
  1034. * tell us, CPUID claiming incorrect flags, or other bugs,
  1035. * we handle them here.
  1036. *
  1037. * At the end of this section, c->x86_capability better
  1038. * indicate the features this CPU genuinely supports!
  1039. */
  1040. if (this_cpu->c_init)
  1041. this_cpu->c_init(c);
  1042. /* Disable the PN if appropriate */
  1043. squash_the_stupid_serial_number(c);
  1044. /* Set up SMEP/SMAP/UMIP */
  1045. setup_smep(c);
  1046. setup_smap(c);
  1047. setup_umip(c);
  1048. /*
  1049. * The vendor-specific functions might have changed features.
  1050. * Now we do "generic changes."
  1051. */
  1052. /* Filter out anything that depends on CPUID levels we don't have */
  1053. filter_cpuid_features(c, true);
  1054. /* If the model name is still unset, do table lookup. */
  1055. if (!c->x86_model_id[0]) {
  1056. const char *p;
  1057. p = table_lookup_model(c);
  1058. if (p)
  1059. strcpy(c->x86_model_id, p);
  1060. else
  1061. /* Last resort... */
  1062. sprintf(c->x86_model_id, "%02x/%02x",
  1063. c->x86, c->x86_model);
  1064. }
  1065. #ifdef CONFIG_X86_64
  1066. detect_ht(c);
  1067. #endif
  1068. x86_init_rdrand(c);
  1069. x86_init_cache_qos(c);
  1070. setup_pku(c);
  1071. /*
  1072. * Clear/Set all flags overridden by options, need do it
  1073. * before following smp all cpus cap AND.
  1074. */
  1075. apply_forced_caps(c);
  1076. /*
  1077. * On SMP, boot_cpu_data holds the common feature set between
  1078. * all CPUs; so make sure that we indicate which features are
  1079. * common between the CPUs. The first time this routine gets
  1080. * executed, c == &boot_cpu_data.
  1081. */
  1082. if (c != &boot_cpu_data) {
  1083. /* AND the already accumulated flags with these */
  1084. for (i = 0; i < NCAPINTS; i++)
  1085. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  1086. /* OR, i.e. replicate the bug flags */
  1087. for (i = NCAPINTS; i < NCAPINTS + NBUGINTS; i++)
  1088. c->x86_capability[i] |= boot_cpu_data.x86_capability[i];
  1089. }
  1090. /* Init Machine Check Exception if available. */
  1091. mcheck_cpu_init(c);
  1092. select_idle_routine(c);
  1093. #ifdef CONFIG_NUMA
  1094. numa_add_cpu(smp_processor_id());
  1095. #endif
  1096. }
  1097. /*
  1098. * Set up the CPU state needed to execute SYSENTER/SYSEXIT instructions
  1099. * on 32-bit kernels:
  1100. */
  1101. #ifdef CONFIG_X86_32
  1102. void enable_sep_cpu(void)
  1103. {
  1104. struct tss_struct *tss;
  1105. int cpu;
  1106. if (!boot_cpu_has(X86_FEATURE_SEP))
  1107. return;
  1108. cpu = get_cpu();
  1109. tss = &per_cpu(cpu_tss_rw, cpu);
  1110. /*
  1111. * We cache MSR_IA32_SYSENTER_CS's value in the TSS's ss1 field --
  1112. * see the big comment in struct x86_hw_tss's definition.
  1113. */
  1114. tss->x86_tss.ss1 = __KERNEL_CS;
  1115. wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0);
  1116. wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1), 0);
  1117. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);
  1118. put_cpu();
  1119. }
  1120. #endif
  1121. void __init identify_boot_cpu(void)
  1122. {
  1123. identify_cpu(&boot_cpu_data);
  1124. #ifdef CONFIG_X86_32
  1125. sysenter_setup();
  1126. enable_sep_cpu();
  1127. #endif
  1128. cpu_detect_tlb(&boot_cpu_data);
  1129. }
  1130. void identify_secondary_cpu(struct cpuinfo_x86 *c)
  1131. {
  1132. BUG_ON(c == &boot_cpu_data);
  1133. identify_cpu(c);
  1134. #ifdef CONFIG_X86_32
  1135. enable_sep_cpu();
  1136. #endif
  1137. mtrr_ap_init();
  1138. validate_apic_and_package_id(c);
  1139. }
  1140. static __init int setup_noclflush(char *arg)
  1141. {
  1142. setup_clear_cpu_cap(X86_FEATURE_CLFLUSH);
  1143. setup_clear_cpu_cap(X86_FEATURE_CLFLUSHOPT);
  1144. return 1;
  1145. }
  1146. __setup("noclflush", setup_noclflush);
  1147. void print_cpu_info(struct cpuinfo_x86 *c)
  1148. {
  1149. const char *vendor = NULL;
  1150. if (c->x86_vendor < X86_VENDOR_NUM) {
  1151. vendor = this_cpu->c_vendor;
  1152. } else {
  1153. if (c->cpuid_level >= 0)
  1154. vendor = c->x86_vendor_id;
  1155. }
  1156. if (vendor && !strstr(c->x86_model_id, vendor))
  1157. pr_cont("%s ", vendor);
  1158. if (c->x86_model_id[0])
  1159. pr_cont("%s", c->x86_model_id);
  1160. else
  1161. pr_cont("%d86", c->x86);
  1162. pr_cont(" (family: 0x%x, model: 0x%x", c->x86, c->x86_model);
  1163. if (c->x86_stepping || c->cpuid_level >= 0)
  1164. pr_cont(", stepping: 0x%x)\n", c->x86_stepping);
  1165. else
  1166. pr_cont(")\n");
  1167. }
  1168. /*
  1169. * clearcpuid= was already parsed in fpu__init_parse_early_param.
  1170. * But we need to keep a dummy __setup around otherwise it would
  1171. * show up as an environment variable for init.
  1172. */
  1173. static __init int setup_clearcpuid(char *arg)
  1174. {
  1175. return 1;
  1176. }
  1177. __setup("clearcpuid=", setup_clearcpuid);
  1178. #ifdef CONFIG_X86_64
  1179. DEFINE_PER_CPU_FIRST(union irq_stack_union,
  1180. irq_stack_union) __aligned(PAGE_SIZE) __visible;
  1181. /*
  1182. * The following percpu variables are hot. Align current_task to
  1183. * cacheline size such that they fall in the same cacheline.
  1184. */
  1185. DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
  1186. &init_task;
  1187. EXPORT_PER_CPU_SYMBOL(current_task);
  1188. DEFINE_PER_CPU(char *, irq_stack_ptr) =
  1189. init_per_cpu_var(irq_stack_union.irq_stack) + IRQ_STACK_SIZE;
  1190. DEFINE_PER_CPU(unsigned int, irq_count) __visible = -1;
  1191. DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT;
  1192. EXPORT_PER_CPU_SYMBOL(__preempt_count);
  1193. /* May not be marked __init: used by software suspend */
  1194. void syscall_init(void)
  1195. {
  1196. extern char _entry_trampoline[];
  1197. extern char entry_SYSCALL_64_trampoline[];
  1198. int cpu = smp_processor_id();
  1199. unsigned long SYSCALL64_entry_trampoline =
  1200. (unsigned long)get_cpu_entry_area(cpu)->entry_trampoline +
  1201. (entry_SYSCALL_64_trampoline - _entry_trampoline);
  1202. wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
  1203. if (static_cpu_has(X86_FEATURE_PTI))
  1204. wrmsrl(MSR_LSTAR, SYSCALL64_entry_trampoline);
  1205. else
  1206. wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
  1207. #ifdef CONFIG_IA32_EMULATION
  1208. wrmsrl(MSR_CSTAR, (unsigned long)entry_SYSCALL_compat);
  1209. /*
  1210. * This only works on Intel CPUs.
  1211. * On AMD CPUs these MSRs are 32-bit, CPU truncates MSR_IA32_SYSENTER_EIP.
  1212. * This does not cause SYSENTER to jump to the wrong location, because
  1213. * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
  1214. */
  1215. wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
  1216. wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1));
  1217. wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
  1218. #else
  1219. wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
  1220. wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)GDT_ENTRY_INVALID_SEG);
  1221. wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
  1222. wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
  1223. #endif
  1224. /* Flags to clear on syscall */
  1225. wrmsrl(MSR_SYSCALL_MASK,
  1226. X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|
  1227. X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT);
  1228. }
  1229. /*
  1230. * Copies of the original ist values from the tss are only accessed during
  1231. * debugging, no special alignment required.
  1232. */
  1233. DEFINE_PER_CPU(struct orig_ist, orig_ist);
  1234. static DEFINE_PER_CPU(unsigned long, debug_stack_addr);
  1235. DEFINE_PER_CPU(int, debug_stack_usage);
  1236. int is_debug_stack(unsigned long addr)
  1237. {
  1238. return __this_cpu_read(debug_stack_usage) ||
  1239. (addr <= __this_cpu_read(debug_stack_addr) &&
  1240. addr > (__this_cpu_read(debug_stack_addr) - DEBUG_STKSZ));
  1241. }
  1242. NOKPROBE_SYMBOL(is_debug_stack);
  1243. DEFINE_PER_CPU(u32, debug_idt_ctr);
  1244. void debug_stack_set_zero(void)
  1245. {
  1246. this_cpu_inc(debug_idt_ctr);
  1247. load_current_idt();
  1248. }
  1249. NOKPROBE_SYMBOL(debug_stack_set_zero);
  1250. void debug_stack_reset(void)
  1251. {
  1252. if (WARN_ON(!this_cpu_read(debug_idt_ctr)))
  1253. return;
  1254. if (this_cpu_dec_return(debug_idt_ctr) == 0)
  1255. load_current_idt();
  1256. }
  1257. NOKPROBE_SYMBOL(debug_stack_reset);
  1258. #else /* CONFIG_X86_64 */
  1259. DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
  1260. EXPORT_PER_CPU_SYMBOL(current_task);
  1261. DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT;
  1262. EXPORT_PER_CPU_SYMBOL(__preempt_count);
  1263. /*
  1264. * On x86_32, vm86 modifies tss.sp0, so sp0 isn't a reliable way to find
  1265. * the top of the kernel stack. Use an extra percpu variable to track the
  1266. * top of the kernel stack directly.
  1267. */
  1268. DEFINE_PER_CPU(unsigned long, cpu_current_top_of_stack) =
  1269. (unsigned long)&init_thread_union + THREAD_SIZE;
  1270. EXPORT_PER_CPU_SYMBOL(cpu_current_top_of_stack);
  1271. #ifdef CONFIG_CC_STACKPROTECTOR
  1272. DEFINE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);
  1273. #endif
  1274. #endif /* CONFIG_X86_64 */
  1275. /*
  1276. * Clear all 6 debug registers:
  1277. */
  1278. static void clear_all_debug_regs(void)
  1279. {
  1280. int i;
  1281. for (i = 0; i < 8; i++) {
  1282. /* Ignore db4, db5 */
  1283. if ((i == 4) || (i == 5))
  1284. continue;
  1285. set_debugreg(0, i);
  1286. }
  1287. }
  1288. #ifdef CONFIG_KGDB
  1289. /*
  1290. * Restore debug regs if using kgdbwait and you have a kernel debugger
  1291. * connection established.
  1292. */
  1293. static void dbg_restore_debug_regs(void)
  1294. {
  1295. if (unlikely(kgdb_connected && arch_kgdb_ops.correct_hw_break))
  1296. arch_kgdb_ops.correct_hw_break();
  1297. }
  1298. #else /* ! CONFIG_KGDB */
  1299. #define dbg_restore_debug_regs()
  1300. #endif /* ! CONFIG_KGDB */
  1301. static void wait_for_master_cpu(int cpu)
  1302. {
  1303. #ifdef CONFIG_SMP
  1304. /*
  1305. * wait for ACK from master CPU before continuing
  1306. * with AP initialization
  1307. */
  1308. WARN_ON(cpumask_test_and_set_cpu(cpu, cpu_initialized_mask));
  1309. while (!cpumask_test_cpu(cpu, cpu_callout_mask))
  1310. cpu_relax();
  1311. #endif
  1312. }
  1313. /*
  1314. * cpu_init() initializes state that is per-CPU. Some data is already
  1315. * initialized (naturally) in the bootstrap process, such as the GDT
  1316. * and IDT. We reload them nevertheless, this function acts as a
  1317. * 'CPU state barrier', nothing should get across.
  1318. * A lot of state is already set up in PDA init for 64 bit
  1319. */
  1320. #ifdef CONFIG_X86_64
  1321. void cpu_init(void)
  1322. {
  1323. struct orig_ist *oist;
  1324. struct task_struct *me;
  1325. struct tss_struct *t;
  1326. unsigned long v;
  1327. int cpu = raw_smp_processor_id();
  1328. int i;
  1329. wait_for_master_cpu(cpu);
  1330. /*
  1331. * Initialize the CR4 shadow before doing anything that could
  1332. * try to read it.
  1333. */
  1334. cr4_init_shadow();
  1335. if (cpu)
  1336. load_ucode_ap();
  1337. t = &per_cpu(cpu_tss_rw, cpu);
  1338. oist = &per_cpu(orig_ist, cpu);
  1339. #ifdef CONFIG_NUMA
  1340. if (this_cpu_read(numa_node) == 0 &&
  1341. early_cpu_to_node(cpu) != NUMA_NO_NODE)
  1342. set_numa_node(early_cpu_to_node(cpu));
  1343. #endif
  1344. me = current;
  1345. pr_debug("Initializing CPU#%d\n", cpu);
  1346. cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  1347. /*
  1348. * Initialize the per-CPU GDT with the boot GDT,
  1349. * and set up the GDT descriptor:
  1350. */
  1351. switch_to_new_gdt(cpu);
  1352. loadsegment(fs, 0);
  1353. load_current_idt();
  1354. memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
  1355. syscall_init();
  1356. wrmsrl(MSR_FS_BASE, 0);
  1357. wrmsrl(MSR_KERNEL_GS_BASE, 0);
  1358. barrier();
  1359. x86_configure_nx();
  1360. x2apic_setup();
  1361. /*
  1362. * set up and load the per-CPU TSS
  1363. */
  1364. if (!oist->ist[0]) {
  1365. char *estacks = get_cpu_entry_area(cpu)->exception_stacks;
  1366. for (v = 0; v < N_EXCEPTION_STACKS; v++) {
  1367. estacks += exception_stack_sizes[v];
  1368. oist->ist[v] = t->x86_tss.ist[v] =
  1369. (unsigned long)estacks;
  1370. if (v == DEBUG_STACK-1)
  1371. per_cpu(debug_stack_addr, cpu) = (unsigned long)estacks;
  1372. }
  1373. }
  1374. t->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
  1375. /*
  1376. * <= is required because the CPU will access up to
  1377. * 8 bits beyond the end of the IO permission bitmap.
  1378. */
  1379. for (i = 0; i <= IO_BITMAP_LONGS; i++)
  1380. t->io_bitmap[i] = ~0UL;
  1381. mmgrab(&init_mm);
  1382. me->active_mm = &init_mm;
  1383. BUG_ON(me->mm);
  1384. initialize_tlbstate_and_flush();
  1385. enter_lazy_tlb(&init_mm, me);
  1386. /*
  1387. * Initialize the TSS. sp0 points to the entry trampoline stack
  1388. * regardless of what task is running.
  1389. */
  1390. set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
  1391. load_TR_desc();
  1392. load_sp0((unsigned long)(cpu_entry_stack(cpu) + 1));
  1393. load_mm_ldt(&init_mm);
  1394. clear_all_debug_regs();
  1395. dbg_restore_debug_regs();
  1396. fpu__init_cpu();
  1397. if (is_uv_system())
  1398. uv_cpu_init();
  1399. load_fixmap_gdt(cpu);
  1400. }
  1401. #else
  1402. void cpu_init(void)
  1403. {
  1404. int cpu = smp_processor_id();
  1405. struct task_struct *curr = current;
  1406. struct tss_struct *t = &per_cpu(cpu_tss_rw, cpu);
  1407. wait_for_master_cpu(cpu);
  1408. /*
  1409. * Initialize the CR4 shadow before doing anything that could
  1410. * try to read it.
  1411. */
  1412. cr4_init_shadow();
  1413. show_ucode_info_early();
  1414. pr_info("Initializing CPU#%d\n", cpu);
  1415. if (cpu_feature_enabled(X86_FEATURE_VME) ||
  1416. boot_cpu_has(X86_FEATURE_TSC) ||
  1417. boot_cpu_has(X86_FEATURE_DE))
  1418. cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  1419. load_current_idt();
  1420. switch_to_new_gdt(cpu);
  1421. /*
  1422. * Set up and load the per-CPU TSS and LDT
  1423. */
  1424. mmgrab(&init_mm);
  1425. curr->active_mm = &init_mm;
  1426. BUG_ON(curr->mm);
  1427. initialize_tlbstate_and_flush();
  1428. enter_lazy_tlb(&init_mm, curr);
  1429. /*
  1430. * Initialize the TSS. Don't bother initializing sp0, as the initial
  1431. * task never enters user mode.
  1432. */
  1433. set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
  1434. load_TR_desc();
  1435. load_mm_ldt(&init_mm);
  1436. t->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
  1437. #ifdef CONFIG_DOUBLEFAULT
  1438. /* Set up doublefault TSS pointer in the GDT */
  1439. __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
  1440. #endif
  1441. clear_all_debug_regs();
  1442. dbg_restore_debug_regs();
  1443. fpu__init_cpu();
  1444. load_fixmap_gdt(cpu);
  1445. }
  1446. #endif
  1447. static void bsp_resume(void)
  1448. {
  1449. if (this_cpu->c_bsp_resume)
  1450. this_cpu->c_bsp_resume(&boot_cpu_data);
  1451. }
  1452. static struct syscore_ops cpu_syscore_ops = {
  1453. .resume = bsp_resume,
  1454. };
  1455. static int __init init_cpu_syscore(void)
  1456. {
  1457. register_syscore_ops(&cpu_syscore_ops);
  1458. return 0;
  1459. }
  1460. core_initcall(init_cpu_syscore);
  1461. /*
  1462. * The microcode loader calls this upon late microcode load to recheck features,
  1463. * only when microcode has been updated. Caller holds microcode_mutex and CPU
  1464. * hotplug lock.
  1465. */
  1466. void microcode_check(void)
  1467. {
  1468. struct cpuinfo_x86 info;
  1469. perf_check_microcode();
  1470. /* Reload CPUID max function as it might've changed. */
  1471. info.cpuid_level = cpuid_eax(0);
  1472. /*
  1473. * Copy all capability leafs to pick up the synthetic ones so that
  1474. * memcmp() below doesn't fail on that. The ones coming from CPUID will
  1475. * get overwritten in get_cpu_cap().
  1476. */
  1477. memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
  1478. get_cpu_cap(&info);
  1479. if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
  1480. return;
  1481. pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");
  1482. pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n");
  1483. }