KVM: arm64: Factor memory allocation out of pgtable.c
[linux-2.6-block.git] / arch / arm64 / kernel / vmlinux.lds.S
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
8c2c3df3
CM
2/*
3 * ld script to make ARM Linux kernel
4 * taken from the i386 version by Russell King
5 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6 */
7
19f6bc32 8#define RO_EXCEPTION_TABLE_ALIGN 8
2883352b 9#define RUNTIME_DISCARD_EXIT
19f6bc32 10
8c2c3df3 11#include <asm-generic/vmlinux.lds.h>
98fb7548 12#include <asm/cache.h>
ce492a16 13#include <asm/hyp_image.h>
87d1587b 14#include <asm/kernel-pgtable.h>
8c2c3df3
CM
15#include <asm/memory.h>
16#include <asm/page.h>
17
a2c1d73b
MR
18#include "image.h"
19
8c2c3df3 20OUTPUT_ARCH(aarch64)
af885f40 21ENTRY(_text)
8c2c3df3
CM
22
23jiffies = jiffies_64;
24
e9ee186b 25
3471ee06 26#ifdef CONFIG_KVM
e9ee186b
JM
27#define HYPERVISOR_EXTABLE \
28 . = ALIGN(SZ_8); \
29 __start___kvm_ex_table = .; \
30 *(__kvm_ex_table) \
31 __stop___kvm_ex_table = .;
30c95391 32
2d7bf218 33#define HYPERVISOR_DATA_SECTIONS \
16174eea
DB
34 HYP_SECTION_NAME(.rodata) : { \
35 __hyp_rodata_start = .; \
2d7bf218 36 *(HYP_SECTION_NAME(.data..ro_after_init)) \
16174eea
DB
37 *(HYP_SECTION_NAME(.rodata)) \
38 __hyp_rodata_end = .; \
2d7bf218
DB
39 }
40
30c95391
DB
41#define HYPERVISOR_PERCPU_SECTION \
42 . = ALIGN(PAGE_SIZE); \
43 HYP_SECTION_NAME(.data..percpu) : { \
44 *(HYP_SECTION_NAME(.data..percpu)) \
45 }
8c49b5d4
DB
46
47#define HYPERVISOR_RELOC_SECTION \
48 .hyp.reloc : ALIGN(4) { \
49 __hyp_reloc_begin = .; \
50 *(.hyp.reloc) \
51 __hyp_reloc_end = .; \
52 }
53
3471ee06
DB
54#else /* CONFIG_KVM */
55#define HYPERVISOR_EXTABLE
2d7bf218 56#define HYPERVISOR_DATA_SECTIONS
30c95391 57#define HYPERVISOR_PERCPU_SECTION
8c49b5d4 58#define HYPERVISOR_RELOC_SECTION
3471ee06 59#endif
e9ee186b 60
2240bbb6
MZ
61#define HYPERVISOR_TEXT \
62 /* \
06f75a1f
AB
63 * Align to 4 KB so that \
64 * a) the HYP vector table is at its minimum \
65 * alignment of 2048 bytes \
66 * b) the HYP init code will not cross a page \
67 * boundary if its size does not exceed \
68 * 4 KB (see related ASSERT() below) \
2240bbb6 69 */ \
06f75a1f 70 . = ALIGN(SZ_4K); \
5c636aa0 71 __hyp_idmap_text_start = .; \
2240bbb6 72 *(.hyp.idmap.text) \
5c636aa0
MY
73 __hyp_idmap_text_end = .; \
74 __hyp_text_start = .; \
2240bbb6 75 *(.hyp.text) \
e9ee186b 76 HYPERVISOR_EXTABLE \
5c636aa0 77 __hyp_text_end = .;
2240bbb6 78
5dfe9d7d
AB
79#define IDMAP_TEXT \
80 . = ALIGN(SZ_4K); \
5c636aa0 81 __idmap_text_start = .; \
5dfe9d7d 82 *(.idmap.text) \
5c636aa0 83 __idmap_text_end = .;
5dfe9d7d 84
82869ac5
JM
85#ifdef CONFIG_HIBERNATION
86#define HIBERNATE_TEXT \
87 . = ALIGN(SZ_4K); \
5c636aa0 88 __hibernate_exit_text_start = .; \
82869ac5 89 *(.hibernate_exit.text) \
5c636aa0 90 __hibernate_exit_text_end = .;
82869ac5
JM
91#else
92#define HIBERNATE_TEXT
93#endif
94
c7b9adaf
WD
95#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
96#define TRAMP_TEXT \
97 . = ALIGN(PAGE_SIZE); \
5c636aa0 98 __entry_tramp_text_start = .; \
c7b9adaf
WD
99 *(.entry.tramp.text) \
100 . = ALIGN(PAGE_SIZE); \
5c636aa0 101 __entry_tramp_text_end = .;
c7b9adaf
WD
102#else
103#define TRAMP_TEXT
104#endif
105
a352ea3e
AB
106/*
107 * The size of the PE/COFF section that covers the kernel image, which
348a625d
AB
108 * runs from _stext to _edata, must be a round multiple of the PE/COFF
109 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
a352ea3e
AB
110 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
111 * boundary should be sufficient.
112 */
113PECOFF_FILE_ALIGNMENT = 0x200;
114
115#ifdef CONFIG_EFI
116#define PECOFF_EDATA_PADDING \
117 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
118#else
119#define PECOFF_EDATA_PADDING
120#endif
121
8c2c3df3
CM
122SECTIONS
123{
124 /*
125 * XXX: The linker does not define how output sections are
126 * assigned to input sections when there are multiple statements
127 * matching the same input section name. There is no documented
128 * order of matching.
129 */
2883352b 130 DISCARDS
8c2c3df3 131 /DISCARD/ : {
1e48ef7f 132 *(.interp .dynamic)
3bbd3db8 133 *(.dynsym .dynstr .hash .gnu.hash)
8c2c3df3
CM
134 }
135
120dc60d 136 . = KIMAGE_VADDR;
8c2c3df3
CM
137
138 .head.text : {
139 _text = .;
140 HEAD_TEXT
141 }
e2a073dd 142 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
8c2c3df3 143 _stext = .; /* Text and read-only data */
8c2c3df3 144 IRQENTRY_TEXT
be7635e7 145 SOFTIRQENTRY_TEXT
888b3c87 146 ENTRY_TEXT
8c2c3df3
CM
147 TEXT_TEXT
148 SCHED_TEXT
6727ad9e 149 CPUIDLE_TEXT
8c2c3df3 150 LOCK_TEXT
2dd0e8d2 151 KPROBES_TEXT
2240bbb6 152 HYPERVISOR_TEXT
5dfe9d7d 153 IDMAP_TEXT
82869ac5 154 HIBERNATE_TEXT
c7b9adaf 155 TRAMP_TEXT
8c2c3df3
CM
156 *(.fixup)
157 *(.gnu.warning)
158 . = ALIGN(16);
159 *(.got) /* Global offset table */
160 }
161
be288182
KC
162 /*
163 * Make sure that the .got.plt is either completely empty or it
164 * contains only the lazy dispatch entries.
165 */
166 .got.plt : { *(.got.plt) }
167 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
168 "Unexpected GOT/PLT entries detected!")
169
97740051 170 . = ALIGN(SEGMENT_ALIGN);
9fdc14c5
AB
171 _etext = .; /* End of text section */
172
19f6bc32
KC
173 /* everything from this point to __init_begin will be marked RO NX */
174 RO_DATA(PAGE_SIZE)
8c2c3df3 175
8eb7e28d
JY
176 idmap_pg_dir = .;
177 . += IDMAP_DIR_SIZE;
9d2d75ed 178 idmap_pg_end = .;
8eb7e28d
JY
179
180#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
181 tramp_pg_dir = .;
182 . += PAGE_SIZE;
183#endif
184
833be850
MR
185 reserved_pg_dir = .;
186 . += PAGE_SIZE;
187
8eb7e28d
JY
188 swapper_pg_dir = .;
189 . += PAGE_SIZE;
8eb7e28d 190
97740051 191 . = ALIGN(SEGMENT_ALIGN);
8c2c3df3 192 __init_begin = .;
2ebe088b 193 __inittext_begin = .;
8c2c3df3
CM
194
195 INIT_TEXT_SECTION(8)
ca2ef4ff
MR
196
197 __exittext_begin = .;
8c2c3df3 198 .exit.text : {
1eae811d 199 EXIT_TEXT
8c2c3df3 200 }
ca2ef4ff 201 __exittext_end = .;
da141706 202
2ebe088b
AB
203 . = ALIGN(4);
204 .altinstructions : {
205 __alt_instructions = .;
206 *(.altinstructions)
207 __alt_instructions_end = .;
208 }
2ebe088b 209
76085aff 210 . = ALIGN(SEGMENT_ALIGN);
2ebe088b
AB
211 __inittext_end = .;
212 __initdata_begin = .;
213
8c2c3df3
CM
214 .init.data : {
215 INIT_DATA
216 INIT_SETUP(16)
217 INIT_CALLS
218 CON_INITCALL
8c2c3df3 219 INIT_RAM_FS
ba4259a6 220 *(.init.altinstructions .init.bss) /* from the EFI stub */
8c2c3df3
CM
221 }
222 .exit.data : {
1eae811d 223 EXIT_DATA
8c2c3df3
CM
224 }
225
98fb7548 226 PERCPU_SECTION(L1_CACHE_BYTES)
30c95391 227 HYPERVISOR_PERCPU_SECTION
8c2c3df3 228
8c49b5d4
DB
229 HYPERVISOR_RELOC_SECTION
230
3bbd3db8 231 .rela.dyn : ALIGN(8) {
1e48ef7f 232 *(.rela .rela*)
1e48ef7f 233 }
e039ee4e 234
3bbd3db8
AB
235 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
236 __rela_size = SIZEOF(.rela.dyn);
0cd3defe 237
5cf896fb
PC
238#ifdef CONFIG_RELR
239 .relr.dyn : ALIGN(8) {
240 *(.relr.dyn)
241 }
242
243 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
244 __relr_size = SIZEOF(.relr.dyn);
245#endif
246
97740051 247 . = ALIGN(SEGMENT_ALIGN);
2ebe088b 248 __initdata_end = .;
9aa4ec15
MR
249 __init_end = .;
250
3c620626 251 _data = .;
3c620626 252 _sdata = .;
c9174047 253 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
b6113038 254
2d7bf218
DB
255 HYPERVISOR_DATA_SECTIONS
256
b6113038
JM
257 /*
258 * Data written with the MMU off but read with the MMU on requires
259 * cache lines to be invalidated, discarding up to a Cache Writeback
260 * Granule (CWG) of data from the cache. Keep the section that
261 * requires this type of maintenance to be in its own Cache Writeback
262 * Granule (CWG) area so the cache maintenance operations don't
263 * interfere with adjacent data.
264 */
265 .mmuoff.data.write : ALIGN(SZ_2K) {
266 __mmuoff_data_start = .;
267 *(.mmuoff.data.write)
268 }
269 . = ALIGN(SZ_2K);
270 .mmuoff.data.read : {
271 *(.mmuoff.data.read)
272 __mmuoff_data_end = .;
273 }
274
a352ea3e 275 PECOFF_EDATA_PADDING
cad27ef2 276 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
3c620626 277 _edata = .;
8c2c3df3 278
8c2c3df3 279 BSS_SECTION(0, 0, 0)
bd00cd5f
MR
280
281 . = ALIGN(PAGE_SIZE);
2b5548b6
JY
282 init_pg_dir = .;
283 . += INIT_DIR_SIZE;
284 init_pg_end = .;
285
76085aff 286 . = ALIGN(SEGMENT_ALIGN);
cad27ef2 287 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
8c2c3df3
CM
288 _end = .;
289
290 STABS_DEBUG
578d7f0f 291 DWARF_DEBUG
c604abc3 292 ELF_DETAILS
a2c1d73b
MR
293
294 HEAD_SYMBOLS
be288182
KC
295
296 /*
297 * Sections that should stay zero sized, which is safer to
298 * explicitly check instead of blindly discarding.
299 */
300 .plt : {
5f692a81 301 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
be288182
KC
302 }
303 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
304
305 .data.rel.ro : { *(.data.rel.ro) }
306 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
8c2c3df3 307}
2240bbb6 308
90776dd1
KC
309#include "image-vars.h"
310
2240bbb6 311/*
5dfe9d7d 312 * The HYP init code and ID map text can't be longer than a page each,
06f75a1f 313 * and should not cross a page boundary.
2240bbb6 314 */
06f75a1f
AB
315ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
316 "HYP init code too big or misaligned")
5dfe9d7d
AB
317ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
318 "ID map text too big or misaligned")
82869ac5
JM
319#ifdef CONFIG_HIBERNATION
320ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
321 <= SZ_4K, "Hibernate exit text too big or misaligned")
322#endif
6c27c408
WD
323#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
324ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
325 "Entry trampoline text too big")
326#endif
da57a369
MR
327/*
328 * If padding is applied before .head.text, virt<->phys conversions will fail.
329 */
120dc60d 330ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
00ef5434
JG
331
332ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
333 "RESERVED_SWAPPER_OFFSET is wrong!")
0188a894
JG
334
335#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
336ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
337 "TRAMP_SWAPPER_OFFSET is wrong!")
338#endif