head_64.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/arch/x86/kernel/head_64.S -- start in 32bit and switch to 64bit
  4. *
  5. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  6. * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
  7. * Copyright (C) 2000 Karsten Keil <kkeil@suse.de>
  8. * Copyright (C) 2001,2002 Andi Kleen <ak@suse.de>
  9. * Copyright (C) 2005 Eric Biederman <ebiederm@xmission.com>
  10. */
  11. #include <linux/export.h>
  12. #include <linux/linkage.h>
  13. #include <linux/threads.h>
  14. #include <linux/init.h>
  15. #include <linux/pgtable.h>
  16. #include <asm/segment.h>
  17. #include <asm/page.h>
  18. #include <asm/msr.h>
  19. #include <asm/cache.h>
  20. #include <asm/processor-flags.h>
  21. #include <asm/percpu.h>
  22. #include <asm/nops.h>
  23. #include "../entry/calling.h"
  24. #include <asm/nospec-branch.h>
  25. #include <asm/apicdef.h>
  26. #include <asm/fixmap.h>
  27. #include <asm/smp.h>
  28. #include <asm/thread_info.h>
  29. /*
  30. * We are not able to switch in one step to the final KERNEL ADDRESS SPACE
  31. * because we need identity-mapped pages.
  32. */
  33. __HEAD
  34. .code64
  35. SYM_CODE_START_NOALIGN(startup_64)
  36. UNWIND_HINT_END_OF_STACK
  37. /*
  38. * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
  39. * and someone has loaded an identity mapped page table
  40. * for us. These identity mapped page tables map all of the
  41. * kernel pages and possibly all of memory.
  42. *
  43. * %RSI holds the physical address of the boot_params structure
  44. * provided by the bootloader. Preserve it in %R15 so C function calls
  45. * will not clobber it.
  46. *
  47. * We come here either directly from a 64bit bootloader, or from
  48. * arch/x86/boot/compressed/head_64.S.
  49. *
  50. * We only come here initially at boot nothing else comes here.
  51. *
  52. * Since we may be loaded at an address different from what we were
  53. * compiled to run at we first fixup the physical addresses in our page
  54. * tables and then reload them.
  55. */
  56. mov %rsi, %r15
  57. /* Set up the stack for verify_cpu() */
  58. leaq __top_init_kernel_stack(%rip), %rsp
  59. /* Setup GSBASE to allow stack canary access for C code */
  60. movl $MSR_GS_BASE, %ecx
  61. leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx
  62. movl %edx, %eax
  63. shrq $32, %rdx
  64. wrmsr
  65. call startup_64_setup_gdt_idt
  66. /* Now switch to __KERNEL_CS so IRET works reliably */
  67. pushq $__KERNEL_CS
  68. leaq .Lon_kernel_cs(%rip), %rax
  69. pushq %rax
  70. lretq
  71. .Lon_kernel_cs:
  72. UNWIND_HINT_END_OF_STACK
  73. #ifdef CONFIG_AMD_MEM_ENCRYPT
  74. /*
  75. * Activate SEV/SME memory encryption if supported/enabled. This needs to
  76. * be done now, since this also includes setup of the SEV-SNP CPUID table,
  77. * which needs to be done before any CPUID instructions are executed in
  78. * subsequent code. Pass the boot_params pointer as the first argument.
  79. */
  80. movq %r15, %rdi
  81. call sme_enable
  82. #endif
  83. /* Sanitize CPU configuration */
  84. call verify_cpu
  85. /*
  86. * Perform pagetable fixups. Additionally, if SME is active, encrypt
  87. * the kernel and retrieve the modifier (SME encryption mask if SME
  88. * is active) to be added to the initial pgdir entry that will be
  89. * programmed into CR3.
  90. */
  91. leaq _text(%rip), %rdi
  92. movq %r15, %rsi
  93. call __startup_64
  94. /* Form the CR3 value being sure to include the CR3 modifier */
  95. leaq early_top_pgt(%rip), %rcx
  96. addq %rcx, %rax
  97. #ifdef CONFIG_AMD_MEM_ENCRYPT
  98. mov %rax, %rdi
  99. /*
  100. * For SEV guests: Verify that the C-bit is correct. A malicious
  101. * hypervisor could lie about the C-bit position to perform a ROP
  102. * attack on the guest by writing to the unencrypted stack and wait for
  103. * the next RET instruction.
  104. */
  105. call sev_verify_cbit
  106. #endif
  107. /*
  108. * Switch to early_top_pgt which still has the identity mappings
  109. * present.
  110. */
  111. movq %rax, %cr3
  112. /* Branch to the common startup code at its kernel virtual address */
  113. ANNOTATE_RETPOLINE_SAFE
  114. jmp *0f(%rip)
  115. SYM_CODE_END(startup_64)
  116. __INITRODATA
  117. 0: .quad common_startup_64
  118. .text
  119. SYM_CODE_START(secondary_startup_64)
  120. UNWIND_HINT_END_OF_STACK
  121. ANNOTATE_NOENDBR
  122. /*
  123. * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
  124. * and someone has loaded a mapped page table.
  125. *
  126. * We come here either from startup_64 (using physical addresses)
  127. * or from trampoline.S (using virtual addresses).
  128. *
  129. * Using virtual addresses from trampoline.S removes the need
  130. * to have any identity mapped pages in the kernel page table
  131. * after the boot processor executes this code.
  132. */
  133. /* Sanitize CPU configuration */
  134. call verify_cpu
  135. /*
  136. * The secondary_startup_64_no_verify entry point is only used by
  137. * SEV-ES guests. In those guests the call to verify_cpu() would cause
  138. * #VC exceptions which can not be handled at this stage of secondary
  139. * CPU bringup.
  140. *
  141. * All non SEV-ES systems, especially Intel systems, need to execute
  142. * verify_cpu() above to make sure NX is enabled.
  143. */
  144. SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
  145. UNWIND_HINT_END_OF_STACK
  146. ANNOTATE_NOENDBR
  147. /* Clear %R15 which holds the boot_params pointer on the boot CPU */
  148. xorl %r15d, %r15d
  149. /* Derive the runtime physical address of init_top_pgt[] */
  150. movq phys_base(%rip), %rax
  151. addq $(init_top_pgt - __START_KERNEL_map), %rax
  152. /*
  153. * Retrieve the modifier (SME encryption mask if SME is active) to be
  154. * added to the initial pgdir entry that will be programmed into CR3.
  155. */
  156. #ifdef CONFIG_AMD_MEM_ENCRYPT
  157. addq sme_me_mask(%rip), %rax
  158. #endif
  159. /*
  160. * Switch to the init_top_pgt here, away from the trampoline_pgd and
  161. * unmap the identity mapped ranges.
  162. */
  163. movq %rax, %cr3
  164. SYM_INNER_LABEL(common_startup_64, SYM_L_LOCAL)
  165. UNWIND_HINT_END_OF_STACK
  166. ANNOTATE_NOENDBR
  167. /*
  168. * Create a mask of CR4 bits to preserve. Omit PGE in order to flush
  169. * global 1:1 translations from the TLBs.
  170. *
  171. * From the SDM:
  172. * "If CR4.PGE is changing from 0 to 1, there were no global TLB
  173. * entries before the execution; if CR4.PGE is changing from 1 to 0,
  174. * there will be no global TLB entries after the execution."
  175. */
  176. movl $(X86_CR4_PAE | X86_CR4_LA57), %edx
  177. #ifdef CONFIG_X86_MCE
  178. /*
  179. * Preserve CR4.MCE if the kernel will enable #MC support.
  180. * Clearing MCE may fault in some environments (that also force #MC
  181. * support). Any machine check that occurs before #MC support is fully
  182. * configured will crash the system regardless of the CR4.MCE value set
  183. * here.
  184. */
  185. orl $X86_CR4_MCE, %edx
  186. #endif
  187. movq %cr4, %rcx
  188. andl %edx, %ecx
  189. /* Even if ignored in long mode, set PSE uniformly on all logical CPUs. */
  190. btsl $X86_CR4_PSE_BIT, %ecx
  191. movq %rcx, %cr4
  192. /*
  193. * Set CR4.PGE to re-enable global translations.
  194. */
  195. btsl $X86_CR4_PGE_BIT, %ecx
  196. movq %rcx, %cr4
  197. #ifdef CONFIG_SMP
  198. /*
  199. * For parallel boot, the APIC ID is read from the APIC, and then
  200. * used to look up the CPU number. For booting a single CPU, the
  201. * CPU number is encoded in smpboot_control.
  202. *
  203. * Bit 31 STARTUP_READ_APICID (Read APICID from APIC)
  204. * Bit 0-23 CPU# if STARTUP_xx flags are not set
  205. */
  206. movl smpboot_control(%rip), %ecx
  207. testl $STARTUP_READ_APICID, %ecx
  208. jnz .Lread_apicid
  209. /*
  210. * No control bit set, single CPU bringup. CPU number is provided
  211. * in bit 0-23. This is also the boot CPU case (CPU number 0).
  212. */
  213. andl $(~STARTUP_PARALLEL_MASK), %ecx
  214. jmp .Lsetup_cpu
  215. .Lread_apicid:
  216. /* Check whether X2APIC mode is already enabled */
  217. mov $MSR_IA32_APICBASE, %ecx
  218. rdmsr
  219. testl $X2APIC_ENABLE, %eax
  220. jnz .Lread_apicid_msr
  221. #ifdef CONFIG_X86_X2APIC
  222. /*
  223. * If system is in X2APIC mode then MMIO base might not be
  224. * mapped causing the MMIO read below to fault. Faults can't
  225. * be handled at that point.
  226. */
  227. cmpl $0, x2apic_mode(%rip)
  228. jz .Lread_apicid_mmio
  229. /* Force the AP into X2APIC mode. */
  230. orl $X2APIC_ENABLE, %eax
  231. wrmsr
  232. jmp .Lread_apicid_msr
  233. #endif
  234. .Lread_apicid_mmio:
  235. /* Read the APIC ID from the fix-mapped MMIO space. */
  236. movq apic_mmio_base(%rip), %rcx
  237. addq $APIC_ID, %rcx
  238. movl (%rcx), %eax
  239. shr $24, %eax
  240. jmp .Llookup_AP
  241. .Lread_apicid_msr:
  242. mov $APIC_X2APIC_ID_MSR, %ecx
  243. rdmsr
  244. .Llookup_AP:
  245. /* EAX contains the APIC ID of the current CPU */
  246. xorl %ecx, %ecx
  247. leaq cpuid_to_apicid(%rip), %rbx
  248. .Lfind_cpunr:
  249. cmpl (%rbx,%rcx,4), %eax
  250. jz .Lsetup_cpu
  251. inc %ecx
  252. #ifdef CONFIG_FORCE_NR_CPUS
  253. cmpl $NR_CPUS, %ecx
  254. #else
  255. cmpl nr_cpu_ids(%rip), %ecx
  256. #endif
  257. jb .Lfind_cpunr
  258. /* APIC ID not found in the table. Drop the trampoline lock and bail. */
  259. movq trampoline_lock(%rip), %rax
  260. movl $0, (%rax)
  261. 1: cli
  262. hlt
  263. jmp 1b
  264. .Lsetup_cpu:
  265. /* Get the per cpu offset for the given CPU# which is in ECX */
  266. movq __per_cpu_offset(,%rcx,8), %rdx
  267. #else
  268. xorl %edx, %edx /* zero-extended to clear all of RDX */
  269. #endif /* CONFIG_SMP */
  270. /*
  271. * Setup a boot time stack - Any secondary CPU will have lost its stack
  272. * by now because the cr3-switch above unmaps the real-mode stack.
  273. *
  274. * RDX contains the per-cpu offset
  275. */
  276. movq pcpu_hot + X86_current_task(%rdx), %rax
  277. movq TASK_threadsp(%rax), %rsp
  278. /*
  279. * Now that this CPU is running on its own stack, drop the realmode
  280. * protection. For the boot CPU the pointer is NULL!
  281. */
  282. movq trampoline_lock(%rip), %rax
  283. testq %rax, %rax
  284. jz .Lsetup_gdt
  285. movl $0, (%rax)
  286. .Lsetup_gdt:
  287. /*
  288. * We must switch to a new descriptor in kernel space for the GDT
  289. * because soon the kernel won't have access anymore to the userspace
  290. * addresses where we're currently running on. We have to do that here
  291. * because in 32bit we couldn't load a 64bit linear address.
  292. */
  293. subq $16, %rsp
  294. movw $(GDT_SIZE-1), (%rsp)
  295. leaq gdt_page(%rdx), %rax
  296. movq %rax, 2(%rsp)
  297. lgdt (%rsp)
  298. addq $16, %rsp
  299. /* set up data segments */
  300. xorl %eax,%eax
  301. movl %eax,%ds
  302. movl %eax,%ss
  303. movl %eax,%es
  304. /*
  305. * We don't really need to load %fs or %gs, but load them anyway
  306. * to kill any stale realmode selectors. This allows execution
  307. * under VT hardware.
  308. */
  309. movl %eax,%fs
  310. movl %eax,%gs
  311. /* Set up %gs.
  312. *
  313. * The base of %gs always points to fixed_percpu_data. If the
  314. * stack protector canary is enabled, it is located at %gs:40.
  315. * Note that, on SMP, the boot cpu uses init data section until
  316. * the per cpu areas are set up.
  317. */
  318. movl $MSR_GS_BASE,%ecx
  319. #ifndef CONFIG_SMP
  320. leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx
  321. #endif
  322. movl %edx, %eax
  323. shrq $32, %rdx
  324. wrmsr
  325. /* Setup and Load IDT */
  326. call early_setup_idt
  327. /* Check if nx is implemented */
  328. movl $0x80000001, %eax
  329. cpuid
  330. movl %edx,%edi
  331. /* Setup EFER (Extended Feature Enable Register) */
  332. movl $MSR_EFER, %ecx
  333. rdmsr
  334. /*
  335. * Preserve current value of EFER for comparison and to skip
  336. * EFER writes if no change was made (for TDX guest)
  337. */
  338. movl %eax, %edx
  339. btsl $_EFER_SCE, %eax /* Enable System Call */
  340. btl $20,%edi /* No Execute supported? */
  341. jnc 1f
  342. btsl $_EFER_NX, %eax
  343. btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
  344. /* Avoid writing EFER if no change was made (for TDX guest) */
  345. 1: cmpl %edx, %eax
  346. je 1f
  347. xor %edx, %edx
  348. wrmsr /* Make changes effective */
  349. 1:
  350. /* Setup cr0 */
  351. movl $CR0_STATE, %eax
  352. /* Make changes effective */
  353. movq %rax, %cr0
  354. /* zero EFLAGS after setting rsp */
  355. pushq $0
  356. popfq
  357. /* Pass the boot_params pointer as first argument */
  358. movq %r15, %rdi
  359. .Ljump_to_C_code:
  360. xorl %ebp, %ebp # clear frame pointer
  361. ANNOTATE_RETPOLINE_SAFE
  362. callq *initial_code(%rip)
  363. ud2
  364. SYM_CODE_END(secondary_startup_64)
  365. #include "verify_cpu.S"
  366. #include "sev_verify_cbit.S"
  367. #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_AMD_MEM_ENCRYPT)
  368. /*
  369. * Entry point for soft restart of a CPU. Invoked from xxx_play_dead() for
  370. * restarting the boot CPU or for restarting SEV guest CPUs after CPU hot
  371. * unplug. Everything is set up already except the stack.
  372. */
  373. SYM_CODE_START(soft_restart_cpu)
  374. ANNOTATE_NOENDBR
  375. UNWIND_HINT_END_OF_STACK
  376. /* Find the idle task stack */
  377. movq PER_CPU_VAR(pcpu_hot + X86_current_task), %rcx
  378. movq TASK_threadsp(%rcx), %rsp
  379. jmp .Ljump_to_C_code
  380. SYM_CODE_END(soft_restart_cpu)
  381. #endif
  382. #ifdef CONFIG_AMD_MEM_ENCRYPT
  383. /*
  384. * VC Exception handler used during early boot when running on kernel
  385. * addresses, but before the switch to the idt_table can be made.
  386. * The early_idt_handler_array can't be used here because it calls into a lot
  387. * of __init code and this handler is also used during CPU offlining/onlining.
  388. * Therefore this handler ends up in the .text section so that it stays around
  389. * when .init.text is freed.
  390. */
  391. SYM_CODE_START_NOALIGN(vc_boot_ghcb)
  392. UNWIND_HINT_IRET_REGS offset=8
  393. ENDBR
  394. /* Build pt_regs */
  395. PUSH_AND_CLEAR_REGS
  396. /* Call C handler */
  397. movq %rsp, %rdi
  398. movq ORIG_RAX(%rsp), %rsi
  399. movq initial_vc_handler(%rip), %rax
  400. ANNOTATE_RETPOLINE_SAFE
  401. call *%rax
  402. /* Unwind pt_regs */
  403. POP_REGS
  404. /* Remove Error Code */
  405. addq $8, %rsp
  406. iretq
  407. SYM_CODE_END(vc_boot_ghcb)
  408. #endif
  409. /* Both SMP bootup and ACPI suspend change these variables */
  410. __REFDATA
  411. .balign 8
  412. SYM_DATA(initial_code, .quad x86_64_start_kernel)
  413. #ifdef CONFIG_AMD_MEM_ENCRYPT
  414. SYM_DATA(initial_vc_handler, .quad handle_vc_boot_ghcb)
  415. #endif
  416. SYM_DATA(trampoline_lock, .quad 0);
  417. __FINITDATA
  418. __INIT
  419. SYM_CODE_START(early_idt_handler_array)
  420. i = 0
  421. .rept NUM_EXCEPTION_VECTORS
  422. .if ((EXCEPTION_ERRCODE_MASK >> i) & 1) == 0
  423. UNWIND_HINT_IRET_REGS
  424. ENDBR
  425. pushq $0 # Dummy error code, to make stack frame uniform
  426. .else
  427. UNWIND_HINT_IRET_REGS offset=8
  428. ENDBR
  429. .endif
  430. pushq $i # 72(%rsp) Vector number
  431. jmp early_idt_handler_common
  432. UNWIND_HINT_IRET_REGS
  433. i = i + 1
  434. .fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
  435. .endr
  436. SYM_CODE_END(early_idt_handler_array)
  437. ANNOTATE_NOENDBR // early_idt_handler_array[NUM_EXCEPTION_VECTORS]
  438. SYM_CODE_START_LOCAL(early_idt_handler_common)
  439. UNWIND_HINT_IRET_REGS offset=16
  440. /*
  441. * The stack is the hardware frame, an error code or zero, and the
  442. * vector number.
  443. */
  444. cld
  445. incl early_recursion_flag(%rip)
  446. /* The vector number is currently in the pt_regs->di slot. */
  447. pushq %rsi /* pt_regs->si */
  448. movq 8(%rsp), %rsi /* RSI = vector number */
  449. movq %rdi, 8(%rsp) /* pt_regs->di = RDI */
  450. pushq %rdx /* pt_regs->dx */
  451. pushq %rcx /* pt_regs->cx */
  452. pushq %rax /* pt_regs->ax */
  453. pushq %r8 /* pt_regs->r8 */
  454. pushq %r9 /* pt_regs->r9 */
  455. pushq %r10 /* pt_regs->r10 */
  456. pushq %r11 /* pt_regs->r11 */
  457. pushq %rbx /* pt_regs->bx */
  458. pushq %rbp /* pt_regs->bp */
  459. pushq %r12 /* pt_regs->r12 */
  460. pushq %r13 /* pt_regs->r13 */
  461. pushq %r14 /* pt_regs->r14 */
  462. pushq %r15 /* pt_regs->r15 */
  463. UNWIND_HINT_REGS
  464. movq %rsp,%rdi /* RDI = pt_regs; RSI is already trapnr */
  465. call do_early_exception
  466. decl early_recursion_flag(%rip)
  467. jmp restore_regs_and_return_to_kernel
  468. SYM_CODE_END(early_idt_handler_common)
  469. #ifdef CONFIG_AMD_MEM_ENCRYPT
  470. /*
  471. * VC Exception handler used during very early boot. The
  472. * early_idt_handler_array can't be used because it returns via the
  473. * paravirtualized INTERRUPT_RETURN and pv-ops don't work that early.
  474. *
  475. * XXX it does, fix this.
  476. *
  477. * This handler will end up in the .init.text section and not be
  478. * available to boot secondary CPUs.
  479. */
  480. SYM_CODE_START_NOALIGN(vc_no_ghcb)
  481. UNWIND_HINT_IRET_REGS offset=8
  482. ENDBR
  483. /* Build pt_regs */
  484. PUSH_AND_CLEAR_REGS
  485. /* Call C handler */
  486. movq %rsp, %rdi
  487. movq ORIG_RAX(%rsp), %rsi
  488. call do_vc_no_ghcb
  489. /* Unwind pt_regs */
  490. POP_REGS
  491. /* Remove Error Code */
  492. addq $8, %rsp
  493. /* Pure iret required here - don't use INTERRUPT_RETURN */
  494. iretq
  495. SYM_CODE_END(vc_no_ghcb)
  496. #endif
  497. #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
  498. /*
  499. * Each PGD needs to be 8k long and 8k aligned. We do not
  500. * ever go out to userspace with these, so we do not
  501. * strictly *need* the second page, but this allows us to
  502. * have a single set_pgd() implementation that does not
  503. * need to worry about whether it has 4k or 8k to work
  504. * with.
  505. *
  506. * This ensures PGDs are 8k long:
  507. */
  508. #define PTI_USER_PGD_FILL 512
  509. /* This ensures they are 8k-aligned: */
  510. #define SYM_DATA_START_PTI_ALIGNED(name) \
  511. SYM_START(name, SYM_L_GLOBAL, .balign 2 * PAGE_SIZE)
  512. #else
  513. #define SYM_DATA_START_PTI_ALIGNED(name) \
  514. SYM_DATA_START_PAGE_ALIGNED(name)
  515. #define PTI_USER_PGD_FILL 0
  516. #endif
  517. __INITDATA
  518. .balign 4
  519. SYM_DATA_START_PTI_ALIGNED(early_top_pgt)
  520. .fill 511,8,0
  521. .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
  522. .fill PTI_USER_PGD_FILL,8,0
  523. SYM_DATA_END(early_top_pgt)
  524. SYM_DATA_START_PAGE_ALIGNED(early_dynamic_pgts)
  525. .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
  526. SYM_DATA_END(early_dynamic_pgts)
  527. SYM_DATA(early_recursion_flag, .long 0)
  528. .data
  529. #if defined(CONFIG_XEN_PV) || defined(CONFIG_PVH)
  530. SYM_DATA_START_PTI_ALIGNED(init_top_pgt)
  531. .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC
  532. .org init_top_pgt + L4_PAGE_OFFSET*8, 0
  533. .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC
  534. .org init_top_pgt + L4_START_KERNEL*8, 0
  535. /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
  536. .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
  537. .fill PTI_USER_PGD_FILL,8,0
  538. SYM_DATA_END(init_top_pgt)
  539. SYM_DATA_START_PAGE_ALIGNED(level3_ident_pgt)
  540. .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC
  541. .fill 511, 8, 0
  542. SYM_DATA_END(level3_ident_pgt)
  543. SYM_DATA_START_PAGE_ALIGNED(level2_ident_pgt)
  544. /*
  545. * Since I easily can, map the first 1G.
  546. * Don't set NX because code runs from these pages.
  547. *
  548. * Note: This sets _PAGE_GLOBAL despite whether
  549. * the CPU supports it or it is enabled. But,
  550. * the CPU should ignore the bit.
  551. */
  552. PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
  553. SYM_DATA_END(level2_ident_pgt)
  554. #else
  555. SYM_DATA_START_PTI_ALIGNED(init_top_pgt)
  556. .fill 512,8,0
  557. .fill PTI_USER_PGD_FILL,8,0
  558. SYM_DATA_END(init_top_pgt)
  559. #endif
  560. #ifdef CONFIG_X86_5LEVEL
  561. SYM_DATA_START_PAGE_ALIGNED(level4_kernel_pgt)
  562. .fill 511,8,0
  563. .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
  564. SYM_DATA_END(level4_kernel_pgt)
  565. #endif
  566. SYM_DATA_START_PAGE_ALIGNED(level3_kernel_pgt)
  567. .fill L3_START_KERNEL,8,0
  568. /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
  569. .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC
  570. .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
  571. SYM_DATA_END(level3_kernel_pgt)
  572. SYM_DATA_START_PAGE_ALIGNED(level2_kernel_pgt)
  573. /*
  574. * Kernel high mapping.
  575. *
  576. * The kernel code+data+bss must be located below KERNEL_IMAGE_SIZE in
  577. * virtual address space, which is 1 GiB if RANDOMIZE_BASE is enabled,
  578. * 512 MiB otherwise.
  579. *
  580. * (NOTE: after that starts the module area, see MODULES_VADDR.)
  581. *
  582. * This table is eventually used by the kernel during normal runtime.
  583. * Care must be taken to clear out undesired bits later, like _PAGE_RW
  584. * or _PAGE_GLOBAL in some cases.
  585. */
  586. PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
  587. SYM_DATA_END(level2_kernel_pgt)
  588. SYM_DATA_START_PAGE_ALIGNED(level2_fixmap_pgt)
  589. .fill (512 - 4 - FIXMAP_PMD_NUM),8,0
  590. pgtno = 0
  591. .rept (FIXMAP_PMD_NUM)
  592. .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \
  593. + _PAGE_TABLE_NOENC;
  594. pgtno = pgtno + 1
  595. .endr
  596. /* 6 MB reserved space + a 2MB hole */
  597. .fill 4,8,0
  598. SYM_DATA_END(level2_fixmap_pgt)
  599. SYM_DATA_START_PAGE_ALIGNED(level1_fixmap_pgt)
  600. .rept (FIXMAP_PMD_NUM)
  601. .fill 512,8,0
  602. .endr
  603. SYM_DATA_END(level1_fixmap_pgt)
  604. .data
  605. .align 16
  606. SYM_DATA(smpboot_control, .long 0)
  607. .align 16
  608. /* This must match the first entry in level2_kernel_pgt */
  609. SYM_DATA(phys_base, .quad 0x0)
  610. EXPORT_SYMBOL(phys_base)
  611. #include "../xen/xen-head.S"
  612. __PAGE_ALIGNED_BSS
  613. SYM_DATA_START_PAGE_ALIGNED(empty_zero_page)
  614. .skip PAGE_SIZE
  615. SYM_DATA_END(empty_zero_page)
  616. EXPORT_SYMBOL(empty_zero_page)