common_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/sched.h>
  4. #include <linux/string.h>
  5. #include <linux/bootmem.h>
  6. #include <linux/bitops.h>
  7. #include <linux/module.h>
  8. #include <linux/kgdb.h>
  9. #include <linux/topology.h>
  10. #include <linux/delay.h>
  11. #include <linux/smp.h>
  12. #include <linux/percpu.h>
  13. #include <asm/i387.h>
  14. #include <asm/msr.h>
  15. #include <asm/io.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/mtrr.h>
  18. #include <asm/mce.h>
  19. #include <asm/pat.h>
  20. #include <asm/numa.h>
  21. #ifdef CONFIG_X86_LOCAL_APIC
  22. #include <asm/mpspec.h>
  23. #include <asm/apic.h>
  24. #include <mach_apic.h>
  25. #endif
  26. #include <asm/pda.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/processor.h>
  29. #include <asm/desc.h>
  30. #include <asm/atomic.h>
  31. #include <asm/proto.h>
  32. #include <asm/sections.h>
  33. #include <asm/setup.h>
  34. #include <asm/genapic.h>
  35. #include "cpu.h"
  36. /* We need valid kernel segments for data and code in long mode too
  37. * IRET will check the segment types kkeil 2000/10/28
  38. * Also sysret mandates a special GDT layout
  39. */
  40. /* The TLS descriptors are currently at a different place compared to i386.
  41. Hopefully nobody expects them at a fixed place (Wine?) */
  42. DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
  43. [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
  44. [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
  45. [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
  46. [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
  47. [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
  48. [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
  49. } };
  50. EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
  51. __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
  52. /* Current gdt points %fs at the "master" per-cpu area: after this,
  53. * it's on the real one. */
  54. void switch_to_new_gdt(void)
  55. {
  56. struct desc_ptr gdt_descr;
  57. gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
  58. gdt_descr.size = GDT_SIZE - 1;
  59. load_gdt(&gdt_descr);
  60. }
  61. struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
  62. static void __cpuinit default_init(struct cpuinfo_x86 *c)
  63. {
  64. display_cacheinfo(c);
  65. }
  66. static struct cpu_dev __cpuinitdata default_cpu = {
  67. .c_init = default_init,
  68. .c_vendor = "Unknown",
  69. };
  70. static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
  71. int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  72. {
  73. unsigned int *v;
  74. if (c->extended_cpuid_level < 0x80000004)
  75. return 0;
  76. v = (unsigned int *) c->x86_model_id;
  77. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  78. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  79. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  80. c->x86_model_id[48] = 0;
  81. return 1;
  82. }
  83. void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  84. {
  85. unsigned int n, dummy, ebx, ecx, edx;
  86. n = c->extended_cpuid_level;
  87. if (n >= 0x80000005) {
  88. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  89. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
  90. "D cache %dK (%d bytes/line)\n",
  91. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  92. c->x86_cache_size = (ecx>>24) + (edx>>24);
  93. /* On K8 L1 TLB is inclusive, so don't count it */
  94. c->x86_tlbsize = 0;
  95. }
  96. if (n >= 0x80000006) {
  97. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  98. ecx = cpuid_ecx(0x80000006);
  99. c->x86_cache_size = ecx >> 16;
  100. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  101. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  102. c->x86_cache_size, ecx & 0xFF);
  103. }
  104. }
  105. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  106. {
  107. #ifdef CONFIG_SMP
  108. u32 eax, ebx, ecx, edx;
  109. int index_msb, core_bits;
  110. cpuid(1, &eax, &ebx, &ecx, &edx);
  111. if (!cpu_has(c, X86_FEATURE_HT))
  112. return;
  113. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  114. goto out;
  115. smp_num_siblings = (ebx & 0xff0000) >> 16;
  116. if (smp_num_siblings == 1) {
  117. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  118. } else if (smp_num_siblings > 1) {
  119. if (smp_num_siblings > NR_CPUS) {
  120. printk(KERN_WARNING "CPU: Unsupported number of "
  121. "siblings %d", smp_num_siblings);
  122. smp_num_siblings = 1;
  123. return;
  124. }
  125. index_msb = get_count_order(smp_num_siblings);
  126. c->phys_proc_id = phys_pkg_id(index_msb);
  127. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  128. index_msb = get_count_order(smp_num_siblings);
  129. core_bits = get_count_order(c->x86_max_cores);
  130. c->cpu_core_id = phys_pkg_id(index_msb) &
  131. ((1 << core_bits) - 1);
  132. }
  133. out:
  134. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  135. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  136. c->phys_proc_id);
  137. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  138. c->cpu_core_id);
  139. }
  140. #endif
  141. }
  142. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  143. {
  144. char *v = c->x86_vendor_id;
  145. int i;
  146. static int printed;
  147. for (i = 0; i < X86_VENDOR_NUM; i++) {
  148. if (cpu_devs[i]) {
  149. if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
  150. (cpu_devs[i]->c_ident[1] &&
  151. !strcmp(v, cpu_devs[i]->c_ident[1]))) {
  152. c->x86_vendor = i;
  153. this_cpu = cpu_devs[i];
  154. return;
  155. }
  156. }
  157. }
  158. if (!printed) {
  159. printed++;
  160. printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
  161. printk(KERN_ERR "CPU: Your system may be unstable.\n");
  162. }
  163. c->x86_vendor = X86_VENDOR_UNKNOWN;
  164. }
  165. static void __init early_cpu_support_print(void)
  166. {
  167. int i,j;
  168. struct cpu_dev *cpu_devx;
  169. printk("KERNEL supported cpus:\n");
  170. for (i = 0; i < X86_VENDOR_NUM; i++) {
  171. cpu_devx = cpu_devs[i];
  172. if (!cpu_devx)
  173. continue;
  174. for (j = 0; j < 2; j++) {
  175. if (!cpu_devx->c_ident[j])
  176. continue;
  177. printk(" %s %s\n", cpu_devx->c_vendor,
  178. cpu_devx->c_ident[j]);
  179. }
  180. }
  181. }
  182. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
  183. void __init early_cpu_init(void)
  184. {
  185. struct cpu_vendor_dev *cvdev;
  186. for (cvdev = __x86cpuvendor_start ;
  187. cvdev < __x86cpuvendor_end ;
  188. cvdev++)
  189. cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
  190. early_cpu_support_print();
  191. early_identify_cpu(&boot_cpu_data);
  192. }
  193. /* Do some early cpuid on the boot CPU to get some parameter that are
  194. needed before check_bugs. Everything advanced is in identify_cpu
  195. below. */
  196. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  197. {
  198. u32 tfms, xlvl;
  199. c->loops_per_jiffy = loops_per_jiffy;
  200. c->x86_cache_size = -1;
  201. c->x86_vendor = X86_VENDOR_UNKNOWN;
  202. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  203. c->x86_vendor_id[0] = '\0'; /* Unset */
  204. c->x86_model_id[0] = '\0'; /* Unset */
  205. c->x86_clflush_size = 64;
  206. c->x86_cache_alignment = c->x86_clflush_size;
  207. c->x86_max_cores = 1;
  208. c->x86_coreid_bits = 0;
  209. c->extended_cpuid_level = 0;
  210. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  211. /* Get vendor name */
  212. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  213. (unsigned int *)&c->x86_vendor_id[0],
  214. (unsigned int *)&c->x86_vendor_id[8],
  215. (unsigned int *)&c->x86_vendor_id[4]);
  216. get_cpu_vendor(c);
  217. /* Initialize the standard set of capabilities */
  218. /* Note that the vendor-specific code below might override */
  219. /* Intel-defined flags: level 0x00000001 */
  220. if (c->cpuid_level >= 0x00000001) {
  221. __u32 misc;
  222. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  223. &c->x86_capability[0]);
  224. c->x86 = (tfms >> 8) & 0xf;
  225. c->x86_model = (tfms >> 4) & 0xf;
  226. c->x86_mask = tfms & 0xf;
  227. if (c->x86 == 0xf)
  228. c->x86 += (tfms >> 20) & 0xff;
  229. if (c->x86 >= 0x6)
  230. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  231. if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
  232. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  233. } else {
  234. /* Have CPUID level 0 only - unheard of */
  235. c->x86 = 4;
  236. }
  237. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
  238. #ifdef CONFIG_SMP
  239. c->phys_proc_id = c->initial_apicid;
  240. #endif
  241. /* AMD-defined flags: level 0x80000001 */
  242. xlvl = cpuid_eax(0x80000000);
  243. c->extended_cpuid_level = xlvl;
  244. if ((xlvl & 0xffff0000) == 0x80000000) {
  245. if (xlvl >= 0x80000001) {
  246. c->x86_capability[1] = cpuid_edx(0x80000001);
  247. c->x86_capability[6] = cpuid_ecx(0x80000001);
  248. }
  249. if (xlvl >= 0x80000004)
  250. get_model_name(c); /* Default name */
  251. }
  252. /* Transmeta-defined flags: level 0x80860001 */
  253. xlvl = cpuid_eax(0x80860000);
  254. if ((xlvl & 0xffff0000) == 0x80860000) {
  255. /* Don't set x86_cpuid_level here for now to not confuse. */
  256. if (xlvl >= 0x80860001)
  257. c->x86_capability[2] = cpuid_edx(0x80860001);
  258. }
  259. c->extended_cpuid_level = cpuid_eax(0x80000000);
  260. if (c->extended_cpuid_level >= 0x80000007)
  261. c->x86_power = cpuid_edx(0x80000007);
  262. if (c->extended_cpuid_level >= 0x80000008) {
  263. u32 eax = cpuid_eax(0x80000008);
  264. c->x86_virt_bits = (eax >> 8) & 0xff;
  265. c->x86_phys_bits = eax & 0xff;
  266. }
  267. /* Assume all 64-bit CPUs support 32-bit syscall */
  268. set_cpu_cap(c, X86_FEATURE_SYSCALL32);
  269. if (c->x86_vendor != X86_VENDOR_UNKNOWN &&
  270. cpu_devs[c->x86_vendor]->c_early_init)
  271. cpu_devs[c->x86_vendor]->c_early_init(c);
  272. validate_pat_support(c);
  273. /* early_param could clear that, but recall get it set again */
  274. if (disable_apic)
  275. clear_cpu_cap(c, X86_FEATURE_APIC);
  276. }
  277. /*
  278. * This does the hard work of actually picking apart the CPU stuff...
  279. */
  280. static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  281. {
  282. int i;
  283. early_identify_cpu(c);
  284. init_scattered_cpuid_features(c);
  285. c->apicid = phys_pkg_id(0);
  286. /*
  287. * Vendor-specific initialization. In this section we
  288. * canonicalize the feature flags, meaning if there are
  289. * features a certain CPU supports which CPUID doesn't
  290. * tell us, CPUID claiming incorrect flags, or other bugs,
  291. * we handle them here.
  292. *
  293. * At the end of this section, c->x86_capability better
  294. * indicate the features this CPU genuinely supports!
  295. */
  296. if (this_cpu->c_init)
  297. this_cpu->c_init(c);
  298. detect_ht(c);
  299. /*
  300. * On SMP, boot_cpu_data holds the common feature set between
  301. * all CPUs; so make sure that we indicate which features are
  302. * common between the CPUs. The first time this routine gets
  303. * executed, c == &boot_cpu_data.
  304. */
  305. if (c != &boot_cpu_data) {
  306. /* AND the already accumulated flags with these */
  307. for (i = 0; i < NCAPINTS; i++)
  308. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  309. }
  310. /* Clear all flags overriden by options */
  311. for (i = 0; i < NCAPINTS; i++)
  312. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  313. #ifdef CONFIG_X86_MCE
  314. mcheck_init(c);
  315. #endif
  316. select_idle_routine(c);
  317. #ifdef CONFIG_NUMA
  318. numa_add_cpu(smp_processor_id());
  319. #endif
  320. }
  321. void __cpuinit identify_boot_cpu(void)
  322. {
  323. identify_cpu(&boot_cpu_data);
  324. }
  325. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  326. {
  327. BUG_ON(c == &boot_cpu_data);
  328. identify_cpu(c);
  329. mtrr_ap_init();
  330. }
  331. static __init int setup_noclflush(char *arg)
  332. {
  333. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  334. return 1;
  335. }
  336. __setup("noclflush", setup_noclflush);
  337. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  338. {
  339. if (c->x86_model_id[0])
  340. printk(KERN_CONT "%s", c->x86_model_id);
  341. if (c->x86_mask || c->cpuid_level >= 0)
  342. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  343. else
  344. printk(KERN_CONT "\n");
  345. }
  346. static __init int setup_disablecpuid(char *arg)
  347. {
  348. int bit;
  349. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  350. setup_clear_cpu_cap(bit);
  351. else
  352. return 0;
  353. return 1;
  354. }
  355. __setup("clearcpuid=", setup_disablecpuid);
  356. cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
  357. struct x8664_pda **_cpu_pda __read_mostly;
  358. EXPORT_SYMBOL(_cpu_pda);
  359. struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
  360. char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
  361. unsigned long __supported_pte_mask __read_mostly = ~0UL;
  362. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  363. static int do_not_nx __cpuinitdata;
  364. /* noexec=on|off
  365. Control non executable mappings for 64bit processes.
  366. on Enable(default)
  367. off Disable
  368. */
  369. static int __init nonx_setup(char *str)
  370. {
  371. if (!str)
  372. return -EINVAL;
  373. if (!strncmp(str, "on", 2)) {
  374. __supported_pte_mask |= _PAGE_NX;
  375. do_not_nx = 0;
  376. } else if (!strncmp(str, "off", 3)) {
  377. do_not_nx = 1;
  378. __supported_pte_mask &= ~_PAGE_NX;
  379. }
  380. return 0;
  381. }
  382. early_param("noexec", nonx_setup);
  383. int force_personality32;
  384. /* noexec32=on|off
  385. Control non executable heap for 32bit processes.
  386. To control the stack too use noexec=off
  387. on PROT_READ does not imply PROT_EXEC for 32bit processes (default)
  388. off PROT_READ implies PROT_EXEC
  389. */
  390. static int __init nonx32_setup(char *str)
  391. {
  392. if (!strcmp(str, "on"))
  393. force_personality32 &= ~READ_IMPLIES_EXEC;
  394. else if (!strcmp(str, "off"))
  395. force_personality32 |= READ_IMPLIES_EXEC;
  396. return 1;
  397. }
  398. __setup("noexec32=", nonx32_setup);
  399. void pda_init(int cpu)
  400. {
  401. struct x8664_pda *pda = cpu_pda(cpu);
  402. /* Setup up data that may be needed in __get_free_pages early */
  403. loadsegment(fs, 0);
  404. loadsegment(gs, 0);
  405. /* Memory clobbers used to order PDA accessed */
  406. mb();
  407. wrmsrl(MSR_GS_BASE, pda);
  408. mb();
  409. pda->cpunumber = cpu;
  410. pda->irqcount = -1;
  411. pda->kernelstack = (unsigned long)stack_thread_info() -
  412. PDA_STACKOFFSET + THREAD_SIZE;
  413. pda->active_mm = &init_mm;
  414. pda->mmu_state = 0;
  415. if (cpu == 0) {
  416. /* others are initialized in smpboot.c */
  417. pda->pcurrent = &init_task;
  418. pda->irqstackptr = boot_cpu_stack;
  419. } else {
  420. pda->irqstackptr = (char *)
  421. __get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER);
  422. if (!pda->irqstackptr)
  423. panic("cannot allocate irqstack for cpu %d", cpu);
  424. if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE)
  425. pda->nodenumber = cpu_to_node(cpu);
  426. }
  427. pda->irqstackptr += IRQSTACKSIZE-64;
  428. }
  429. char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ +
  430. DEBUG_STKSZ]
  431. __attribute__((section(".bss.page_aligned")));
  432. extern asmlinkage void ignore_sysret(void);
  433. /* May not be marked __init: used by software suspend */
  434. void syscall_init(void)
  435. {
  436. /*
  437. * LSTAR and STAR live in a bit strange symbiosis.
  438. * They both write to the same internal register. STAR allows to
  439. * set CS/DS but only a 32bit target. LSTAR sets the 64bit rip.
  440. */
  441. wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32);
  442. wrmsrl(MSR_LSTAR, system_call);
  443. wrmsrl(MSR_CSTAR, ignore_sysret);
  444. #ifdef CONFIG_IA32_EMULATION
  445. syscall32_cpu_init();
  446. #endif
  447. /* Flags to clear on syscall */
  448. wrmsrl(MSR_SYSCALL_MASK,
  449. X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
  450. }
  451. void __cpuinit check_efer(void)
  452. {
  453. unsigned long efer;
  454. rdmsrl(MSR_EFER, efer);
  455. if (!(efer & EFER_NX) || do_not_nx)
  456. __supported_pte_mask &= ~_PAGE_NX;
  457. }
  458. unsigned long kernel_eflags;
  459. /*
  460. * Copies of the original ist values from the tss are only accessed during
  461. * debugging, no special alignment required.
  462. */
  463. DEFINE_PER_CPU(struct orig_ist, orig_ist);
  464. /*
  465. * cpu_init() initializes state that is per-CPU. Some data is already
  466. * initialized (naturally) in the bootstrap process, such as the GDT
  467. * and IDT. We reload them nevertheless, this function acts as a
  468. * 'CPU state barrier', nothing should get across.
  469. * A lot of state is already set up in PDA init.
  470. */
  471. void __cpuinit cpu_init(void)
  472. {
  473. int cpu = stack_smp_processor_id();
  474. struct tss_struct *t = &per_cpu(init_tss, cpu);
  475. struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
  476. unsigned long v;
  477. char *estacks = NULL;
  478. struct task_struct *me;
  479. int i;
  480. /* CPU 0 is initialised in head64.c */
  481. if (cpu != 0)
  482. pda_init(cpu);
  483. else
  484. estacks = boot_exception_stacks;
  485. me = current;
  486. if (cpu_test_and_set(cpu, cpu_initialized))
  487. panic("CPU#%d already initialized!\n", cpu);
  488. printk(KERN_INFO "Initializing CPU#%d\n", cpu);
  489. clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  490. /*
  491. * Initialize the per-CPU GDT with the boot GDT,
  492. * and set up the GDT descriptor:
  493. */
  494. switch_to_new_gdt();
  495. load_idt((const struct desc_ptr *)&idt_descr);
  496. memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
  497. syscall_init();
  498. wrmsrl(MSR_FS_BASE, 0);
  499. wrmsrl(MSR_KERNEL_GS_BASE, 0);
  500. barrier();
  501. check_efer();
  502. /*
  503. * set up and load the per-CPU TSS
  504. */
  505. for (v = 0; v < N_EXCEPTION_STACKS; v++) {
  506. static const unsigned int order[N_EXCEPTION_STACKS] = {
  507. [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
  508. [DEBUG_STACK - 1] = DEBUG_STACK_ORDER
  509. };
  510. if (cpu) {
  511. estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
  512. if (!estacks)
  513. panic("Cannot allocate exception stack %ld %d\n",
  514. v, cpu);
  515. }
  516. estacks += PAGE_SIZE << order[v];
  517. orig_ist->ist[v] = t->x86_tss.ist[v] = (unsigned long)estacks;
  518. }
  519. t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
  520. /*
  521. * <= is required because the CPU will access up to
  522. * 8 bits beyond the end of the IO permission bitmap.
  523. */
  524. for (i = 0; i <= IO_BITMAP_LONGS; i++)
  525. t->io_bitmap[i] = ~0UL;
  526. atomic_inc(&init_mm.mm_count);
  527. me->active_mm = &init_mm;
  528. if (me->mm)
  529. BUG();
  530. enter_lazy_tlb(&init_mm, me);
  531. load_sp0(t, &current->thread);
  532. set_tss_desc(cpu, t);
  533. load_TR_desc();
  534. load_LDT(&init_mm.context);
  535. #ifdef CONFIG_KGDB
  536. /*
  537. * If the kgdb is connected no debug regs should be altered. This
  538. * is only applicable when KGDB and a KGDB I/O module are built
  539. * into the kernel and you are using early debugging with
  540. * kgdbwait. KGDB will control the kernel HW breakpoint registers.
  541. */
  542. if (kgdb_connected && arch_kgdb_ops.correct_hw_break)
  543. arch_kgdb_ops.correct_hw_break();
  544. else {
  545. #endif
  546. /*
  547. * Clear all 6 debug registers:
  548. */
  549. set_debugreg(0UL, 0);
  550. set_debugreg(0UL, 1);
  551. set_debugreg(0UL, 2);
  552. set_debugreg(0UL, 3);
  553. set_debugreg(0UL, 6);
  554. set_debugreg(0UL, 7);
  555. #ifdef CONFIG_KGDB
  556. /* If the kgdb is connected no debug regs should be altered. */
  557. }
  558. #endif
  559. fpu_init();
  560. raw_local_save_flags(kernel_eflags);
  561. if (is_uv_system())
  562. uv_cpu_init();
  563. }