intel.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. #include <linux/kernel.h>
  2. #include <linux/string.h>
  3. #include <linux/bitops.h>
  4. #include <linux/smp.h>
  5. #include <linux/sched.h>
  6. #include <linux/thread_info.h>
  7. #include <linux/init.h>
  8. #include <linux/uaccess.h>
  9. #include <asm/cpufeature.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/msr.h>
  12. #include <asm/bugs.h>
  13. #include <asm/cpu.h>
  14. #include <asm/intel-family.h>
  15. #ifdef CONFIG_X86_64
  16. #include <linux/topology.h>
  17. #endif
  18. #include "cpu.h"
  19. #ifdef CONFIG_X86_LOCAL_APIC
  20. #include <asm/mpspec.h>
  21. #include <asm/apic.h>
  22. #endif
  23. /*
  24. * Just in case our CPU detection goes bad, or you have a weird system,
  25. * allow a way to override the automatic disabling of MPX.
  26. */
  27. static int forcempx;
  28. static int __init forcempx_setup(char *__unused)
  29. {
  30. forcempx = 1;
  31. return 1;
  32. }
  33. __setup("intel-skd-046-workaround=disable", forcempx_setup);
  34. void check_mpx_erratum(struct cpuinfo_x86 *c)
  35. {
  36. if (forcempx)
  37. return;
  38. /*
  39. * Turn off the MPX feature on CPUs where SMEP is not
  40. * available or disabled.
  41. *
  42. * Works around Intel Erratum SKD046: "Branch Instructions
  43. * May Initialize MPX Bound Registers Incorrectly".
  44. *
  45. * This might falsely disable MPX on systems without
  46. * SMEP, like Atom processors without SMEP. But there
  47. * is no such hardware known at the moment.
  48. */
  49. if (cpu_has(c, X86_FEATURE_MPX) && !cpu_has(c, X86_FEATURE_SMEP)) {
  50. setup_clear_cpu_cap(X86_FEATURE_MPX);
  51. pr_warn("x86/mpx: Disabling MPX since SMEP not present\n");
  52. }
  53. }
  54. /*
  55. * Early microcode releases for the Spectre v2 mitigation were broken.
  56. * Information taken from;
  57. * - https://newsroom.intel.com/wp-content/uploads/sites/11/2018/03/microcode-update-guidance.pdf
  58. * - https://kb.vmware.com/s/article/52345
  59. * - Microcode revisions observed in the wild
  60. * - Release note from 20180108 microcode release
  61. */
  62. struct sku_microcode {
  63. u8 model;
  64. u8 stepping;
  65. u32 microcode;
  66. };
  67. static const struct sku_microcode spectre_bad_microcodes[] = {
  68. { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0B, 0x80 },
  69. { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0A, 0x80 },
  70. { INTEL_FAM6_KABYLAKE_DESKTOP, 0x09, 0x80 },
  71. { INTEL_FAM6_KABYLAKE_MOBILE, 0x0A, 0x80 },
  72. { INTEL_FAM6_KABYLAKE_MOBILE, 0x09, 0x80 },
  73. { INTEL_FAM6_SKYLAKE_X, 0x03, 0x0100013e },
  74. { INTEL_FAM6_SKYLAKE_X, 0x04, 0x0200003c },
  75. { INTEL_FAM6_BROADWELL_CORE, 0x04, 0x28 },
  76. { INTEL_FAM6_BROADWELL_GT3E, 0x01, 0x1b },
  77. { INTEL_FAM6_BROADWELL_XEON_D, 0x02, 0x14 },
  78. { INTEL_FAM6_BROADWELL_XEON_D, 0x03, 0x07000011 },
  79. { INTEL_FAM6_BROADWELL_X, 0x01, 0x0b000025 },
  80. { INTEL_FAM6_HASWELL_ULT, 0x01, 0x21 },
  81. { INTEL_FAM6_HASWELL_GT3E, 0x01, 0x18 },
  82. { INTEL_FAM6_HASWELL_CORE, 0x03, 0x23 },
  83. { INTEL_FAM6_HASWELL_X, 0x02, 0x3b },
  84. { INTEL_FAM6_HASWELL_X, 0x04, 0x10 },
  85. { INTEL_FAM6_IVYBRIDGE_X, 0x04, 0x42a },
  86. /* Observed in the wild */
  87. { INTEL_FAM6_SANDYBRIDGE_X, 0x06, 0x61b },
  88. { INTEL_FAM6_SANDYBRIDGE_X, 0x07, 0x712 },
  89. };
  90. static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
  91. {
  92. int i;
  93. /*
  94. * We know that the hypervisor lie to us on the microcode version so
  95. * we may as well hope that it is running the correct version.
  96. */
  97. if (cpu_has(c, X86_FEATURE_HYPERVISOR))
  98. return false;
  99. for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
  100. if (c->x86_model == spectre_bad_microcodes[i].model &&
  101. c->x86_stepping == spectre_bad_microcodes[i].stepping)
  102. return (c->microcode <= spectre_bad_microcodes[i].microcode);
  103. }
  104. return false;
  105. }
  106. static void early_init_intel(struct cpuinfo_x86 *c)
  107. {
  108. u64 misc_enable;
  109. /* Unmask CPUID levels if masked: */
  110. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  111. if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
  112. MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) {
  113. c->cpuid_level = cpuid_eax(0);
  114. get_cpu_cap(c);
  115. }
  116. }
  117. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  118. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  119. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  120. if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64)) {
  121. unsigned lower_word;
  122. wrmsr(MSR_IA32_UCODE_REV, 0, 0);
  123. /* Required by the SDM */
  124. sync_core();
  125. rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode);
  126. }
  127. /* Now if any of them are set, check the blacklist and clear the lot */
  128. if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) ||
  129. cpu_has(c, X86_FEATURE_INTEL_STIBP) ||
  130. cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
  131. cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
  132. pr_warn("Intel Spectre v2 broken microcode detected; disabling Speculation Control\n");
  133. setup_clear_cpu_cap(X86_FEATURE_IBRS);
  134. setup_clear_cpu_cap(X86_FEATURE_IBPB);
  135. setup_clear_cpu_cap(X86_FEATURE_STIBP);
  136. setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
  137. setup_clear_cpu_cap(X86_FEATURE_MSR_SPEC_CTRL);
  138. setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
  139. setup_clear_cpu_cap(X86_FEATURE_SSBD);
  140. setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL_SSBD);
  141. }
  142. /*
  143. * Atom erratum AAE44/AAF40/AAG38/AAH41:
  144. *
  145. * A race condition between speculative fetches and invalidating
  146. * a large page. This is worked around in microcode, but we
  147. * need the microcode to have already been loaded... so if it is
  148. * not, recommend a BIOS update and disable large pages.
  149. */
  150. if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_stepping <= 2 &&
  151. c->microcode < 0x20e) {
  152. pr_warn("Atom PSE erratum detected, BIOS microcode update recommended\n");
  153. clear_cpu_cap(c, X86_FEATURE_PSE);
  154. }
  155. #ifdef CONFIG_X86_64
  156. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  157. #else
  158. /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
  159. if (c->x86 == 15 && c->x86_cache_alignment == 64)
  160. c->x86_cache_alignment = 128;
  161. #endif
  162. /* CPUID workaround for 0F33/0F34 CPU */
  163. if (c->x86 == 0xF && c->x86_model == 0x3
  164. && (c->x86_stepping == 0x3 || c->x86_stepping == 0x4))
  165. c->x86_phys_bits = 36;
  166. /*
  167. * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
  168. * with P/T states and does not stop in deep C-states.
  169. *
  170. * It is also reliable across cores and sockets. (but not across
  171. * cabinets - we turn it off in that case explicitly.)
  172. */
  173. if (c->x86_power & (1 << 8)) {
  174. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  175. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  176. if (!check_tsc_unstable())
  177. set_sched_clock_stable();
  178. }
  179. /* Penwell and Cloverview have the TSC which doesn't sleep on S3 */
  180. if (c->x86 == 6) {
  181. switch (c->x86_model) {
  182. case 0x27: /* Penwell */
  183. case 0x35: /* Cloverview */
  184. case 0x4a: /* Merrifield */
  185. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC_S3);
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. /*
  192. * There is a known erratum on Pentium III and Core Solo
  193. * and Core Duo CPUs.
  194. * " Page with PAT set to WC while associated MTRR is UC
  195. * may consolidate to UC "
  196. * Because of this erratum, it is better to stick with
  197. * setting WC in MTRR rather than using PAT on these CPUs.
  198. *
  199. * Enable PAT WC only on P4, Core 2 or later CPUs.
  200. */
  201. if (c->x86 == 6 && c->x86_model < 15)
  202. clear_cpu_cap(c, X86_FEATURE_PAT);
  203. #ifdef CONFIG_KMEMCHECK
  204. /*
  205. * P4s have a "fast strings" feature which causes single-
  206. * stepping REP instructions to only generate a #DB on
  207. * cache-line boundaries.
  208. *
  209. * Ingo Molnar reported a Pentium D (model 6) and a Xeon
  210. * (model 2) with the same problem.
  211. */
  212. if (c->x86 == 15)
  213. if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
  214. MSR_IA32_MISC_ENABLE_FAST_STRING_BIT) > 0)
  215. pr_info("kmemcheck: Disabling fast string operations\n");
  216. #endif
  217. /*
  218. * If fast string is not enabled in IA32_MISC_ENABLE for any reason,
  219. * clear the fast string and enhanced fast string CPU capabilities.
  220. */
  221. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  222. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  223. if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
  224. pr_info("Disabled fast string operations\n");
  225. setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
  226. setup_clear_cpu_cap(X86_FEATURE_ERMS);
  227. }
  228. }
  229. /*
  230. * Intel Quark Core DevMan_001.pdf section 6.4.11
  231. * "The operating system also is required to invalidate (i.e., flush)
  232. * the TLB when any changes are made to any of the page table entries.
  233. * The operating system must reload CR3 to cause the TLB to be flushed"
  234. *
  235. * As a result, boot_cpu_has(X86_FEATURE_PGE) in arch/x86/include/asm/tlbflush.h
  236. * should be false so that __flush_tlb_all() causes CR3 insted of CR4.PGE
  237. * to be modified.
  238. */
  239. if (c->x86 == 5 && c->x86_model == 9) {
  240. pr_info("Disabling PGE capability bit\n");
  241. setup_clear_cpu_cap(X86_FEATURE_PGE);
  242. }
  243. if (c->cpuid_level >= 0x00000001) {
  244. u32 eax, ebx, ecx, edx;
  245. cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
  246. /*
  247. * If HTT (EDX[28]) is set EBX[16:23] contain the number of
  248. * apicids which are reserved per package. Store the resulting
  249. * shift value for the package management code.
  250. */
  251. if (edx & (1U << 28))
  252. c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
  253. }
  254. check_mpx_erratum(c);
  255. }
  256. #ifdef CONFIG_X86_32
  257. /*
  258. * Early probe support logic for ppro memory erratum #50
  259. *
  260. * This is called before we do cpu ident work
  261. */
  262. int ppro_with_ram_bug(void)
  263. {
  264. /* Uses data from early_cpu_detect now */
  265. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  266. boot_cpu_data.x86 == 6 &&
  267. boot_cpu_data.x86_model == 1 &&
  268. boot_cpu_data.x86_stepping < 8) {
  269. pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n");
  270. return 1;
  271. }
  272. return 0;
  273. }
  274. static void intel_smp_check(struct cpuinfo_x86 *c)
  275. {
  276. /* calling is from identify_secondary_cpu() ? */
  277. if (!c->cpu_index)
  278. return;
  279. /*
  280. * Mask B, Pentium, but not Pentium MMX
  281. */
  282. if (c->x86 == 5 &&
  283. c->x86_stepping >= 1 && c->x86_stepping <= 4 &&
  284. c->x86_model <= 3) {
  285. /*
  286. * Remember we have B step Pentia with bugs
  287. */
  288. WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
  289. "with B stepping processors.\n");
  290. }
  291. }
  292. static int forcepae;
  293. static int __init forcepae_setup(char *__unused)
  294. {
  295. forcepae = 1;
  296. return 1;
  297. }
  298. __setup("forcepae", forcepae_setup);
  299. static void intel_workarounds(struct cpuinfo_x86 *c)
  300. {
  301. #ifdef CONFIG_X86_F00F_BUG
  302. /*
  303. * All models of Pentium and Pentium with MMX technology CPUs
  304. * have the F0 0F bug, which lets nonprivileged users lock up the
  305. * system. Announce that the fault handler will be checking for it.
  306. * The Quark is also family 5, but does not have the same bug.
  307. */
  308. clear_cpu_bug(c, X86_BUG_F00F);
  309. if (c->x86 == 5 && c->x86_model < 9) {
  310. static int f00f_workaround_enabled;
  311. set_cpu_bug(c, X86_BUG_F00F);
  312. if (!f00f_workaround_enabled) {
  313. pr_notice("Intel Pentium with F0 0F bug - workaround enabled.\n");
  314. f00f_workaround_enabled = 1;
  315. }
  316. }
  317. #endif
  318. /*
  319. * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
  320. * model 3 mask 3
  321. */
  322. if ((c->x86<<8 | c->x86_model<<4 | c->x86_stepping) < 0x633)
  323. clear_cpu_cap(c, X86_FEATURE_SEP);
  324. /*
  325. * PAE CPUID issue: many Pentium M report no PAE but may have a
  326. * functionally usable PAE implementation.
  327. * Forcefully enable PAE if kernel parameter "forcepae" is present.
  328. */
  329. if (forcepae) {
  330. pr_warn("PAE forced!\n");
  331. set_cpu_cap(c, X86_FEATURE_PAE);
  332. add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE);
  333. }
  334. /*
  335. * P4 Xeon erratum 037 workaround.
  336. * Hardware prefetcher may cause stale data to be loaded into the cache.
  337. */
  338. if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_stepping == 1)) {
  339. if (msr_set_bit(MSR_IA32_MISC_ENABLE,
  340. MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT) > 0) {
  341. pr_info("CPU: C0 stepping P4 Xeon detected.\n");
  342. pr_info("CPU: Disabling hardware prefetching (Erratum 037)\n");
  343. }
  344. }
  345. /*
  346. * See if we have a good local APIC by checking for buggy Pentia,
  347. * i.e. all B steppings and the C2 stepping of P54C when using their
  348. * integrated APIC (see 11AP erratum in "Pentium Processor
  349. * Specification Update").
  350. */
  351. if (boot_cpu_has(X86_FEATURE_APIC) && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
  352. (c->x86_stepping < 0x6 || c->x86_stepping == 0xb))
  353. set_cpu_bug(c, X86_BUG_11AP);
  354. #ifdef CONFIG_X86_INTEL_USERCOPY
  355. /*
  356. * Set up the preferred alignment for movsl bulk memory moves
  357. */
  358. switch (c->x86) {
  359. case 4: /* 486: untested */
  360. break;
  361. case 5: /* Old Pentia: untested */
  362. break;
  363. case 6: /* PII/PIII only like movsl with 8-byte alignment */
  364. movsl_mask.mask = 7;
  365. break;
  366. case 15: /* P4 is OK down to 8-byte alignment */
  367. movsl_mask.mask = 7;
  368. break;
  369. }
  370. #endif
  371. intel_smp_check(c);
  372. }
  373. #else
  374. static void intel_workarounds(struct cpuinfo_x86 *c)
  375. {
  376. }
  377. #endif
  378. static void srat_detect_node(struct cpuinfo_x86 *c)
  379. {
  380. #ifdef CONFIG_NUMA
  381. unsigned node;
  382. int cpu = smp_processor_id();
  383. /* Don't do the funky fallback heuristics the AMD version employs
  384. for now. */
  385. node = numa_cpu_node(cpu);
  386. if (node == NUMA_NO_NODE || !node_online(node)) {
  387. /* reuse the value from init_cpu_to_node() */
  388. node = cpu_to_node(cpu);
  389. }
  390. numa_set_node(cpu, node);
  391. #endif
  392. }
  393. /*
  394. * find out the number of processor cores on the die
  395. */
  396. static int intel_num_cpu_cores(struct cpuinfo_x86 *c)
  397. {
  398. unsigned int eax, ebx, ecx, edx;
  399. if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4)
  400. return 1;
  401. /* Intel has a non-standard dependency on %ecx for this CPUID level. */
  402. cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
  403. if (eax & 0x1f)
  404. return (eax >> 26) + 1;
  405. else
  406. return 1;
  407. }
  408. static void detect_vmx_virtcap(struct cpuinfo_x86 *c)
  409. {
  410. /* Intel VMX MSR indicated features */
  411. #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
  412. #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
  413. #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
  414. #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
  415. #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
  416. #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
  417. u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
  418. clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  419. clear_cpu_cap(c, X86_FEATURE_VNMI);
  420. clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  421. clear_cpu_cap(c, X86_FEATURE_EPT);
  422. clear_cpu_cap(c, X86_FEATURE_VPID);
  423. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
  424. msr_ctl = vmx_msr_high | vmx_msr_low;
  425. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
  426. set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  427. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
  428. set_cpu_cap(c, X86_FEATURE_VNMI);
  429. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
  430. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
  431. vmx_msr_low, vmx_msr_high);
  432. msr_ctl2 = vmx_msr_high | vmx_msr_low;
  433. if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
  434. (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
  435. set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  436. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
  437. set_cpu_cap(c, X86_FEATURE_EPT);
  438. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
  439. set_cpu_cap(c, X86_FEATURE_VPID);
  440. }
  441. }
  442. static void init_intel_energy_perf(struct cpuinfo_x86 *c)
  443. {
  444. u64 epb;
  445. /*
  446. * Initialize MSR_IA32_ENERGY_PERF_BIAS if not already initialized.
  447. * (x86_energy_perf_policy(8) is available to change it at run-time.)
  448. */
  449. if (!cpu_has(c, X86_FEATURE_EPB))
  450. return;
  451. rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  452. if ((epb & 0xF) != ENERGY_PERF_BIAS_PERFORMANCE)
  453. return;
  454. pr_warn_once("ENERGY_PERF_BIAS: Set to 'normal', was 'performance'\n");
  455. pr_warn_once("ENERGY_PERF_BIAS: View and update with x86_energy_perf_policy(8)\n");
  456. epb = (epb & ~0xF) | ENERGY_PERF_BIAS_NORMAL;
  457. wrmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  458. }
  459. static void intel_bsp_resume(struct cpuinfo_x86 *c)
  460. {
  461. /*
  462. * MSR_IA32_ENERGY_PERF_BIAS is lost across suspend/resume,
  463. * so reinitialize it properly like during bootup:
  464. */
  465. init_intel_energy_perf(c);
  466. }
  467. static void init_intel(struct cpuinfo_x86 *c)
  468. {
  469. unsigned int l2 = 0;
  470. early_init_intel(c);
  471. intel_workarounds(c);
  472. /*
  473. * Detect the extended topology information if available. This
  474. * will reinitialise the initial_apicid which will be used
  475. * in init_intel_cacheinfo()
  476. */
  477. detect_extended_topology(c);
  478. if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
  479. /*
  480. * let's use the legacy cpuid vector 0x1 and 0x4 for topology
  481. * detection.
  482. */
  483. c->x86_max_cores = intel_num_cpu_cores(c);
  484. #ifdef CONFIG_X86_32
  485. detect_ht(c);
  486. #endif
  487. }
  488. l2 = init_intel_cacheinfo(c);
  489. /* Detect legacy cache sizes if init_intel_cacheinfo did not */
  490. if (l2 == 0) {
  491. cpu_detect_cache_sizes(c);
  492. l2 = c->x86_cache_size;
  493. }
  494. if (c->cpuid_level > 9) {
  495. unsigned eax = cpuid_eax(10);
  496. /* Check for version and the number of counters */
  497. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  498. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  499. }
  500. if (cpu_has(c, X86_FEATURE_XMM2))
  501. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  502. if (boot_cpu_has(X86_FEATURE_DS)) {
  503. unsigned int l1;
  504. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  505. if (!(l1 & (1<<11)))
  506. set_cpu_cap(c, X86_FEATURE_BTS);
  507. if (!(l1 & (1<<12)))
  508. set_cpu_cap(c, X86_FEATURE_PEBS);
  509. }
  510. if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_CLFLUSH) &&
  511. (c->x86_model == 29 || c->x86_model == 46 || c->x86_model == 47))
  512. set_cpu_bug(c, X86_BUG_CLFLUSH_MONITOR);
  513. if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_MWAIT) &&
  514. ((c->x86_model == INTEL_FAM6_ATOM_GOLDMONT)))
  515. set_cpu_bug(c, X86_BUG_MONITOR);
  516. #ifdef CONFIG_X86_64
  517. if (c->x86 == 15)
  518. c->x86_cache_alignment = c->x86_clflush_size * 2;
  519. if (c->x86 == 6)
  520. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  521. #else
  522. /*
  523. * Names for the Pentium II/Celeron processors
  524. * detectable only by also checking the cache size.
  525. * Dixon is NOT a Celeron.
  526. */
  527. if (c->x86 == 6) {
  528. char *p = NULL;
  529. switch (c->x86_model) {
  530. case 5:
  531. if (l2 == 0)
  532. p = "Celeron (Covington)";
  533. else if (l2 == 256)
  534. p = "Mobile Pentium II (Dixon)";
  535. break;
  536. case 6:
  537. if (l2 == 128)
  538. p = "Celeron (Mendocino)";
  539. else if (c->x86_stepping == 0 || c->x86_stepping == 5)
  540. p = "Celeron-A";
  541. break;
  542. case 8:
  543. if (l2 == 128)
  544. p = "Celeron (Coppermine)";
  545. break;
  546. }
  547. if (p)
  548. strcpy(c->x86_model_id, p);
  549. }
  550. if (c->x86 == 15)
  551. set_cpu_cap(c, X86_FEATURE_P4);
  552. if (c->x86 == 6)
  553. set_cpu_cap(c, X86_FEATURE_P3);
  554. #endif
  555. /* Work around errata */
  556. srat_detect_node(c);
  557. if (cpu_has(c, X86_FEATURE_VMX))
  558. detect_vmx_virtcap(c);
  559. init_intel_energy_perf(c);
  560. }
  561. #ifdef CONFIG_X86_32
  562. static unsigned int intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  563. {
  564. /*
  565. * Intel PIII Tualatin. This comes in two flavours.
  566. * One has 256kb of cache, the other 512. We have no way
  567. * to determine which, so we use a boottime override
  568. * for the 512kb model, and assume 256 otherwise.
  569. */
  570. if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
  571. size = 256;
  572. /*
  573. * Intel Quark SoC X1000 contains a 4-way set associative
  574. * 16K cache with a 16 byte cache line and 256 lines per tag
  575. */
  576. if ((c->x86 == 5) && (c->x86_model == 9))
  577. size = 16;
  578. return size;
  579. }
  580. #endif
  581. #define TLB_INST_4K 0x01
  582. #define TLB_INST_4M 0x02
  583. #define TLB_INST_2M_4M 0x03
  584. #define TLB_INST_ALL 0x05
  585. #define TLB_INST_1G 0x06
  586. #define TLB_DATA_4K 0x11
  587. #define TLB_DATA_4M 0x12
  588. #define TLB_DATA_2M_4M 0x13
  589. #define TLB_DATA_4K_4M 0x14
  590. #define TLB_DATA_1G 0x16
  591. #define TLB_DATA0_4K 0x21
  592. #define TLB_DATA0_4M 0x22
  593. #define TLB_DATA0_2M_4M 0x23
  594. #define STLB_4K 0x41
  595. #define STLB_4K_2M 0x42
  596. static const struct _tlb_table intel_tlb_table[] = {
  597. { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative" },
  598. { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" },
  599. { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative" },
  600. { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative" },
  601. { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative" },
  602. { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative" },
  603. { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages */" },
  604. { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  605. { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  606. { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  607. { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
  608. { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associative" },
  609. { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" },
  610. { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" },
  611. { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way set associative" },
  612. { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" },
  613. { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" },
  614. { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" },
  615. { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" },
  616. { 0x63, TLB_DATA_1G, 4, " TLB_DATA 1 GByte pages, 4-way set associative" },
  617. { 0x76, TLB_INST_2M_4M, 8, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
  618. { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associative" },
  619. { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M pages, 4-way entries" },
  620. { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative" },
  621. { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associative" },
  622. { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" },
  623. { 0xb5, TLB_INST_4K, 64, " TLB_INST 4 KByte pages, 8-way set associative" },
  624. { 0xb6, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 8-way set associative" },
  625. { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" },
  626. { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way associative" },
  627. { 0xc1, STLB_4K_2M, 1024, " STLB 4 KByte and 2 MByte pages, 8-way associative" },
  628. { 0xc2, TLB_DATA_2M_4M, 16, " DTLB 2 MByte/4MByte pages, 4-way associative" },
  629. { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" },
  630. { 0x00, 0, 0 }
  631. };
  632. static void intel_tlb_lookup(const unsigned char desc)
  633. {
  634. unsigned char k;
  635. if (desc == 0)
  636. return;
  637. /* look up this descriptor in the table */
  638. for (k = 0; intel_tlb_table[k].descriptor != desc && \
  639. intel_tlb_table[k].descriptor != 0; k++)
  640. ;
  641. if (intel_tlb_table[k].tlb_type == 0)
  642. return;
  643. switch (intel_tlb_table[k].tlb_type) {
  644. case STLB_4K:
  645. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  646. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  647. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  648. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  649. break;
  650. case STLB_4K_2M:
  651. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  652. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  653. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  654. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  655. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  656. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  657. if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
  658. tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
  659. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  660. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  661. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  662. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  663. break;
  664. case TLB_INST_ALL:
  665. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  666. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  667. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  668. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  669. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  670. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  671. break;
  672. case TLB_INST_4K:
  673. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  674. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  675. break;
  676. case TLB_INST_4M:
  677. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  678. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  679. break;
  680. case TLB_INST_2M_4M:
  681. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  682. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  683. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  684. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  685. break;
  686. case TLB_DATA_4K:
  687. case TLB_DATA0_4K:
  688. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  689. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  690. break;
  691. case TLB_DATA_4M:
  692. case TLB_DATA0_4M:
  693. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  694. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  695. break;
  696. case TLB_DATA_2M_4M:
  697. case TLB_DATA0_2M_4M:
  698. if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
  699. tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
  700. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  701. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  702. break;
  703. case TLB_DATA_4K_4M:
  704. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  705. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  706. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  707. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  708. break;
  709. case TLB_DATA_1G:
  710. if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries)
  711. tlb_lld_1g[ENTRIES] = intel_tlb_table[k].entries;
  712. break;
  713. }
  714. }
  715. static void intel_detect_tlb(struct cpuinfo_x86 *c)
  716. {
  717. int i, j, n;
  718. unsigned int regs[4];
  719. unsigned char *desc = (unsigned char *)regs;
  720. if (c->cpuid_level < 2)
  721. return;
  722. /* Number of times to iterate */
  723. n = cpuid_eax(2) & 0xFF;
  724. for (i = 0 ; i < n ; i++) {
  725. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  726. /* If bit 31 is set, this is an unknown format */
  727. for (j = 0 ; j < 3 ; j++)
  728. if (regs[j] & (1 << 31))
  729. regs[j] = 0;
  730. /* Byte 0 is level count, not a descriptor */
  731. for (j = 1 ; j < 16 ; j++)
  732. intel_tlb_lookup(desc[j]);
  733. }
  734. }
  735. static const struct cpu_dev intel_cpu_dev = {
  736. .c_vendor = "Intel",
  737. .c_ident = { "GenuineIntel" },
  738. #ifdef CONFIG_X86_32
  739. .legacy_models = {
  740. { .family = 4, .model_names =
  741. {
  742. [0] = "486 DX-25/33",
  743. [1] = "486 DX-50",
  744. [2] = "486 SX",
  745. [3] = "486 DX/2",
  746. [4] = "486 SL",
  747. [5] = "486 SX/2",
  748. [7] = "486 DX/2-WB",
  749. [8] = "486 DX/4",
  750. [9] = "486 DX/4-WB"
  751. }
  752. },
  753. { .family = 5, .model_names =
  754. {
  755. [0] = "Pentium 60/66 A-step",
  756. [1] = "Pentium 60/66",
  757. [2] = "Pentium 75 - 200",
  758. [3] = "OverDrive PODP5V83",
  759. [4] = "Pentium MMX",
  760. [7] = "Mobile Pentium 75 - 200",
  761. [8] = "Mobile Pentium MMX",
  762. [9] = "Quark SoC X1000",
  763. }
  764. },
  765. { .family = 6, .model_names =
  766. {
  767. [0] = "Pentium Pro A-step",
  768. [1] = "Pentium Pro",
  769. [3] = "Pentium II (Klamath)",
  770. [4] = "Pentium II (Deschutes)",
  771. [5] = "Pentium II (Deschutes)",
  772. [6] = "Mobile Pentium II",
  773. [7] = "Pentium III (Katmai)",
  774. [8] = "Pentium III (Coppermine)",
  775. [10] = "Pentium III (Cascades)",
  776. [11] = "Pentium III (Tualatin)",
  777. }
  778. },
  779. { .family = 15, .model_names =
  780. {
  781. [0] = "Pentium 4 (Unknown)",
  782. [1] = "Pentium 4 (Willamette)",
  783. [2] = "Pentium 4 (Northwood)",
  784. [4] = "Pentium 4 (Foster)",
  785. [5] = "Pentium 4 (Foster)",
  786. }
  787. },
  788. },
  789. .legacy_cache_size = intel_size_cache,
  790. #endif
  791. .c_detect_tlb = intel_detect_tlb,
  792. .c_early_init = early_init_intel,
  793. .c_init = init_intel,
  794. .c_bsp_resume = intel_bsp_resume,
  795. .c_x86_vendor = X86_VENDOR_INTEL,
  796. };
  797. cpu_dev_register(intel_cpu_dev);