Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp692440pxf; Thu, 1 Apr 2021 11:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAuWFaIFECKRm+ZoysmvXsKYTbYVB5C6G0jd/y/TKZMI0TkjNVRl9as0G5N5GtV/XldTwx X-Received: by 2002:a02:a606:: with SMTP id c6mr9386201jam.108.1617300193386; Thu, 01 Apr 2021 11:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617300193; cv=none; d=google.com; s=arc-20160816; b=yl8lf7b1y3zg/wNKcv53dTBgFHMytAHJuJ9nzF/9AkA1+cKx9I5pAegd4+7fDSFQ8c gu1z32BvztlI26uFN6Hz9pJD5zsZgBF9CiViEkOK4BA9wNjk1ofjlXao7hdBcv/u06LW 4Z2+9czEpLFGnQgpHMN4kVUsLNSYrSrVdUG+w6QGcnA5GYIfZUYCNOTftxSc0q46Oc3I yh0aEVaiyhtVW7Bv6DnrBANaMl9xHzqSzd3lp0Gl4e2/qSFqZZAhuGeLZurqVbR3Aqgm wH3nRu0LsrOpI6VHOIl5ZfI7Bw+2BOPOAmqvs94OTYJex67A9YN4UErG/ieDw+dG6Dk8 UH+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=ChgJN0+EdREZs13+PkFeau29TlB3PWgLKsR+gb29ttA=; b=Rro9YcX03vSCGeesxDU4ICf9clPTmlewOJJggHj6fcZoKI0c2ZQe/xhZoHt/dwX0EM d6YCl/SBTchdlkWWERv6rZmGu5B3/UH9TxVYO63LbS5s6xRWHU4/o1XVfysoz22M7EVE 1v4fmeo81RA4dQmq/JX9rDb7964/1FVnKeS/xzX1zvHtJ8COMzEdIfavr1ggzOusgWV2 UAwTJhME4fUfdBlW2d7jctnB+RLKjvXUYfPQfM+bcLrPdh7jPB+kP6PmGuc/K0CCQ/iR m9IybLxeMMGJfh2CtCCjW9D3ZA7iCCrUjhTd7wG1pyFYj6HLLTZsXjP4w1ADKJRBAN8h MiiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si5336415ilj.28.2021.04.01.11.02.59; Thu, 01 Apr 2021 11:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235531AbhDASBp (ORCPT + 99 others); Thu, 1 Apr 2021 14:01:45 -0400 Received: from mail.loongson.cn ([114.242.206.163]:43914 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234959AbhDARq4 (ORCPT ); Thu, 1 Apr 2021 13:46:56 -0400 Received: from loongson.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxX8s0ymVgtFkDAA--.7389S2; Thu, 01 Apr 2021 21:27:16 +0800 (CST) From: Jinyang He To: Thomas Bogendoerfer , Paul Burton 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 Message-Id: <1617283633-18598-1-git-send-email-hejinyang@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9DxX8s0ymVgtFkDAA--.7389S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCF4kZw4DCr4ftr48Kw4Durg_yoWrAw48pw s7Cw1xtw4vgrW8tw4fJryj9w13Jr95J3yYgFnrKryrJ3WagFn7Xr1SkrnxWrWUJryFqa9Y 934qgrWxCr4SyaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc2xSY4AK67AK6ry8MxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42 IY6xAIw20EY4v20xvaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IUY8nY7UUUUU== X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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