common_64.c 17 KB

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