Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6513009ybf; Thu, 5 Mar 2020 22:42:29 -0800 (PST) X-Google-Smtp-Source: ADFU+vu7AS/NWKQ93RHPi0TCCk51aaFhwcPq+q6i8fcJH+Fcg0haBRQiqHqK8fXU8YfehNijHCsy X-Received: by 2002:aca:280a:: with SMTP id 10mr1546833oix.22.1583476948968; Thu, 05 Mar 2020 22:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583476948; cv=none; d=google.com; s=arc-20160816; b=bo/5kY8QMusZ6dIr9oLZ3gxszM93rUk1VRavlJ6IDxmIcFLGXDO7sPAHcoUXp8RHvg sGRKaqBLaIKtHlPXyNX+VpsQbtpcQ4qqWgLwaOesC+2C+la4aBFNeEvn/dfFt/MJ5t7m 1rVJEHzFhOM9JpMaG5Nc+23dfHDWoYNfpFqK+fptBp9aLXBTiRNy5zxIOmya3pxxWMb6 i7FsPYfP9y+cUjouQPYw4zVuDysh+tTpskTyyROdA0Vt7IpujWfe7VzrpoxBDoBvYHUt SbyF8RFBVGPDP18UHQ2FkihkfFohpRmH8baOcXXxq48dj3JJWC/yI54nRYgVlyyrox6u nv/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=gy9hK7jk8fXgAdtyU0dHHkSP/PPkskiqNrUZw7S8/1Q=; b=JLXhqgvA9iLvupJPecY9jiZmt6pOcsVMk9FyLMbCKLreB7/6MQsSDyQzBoFs7MnwT4 wtijkZR9NCJZ4dh9zvAygS7ORmz8mCTCBVo2qqHKSUiYg/2OZNYhtiUKCiWi0ExD1Jea s7DB0pzuoFZ6msP4zK0DVoZRy4YNYJ/62ok07x8OEy0duG3OHdhrVZz8NHVVsHGZ5NkL fN3BGpg+WUPCJ/sWkHn6a3cu11ZxG97XEy6v73Rb5v6iTYKLzPHeNHi4k3gBFKvw5bQo SnBMoiFvVdQnUvThxeuOLh51vtdXZH8gEnqnp4F5+iA5nPu6uZY1X2QYhP5Q2Xl5/izr IGSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si756705otl.278.2020.03.05.22.42.16; Thu, 05 Mar 2020 22:42:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726010AbgCFGl6 (ORCPT + 99 others); Fri, 6 Mar 2020 01:41:58 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11597 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725835AbgCFGl6 (ORCPT ); Fri, 6 Mar 2020 01:41:58 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 50BDDE1792697A077368; Fri, 6 Mar 2020 14:41:56 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Fri, 6 Mar 2020 14:41:47 +0800 From: Jason Yan To: , , , , , , , , , CC: , , , Jason Yan Subject: [PATCH v4 0/6] implement KASLR for powerpc/fsl_booke/64 Date: Fri, 6 Mar 2020 14:40:27 +0800 Message-ID: <20200306064033.3398-1-yanaijie@huawei.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a try to implement KASLR for Freescale BookE64 which is based on my earlier implementation for Freescale BookE32: https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=131718&state=* The implementation for Freescale BookE64 is similar as BookE32. One difference is that Freescale BookE64 set up a TLB mapping of 1G during booting. Another difference is that ppc64 needs the kernel to be 64K-aligned. So we can randomize the kernel in this 1G mapping and make it 64K-aligned. This can save some code to creat another TLB map at early boot. The disadvantage is that we only have about 1G/64K = 16384 slots to put the kernel in. KERNELBASE 64K |--> kernel <--| | | | +--+--+--+ +--+--+--+--+--+--+--+--+--+ +--+--+ | | | |....| | | | | | | | | |....| | | +--+--+--+ +--+--+--+--+--+--+--+--+--+ +--+--+ | | 1G |-----> offset <-----| kernstart_virt_addr I'm not sure if the slot numbers is enough or the design has any defects. If you have some better ideas, I would be happy to hear that. Thank you all. v3->v4: Do not define __kaslr_offset as a fixed symbol. Reference __run_at_load and __kaslr_offset by symbol instead of magic offsets. Use IS_ENABLED(CONFIG_PPC32) instead of #ifdef CONFIG_PPC32. Change kaslr-booke32 to kaslr-booke in index.rst Switch some instructions to 64-bit. v2->v3: Fix build error when KASLR is disabled. v1->v2: Add __kaslr_offset for the secondary cpu boot up. Jason Yan (6): powerpc/fsl_booke/kaslr: refactor kaslr_legal_offset() and kaslr_early_init() powerpc/fsl_booke/64: introduce reloc_kernel_entry() helper powerpc/fsl_booke/64: implement KASLR for fsl_booke64 powerpc/fsl_booke/64: do not clear the BSS for the second pass powerpc/fsl_booke/64: clear the original kernel if randomized powerpc/fsl_booke/kaslr: rename kaslr-booke32.rst to kaslr-booke.rst and add 64bit part Documentation/powerpc/index.rst | 2 +- .../{kaslr-booke32.rst => kaslr-booke.rst} | 35 +++++++- arch/powerpc/Kconfig | 2 +- arch/powerpc/kernel/exceptions-64e.S | 23 +++++ arch/powerpc/kernel/head_64.S | 13 +++ arch/powerpc/kernel/setup_64.c | 3 + arch/powerpc/mm/mmu_decl.h | 23 ++--- arch/powerpc/mm/nohash/kaslr_booke.c | 88 +++++++++++++------ 8 files changed, 144 insertions(+), 45 deletions(-) rename Documentation/powerpc/{kaslr-booke32.rst => kaslr-booke.rst} (59%) -- 2.17.2