aboutsummaryrefslogtreecommitdiff
path: root/arch/loongarch/include
diff options
context:
space:
mode:
authorGravatar Youling Tang <tangyouling@loongson.cn> 2023-02-25 15:52:56 +0800
committerGravatar Huacai Chen <chenhuacai@loongson.cn> 2023-02-25 22:12:16 +0800
commitd8da19fbdedd5852592fbba18a7348e3f09500e6 (patch)
treea6a4a921da97d0b7379e9034532c8267a14b631e /arch/loongarch/include
parentLoongArch: Add la_abs macro implementation (diff)
downloadlinux-d8da19fbdedd5852592fbba18a7348e3f09500e6.tar.gz
linux-d8da19fbdedd5852592fbba18a7348e3f09500e6.tar.bz2
linux-d8da19fbdedd5852592fbba18a7348e3f09500e6.zip
LoongArch: Add support for kernel relocation
This config allows to compile kernel as PIE and to relocate it at any virtual address at runtime: this paves the way to KASLR. Runtime relocation is possible since relocation metadata are embedded into the kernel. Signed-off-by: Youling Tang <tangyouling@loongson.cn> Signed-off-by: Xi Ruoyao <xry111@xry111.site> # Use arch_initcall Signed-off-by: Jinyang He <hejinyang@loongson.cn> # Provide la_abs relocation code Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'arch/loongarch/include')
-rw-r--r--arch/loongarch/include/asm/asmmacro.h13
-rw-r--r--arch/loongarch/include/asm/setup.h16
2 files changed, 29 insertions, 0 deletions
diff --git a/arch/loongarch/include/asm/asmmacro.h b/arch/loongarch/include/asm/asmmacro.h
index cdc9935d5554..c51a1b43acb4 100644
--- a/arch/loongarch/include/asm/asmmacro.h
+++ b/arch/loongarch/include/asm/asmmacro.h
@@ -275,7 +275,20 @@
.endm
.macro la_abs reg, sym
+#ifndef CONFIG_RELOCATABLE
la.abs \reg, \sym
+#else
+ 766:
+ lu12i.w \reg, 0
+ ori \reg, \reg, 0
+ lu32i.d \reg, 0
+ lu52i.d \reg, \reg, 0
+ .pushsection ".la_abs", "aw", %progbits
+ 768:
+ .dword 768b-766b
+ .dword \sym
+ .popsection
+#endif
.endm
#endif /* _ASM_ASMMACRO_H */
diff --git a/arch/loongarch/include/asm/setup.h b/arch/loongarch/include/asm/setup.h
index 72ead58039f3..27d968655b4b 100644
--- a/arch/loongarch/include/asm/setup.h
+++ b/arch/loongarch/include/asm/setup.h
@@ -21,4 +21,20 @@ extern void per_cpu_trap_init(int cpu);
extern void set_handler(unsigned long offset, void *addr, unsigned long len);
extern void set_merr_handler(unsigned long offset, void *addr, unsigned long len);
+#ifdef CONFIG_RELOCATABLE
+
+struct rela_la_abs {
+ long offset;
+ long symvalue;
+};
+
+extern long __la_abs_begin;
+extern long __la_abs_end;
+extern long __rela_dyn_begin;
+extern long __rela_dyn_end;
+
+extern void __init relocate_kernel(void);
+
+#endif
+
#endif /* __SETUP_H */