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