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