Skip to content

Commit 9fbcc07

Browse files
zhangqingmychenhuacai
authored andcommitted
LoongArch: Simplify the processing of jumping new kernel for KASLR
Modified relocate_kernel() doesn't return new kernel's entry point but the random_offset. In this way we share the start_kernel() processing with the normal kernel, which avoids calling 'jr a0' directly and allows some other operations (e.g, kasan_early_init) before start_kernel() when KASLR (CONFIG_RANDOMIZE_BASE) is turned on. Signed-off-by: Qing Zhang <zhangqing@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent fb6d5c1 commit 9fbcc07

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

arch/loongarch/include/asm/setup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern long __la_abs_end;
3434
extern long __rela_dyn_begin;
3535
extern long __rela_dyn_end;
3636

37-
extern void * __init relocate_kernel(void);
37+
extern unsigned long __init relocate_kernel(void);
3838

3939
#endif
4040

arch/loongarch/kernel/head.S

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ SYM_CODE_START(kernel_entry) # kernel entry point
9595
PTR_LI sp, (_THREAD_SIZE - PT_SIZE)
9696
PTR_ADD sp, sp, tp
9797
set_saved_sp sp, t0, t1
98-
#endif
9998

100-
/* relocate_kernel() returns the new kernel entry point */
101-
jr a0
102-
ASM_BUG()
99+
/* Jump to the new kernel: new_pc = current_pc + random_offset */
100+
pcaddi t0, 0
101+
add.d t0, t0, a0
102+
jirl zero, t0, 0xc
103+
#endif /* CONFIG_RANDOMIZE_BASE */
103104

104-
#endif
105+
#endif /* CONFIG_RELOCATABLE */
105106

106107
bl start_kernel
107108
ASM_BUG()

arch/loongarch/kernel/relocate.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,11 @@ static inline void __init update_reloc_offset(unsigned long *addr, long random_o
157157
*new_addr = (unsigned long)reloc_offset;
158158
}
159159

160-
void * __init relocate_kernel(void)
160+
unsigned long __init relocate_kernel(void)
161161
{
162162
unsigned long kernel_length;
163163
unsigned long random_offset = 0;
164164
void *location_new = _text; /* Default to original kernel start */
165-
void *kernel_entry = start_kernel; /* Default to original kernel entry point */
166165
char *cmdline = early_ioremap(fw_arg1, COMMAND_LINE_SIZE); /* Boot command line is passed in fw_arg1 */
167166

168167
strscpy(boot_command_line, cmdline, COMMAND_LINE_SIZE);
@@ -190,9 +189,6 @@ void * __init relocate_kernel(void)
190189

191190
reloc_offset += random_offset;
192191

193-
/* Return the new kernel's entry point */
194-
kernel_entry = RELOCATED_KASLR(start_kernel);
195-
196192
/* The current thread is now within the relocated kernel */
197193
__current_thread_info = RELOCATED_KASLR(__current_thread_info);
198194

@@ -204,7 +200,7 @@ void * __init relocate_kernel(void)
204200

205201
relocate_absolute(random_offset);
206202

207-
return kernel_entry;
203+
return random_offset;
208204
}
209205

210206
/*

0 commit comments

Comments
 (0)