common_64.c 17 KB

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