1818
1919extern const u8 __eh_frame_start [], __eh_frame_end [];
2020
21- extern void idmap_cpu_replace_ttbr1 (void * pgdir );
21+ extern void idmap_cpu_replace_ttbr1 (phys_addr_t pgdir );
2222
23- static void __init map_segment (pgd_t * pg_dir , u64 * pgd , u64 va_offset ,
23+ static void __init map_segment (pgd_t * pg_dir , phys_addr_t * pgd , u64 va_offset ,
2424 void * start , void * end , pgprot_t prot ,
2525 bool may_use_cont , int root_level )
2626{
@@ -40,7 +40,7 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_offset, int root_level)
4040{
4141 bool enable_scs = IS_ENABLED (CONFIG_UNWIND_PATCH_PAC_INTO_SCS );
4242 bool twopass = IS_ENABLED (CONFIG_RELOCATABLE );
43- u64 pgdp = (u64 )init_pg_dir + PAGE_SIZE ;
43+ phys_addr_t pgdp = (phys_addr_t )init_pg_dir + PAGE_SIZE ;
4444 pgprot_t text_prot = PAGE_KERNEL_ROX ;
4545 pgprot_t data_prot = PAGE_KERNEL ;
4646 pgprot_t prot ;
@@ -78,6 +78,12 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_offset, int root_level)
7878 twopass |= enable_scs ;
7979 prot = twopass ? data_prot : text_prot ;
8080
81+ /*
82+ * [_stext, _text) isn't executed after boot and contains some
83+ * non-executable, unpredictable data, so map it non-executable.
84+ */
85+ map_segment (init_pg_dir , & pgdp , va_offset , _text , _stext , data_prot ,
86+ false, root_level );
8187 map_segment (init_pg_dir , & pgdp , va_offset , _stext , _etext , prot ,
8288 !twopass , root_level );
8389 map_segment (init_pg_dir , & pgdp , va_offset , __start_rodata ,
@@ -90,7 +96,7 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_offset, int root_level)
9096 true, root_level );
9197 dsb (ishst );
9298
93- idmap_cpu_replace_ttbr1 (init_pg_dir );
99+ idmap_cpu_replace_ttbr1 (( phys_addr_t ) init_pg_dir );
94100
95101 if (twopass ) {
96102 if (IS_ENABLED (CONFIG_RELOCATABLE ))
@@ -129,10 +135,10 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_offset, int root_level)
129135 /* Copy the root page table to its final location */
130136 memcpy ((void * )swapper_pg_dir + va_offset , init_pg_dir , PAGE_SIZE );
131137 dsb (ishst );
132- idmap_cpu_replace_ttbr1 (swapper_pg_dir );
138+ idmap_cpu_replace_ttbr1 (( phys_addr_t ) swapper_pg_dir );
133139}
134140
135- static void noinline __section (".idmap.text" ) set_ttbr0_for_lpa2 (u64 ttbr )
141+ static void noinline __section (".idmap.text" ) set_ttbr0_for_lpa2 (phys_addr_t ttbr )
136142{
137143 u64 sctlr = read_sysreg (sctlr_el1 );
138144 u64 tcr = read_sysreg (tcr_el1 ) | TCR_DS ;
@@ -172,30 +178,30 @@ static void __init remap_idmap_for_lpa2(void)
172178 */
173179 create_init_idmap (init_pg_dir , mask );
174180 dsb (ishst );
175- set_ttbr0_for_lpa2 ((u64 )init_pg_dir );
181+ set_ttbr0_for_lpa2 ((phys_addr_t )init_pg_dir );
176182
177183 /*
178184 * Recreate the initial ID map with the same granularity as before.
179185 * Don't bother with the FDT, we no longer need it after this.
180186 */
181187 memset (init_idmap_pg_dir , 0 ,
182- (u64 )init_idmap_pg_end - (u64 )init_idmap_pg_dir );
188+ (char * )init_idmap_pg_end - (char * )init_idmap_pg_dir );
183189
184190 create_init_idmap (init_idmap_pg_dir , mask );
185191 dsb (ishst );
186192
187193 /* switch back to the updated initial ID map */
188- set_ttbr0_for_lpa2 ((u64 )init_idmap_pg_dir );
194+ set_ttbr0_for_lpa2 ((phys_addr_t )init_idmap_pg_dir );
189195
190196 /* wipe the temporary ID map from memory */
191- memset (init_pg_dir , 0 , (u64 )init_pg_end - (u64 )init_pg_dir );
197+ memset (init_pg_dir , 0 , (char * )init_pg_end - (char * )init_pg_dir );
192198}
193199
194- static void __init map_fdt (u64 fdt )
200+ static void * __init map_fdt (phys_addr_t fdt )
195201{
196202 static u8 ptes [INIT_IDMAP_FDT_SIZE ] __initdata __aligned (PAGE_SIZE );
197- u64 efdt = fdt + MAX_FDT_SIZE ;
198- u64 ptep = (u64 )ptes ;
203+ phys_addr_t efdt = fdt + MAX_FDT_SIZE ;
204+ phys_addr_t ptep = (phys_addr_t )ptes ; /* We're idmapped when called */
199205
200206 /*
201207 * Map up to MAX_FDT_SIZE bytes, but avoid overlap with
@@ -205,6 +211,8 @@ static void __init map_fdt(u64 fdt)
205211 fdt , PAGE_KERNEL , IDMAP_ROOT_LEVEL ,
206212 (pte_t * )init_idmap_pg_dir , false, 0 );
207213 dsb (ishst );
214+
215+ return (void * )fdt ;
208216}
209217
210218/*
@@ -230,23 +238,22 @@ static bool __init ng_mappings_allowed(void)
230238 return true;
231239}
232240
233- asmlinkage void __init early_map_kernel (u64 boot_status , void * fdt )
241+ asmlinkage void __init early_map_kernel (u64 boot_status , phys_addr_t fdt )
234242{
235243 static char const chosen_str [] __initconst = "/chosen" ;
236244 u64 va_base , pa_base = (u64 )& _text ;
237245 u64 kaslr_offset = pa_base % MIN_KIMG_ALIGN ;
238246 int root_level = 4 - CONFIG_PGTABLE_LEVELS ;
239247 int va_bits = VA_BITS ;
240248 int chosen ;
241-
242- map_fdt ((u64 )fdt );
249+ void * fdt_mapped = map_fdt (fdt );
243250
244251 /* Clear BSS and the initial page tables */
245- memset (__bss_start , 0 , (u64 )init_pg_end - (u64 )__bss_start );
252+ memset (__bss_start , 0 , (char * )init_pg_end - (char * )__bss_start );
246253
247254 /* Parse the command line for CPU feature overrides */
248- chosen = fdt_path_offset (fdt , chosen_str );
249- init_feature_override (boot_status , fdt , chosen );
255+ chosen = fdt_path_offset (fdt_mapped , chosen_str );
256+ init_feature_override (boot_status , fdt_mapped , chosen );
250257
251258 if (IS_ENABLED (CONFIG_ARM64_64K_PAGES ) && !cpu_has_lva ()) {
252259 va_bits = VA_BITS_MIN ;
@@ -266,7 +273,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status, void *fdt)
266273 * fill in the high bits from the seed.
267274 */
268275 if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) {
269- u64 kaslr_seed = kaslr_early_init (fdt , chosen );
276+ u64 kaslr_seed = kaslr_early_init (fdt_mapped , chosen );
270277
271278 if (kaslr_seed && kaslr_requires_kpti ())
272279 arm64_use_ng_mappings = ng_mappings_allowed ();
0 commit comments