Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1518185ybj; Fri, 20 Sep 2019 11:47:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFOQBSEWPk5CNrQFm3MtwBoOvC1hcwd5IdHB/t7J0tmdGAdzHC4yFVwX39Q5CqWrBgLS0g X-Received: by 2002:a05:6402:17a2:: with SMTP id j2mr6233118edy.121.1569005277605; Fri, 20 Sep 2019 11:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569005277; cv=none; d=google.com; s=arc-20160816; b=S4KWVzKBNUW8LO47iMzlwn/XJcx11vVB+D5uuyMGkkf8YVKrZdJFxxNESSgEBph9OX 5SRVvp2O7gMyJnkwNbKl4kaDP5Znk6wl1pF0GcG0d3wa4/V2pDicmUOgEp7KaLPEIK3z rCZLV+3mANNwFEukMoZchzLt3G3jx7KELhvIE8mjMdqPW18w6PcmqYtOxs7qqB5UPrzT P9l34Pc2JdG1oO3VC+qQL6gNH1H7P+AeyCER4M+u9ElmGoOGGdyHqXWLDCc7Diwt5rqx gY6ZZslL5UTBtulCLHhLOt74pVdHKCFXwo/NPGm/Q4pZtHmlUEzavdOvpMQR8FQqMTaM RV9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=8o1F4XtXo7knCo0/NHlCCntnhhNt15bexHzaysurUFI=; b=du8NIfVt/hJLNAkiDfbMdHeiW3AwcQb0MMQ7uQulPHWG1zojLSxkYygSKNxPvcb6iY zo6uTrifJ9mfV7v77rZlJQMi8AafNe8pluw7NsoD4d5Hi+5PQDP6i6A6QnP4D+Z5Pp8l plUsHQ6OjsVSgeYE2A+YADrlCflCTeR1ccfTnhgvorANtpJ8WmzK0K9YUVGIMgTZtGrZ fyFX/D8PbGO713brkRVMd2LBxXXaDyCCVrU5fx1Ef1AHOE8opp/gzgUs44RLjYPanyDa oTGJwuY/7S2XeYpopokJr0j1eSIaKiIaYi7XxKKDSPoRgBMZeKrHFgssFfF4jz7aWDit Uatg== 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 a30si2014108eda.39.2019.09.20.11.47.34; Fri, 20 Sep 2019 11:47:57 -0700 (PDT) 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 S2408524AbfITJZl (ORCPT + 99 others); Fri, 20 Sep 2019 05:25:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2754 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2408490AbfITJZc (ORCPT ); Fri, 20 Sep 2019 05:25:32 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 62DC7CFBADBB5743B55A; Fri, 20 Sep 2019 17:25:29 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Fri, 20 Sep 2019 17:25:20 +0800 From: Jason Yan To: , , , , , , , , CC: , , , , , , , Jason Yan Subject: [PATCH v7 04/12] powerpc/fsl_booke/32: introduce create_kaslr_tlb_entry() helper Date: Fri, 20 Sep 2019 17:45:38 +0800 Message-ID: <20190920094546.44948-5-yanaijie@huawei.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190920094546.44948-1-yanaijie@huawei.com> References: <20190920094546.44948-1-yanaijie@huawei.com> 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 Add a new helper create_kaslr_tlb_entry() to create a tlb entry by the virtual and physical address. This is a preparation to support boot kernel at a randomized address. Signed-off-by: Jason Yan Cc: Diana Craciun Cc: Michael Ellerman Cc: Christophe Leroy Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Nicholas Piggin Cc: Kees Cook Reviewed-by: Christophe Leroy Reviewed-by: Diana Craciun Tested-by: Diana Craciun --- arch/powerpc/kernel/head_fsl_booke.S | 35 ++++++++++++++++++++++++++++ arch/powerpc/mm/mmu_decl.h | 1 + 2 files changed, 36 insertions(+) diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index adf0505dbe02..8c1928176ffe 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -1114,6 +1114,41 @@ __secondary_hold_acknowledge: .long -1 #endif +/* + * Create a 64M tlb by address and entry + * r3 - entry + * r4 - virtual address + * r5/r6 - physical address + */ +_GLOBAL(create_kaslr_tlb_entry) + lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */ + rlwimi r7,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r6) */ + mtspr SPRN_MAS0,r7 /* Write MAS0 */ + + lis r3,(MAS1_VALID|MAS1_IPROT)@h + ori r3,r3,(MAS1_TSIZE(BOOK3E_PAGESZ_64M))@l + mtspr SPRN_MAS1,r3 /* Write MAS1 */ + + lis r3,MAS2_EPN_MASK(BOOK3E_PAGESZ_64M)@h + ori r3,r3,MAS2_EPN_MASK(BOOK3E_PAGESZ_64M)@l + and r3,r3,r4 + ori r3,r3,MAS2_M_IF_NEEDED@l + mtspr SPRN_MAS2,r3 /* Write MAS2(EPN) */ + +#ifdef CONFIG_PHYS_64BIT + ori r8,r6,(MAS3_SW|MAS3_SR|MAS3_SX) + mtspr SPRN_MAS3,r8 /* Write MAS3(RPN) */ + mtspr SPRN_MAS7,r5 +#else + ori r8,r5,(MAS3_SW|MAS3_SR|MAS3_SX) + mtspr SPRN_MAS3,r8 /* Write MAS3(RPN) */ +#endif + + tlbwe /* Write TLB */ + isync + sync + blr + /* * Create a tlb entry with the same effective and physical address as * the tlb entry used by the current running code. But set the TS to 1. diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index 32c1a191c28a..a492ece08f64 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h @@ -142,6 +142,7 @@ extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt, extern void adjust_total_lowmem(void); extern int switch_to_as1(void); extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); +void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys); #endif extern void loadcam_entry(unsigned int index); extern void loadcam_multi(int first_idx, int num, int tmp_idx); -- 2.17.2