Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2FA5C636D3 for ; Wed, 8 Feb 2023 17:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbjBHRQf (ORCPT ); Wed, 8 Feb 2023 12:16:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjBHRQb (ORCPT ); Wed, 8 Feb 2023 12:16:31 -0500 Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEBD928D03 for ; Wed, 8 Feb 2023 09:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1675876585; bh=EJ9NVe253KjmTra80L8ReGUQvb0ZTCo7dnOHVEPK+Pc=; h=From:To:Cc:Subject:Date:From; b=je3ll1bBqQBDkdYtOapkJMEg9JcFZoNvog+AyMHyFs9uArqxgb74J+7bQucywo7x8 kVC9rEj8NWAQPOyjksILpJUSa8f3DLgVN6wASTzQx2cHT9EVEl+xtWUXWFNYW6laqu 35MSdl8t/X4rHK2rwqu1ZPDOWV2wVPamEbTdvDYw= Received: from xry111-x57s1.. (unknown [IPv6:240e:358:1174:d100:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 3FC6665C4F; Wed, 8 Feb 2023 12:16:21 -0500 (EST) From: Xi Ruoyao To: Youling Tang , Huacai Chen , Jinyang He Cc: Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Xi Ruoyao Subject: [PATCH v3 0/5] LoongArch: Add kernel relocation and KASLR support Date: Thu, 9 Feb 2023 01:16:02 +0800 Message-Id: <20230208171607.391107-1-xry111@xry111.site> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series to support kernel relocation and KASLR (only 64bit). Tested the kernel images built with new toolchain (Binutils-2.40 + patched GCC-12.2) and old toolchain (kernel.org cross toolchain [1]) on a 3A5000-7A2000-EVB. With CONFIG_RANDOMIZE_BASE=y, the results are: 1. first boot, new toolchain: $ sudo cat /proc/iomem | grep Kernel 01080000-0189ffff : Kernel code 018a0000-01deb5ff : Kernel data 01deb600-01ef6e9f : Kernel bss 2. second boot, new toolchain: $ sudo cat /proc/iomem | grep Kernel 012f0000-01b0ffff : Kernel code 01b10000-0205b5ff : Kernel data 0205b600-02166e9f : Kernel bss 3. first boot, old toolchain: 010e0000-018fffff : Kernel code 01900000-01e591ff : Kernel data 01e59200-01f56dcf : Kernel bss 4. second boot, old toolchain: 010b0000-018cffff : Kernel code 018d0000-01e291ff : Kernel data 01e29200-01f26dcf : Kernel bss Changes from v2: - Correctly fixup pcaddi12i/ori/lu32i.d/lu52i.d sequence generated by GNU as <= 2.39 for la.pcrel. Changes from v1 to v2: - Relocate the handlers instead of using a trampoline, to avoid performance issue on NUMA systems. - Fix compiler warnings. Xi Ruoyao (2): LoongArch: Use la.pcrel instead of la.abs when it's trivially possible LoongArch: Use la.pcrel instead of la.abs for exception handlers 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/inst.h | 1 + arch/loongarch/include/asm/page.h | 6 + arch/loongarch/include/asm/setup.h | 6 +- arch/loongarch/include/asm/stackframe.h | 13 +- arch/loongarch/include/asm/uaccess.h | 1 - arch/loongarch/kernel/Makefile | 2 + arch/loongarch/kernel/entry.S | 2 +- arch/loongarch/kernel/genex.S | 40 ++++- arch/loongarch/kernel/head.S | 30 +++- arch/loongarch/kernel/relocate.c | 211 ++++++++++++++++++++++++ arch/loongarch/kernel/setup.c | 3 + arch/loongarch/kernel/traps.c | 158 +++++++++++++++--- arch/loongarch/kernel/vmlinux.lds.S | 11 +- arch/loongarch/mm/tlb.c | 23 +-- arch/loongarch/mm/tlbex.S | 72 +++++++- arch/loongarch/power/suspend_asm.S | 5 +- 18 files changed, 564 insertions(+), 62 deletions(-) create mode 100644 arch/loongarch/kernel/relocate.c -- 2.39.1