linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jinyang He <hejinyang@loongson.cn>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Paul Burton <paulburton@kernel.org>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/5] MIPS: relocate: Use CONFIG_RANDOMIZE_BASE to enable kaslr
Date: Mon, 12 Apr 2021 20:28:11 +0800	[thread overview]
Message-ID: <1618230494-6207-3-git-send-email-hejinyang@loongson.cn> (raw)
In-Reply-To: <1618230494-6207-1-git-send-email-hejinyang@loongson.cn>

Currently, the difference between using CONFIG_RELOCATABLE and
CONFIG_RANDOMIZE_BASE is determine_relocation_address().
CONFIG_RANDOMIZE_BASE achieves randomization. CONFIG_RELOCATABLE
relocate the kernel is very limited, currently returns a constant.
Therefore, drop determine_relocation_address() if CONFIG_RELOCATABLE.
Rename relocate.c to kaslr.c and use CONFIG_RANDOMIZE_BASE to enable
the kaslr function.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/cavium-octeon/smp.c                             |  8 ++++----
 arch/mips/generic/init.c                                  |  4 ++--
 arch/mips/include/asm/bootinfo.h                          |  4 ++--
 .../include/asm/mach-cavium-octeon/kernel-entry-init.h    |  4 ++--
 arch/mips/kernel/Makefile                                 |  2 +-
 arch/mips/kernel/head.S                                   |  6 +++---
 arch/mips/kernel/{relocate.c => kaslr.c}                  | 15 ---------------
 7 files changed, 14 insertions(+), 29 deletions(-)
 rename arch/mips/kernel/{relocate.c => kaslr.c} (97%)

diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 66ce552..dfdbc79 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -28,9 +28,9 @@
 volatile unsigned long octeon_processor_boot = 0xff;
 volatile unsigned long octeon_processor_sp;
 volatile unsigned long octeon_processor_gp;
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 volatile unsigned long octeon_processor_relocated_kernel_entry;
-#endif /* CONFIG_RELOCATABLE */
+#endif /* CONFIG_RANDOMIZE_BASE */
 
 #ifdef CONFIG_HOTPLUG_CPU
 uint64_t octeon_bootloader_entry_addr;
@@ -190,7 +190,7 @@ static void __init octeon_smp_setup(void)
 }
 
 
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 int plat_post_relocation(long offset)
 {
 	unsigned long entry = (unsigned long)kernel_entry;
@@ -200,7 +200,7 @@ int plat_post_relocation(long offset)
 
 	return 0;
 }
-#endif /* CONFIG_RELOCATABLE */
+#endif /* CONFIG_RANDOMIZE_BASE */
 
 /**
  * Firmware CPU startup hook
diff --git a/arch/mips/generic/init.c b/arch/mips/generic/init.c
index 1842cdd..f7a4e29 100644
--- a/arch/mips/generic/init.c
+++ b/arch/mips/generic/init.c
@@ -82,7 +82,7 @@ void __init *plat_get_fdt(void)
 	return (void *)fdt;
 }
 
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 
 void __init plat_fdt_relocated(void *new_location)
 {
@@ -97,7 +97,7 @@ void __init plat_fdt_relocated(void *new_location)
 		fw_arg1 = (unsigned long)new_location;
 }
 
-#endif /* CONFIG_RELOCATABLE */
+#endif /* CONFIG_RANDOMIZE_BASE */
 
 void __init plat_mem_setup(void)
 {
diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h
index 5be10ece..6b37663 100644
--- a/arch/mips/include/asm/bootinfo.h
+++ b/arch/mips/include/asm/bootinfo.h
@@ -169,7 +169,7 @@ static inline void plat_swiotlb_setup(void) {}
  */
 extern void *plat_get_fdt(void);
 
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 
 /**
  * plat_fdt_relocated() - Update platform's information about relocated dtb
@@ -180,7 +180,7 @@ extern void *plat_get_fdt(void);
  */
 void plat_fdt_relocated(void *new_location);
 
-#endif /* CONFIG_RELOCATABLE */
+#endif /* CONFIG_RANDOMIZE_BASE */
 #endif /* CONFIG_USE_OF */
 
 #endif /* _ASM_BOOTINFO_H */
diff --git a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h
index c38b38c..e66767d 100644
--- a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h
+++ b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h
@@ -100,7 +100,7 @@
 	#
 
 octeon_spin_wait_boot:
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 	PTR_LA	t0, octeon_processor_relocated_kernel_entry
 	LONG_L	t0, (t0)
 	beq	zero, t0, 1f
@@ -109,7 +109,7 @@
 	jr	t0
 	nop
 1:
-#endif /* CONFIG_RELOCATABLE */
+#endif /* CONFIG_RANDOMIZE_BASE */
 
 	# This is the variable where the next core to boot is stored
 	PTR_LA	t0, octeon_processor_boot
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index b4a57f1..bf7ac86 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -92,7 +92,7 @@ obj-$(CONFIG_I8253)		+= i8253.o
 
 obj-$(CONFIG_GPIO_TXX9)		+= gpio_txx9.o
 
-obj-$(CONFIG_RELOCATABLE)	+= relocate.o
+obj-$(CONFIG_RANDOMIZE_BASE)	+= kaslr.o
 
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o crash.o
 obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index b825ed4..a25af1d 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -118,7 +118,7 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	set_saved_sp	sp, t0, t1
 	PTR_SUBU	sp, 4 * SZREG		# init stack pointer
 
-#ifdef CONFIG_RELOCATABLE
+#ifdef CONFIG_RANDOMIZE_BASE
 	/* Copy kernel and apply the relocations */
 	jal		relocate_kernel
 
@@ -136,9 +136,9 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	 * newly sync'd icache.
 	 */
 	jr.hb		v0
-#else  /* !CONFIG_RELOCATABLE */
+#else  /* !CONFIG_RANDOMIZE_BASE */
 	j		start_kernel
-#endif /* !CONFIG_RELOCATABLE */
+#endif /* !CONFIG_RANDOMIZE_BASE */
 	END(kernel_entry)
 
 #ifdef CONFIG_SMP
diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/kaslr.c
similarity index 97%
rename from arch/mips/kernel/relocate.c
rename to arch/mips/kernel/kaslr.c
index 499a535..6742d58 100644
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/kaslr.c
@@ -188,8 +188,6 @@ static int __init relocate_exception_table(long offset)
 	return 0;
 }
 
-#ifdef CONFIG_RANDOMIZE_BASE
-
 static inline __init unsigned long rotate_xor(unsigned long hash,
 					      const void *area, size_t size)
 {
@@ -280,19 +278,6 @@ static inline void __init *determine_relocation_address(void)
 	return RELOCATED(dest);
 }
 
-#else
-
-static inline void __init *determine_relocation_address(void)
-{
-	/*
-	 * Choose a new address for the kernel
-	 * For now we'll hard code the destination
-	 */
-	return (void *)0xffffffff81000000;
-}
-
-#endif
-
 static inline int __init relocation_addr_valid(void *loc_new)
 {
 	if ((unsigned long)loc_new & 0x0000ffff) {
-- 
2.1.0


  parent reply	other threads:[~2021-04-12 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 12:28 [PATCH v2 0/5] MIPS: relocate: Add automatic relocation to CONFIG_RELOCATABLE Jinyang He
2021-04-12 12:28 ` [PATCH v2 1/5] MIPS: relocate: Only compile relocs when CONFIG_RELOCATABLE is enabled Jinyang He
2021-04-12 12:28 ` Jinyang He [this message]
2021-04-12 12:28 ` [PATCH v2 3/5] MIPS: Jump to kernel linked address by PC relative way Jinyang He
2021-04-12 12:28 ` [PATCH v2 4/5] MIPS: cavium-octeon: Execute the smp handle after jumping to kernel linked address Jinyang He
2021-04-12 12:28 ` [PATCH v2 5/5] MIPS: relocate: Add support to auto relocate kernel Jinyang He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1618230494-6207-3-git-send-email-hejinyang@loongson.cn \
    --to=hejinyang@loongson.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=paulburton@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).