Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5933403rwl; Mon, 9 Jan 2023 01:42:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXthT5KYCnO5tk2e6izZZ7dUhEgHdTXDy9CvNMpyItakR7Lu9vax1LpLIN86PMZGXrXjnZCe X-Received: by 2002:a05:6402:1801:b0:499:bf81:be6 with SMTP id g1-20020a056402180100b00499bf810be6mr226841edy.37.1673257376048; Mon, 09 Jan 2023 01:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673257376; cv=none; d=google.com; s=arc-20160816; b=QXopKmoxyqYLJOcXVynSQ1/dIfMhHtqK0tGtFo51JLnX6fO/lGo9wKFT+S7sA0Nzwt 7pIAaY99IQ9X0kwDsF9ewVqiyj9zdfVpVDNXcabp314gn2BRmgj7jrQOGeHSdwX2Wn7N bQVN4GHvvMykdeLZiJps9quQa4R/MadFp1PWKYrkIEPorIZUkl43gibqTtMQTLV+Ln8D /Qa9nEYbAyq+fAAMOyyggYxqfUps6c5kJyBfXkb0c8Q4GJfdVOsZpY82eELoka7eSUXe s9IImrnFzAi6bZIL0dOXEaqtzl7PAejEgtcy/7ipaNASwUibAlbKRS5+kljiDIEwvBaz uQSw== 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=AWRWs007ixrcdQWRzeU/r1l76u8Z4OJpoX7uOEo5WFU=; b=D6BXYYNqYDiKjjy5VRtj+aYhJbcgjpICuG57bzwMlzgCVdw3tTokNYYQF5rjkkEbo3 cK3oLsXoU5LFWFWUdjeOyWvChAWb3HwC5xud4+bnW32Vvsn4Ne+4HwzGqxMXqCzzKruf l2eF5i22PIfD/dttVrqOUhpsGdvUqyOZn6kbrr3g07LJ+cLSKZ5VlRIluJAEbt4bKIIx HzdJwkz8tMbX4hQ5Elv0JPzDwEqYGvnjwbsPMu56mROYxw6NOjVBTSk0Mn98PsMYov7h E5szpxjd/6+/lsQAkGjGuSRhUsm4s+cq842LNcmQtR/DdXrVuiNOZn8itjBPMZ4kMHPt PtOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020aa7d8da000000b0048ee8cf8bb8si7818938eds.53.2023.01.09.01.42.43; Mon, 09 Jan 2023 01:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236971AbjAIJMK (ORCPT + 54 others); Mon, 9 Jan 2023 04:12:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236883AbjAIJLq (ORCPT ); Mon, 9 Jan 2023 04:11:46 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A3DE178AD for ; Mon, 9 Jan 2023 01:08:02 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8CxYvBx2btjdXUAAA--.1873S3; Mon, 09 Jan 2023 17:08:01 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxTuRw2btj_6sWAA--.4042S2; Mon, 09 Jan 2023 17:08:01 +0800 (CST) From: Youling Tang To: Huacai Chen , Xi Ruoyao , Jinyang He Cc: Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 0/4] LoongArch: Add kernel relocation and KASLR support Date: Mon, 9 Jan 2023 17:07:50 +0800 Message-Id: <1673255274-18238-1-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8DxTuRw2btj_6sWAA--.4042S2 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7uF45CFyfuFWUGr15Ww15Jwb_yoW8KFyUpr 1Yyrn8GFW8GrnxJrW7ta4fur1rtwn2kF13X3ZxtryruFW3XF1UAw18Zr9rXFyDtw4rKrWI qrn5Gw1aq3W5ZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4U McvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr 0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8xuctUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series to support kernel relocation and KASLR (only 64bit). Both old[1] and new[2] toolchains support this feature, and the test results are as follows: 1) Enable CONFING_RELOCATABLE # cat /proc/iomem 00000000-0fffffff : System RAM 00000000-002c3fff : Reserved 002c4000-008c3fff : Reserved 02000000-02f4ffff : Kernel code 02f50000-0381cbff : Kernel data 0381cc00-0394ae37 : Kernel bss 2) Enable CONFING_RANDOMIZE_BASE (KASLR) first: # cat /proc/iomem 00000000-0fffffff : System RAM 00000000-002c3fff : Reserved 002c4000-008c3fff : Reserved 02550000-0349ffff : Kernel code 034a0000-03d6cbff : Kernel data 03d6cc00-03e9ae37 : Kernel bss second: # cat /proc/iomem 00000000-0fffffff : System RAM 00000000-002c3fff : Reserved 002c4000-008c3fff : Reserved 02ad0000-03a1ffff : Kernel code 03a20000-042ecbff : Kernel data 042ecc00-0441ae37 : Kernel bss Thanks to @Ruoyao's and @Jinyang's for their help and suggestions. Links: [1]: https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/download/5.0/loongarch64-clfs-5.1-cross-tools-c-only.tar.xz [2]: https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/download/6.0/loongarch64-clfs-6.3-cross-tools-c-only.tar.xz Xi Ruoyao (1): LoongArch: Use trampoline for exception handlers and kill la.abs Youling Tang (3): LoongArch: Add JUMP_LINK_ADDR macro implementation to avoid using la.abs LoongArch: Add support for kernel relocation LoongArch: Add support for kernel address space layout randomization (KASLR) arch/loongarch/Kconfig | 37 +++++ arch/loongarch/Makefile | 5 + arch/loongarch/include/asm/page.h | 6 + arch/loongarch/include/asm/stackframe.h | 16 +- arch/loongarch/include/asm/uaccess.h | 1 - arch/loongarch/kernel/Makefile | 2 + arch/loongarch/kernel/entry.S | 6 +- arch/loongarch/kernel/genex.S | 20 +-- arch/loongarch/kernel/head.S | 30 +++- arch/loongarch/kernel/relocate.c | 210 ++++++++++++++++++++++++ arch/loongarch/kernel/setup.c | 3 + arch/loongarch/kernel/traps.c | 4 +- arch/loongarch/kernel/vmlinux.lds.S | 11 +- arch/loongarch/mm/tlbex.S | 28 +--- arch/loongarch/power/suspend_asm.S | 5 +- 15 files changed, 333 insertions(+), 51 deletions(-) create mode 100644 arch/loongarch/kernel/relocate.c -- 2.37.1