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