1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Linker script variables to be set after section resolution, as
4  * ld.lld does not like variables assigned before SECTIONS is processed.
5  */
6 #ifndef __ARM64_KERNEL_IMAGE_VARS_H
7 #define __ARM64_KERNEL_IMAGE_VARS_H
8 
9 #ifndef LINKER_SCRIPT
10 #error This file should only be included in vmlinux.lds.S
11 #endif
12 
13 #if defined(CONFIG_LD_IS_LLD) && CONFIG_LLD_VERSION < 210000
14 #define ASSERT(...)
15 #endif
16 
17 #define PI_EXPORT_SYM(sym)		\
18 	__PI_EXPORT_SYM(sym, __pi_ ## sym, Cannot export BSS symbol sym to startup code)
19 #define __PI_EXPORT_SYM(sym, pisym, msg)\
20 	PROVIDE(pisym = sym);		\
21 	ASSERT((sym - KIMAGE_VADDR) < (__bss_start - KIMAGE_VADDR), #msg)
22 
23 PROVIDE(__efistub_primary_entry		= primary_entry);
24 
25 /*
26  * The EFI stub has its own symbol namespace prefixed by __efistub_, to
27  * isolate it from the kernel proper. The following symbols are legally
28  * accessed by the stub, so provide some aliases to make them accessible.
29  * Only include data symbols here, or text symbols of functions that are
30  * guaranteed to be safe when executed at another offset than they were
31  * linked at. The routines below are all implemented in assembler in a
32  * position independent manner
33  */
34 PROVIDE(__efistub_caches_clean_inval_pou = __pi_caches_clean_inval_pou);
35 
36 PROVIDE(__efistub__text			= _text);
37 PROVIDE(__efistub__end			= _end);
38 PROVIDE(__efistub___inittext_end       	= __inittext_end);
39 PROVIDE(__efistub__edata		= _edata);
40 #if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
41 PROVIDE(__efistub_screen_info		= screen_info);
42 #endif
43 PROVIDE(__efistub__ctype		= _ctype);
44 
45 PROVIDE(__pi___memcpy			= __pi_memcpy);
46 PROVIDE(__pi___memmove			= __pi_memmove);
47 PROVIDE(__pi___memset			= __pi_memset);
48 
49 PI_EXPORT_SYM(id_aa64isar1_override);
50 PI_EXPORT_SYM(id_aa64isar2_override);
51 PI_EXPORT_SYM(id_aa64mmfr0_override);
52 PI_EXPORT_SYM(id_aa64mmfr1_override);
53 PI_EXPORT_SYM(id_aa64mmfr2_override);
54 PI_EXPORT_SYM(id_aa64pfr0_override);
55 PI_EXPORT_SYM(id_aa64pfr1_override);
56 PI_EXPORT_SYM(id_aa64smfr0_override);
57 PI_EXPORT_SYM(id_aa64zfr0_override);
58 PI_EXPORT_SYM(arm64_sw_feature_override);
59 PI_EXPORT_SYM(arm64_use_ng_mappings);
60 PI_EXPORT_SYM(_ctype);
61 
62 PI_EXPORT_SYM(swapper_pg_dir);
63 
64 PI_EXPORT_SYM(_text);
65 PI_EXPORT_SYM(_stext);
66 PI_EXPORT_SYM(_etext);
67 PI_EXPORT_SYM(__start_rodata);
68 PI_EXPORT_SYM(__inittext_begin);
69 PI_EXPORT_SYM(__inittext_end);
70 PI_EXPORT_SYM(__initdata_begin);
71 PI_EXPORT_SYM(__initdata_end);
72 PI_EXPORT_SYM(_data);
73 
74 #ifdef CONFIG_KVM
75 
76 /*
77  * KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_, to
78  * separate it from the kernel proper. The following symbols are legally
79  * accessed by it, therefore provide aliases to make them linkable.
80  * Do not include symbols which may not be safely accessed under hypervisor
81  * memory mappings.
82  */
83 
84 /* Alternative callbacks for init-time patching of nVHE hyp code. */
85 KVM_NVHE_ALIAS(kvm_patch_vector_branch);
86 KVM_NVHE_ALIAS(kvm_update_va_mask);
87 KVM_NVHE_ALIAS(kvm_get_kimage_voffset);
88 KVM_NVHE_ALIAS(kvm_compute_final_ctr_el0);
89 KVM_NVHE_ALIAS(spectre_bhb_patch_loop_iter);
90 KVM_NVHE_ALIAS(spectre_bhb_patch_loop_mitigation_enable);
91 KVM_NVHE_ALIAS(spectre_bhb_patch_wa3);
92 KVM_NVHE_ALIAS(spectre_bhb_patch_clearbhb);
93 KVM_NVHE_ALIAS(alt_cb_patch_nops);
94 
95 /* Global kernel state accessed by nVHE hyp code. */
96 KVM_NVHE_ALIAS(kvm_vgic_global_state);
97 
98 /* Kernel symbols used to call panic() from nVHE hyp code (via ERET). */
99 KVM_NVHE_ALIAS(nvhe_hyp_panic_handler);
100 
101 /* Vectors installed by hyp-init on reset HVC. */
102 KVM_NVHE_ALIAS(__hyp_stub_vectors);
103 
104 /* Static keys which are set if a vGIC trap should be handled in hyp. */
105 KVM_NVHE_ALIAS(vgic_v2_cpuif_trap);
106 KVM_NVHE_ALIAS(vgic_v3_cpuif_trap);
107 
108 /* Static key which is set if CNTVOFF_EL2 is unusable */
109 KVM_NVHE_ALIAS(broken_cntvoff_key);
110 
111 /* EL2 exception handling */
112 KVM_NVHE_ALIAS(__start___kvm_ex_table);
113 KVM_NVHE_ALIAS(__stop___kvm_ex_table);
114 
115 /* Position-independent library routines */
116 KVM_NVHE_ALIAS_HYP(clear_page, __pi_clear_page);
117 KVM_NVHE_ALIAS_HYP(copy_page, __pi_copy_page);
118 KVM_NVHE_ALIAS_HYP(memcpy, __pi_memcpy);
119 KVM_NVHE_ALIAS_HYP(memset, __pi_memset);
120 
121 #ifdef CONFIG_KASAN
122 KVM_NVHE_ALIAS_HYP(__memcpy, __pi_memcpy);
123 KVM_NVHE_ALIAS_HYP(__memset, __pi_memset);
124 #endif
125 
126 /* Hyp memory sections */
127 KVM_NVHE_ALIAS(__hyp_idmap_text_start);
128 KVM_NVHE_ALIAS(__hyp_idmap_text_end);
129 KVM_NVHE_ALIAS(__hyp_text_start);
130 KVM_NVHE_ALIAS(__hyp_text_end);
131 KVM_NVHE_ALIAS(__hyp_bss_start);
132 KVM_NVHE_ALIAS(__hyp_bss_end);
133 KVM_NVHE_ALIAS(__hyp_data_start);
134 KVM_NVHE_ALIAS(__hyp_data_end);
135 KVM_NVHE_ALIAS(__hyp_rodata_start);
136 KVM_NVHE_ALIAS(__hyp_rodata_end);
137 
138 /* pKVM static key */
139 KVM_NVHE_ALIAS(kvm_protected_mode_initialized);
140 
141 #endif /* CONFIG_KVM */
142 
143 #ifdef CONFIG_EFI_ZBOOT
144 _kernel_codesize = ABSOLUTE(__inittext_end - _text);
145 #endif
146 
147 /*
148  * LLD will occasionally error out with a '__init_end does not converge' error
149  * if INIT_IDMAP_DIR_SIZE is defined in terms of _end, as this results in a
150  * circular dependency. Counter this by dimensioning the initial IDMAP page
151  * tables based on kimage_limit, which is defined such that its value should
152  * not change as a result of the initdata segment being pushed over a 64k
153  * segment boundary due to changes in INIT_IDMAP_DIR_SIZE, provided that its
154  * value doesn't change by more than 2M between linker passes.
155  */
156 kimage_limit = ALIGN(ABSOLUTE(_end + SZ_64K), SZ_2M);
157 
158 #undef ASSERT
159 
160 #endif /* __ARM64_KERNEL_IMAGE_VARS_H */
161