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 RFC 0/3] Some update for relocate
Date: Thu,  1 Apr 2021 21:27:10 +0800	[thread overview]
Message-ID: <1617283633-18598-1-git-send-email-hejinyang@loongson.cn> (raw)

Two questions at least here,

1. cavium-octeon platform seems start with smp cpus, it may broke this function
2. Commit 15ad838d281b ("[MIPS] Always do the ARC64_TWIDDLE_PC thing."), I don't
   know whether broken it.

So RFC to get helps. Thanks!

And Patch3 can be tested by vmlinuz. e.g. Use the follow patch,

diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index f93f72b..499b38d 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -28,12 +28,11 @@ KBUILD_CFLAGS := $(filter-out -march=loongson3a, $(KBUILD_CFLAGS)) -march=mips64
 endif
 
 KBUILD_CFLAGS := $(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \
-	-DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull"
-
-KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ \
-	-DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) \
+	-DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull"	\
 	-DKERNEL_ENTRY=$(VMLINUX_ENTRY_ADDRESS)
 
+KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE)
+
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT		:= n
 GCOV_PROFILE := n
diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c
index 3d70d15..3f5cac9 100644
--- a/arch/mips/boot/compressed/decompress.c
+++ b/arch/mips/boot/compressed/decompress.c
@@ -85,9 +85,11 @@ void __stack_chk_fail(void)
 	error("stack-protector: Kernel stack is corrupted\n");
 }
 
-void decompress_kernel(unsigned long boot_heap_start)
+unsigned long decompress_kernel(unsigned long boot_heap_start)
 {
 	unsigned long zimage_start, zimage_size;
+	unsigned long offset = 0x8000000;
+	unsigned long long load_address = VMLINUX_LOAD_ADDRESS_ULL + offset;
 
 	zimage_start = (unsigned long)(&__image_begin);
 	zimage_size = (unsigned long)(&__image_end) -
@@ -105,12 +107,12 @@ void decompress_kernel(unsigned long boot_heap_start)
 
 	/* Display standard Linux/MIPS boot prompt */
 	puts("Uncompressing Linux at load address ");
-	puthex(VMLINUX_LOAD_ADDRESS_ULL);
+	puthex(load_address);
 	puts("\n");
 
 	/* Decompress the kernel with according algorithm */
 	__decompress((char *)zimage_start, zimage_size, 0, 0,
-		   (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
+		   (void *)load_address, 0, 0, error);
 
 	if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
 	    fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
@@ -125,14 +127,16 @@ void decompress_kernel(unsigned long boot_heap_start)
 		image_size = ALIGN(image_size, STRUCT_ALIGNMENT);
 
 		puts("Copy device tree to address  ");
-		puthex(VMLINUX_LOAD_ADDRESS_ULL + image_size);
+		puthex(load_address + image_size);
 		puts("\n");
 
 		/* copy dtb to where the booted kernel will expect it */
-		memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
+		memcpy((void *)load_address + image_size,
 		       __appended_dtb, dtb_size);
 	}
 
 	/* FIXME: should we flush cache here? */
 	puts("Now, booting the kernel...\n");
+
+	return (KERNEL_ENTRY + offset);
 }
diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
index 5795d0a..36c5809 100644
--- a/arch/mips/boot/compressed/head.S
+++ b/arch/mips/boot/compressed/head.S
@@ -40,8 +40,7 @@
 	move	a1, s1
 	move	a2, s2
 	move	a3, s3
-	PTR_LI	t9, KERNEL_ENTRY
-	jalr	t9
+	jalr	v0
 
 3:
 	b	3b

Jinyang He (3):
  MIPS: relocate: Only compile relocs when CONFIG_RELOCATABLE is enabled
  MIPS: relocate: Use CONFIG_RANDOMIZE_BASE to configure kaslr
  MIPS: relocate: Add support to relocate kernel auto

 arch/mips/Makefile                                 |   2 +
 arch/mips/cavium-octeon/smp.c                      |   8 +-
 arch/mips/generic/init.c                           |   4 +-
 arch/mips/include/asm/bootinfo.h                   |   4 +-
 .../asm/mach-cavium-octeon/kernel-entry-init.h     |   4 +-
 arch/mips/kernel/Makefile                          |   2 +-
 arch/mips/kernel/head.S                            | 155 ++++++++++++++++++++-
 arch/mips/kernel/{relocate.c => kaslr.c}           |  15 --
 8 files changed, 165 insertions(+), 29 deletions(-)
 rename arch/mips/kernel/{relocate.c => kaslr.c} (97%)

-- 
2.1.0


             reply	other threads:[~2021-04-01 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 13:27 Jinyang He [this message]
2021-04-01 13:27 ` [PATCH RFC 1/3] MIPS: relocate: Only compile relocs when CONFIG_RELOCATABLE is enabled Jinyang He
2021-04-01 13:27 ` [PATCH RFC 2/3] MIPS: relocate: Use CONFIG_RANDOMIZE_BASE to configure kaslr Jinyang He
2021-04-01 13:27 ` [PATCH RFC 3/3] MIPS: relocate: Add support to relocate kernel auto 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=1617283633-18598-1-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).