common.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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, cpu_kernelmode_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 >= 0x80000008) {
  711. cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
  712. c->x86_capability[CPUID_8000_0008_EBX] = ebx;
  713. }
  714. if (c->extended_cpuid_level >= 0x8000000a)
  715. c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a);
  716. init_scattered_cpuid_features(c);
  717. init_speculation_control(c);
  718. /*
  719. * Clear/Set all flags overridden by options, after probe.
  720. * This needs to happen each time we re-probe, which may happen
  721. * several times during CPU initialization.
  722. */
  723. apply_forced_caps(c);
  724. }
  725. static void get_cpu_address_sizes(struct cpuinfo_x86 *c)
  726. {
  727. u32 eax, ebx, ecx, edx;
  728. if (c->extended_cpuid_level >= 0x80000008) {
  729. cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
  730. c->x86_virt_bits = (eax >> 8) & 0xff;
  731. c->x86_phys_bits = eax & 0xff;
  732. }
  733. #ifdef CONFIG_X86_32
  734. else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
  735. c->x86_phys_bits = 36;
  736. #endif
  737. }
  738. static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
  739. {
  740. #ifdef CONFIG_X86_32
  741. int i;
  742. /*
  743. * First of all, decide if this is a 486 or higher
  744. * It's a 486 if we can modify the AC flag
  745. */
  746. if (flag_is_changeable_p(X86_EFLAGS_AC))
  747. c->x86 = 4;
  748. else
  749. c->x86 = 3;
  750. for (i = 0; i < X86_VENDOR_NUM; i++)
  751. if (cpu_devs[i] && cpu_devs[i]->c_identify) {
  752. c->x86_vendor_id[0] = 0;
  753. cpu_devs[i]->c_identify(c);
  754. if (c->x86_vendor_id[0]) {
  755. get_cpu_vendor(c);
  756. break;
  757. }
  758. }
  759. #endif
  760. }
  761. static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
  762. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW, X86_FEATURE_ANY },
  763. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW, X86_FEATURE_ANY },
  764. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT, X86_FEATURE_ANY },
  765. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL, X86_FEATURE_ANY },
  766. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW, X86_FEATURE_ANY },
  767. { X86_VENDOR_CENTAUR, 5 },
  768. { X86_VENDOR_INTEL, 5 },
  769. { X86_VENDOR_NSC, 5 },
  770. { X86_VENDOR_ANY, 4 },
  771. {}
  772. };
  773. static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
  774. { X86_VENDOR_AMD },
  775. {}
  776. };
  777. static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c)
  778. {
  779. u64 ia32_cap = 0;
  780. if (x86_match_cpu(cpu_no_meltdown))
  781. return false;
  782. if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
  783. rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
  784. /* Rogue Data Cache Load? No! */
  785. if (ia32_cap & ARCH_CAP_RDCL_NO)
  786. return false;
  787. return true;
  788. }
  789. /*
  790. * Do minimum CPU detection early.
  791. * Fields really needed: vendor, cpuid_level, family, model, mask,
  792. * cache alignment.
  793. * The others are not touched to avoid unwanted side effects.
  794. *
  795. * WARNING: this function is only called on the boot CPU. Don't add code
  796. * here that is supposed to run on all CPUs.
  797. */
  798. static void __init early_identify_cpu(struct cpuinfo_x86 *c)
  799. {
  800. #ifdef CONFIG_X86_64
  801. c->x86_clflush_size = 64;
  802. c->x86_phys_bits = 36;
  803. c->x86_virt_bits = 48;
  804. #else
  805. c->x86_clflush_size = 32;
  806. c->x86_phys_bits = 32;
  807. c->x86_virt_bits = 32;
  808. #endif
  809. c->x86_cache_alignment = c->x86_clflush_size;
  810. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  811. c->extended_cpuid_level = 0;
  812. /* cyrix could have cpuid enabled via c_identify()*/
  813. if (have_cpuid_p()) {
  814. cpu_detect(c);
  815. get_cpu_vendor(c);
  816. get_cpu_cap(c);
  817. get_cpu_address_sizes(c);
  818. setup_force_cpu_cap(X86_FEATURE_CPUID);
  819. if (this_cpu->c_early_init)
  820. this_cpu->c_early_init(c);
  821. c->cpu_index = 0;
  822. filter_cpuid_features(c, false);
  823. if (this_cpu->c_bsp_init)
  824. this_cpu->c_bsp_init(c);
  825. } else {
  826. identify_cpu_without_cpuid(c);
  827. setup_clear_cpu_cap(X86_FEATURE_CPUID);
  828. }
  829. setup_force_cpu_cap(X86_FEATURE_ALWAYS);
  830. if (!x86_match_cpu(cpu_no_speculation)) {
  831. if (cpu_vulnerable_to_meltdown(c))
  832. setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
  833. setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
  834. setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
  835. }
  836. fpu__init_system(c);
  837. #ifdef CONFIG_X86_32
  838. /*
  839. * Regardless of whether PCID is enumerated, the SDM says
  840. * that it can't be enabled in 32-bit mode.
  841. */
  842. setup_clear_cpu_cap(X86_FEATURE_PCID);
  843. #endif
  844. }
  845. void __init early_cpu_init(void)
  846. {
  847. const struct cpu_dev *const *cdev;
  848. int count = 0;
  849. #ifdef CONFIG_PROCESSOR_SELECT
  850. pr_info("KERNEL supported cpus:\n");
  851. #endif
  852. for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
  853. const struct cpu_dev *cpudev = *cdev;
  854. if (count >= X86_VENDOR_NUM)
  855. break;
  856. cpu_devs[count] = cpudev;
  857. count++;
  858. #ifdef CONFIG_PROCESSOR_SELECT
  859. {
  860. unsigned int j;
  861. for (j = 0; j < 2; j++) {
  862. if (!cpudev->c_ident[j])
  863. continue;
  864. pr_info(" %s %s\n", cpudev->c_vendor,
  865. cpudev->c_ident[j]);
  866. }
  867. }
  868. #endif
  869. }
  870. early_identify_cpu(&boot_cpu_data);
  871. }
  872. /*
  873. * The NOPL instruction is supposed to exist on all CPUs of family >= 6;
  874. * unfortunately, that's not true in practice because of early VIA
  875. * chips and (more importantly) broken virtualizers that are not easy
  876. * to detect. In the latter case it doesn't even *fail* reliably, so
  877. * probing for it doesn't even work. Disable it completely on 32-bit
  878. * unless we can find a reliable way to detect all the broken cases.
  879. * Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
  880. */
  881. static void detect_nopl(struct cpuinfo_x86 *c)
  882. {
  883. #ifdef CONFIG_X86_32
  884. clear_cpu_cap(c, X86_FEATURE_NOPL);
  885. #else
  886. set_cpu_cap(c, X86_FEATURE_NOPL);
  887. #endif
  888. }
  889. static void detect_null_seg_behavior(struct cpuinfo_x86 *c)
  890. {
  891. #ifdef CONFIG_X86_64
  892. /*
  893. * Empirically, writing zero to a segment selector on AMD does
  894. * not clear the base, whereas writing zero to a segment
  895. * selector on Intel does clear the base. Intel's behavior
  896. * allows slightly faster context switches in the common case
  897. * where GS is unused by the prev and next threads.
  898. *
  899. * Since neither vendor documents this anywhere that I can see,
  900. * detect it directly instead of hardcoding the choice by
  901. * vendor.
  902. *
  903. * I've designated AMD's behavior as the "bug" because it's
  904. * counterintuitive and less friendly.
  905. */
  906. unsigned long old_base, tmp;
  907. rdmsrl(MSR_FS_BASE, old_base);
  908. wrmsrl(MSR_FS_BASE, 1);
  909. loadsegment(fs, 0);
  910. rdmsrl(MSR_FS_BASE, tmp);
  911. if (tmp != 0)
  912. set_cpu_bug(c, X86_BUG_NULL_SEG);
  913. wrmsrl(MSR_FS_BASE, old_base);
  914. #endif
  915. }
  916. static void generic_identify(struct cpuinfo_x86 *c)
  917. {
  918. c->extended_cpuid_level = 0;
  919. if (!have_cpuid_p())
  920. identify_cpu_without_cpuid(c);
  921. /* cyrix could have cpuid enabled via c_identify()*/
  922. if (!have_cpuid_p())
  923. return;
  924. cpu_detect(c);
  925. get_cpu_vendor(c);
  926. get_cpu_cap(c);
  927. get_cpu_address_sizes(c);
  928. if (c->cpuid_level >= 0x00000001) {
  929. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
  930. #ifdef CONFIG_X86_32
  931. # ifdef CONFIG_SMP
  932. c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
  933. # else
  934. c->apicid = c->initial_apicid;
  935. # endif
  936. #endif
  937. c->phys_proc_id = c->initial_apicid;
  938. }
  939. get_model_name(c); /* Default name */
  940. detect_nopl(c);
  941. detect_null_seg_behavior(c);
  942. /*
  943. * ESPFIX is a strange bug. All real CPUs have it. Paravirt
  944. * systems that run Linux at CPL > 0 may or may not have the
  945. * issue, but, even if they have the issue, there's absolutely
  946. * nothing we can do about it because we can't use the real IRET
  947. * instruction.
  948. *
  949. * NB: For the time being, only 32-bit kernels support
  950. * X86_BUG_ESPFIX as such. 64-bit kernels directly choose
  951. * whether to apply espfix using paravirt hooks. If any
  952. * non-paravirt system ever shows up that does *not* have the
  953. * ESPFIX issue, we can change this.
  954. */
  955. #ifdef CONFIG_X86_32
  956. # ifdef CONFIG_PARAVIRT
  957. do {
  958. extern void native_iret(void);
  959. if (pv_cpu_ops.iret == native_iret)
  960. set_cpu_bug(c, X86_BUG_ESPFIX);
  961. } while (0);
  962. # else
  963. set_cpu_bug(c, X86_BUG_ESPFIX);
  964. # endif
  965. #endif
  966. }
  967. static void x86_init_cache_qos(struct cpuinfo_x86 *c)
  968. {
  969. /*
  970. * The heavy lifting of max_rmid and cache_occ_scale are handled
  971. * in get_cpu_cap(). Here we just set the max_rmid for the boot_cpu
  972. * in case CQM bits really aren't there in this CPU.
  973. */
  974. if (c != &boot_cpu_data) {
  975. boot_cpu_data.x86_cache_max_rmid =
  976. min(boot_cpu_data.x86_cache_max_rmid,
  977. c->x86_cache_max_rmid);
  978. }
  979. }
  980. /*
  981. * Validate that ACPI/mptables have the same information about the
  982. * effective APIC id and update the package map.
  983. */
  984. static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
  985. {
  986. #ifdef CONFIG_SMP
  987. unsigned int apicid, cpu = smp_processor_id();
  988. apicid = apic->cpu_present_to_apicid(cpu);
  989. if (apicid != c->apicid) {
  990. pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n",
  991. cpu, apicid, c->initial_apicid);
  992. }
  993. BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
  994. #else
  995. c->logical_proc_id = 0;
  996. #endif
  997. }
  998. /*
  999. * This does the hard work of actually picking apart the CPU stuff...
  1000. */
  1001. static void identify_cpu(struct cpuinfo_x86 *c)
  1002. {
  1003. int i;
  1004. c->loops_per_jiffy = loops_per_jiffy;
  1005. c->x86_cache_size = 0;
  1006. c->x86_vendor = X86_VENDOR_UNKNOWN;
  1007. c->x86_model = c->x86_stepping = 0; /* So far unknown... */
  1008. c->x86_vendor_id[0] = '\0'; /* Unset */
  1009. c->x86_model_id[0] = '\0'; /* Unset */
  1010. c->x86_max_cores = 1;
  1011. c->x86_coreid_bits = 0;
  1012. c->cu_id = 0xff;
  1013. #ifdef CONFIG_X86_64
  1014. c->x86_clflush_size = 64;
  1015. c->x86_phys_bits = 36;
  1016. c->x86_virt_bits = 48;
  1017. #else
  1018. c->cpuid_level = -1; /* CPUID not detected */
  1019. c->x86_clflush_size = 32;
  1020. c->x86_phys_bits = 32;
  1021. c->x86_virt_bits = 32;
  1022. #endif
  1023. c->x86_cache_alignment = c->x86_clflush_size;
  1024. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  1025. generic_identify(c);
  1026. if (this_cpu->c_identify)
  1027. this_cpu->c_identify(c);
  1028. /* Clear/Set all flags overridden by options, after probe */
  1029. apply_forced_caps(c);
  1030. #ifdef CONFIG_X86_64
  1031. c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
  1032. #endif
  1033. /*
  1034. * Vendor-specific initialization. In this section we
  1035. * canonicalize the feature flags, meaning if there are
  1036. * features a certain CPU supports which CPUID doesn't
  1037. * tell us, CPUID claiming incorrect flags, or other bugs,
  1038. * we handle them here.
  1039. *
  1040. * At the end of this section, c->x86_capability better
  1041. * indicate the features this CPU genuinely supports!
  1042. */
  1043. if (this_cpu->c_init)
  1044. this_cpu->c_init(c);
  1045. /* Disable the PN if appropriate */
  1046. squash_the_stupid_serial_number(c);
  1047. /* Set up SMEP/SMAP/UMIP */
  1048. setup_smep(c);
  1049. setup_smap(c);
  1050. setup_umip(c);
  1051. /*
  1052. * The vendor-specific functions might have changed features.
  1053. * Now we do "generic changes."
  1054. */
  1055. /* Filter out anything that depends on CPUID levels we don't have */
  1056. filter_cpuid_features(c, true);
  1057. /* If the model name is still unset, do table lookup. */
  1058. if (!c->x86_model_id[0]) {
  1059. const char *p;
  1060. p = table_lookup_model(c);
  1061. if (p)
  1062. strcpy(c->x86_model_id, p);
  1063. else
  1064. /* Last resort... */
  1065. sprintf(c->x86_model_id, "%02x/%02x",
  1066. c->x86, c->x86_model);
  1067. }
  1068. #ifdef CONFIG_X86_64
  1069. detect_ht(c);
  1070. #endif
  1071. x86_init_rdrand(c);
  1072. x86_init_cache_qos(c);
  1073. setup_pku(c);
  1074. /*
  1075. * Clear/Set all flags overridden by options, need do it
  1076. * before following smp all cpus cap AND.
  1077. */
  1078. apply_forced_caps(c);
  1079. /*
  1080. * On SMP, boot_cpu_data holds the common feature set between
  1081. * all CPUs; so make sure that we indicate which features are
  1082. * common between the CPUs. The first time this routine gets
  1083. * executed, c == &boot_cpu_data.
  1084. */
  1085. if (c != &boot_cpu_data) {
  1086. /* AND the already accumulated flags with these */
  1087. for (i = 0; i < NCAPINTS; i++)
  1088. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  1089. /* OR, i.e. replicate the bug flags */
  1090. for (i = NCAPINTS; i < NCAPINTS + NBUGINTS; i++)
  1091. c->x86_capability[i] |= boot_cpu_data.x86_capability[i];
  1092. }
  1093. /* Init Machine Check Exception if available. */
  1094. mcheck_cpu_init(c);
  1095. select_idle_routine(c);
  1096. #ifdef CONFIG_NUMA
  1097. numa_add_cpu(smp_processor_id());
  1098. #endif
  1099. }
  1100. /*
  1101. * Set up the CPU state needed to execute SYSENTER/SYSEXIT instructions
  1102. * on 32-bit kernels:
  1103. */
  1104. #ifdef CONFIG_X86_32
  1105. void enable_sep_cpu(void)
  1106. {
  1107. struct tss_struct *tss;
  1108. int cpu;
  1109. if (!boot_cpu_has(X86_FEATURE_SEP))
  1110. return;
  1111. cpu = get_cpu();
  1112. tss = &per_cpu(cpu_tss_rw, cpu);
  1113. /*
  1114. * We cache MSR_IA32_SYSENTER_CS's value in the TSS's ss1 field --
  1115. * see the big comment in struct x86_hw_tss's definition.
  1116. */
  1117. tss->x86_tss.ss1 = __KERNEL_CS;
  1118. wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0);
  1119. wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1), 0);
  1120. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);
  1121. put_cpu();
  1122. }
  1123. #endif
  1124. void __init identify_boot_cpu(void)
  1125. {
  1126. identify_cpu(&boot_cpu_data);
  1127. #ifdef CONFIG_X86_32
  1128. sysenter_setup();
  1129. enable_sep_cpu();
  1130. #endif
  1131. cpu_detect_tlb(&boot_cpu_data);
  1132. }
  1133. void identify_secondary_cpu(struct cpuinfo_x86 *c)
  1134. {
  1135. BUG_ON(c == &boot_cpu_data);
  1136. identify_cpu(c);
  1137. #ifdef CONFIG_X86_32
  1138. enable_sep_cpu();
  1139. #endif
  1140. mtrr_ap_init();
  1141. validate_apic_and_package_id(c);
  1142. }
  1143. static __init int setup_noclflush(char *arg)
  1144. {
  1145. setup_clear_cpu_cap(X86_FEATURE_CLFLUSH);
  1146. setup_clear_cpu_cap(X86_FEATURE_CLFLUSHOPT);
  1147. return 1;
  1148. }
  1149. __setup("noclflush", setup_noclflush);
  1150. void print_cpu_info(struct cpuinfo_x86 *c)
  1151. {
  1152. const char *vendor = NULL;
  1153. if (c->x86_vendor < X86_VENDOR_NUM) {
  1154. vendor = this_cpu->c_vendor;
  1155. } else {
  1156. if (c->cpuid_level >= 0)
  1157. vendor = c->x86_vendor_id;
  1158. }
  1159. if (vendor && !strstr(c->x86_model_id, vendor))
  1160. pr_cont("%s ", vendor);
  1161. if (c->x86_model_id[0])
  1162. pr_cont("%s", c->x86_model_id);
  1163. else
  1164. pr_cont("%d86", c->x86);
  1165. pr_cont(" (family: 0x%x, model: 0x%x", c->x86, c->x86_model);
  1166. if (c->x86_stepping || c->cpuid_level >= 0)
  1167. pr_cont(", stepping: 0x%x)\n", c->x86_stepping);
  1168. else
  1169. pr_cont(")\n");
  1170. }
  1171. /*
  1172. * clearcpuid= was already parsed in fpu__init_parse_early_param.
  1173. * But we need to keep a dummy __setup around otherwise it would
  1174. * show up as an environment variable for init.
  1175. */
  1176. static __init int setup_clearcpuid(char *arg)
  1177. {
  1178. return 1;
  1179. }
  1180. __setup("clearcpuid=", setup_clearcpuid);
  1181. #ifdef CONFIG_X86_64
  1182. DEFINE_PER_CPU_FIRST(union irq_stack_union,
  1183. irq_stack_union) __aligned(PAGE_SIZE) __visible;
  1184. EXPORT_PER_CPU_SYMBOL_GPL(irq_stack_union);
  1185. /*
  1186. * The following percpu variables are hot. Align current_task to
  1187. * cacheline size such that they fall in the same cacheline.
  1188. */
  1189. DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
  1190. &init_task;
  1191. EXPORT_PER_CPU_SYMBOL(current_task);
  1192. DEFINE_PER_CPU(char *, irq_stack_ptr) =
  1193. init_per_cpu_var(irq_stack_union.irq_stack) + IRQ_STACK_SIZE;
  1194. DEFINE_PER_CPU(unsigned int, irq_count) __visible = -1;
  1195. DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT;
  1196. EXPORT_PER_CPU_SYMBOL(__preempt_count);
  1197. /* May not be marked __init: used by software suspend */
  1198. void syscall_init(void)
  1199. {
  1200. extern char _entry_trampoline[];
  1201. extern char entry_SYSCALL_64_trampoline[];
  1202. int cpu = smp_processor_id();
  1203. unsigned long SYSCALL64_entry_trampoline =
  1204. (unsigned long)get_cpu_entry_area(cpu)->entry_trampoline +
  1205. (entry_SYSCALL_64_trampoline - _entry_trampoline);
  1206. wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
  1207. if (static_cpu_has(X86_FEATURE_PTI))
  1208. wrmsrl(MSR_LSTAR, SYSCALL64_entry_trampoline);
  1209. else
  1210. wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
  1211. #ifdef CONFIG_IA32_EMULATION
  1212. wrmsrl(MSR_CSTAR, (unsigned long)entry_SYSCALL_compat);
  1213. /*
  1214. * This only works on Intel CPUs.
  1215. * On AMD CPUs these MSRs are 32-bit, CPU truncates MSR_IA32_SYSENTER_EIP.
  1216. * This does not cause SYSENTER to jump to the wrong location, because
  1217. * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
  1218. */
  1219. wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
  1220. wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1));
  1221. wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
  1222. #else
  1223. wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
  1224. wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)GDT_ENTRY_INVALID_SEG);
  1225. wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
  1226. wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
  1227. #endif
  1228. /* Flags to clear on syscall */
  1229. wrmsrl(MSR_SYSCALL_MASK,
  1230. X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|
  1231. X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT);
  1232. }
  1233. /*
  1234. * Copies of the original ist values from the tss are only accessed during
  1235. * debugging, no special alignment required.
  1236. */
  1237. DEFINE_PER_CPU(struct orig_ist, orig_ist);
  1238. static DEFINE_PER_CPU(unsigned long, debug_stack_addr);
  1239. DEFINE_PER_CPU(int, debug_stack_usage);
  1240. int is_debug_stack(unsigned long addr)
  1241. {
  1242. return __this_cpu_read(debug_stack_usage) ||
  1243. (addr <= __this_cpu_read(debug_stack_addr) &&
  1244. addr > (__this_cpu_read(debug_stack_addr) - DEBUG_STKSZ));
  1245. }
  1246. NOKPROBE_SYMBOL(is_debug_stack);
  1247. DEFINE_PER_CPU(u32, debug_idt_ctr);
  1248. void debug_stack_set_zero(void)
  1249. {
  1250. this_cpu_inc(debug_idt_ctr);
  1251. load_current_idt();
  1252. }
  1253. NOKPROBE_SYMBOL(debug_stack_set_zero);
  1254. void debug_stack_reset(void)
  1255. {
  1256. if (WARN_ON(!this_cpu_read(debug_idt_ctr)))
  1257. return;
  1258. if (this_cpu_dec_return(debug_idt_ctr) == 0)
  1259. load_current_idt();
  1260. }
  1261. NOKPROBE_SYMBOL(debug_stack_reset);
  1262. #else /* CONFIG_X86_64 */
  1263. DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
  1264. EXPORT_PER_CPU_SYMBOL(current_task);
  1265. DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT;
  1266. EXPORT_PER_CPU_SYMBOL(__preempt_count);
  1267. /*
  1268. * On x86_32, vm86 modifies tss.sp0, so sp0 isn't a reliable way to find
  1269. * the top of the kernel stack. Use an extra percpu variable to track the
  1270. * top of the kernel stack directly.
  1271. */
  1272. DEFINE_PER_CPU(unsigned long, cpu_current_top_of_stack) =
  1273. (unsigned long)&init_thread_union + THREAD_SIZE;
  1274. EXPORT_PER_CPU_SYMBOL(cpu_current_top_of_stack);
  1275. #ifdef CONFIG_CC_STACKPROTECTOR
  1276. DEFINE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);
  1277. #endif
  1278. #endif /* CONFIG_X86_64 */
  1279. /*
  1280. * Clear all 6 debug registers:
  1281. */
  1282. static void clear_all_debug_regs(void)
  1283. {
  1284. int i;
  1285. for (i = 0; i < 8; i++) {
  1286. /* Ignore db4, db5 */
  1287. if ((i == 4) || (i == 5))
  1288. continue;
  1289. set_debugreg(0, i);
  1290. }
  1291. }
  1292. #ifdef CONFIG_KGDB
  1293. /*
  1294. * Restore debug regs if using kgdbwait and you have a kernel debugger
  1295. * connection established.
  1296. */
  1297. static void dbg_restore_debug_regs(void)
  1298. {
  1299. if (unlikely(kgdb_connected && arch_kgdb_ops.correct_hw_break))
  1300. arch_kgdb_ops.correct_hw_break();
  1301. }
  1302. #else /* ! CONFIG_KGDB */
  1303. #define dbg_restore_debug_regs()
  1304. #endif /* ! CONFIG_KGDB */
  1305. static void wait_for_master_cpu(int cpu)
  1306. {
  1307. #ifdef CONFIG_SMP
  1308. /*
  1309. * wait for ACK from master CPU before continuing
  1310. * with AP initialization
  1311. */
  1312. WARN_ON(cpumask_test_and_set_cpu(cpu, cpu_initialized_mask));
  1313. while (!cpumask_test_cpu(cpu, cpu_callout_mask))
  1314. cpu_relax();
  1315. #endif
  1316. }
  1317. /*
  1318. * cpu_init() initializes state that is per-CPU. Some data is already
  1319. * initialized (naturally) in the bootstrap process, such as the GDT
  1320. * and IDT. We reload them nevertheless, this function acts as a
  1321. * 'CPU state barrier', nothing should get across.
  1322. * A lot of state is already set up in PDA init for 64 bit
  1323. */
  1324. #ifdef CONFIG_X86_64
  1325. void cpu_init(void)
  1326. {
  1327. struct orig_ist *oist;
  1328. struct task_struct *me;
  1329. struct tss_struct *t;
  1330. unsigned long v;
  1331. int cpu = raw_smp_processor_id();
  1332. int i;
  1333. wait_for_master_cpu(cpu);
  1334. /*
  1335. * Initialize the CR4 shadow before doing anything that could
  1336. * try to read it.
  1337. */
  1338. cr4_init_shadow();
  1339. if (cpu)
  1340. load_ucode_ap();
  1341. t = &per_cpu(cpu_tss_rw, cpu);
  1342. oist = &per_cpu(orig_ist, cpu);
  1343. #ifdef CONFIG_NUMA
  1344. if (this_cpu_read(numa_node) == 0 &&
  1345. early_cpu_to_node(cpu) != NUMA_NO_NODE)
  1346. set_numa_node(early_cpu_to_node(cpu));
  1347. #endif
  1348. me = current;
  1349. pr_debug("Initializing CPU#%d\n", cpu);
  1350. cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  1351. /*
  1352. * Initialize the per-CPU GDT with the boot GDT,
  1353. * and set up the GDT descriptor:
  1354. */
  1355. switch_to_new_gdt(cpu);
  1356. loadsegment(fs, 0);
  1357. load_current_idt();
  1358. memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
  1359. syscall_init();
  1360. wrmsrl(MSR_FS_BASE, 0);
  1361. wrmsrl(MSR_KERNEL_GS_BASE, 0);
  1362. barrier();
  1363. x86_configure_nx();
  1364. x2apic_setup();
  1365. /*
  1366. * set up and load the per-CPU TSS
  1367. */
  1368. if (!oist->ist[0]) {
  1369. char *estacks = get_cpu_entry_area(cpu)->exception_stacks;
  1370. for (v = 0; v < N_EXCEPTION_STACKS; v++) {
  1371. estacks += exception_stack_sizes[v];
  1372. oist->ist[v] = t->x86_tss.ist[v] =
  1373. (unsigned long)estacks;
  1374. if (v == DEBUG_STACK-1)
  1375. per_cpu(debug_stack_addr, cpu) = (unsigned long)estacks;
  1376. }
  1377. }
  1378. t->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
  1379. /*
  1380. * <= is required because the CPU will access up to
  1381. * 8 bits beyond the end of the IO permission bitmap.
  1382. */
  1383. for (i = 0; i <= IO_BITMAP_LONGS; i++)
  1384. t->io_bitmap[i] = ~0UL;
  1385. mmgrab(&init_mm);
  1386. me->active_mm = &init_mm;
  1387. BUG_ON(me->mm);
  1388. initialize_tlbstate_and_flush();
  1389. enter_lazy_tlb(&init_mm, me);
  1390. /*
  1391. * Initialize the TSS. sp0 points to the entry trampoline stack
  1392. * regardless of what task is running.
  1393. */
  1394. set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
  1395. load_TR_desc();
  1396. load_sp0((unsigned long)(cpu_entry_stack(cpu) + 1));
  1397. load_mm_ldt(&init_mm);
  1398. clear_all_debug_regs();
  1399. dbg_restore_debug_regs();
  1400. fpu__init_cpu();
  1401. if (is_uv_system())
  1402. uv_cpu_init();
  1403. load_fixmap_gdt(cpu);
  1404. }
  1405. #else
  1406. void cpu_init(void)
  1407. {
  1408. int cpu = smp_processor_id();
  1409. struct task_struct *curr = current;
  1410. struct tss_struct *t = &per_cpu(cpu_tss_rw, cpu);
  1411. wait_for_master_cpu(cpu);
  1412. /*
  1413. * Initialize the CR4 shadow before doing anything that could
  1414. * try to read it.
  1415. */
  1416. cr4_init_shadow();
  1417. show_ucode_info_early();
  1418. pr_info("Initializing CPU#%d\n", cpu);
  1419. if (cpu_feature_enabled(X86_FEATURE_VME) ||
  1420. boot_cpu_has(X86_FEATURE_TSC) ||
  1421. boot_cpu_has(X86_FEATURE_DE))
  1422. cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  1423. load_current_idt();
  1424. switch_to_new_gdt(cpu);
  1425. /*
  1426. * Set up and load the per-CPU TSS and LDT
  1427. */
  1428. mmgrab(&init_mm);
  1429. curr->active_mm = &init_mm;
  1430. BUG_ON(curr->mm);
  1431. initialize_tlbstate_and_flush();
  1432. enter_lazy_tlb(&init_mm, curr);
  1433. /*
  1434. * Initialize the TSS. Don't bother initializing sp0, as the initial
  1435. * task never enters user mode.
  1436. */
  1437. set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
  1438. load_TR_desc();
  1439. load_mm_ldt(&init_mm);
  1440. t->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
  1441. #ifdef CONFIG_DOUBLEFAULT
  1442. /* Set up doublefault TSS pointer in the GDT */
  1443. __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
  1444. #endif
  1445. clear_all_debug_regs();
  1446. dbg_restore_debug_regs();
  1447. fpu__init_cpu();
  1448. load_fixmap_gdt(cpu);
  1449. }
  1450. #endif
  1451. static void bsp_resume(void)
  1452. {
  1453. if (this_cpu->c_bsp_resume)
  1454. this_cpu->c_bsp_resume(&boot_cpu_data);
  1455. }
  1456. static struct syscore_ops cpu_syscore_ops = {
  1457. .resume = bsp_resume,
  1458. };
  1459. static int __init init_cpu_syscore(void)
  1460. {
  1461. register_syscore_ops(&cpu_syscore_ops);
  1462. return 0;
  1463. }
  1464. core_initcall(init_cpu_syscore);
  1465. /*
  1466. * The microcode loader calls this upon late microcode load to recheck features,
  1467. * only when microcode has been updated. Caller holds microcode_mutex and CPU
  1468. * hotplug lock.
  1469. */
  1470. void microcode_check(void)
  1471. {
  1472. struct cpuinfo_x86 info;
  1473. perf_check_microcode();
  1474. /* Reload CPUID max function as it might've changed. */
  1475. info.cpuid_level = cpuid_eax(0);
  1476. /*
  1477. * Copy all capability leafs to pick up the synthetic ones so that
  1478. * memcmp() below doesn't fail on that. The ones coming from CPUID will
  1479. * get overwritten in get_cpu_cap().
  1480. */
  1481. memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
  1482. get_cpu_cap(&info);
  1483. if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
  1484. return;
  1485. pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");
  1486. pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n");
  1487. }