From patchwork Sat Jul 18 20:08:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 497399 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E04DD140B0E for ; Sun, 19 Jul 2015 06:11:41 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id C70D01A1D0A for ; Sun, 19 Jul 2015 06:11:41 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0130.outbound.protection.outlook.com [157.56.110.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id B31BA1A0CEC for ; Sun, 19 Jul 2015 06:09:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=none (message not signed) header.d=none; Received: from snotra.am.freescale.net (192.88.168.49) by CY1PR03MB1486.namprd03.prod.outlook.com (10.163.17.16) with Microsoft SMTP Server (TLS) id 15.1.213.14; Sat, 18 Jul 2015 20:09:12 +0000 From: Scott Wood To: Subject: [RFC PATCH 01/17] powerpc/85xx: Load all early TLB entries at once Date: Sat, 18 Jul 2015 15:08:38 -0500 Message-ID: <1437250134-307-2-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437250134-307-1-git-send-email-scottwood@freescale.com> References: <1437250134-307-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-Originating-IP: [192.88.168.49] X-ClientProxiedBy: BY2PR21CA0002.namprd21.prod.outlook.com (25.162.74.140) To CY1PR03MB1486.namprd03.prod.outlook.com (25.163.17.16) X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1486; 2:LgiI1nFW2scGI2z6DbeTZzUdFJ2NDSDE2T4dYdKbkku3DxxnZtyfFu4QRowSAVJn; 3:/oAqE2F04EGwdDorcAW2YWSx9kREegrO82TTRRQ6PatsIAARBmT5QvUviANtWEEepYYLRzWh0XEHvsab+gY9KnQPL7VuUpSQ/7T9oOOrPrEr1epnYkfutTqCJsPD5dqLF5BfZxLly/hQrcP3D9WgDw==; 25:78XADrBEUkOMMPqjYJ2UWysgE8pASnkQbSsMBFc209DiVkuh8PfYBvJxEzHe8LxLsaLrmEilMqNCglvebGlDAn38BoJ2eljKcx3hQudq0GEiU8iOWgymOlS2k4YXJHWgsYgMN1uLRsLD9SG283bgLEWsTE/0V6DJN8MR1XMxNRgXS7G0kWUBh2ik+knegLMyHQFMSL3UEeu9slHL+o6/afuqNm687o642td1UeTWlfgb4SJCSdUT4nhdCkxBkSZ4SF1se7Ikf1gLxPZhwCzSuQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1486; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1486; 20:QOFMPX2ecV124OUGnwa5lBlQ973L85h+Unyz74KKgfl/dpIiY+oPjlxLTbgHTVnZ7XQX+0uZ7MrAwfrjj4wqgZpID3+XA8XezY04Zyo5LKL7oKBkJtfohOnLpx8IbuQOoMccP7HreRIXqy8TPrH3MxC/1EgpNvApuPjt6FvKKH3ISqi9j8BdgY+JBET7dOeWwasDmV1EANl13P6un5L94PpuCB+jI+jfu4/aycOFldzOxHhkJvYg8Ea+5BBv2YgUuB2Lv3YosavwlD8/rtkUsV1gaf+kVS3mAx03FoEBvKmTlr51tD8oX/m5+llrKRkw+ZV8j1nmZ8S2H442dKZU9sG3qFjoi67fNia73vW9SMvXZxo96YqZezt+2u91/3pApjW0EmqlJWNR2xo4gAuSo1rlGXX2s8EKRmBBej/CB2p7mTAQGFZaiGnlWRJ0t9I7JX55ajc41CWgA9KeWJOxbTBOsqjNM7oGgqUNGKSyrU8xTo54GJAn5wP2/sRdvWXe; 4:QWeEf+4/g847WX/L536AvNsY/ugFm8bKGez6nhEN6me60tRP6P7XnYsj9AGffj5e/YKBT/BRyOGdBROqMZLgUhF/YhyO8cfHlJLIG557l+MavcOoKmeLEc/t3XPHJQm6SnZJIvQM/m7sLT0yqWI4O4ZRQT4e7zjyqsVRNW/o8ID78ogzQK/vxPgHcWjgNkzSVZas+XeCQXipBrRZogVCNTd+YRXSjnxxBBONiHOx+k4KzNKKdEfrbnuGsPJdNACaKKReaay1xuqS9Gxq5cJ+b/AOJy+1vKhJVM1aDPe3Zac= CY1PR03MB1486: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:CY1PR03MB1486; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1486; X-Forefront-PRVS: 0641678E68 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(19580395003)(50466002)(19580405001)(229853001)(36756003)(46102003)(2351001)(42186005)(40100003)(87976001)(122386002)(33646002)(86362001)(62966003)(5001960100002)(5001920100001)(92566002)(2950100001)(110136002)(77096005)(107886002)(48376002)(77156002)(50986999)(76176999)(66066001)(47776003)(50226001)(5003940100001)(189998001)(217873001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB1486; H:snotra.am.freescale.net; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1486; 23:TNTjCqoGDdkOKwIjLbHS1tNGIVDxByg+WUiPWMkuv4x/5Bg9fehNDFDSWkg0xw3MTPU0CuWUSAbjXlE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IFiCBuRy+WKa0TXRcmBwRW2WUQ/QBJjrtNjht9C/vJaD2o/85auqTyGuSACwWg4ajcQpcWhsRgcPOwPf3cQlwLxr1c=; 20:3I7hhqADoV+ohb2efyy/oGO07j0CsYDpDSe6guV/U/8jyqKLlxPrPTzSWPC7H8RyD0w5CPz/TGWYOCfNU1YYLA== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2015 20:09:12.8547 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1486 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Scott Wood , Tiejun Chen , kexec@lists.infradead.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Use an AS=1 trampoline TLB entry to allow all normal TLB1 entries to be loaded at once. This avoids the need to keep the translation that code is executing from in the same TLB entry in the final TLB configuration as during early boot, which in turn is helpful for relocatable kernels (e.g. kdump) where the kernel is not running from what would be the first TLB entry. On e6500, we limit map_mem_in_cams() to the primary hwthread of a core (the boot cpu is always considered primary, as a kdump kernel can be entered on any cpu), Each TLB only needs to be set up once, and when we do, we don't want another thread to be running when we create a temporary trampoline TLB1 entry. Signed-off-by: Scott Wood --- arch/powerpc/kernel/setup_64.c | 8 +++++ arch/powerpc/mm/fsl_booke_mmu.c | 15 ++++++++-- arch/powerpc/mm/mmu_decl.h | 1 + arch/powerpc/mm/tlb_nohash.c | 19 +++++++++++- arch/powerpc/mm/tlb_nohash_low.S | 63 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index bdcbb71..505ec2c 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -108,6 +108,14 @@ static void setup_tlb_core_data(void) for_each_possible_cpu(cpu) { int first = cpu_first_thread_sibling(cpu); + /* + * If we boot via kdump on a non-primary thread, + * make sure we point at the thread that actually + * set up this TLB. + */ + if (cpu_first_thread_sibling(boot_cpuid) == first) + first = boot_cpuid; + paca[cpu].tcd_ptr = &paca[first].tcd; /* diff --git a/arch/powerpc/mm/fsl_booke_mmu.c b/arch/powerpc/mm/fsl_booke_mmu.c index 354ba3c..36d3c55 100644 --- a/arch/powerpc/mm/fsl_booke_mmu.c +++ b/arch/powerpc/mm/fsl_booke_mmu.c @@ -105,8 +105,9 @@ unsigned long p_mapped_by_tlbcam(phys_addr_t pa) * an unsigned long (for example, 32-bit implementations cannot support a 4GB * size). */ -static void settlbcam(int index, unsigned long virt, phys_addr_t phys, - unsigned long size, unsigned long flags, unsigned int pid) +static void preptlbcam(int index, unsigned long virt, phys_addr_t phys, + unsigned long size, unsigned long flags, + unsigned int pid) { unsigned int tsize; @@ -141,7 +142,13 @@ static void settlbcam(int index, unsigned long virt, phys_addr_t phys, tlbcam_addrs[index].start = virt; tlbcam_addrs[index].limit = virt + size - 1; tlbcam_addrs[index].phys = phys; +} +void settlbcam(int index, unsigned long virt, phys_addr_t phys, + unsigned long size, unsigned long flags, + unsigned int pid) +{ + preptlbcam(index, virt, phys, size, flags, pid); loadcam_entry(index); } @@ -181,13 +188,15 @@ static unsigned long map_mem_in_cams_addr(phys_addr_t phys, unsigned long virt, unsigned long cam_sz; cam_sz = calc_cam_sz(ram, virt, phys); - settlbcam(i, virt, phys, cam_sz, pgprot_val(PAGE_KERNEL_X), 0); + preptlbcam(i, virt, phys, cam_sz, pgprot_val(PAGE_KERNEL_X), 0); ram -= cam_sz; amount_mapped += cam_sz; virt += cam_sz; phys += cam_sz; } + + loadcam_multi(0, i, max_cam_idx); tlbcam_index = i; #ifdef CONFIG_PPC64 diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index 085b66b..27c3a2d 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h @@ -152,6 +152,7 @@ extern int switch_to_as1(void); extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); #endif extern void loadcam_entry(unsigned int index); +extern void loadcam_multi(int first_idx, int num, int tmp_idx); struct tlbcam { u32 MAS0; diff --git a/arch/powerpc/mm/tlb_nohash.c b/arch/powerpc/mm/tlb_nohash.c index 723a099..a7381fb 100644 --- a/arch/powerpc/mm/tlb_nohash.c +++ b/arch/powerpc/mm/tlb_nohash.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -628,10 +629,26 @@ static void early_init_this_mmu(void) #ifdef CONFIG_PPC_FSL_BOOK3E if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) { unsigned int num_cams; + int __maybe_unused cpu = smp_processor_id(); + bool map = true; /* use a quarter of the TLBCAM for bolted linear map */ num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4; - linear_map_top = map_mem_in_cams(linear_map_top, num_cams); + + /* + * Only do the mapping once per core, or else the + * transient mapping would cause problems. + */ +#ifdef CONFIG_SMP + if (cpu != boot_cpuid && + (cpu != cpu_first_thread_sibling(cpu) || + cpu == cpu_first_thread_sibling(boot_cpuid))) + map = false; +#endif + + if (map) + linear_map_top = map_mem_in_cams(linear_map_top, + num_cams); } #endif diff --git a/arch/powerpc/mm/tlb_nohash_low.S b/arch/powerpc/mm/tlb_nohash_low.S index 43ff3c7..68c4775 100644 --- a/arch/powerpc/mm/tlb_nohash_low.S +++ b/arch/powerpc/mm/tlb_nohash_low.S @@ -400,6 +400,7 @@ _GLOBAL(set_context) * extern void loadcam_entry(unsigned int index) * * Load TLBCAM[index] entry in to the L2 CAM MMU + * Must preserve r7, r8, r9, and r10 */ _GLOBAL(loadcam_entry) mflr r5 @@ -423,4 +424,66 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS) tlbwe isync blr + +/* + * Load multiple TLB entries at once, using an alternate-space + * trampoline so that we don't have to care about whether the same + * TLB entry maps us before and after. + * + * r3 = first entry to write + * r4 = number of entries to write + * r5 = temporary tlb entry + */ +_GLOBAL(loadcam_multi) + mflr r8 + + /* + * Set up temporary TLB entry that is the same as what we're + * running from, but in AS=1. + */ + bl 1f +1: mflr r6 + tlbsx 0,r8 + mfspr r6,SPRN_MAS1 + ori r6,r6,MAS1_TS + mtspr SPRN_MAS1,r6 + mfspr r6,SPRN_MAS0 + rlwimi r6,r5,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK + mr r7,r5 + mtspr SPRN_MAS0,r6 + isync + tlbwe + isync + + /* Switch to AS=1 */ + mfmsr r6 + ori r6,r6,MSR_IS|MSR_DS + mtmsr r6 + isync + + mr r9,r3 + add r10,r3,r4 +2: bl loadcam_entry + addi r9,r9,1 + cmpw r9,r10 + mr r3,r9 + blt 2b + + /* Return to AS=0 and clear the temporary entry */ + mfmsr r6 + rlwinm. r6,r6,0,~(MSR_IS|MSR_DS) + mtmsr r6 + isync + + li r6,0 + mtspr SPRN_MAS1,r6 + rlwinm r6,r7,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK + oris r6,r6,MAS0_TLBSEL(1)@h + mtspr SPRN_MAS0,r6 + isync + tlbwe + isync + + mtlr r8 + blr #endif