linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: [PATCH v2 32/45] powerpc/8xx: Always pin TLBs at startup.
Date: Wed,  6 May 2020 16:48:38 +0000 (UTC)	[thread overview]
Message-ID: <f81a41eccde4eb1688eb1c9a9d5a170feba54b2d.1588783498.git.christophe.leroy@csgroup.eu> (raw)
In-Reply-To: <cover.1588783498.git.christophe.leroy@csgroup.eu>

At startup, map 32 Mbytes of memory through 4 pages of 8M,
and PIN them inconditionnaly. They need to be pinned because
KASAN is using page tables early and the TLBs might be
dynamically replaced otherwise.

Remove RSV4I flag after installing mappings unless
CONFIG_PIN_TLB_XXXX is selected.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/kernel/head_8xx.S | 31 +++++++++++++++++--------------
 arch/powerpc/mm/nohash/8xx.c   | 19 +------------------
 2 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index d607f4b53e0f..b0cceee6405c 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -765,6 +765,14 @@ start_here:
 	mtspr	SPRN_MD_RPN, r0
 	lis	r0, (MD_TWAM | MD_RSV4I)@h
 	mtspr	SPRN_MD_CTR, r0
+#endif
+#ifndef CONFIG_PIN_TLB_TEXT
+	li	r0, 0
+	mtspr	SPRN_MI_CTR, r0
+#endif
+#if !defined(CONFIG_PIN_TLB_DATA) && !defined(CONFIG_PIN_TLB_IMMR)
+	lis	r0, MD_TWAM@h
+	mtspr	SPRN_MD_CTR, r0
 #endif
 	tlbia			/* Clear all TLB entries */
 	sync			/* wait for tlbia/tlbie to finish */
@@ -802,10 +810,6 @@ initial_mmu:
 	mtspr	SPRN_MD_CTR, r10	/* remove PINNED DTLB entries */
 
 	tlbia			/* Invalidate all TLB entries */
-#ifdef CONFIG_PIN_TLB_DATA
-	oris	r10, r10, MD_RSV4I@h
-	mtspr	SPRN_MD_CTR, r10	/* Set data TLB control */
-#endif
 
 	lis	r8, MI_APG_INIT@h	/* Set protection modes */
 	ori	r8, r8, MI_APG_INIT@l
@@ -814,33 +818,32 @@ initial_mmu:
 	ori	r8, r8, MD_APG_INIT@l
 	mtspr	SPRN_MD_AP, r8
 
-	/* Now map the lower RAM (up to 32 Mbytes) into the ITLB. */
-#ifdef CONFIG_PIN_TLB_TEXT
+	/* Map the lower RAM (up to 32 Mbytes) into the ITLB and DTLB */
 	lis	r8, MI_RSV4I@h
 	ori	r8, r8, 0x1c00
-#endif
+	oris	r12, r10, MD_RSV4I@h
+	ori	r12, r12, 0x1c00
 	li	r9, 4				/* up to 4 pages of 8M */
 	mtctr	r9
 	lis	r9, KERNELBASE@h		/* Create vaddr for TLB */
 	li	r10, MI_PS8MEG | MI_SVALID	/* Set 8M byte page */
 	li	r11, MI_BOOTINIT		/* Create RPN for address 0 */
-	lis	r12, _einittext@h
-	ori	r12, r12, _einittext@l
 1:
-#ifdef CONFIG_PIN_TLB_TEXT
 	mtspr	SPRN_MI_CTR, r8	/* Set instruction MMU control */
 	addi	r8, r8, 0x100
-#endif
-
 	ori	r0, r9, MI_EVALID		/* Mark it valid */
 	mtspr	SPRN_MI_EPN, r0
 	mtspr	SPRN_MI_TWC, r10
 	mtspr	SPRN_MI_RPN, r11		/* Store TLB entry */
+	mtspr	SPRN_MD_CTR, r12
+	addi	r12, r12, 0x100
+	mtspr	SPRN_MD_EPN, r0
+	mtspr	SPRN_MD_TWC, r10
+	mtspr	SPRN_MD_RPN, r11
 	addis	r9, r9, 0x80
 	addis	r11, r11, 0x80
 
-	cmpl	cr0, r9, r12
-	bdnzf	gt, 1b
+	bdnz	1b
 
 	/* Since the cache is enabled according to the information we
 	 * just loaded into the TLB, invalidate and enable the caches here.
diff --git a/arch/powerpc/mm/nohash/8xx.c b/arch/powerpc/mm/nohash/8xx.c
index d54d395c3378..43578a8a8cad 100644
--- a/arch/powerpc/mm/nohash/8xx.c
+++ b/arch/powerpc/mm/nohash/8xx.c
@@ -61,23 +61,6 @@ unsigned long p_block_mapped(phys_addr_t pa)
  */
 void __init MMU_init_hw(void)
 {
-	/* PIN up to the 3 first 8Mb after IMMR in DTLB table */
-	if (IS_ENABLED(CONFIG_PIN_TLB_DATA)) {
-		unsigned long ctr = mfspr(SPRN_MD_CTR) & 0xfe000000;
-		unsigned long flags = 0xf0 | MD_SPS16K | _PAGE_SH | _PAGE_DIRTY;
-		int i = 28;
-		unsigned long addr = 0;
-		unsigned long mem = total_lowmem;
-
-		for (; i < 32 && mem >= LARGE_PAGE_SIZE_8M; i++) {
-			mtspr(SPRN_MD_CTR, ctr | (i << 8));
-			mtspr(SPRN_MD_EPN, (unsigned long)__va(addr) | MD_EVALID);
-			mtspr(SPRN_MD_TWC, MD_PS8MEG | MD_SVALID);
-			mtspr(SPRN_MD_RPN, addr | flags | _PAGE_PRESENT);
-			addr += LARGE_PAGE_SIZE_8M;
-			mem -= LARGE_PAGE_SIZE_8M;
-		}
-	}
 }
 
 static bool immr_is_mapped __initdata;
@@ -225,7 +208,7 @@ void __init setup_initial_memory_limit(phys_addr_t first_memblock_base,
 	BUG_ON(first_memblock_base != 0);
 
 	/* 8xx can only access 32MB at the moment */
-	memblock_set_current_limit(min_t(u64, first_memblock_size, 0x02000000));
+	memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_32M));
 }
 
 /*
-- 
2.25.0


  parent reply	other threads:[~2020-05-06 16:48 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 16:48 [PATCH v2 00/45] Use hugepages to map kernel mem on 8xx Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 01/45] powerpc/kasan: Fix error detection on memory allocation Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 02/45] powerpc/kasan: Fix issues by lowering KASAN_SHADOW_END Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 03/45] powerpc/kasan: Fix shadow pages allocation failure Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 04/45] powerpc/kasan: Remove unnecessary page table locking Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 05/45] powerpc/kasan: Refactor update of early shadow mappings Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 06/45] powerpc/kasan: Declare kasan_init_region() weak Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 07/45] powerpc/ptdump: Limit size of flags text to 1/2 chars on PPC32 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 08/45] powerpc/ptdump: Reorder flags Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 09/45] powerpc/ptdump: Add _PAGE_COHERENT flag Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 10/45] powerpc/ptdump: Display size of BATs Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 11/45] powerpc/ptdump: Standardise display of BAT flags Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 12/45] powerpc/ptdump: Properly handle non standard page size Christophe Leroy
2020-05-07 16:12   ` kbuild test robot
2020-05-06 16:48 ` [PATCH v2 13/45] powerpc/ptdump: Handle hugepd at PGD level Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 14/45] powerpc/32s: Don't warn when mapping RO data ROX Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 15/45] powerpc/mm: Allocate static page tables for fixmap Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 16/45] powerpc/mm: Fix conditions to perform MMU specific management by blocks on PPC32 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 17/45] powerpc/mm: PTE_ATOMIC_UPDATES is only for 40x Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 18/45] powerpc/mm: Refactor pte_update() on nohash/32 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 19/45] powerpc/mm: Refactor pte_update() on book3s/32 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 20/45] powerpc/mm: Standardise __ptep_test_and_clear_young() params between PPC32 and PPC64 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 21/45] powerpc/mm: Standardise pte_update() prototype " Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 22/45] powerpc/mm: Create a dedicated pte_update() for 8xx Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 23/45] powerpc/mm: Reduce hugepd size for 8M hugepages on 8xx Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 24/45] powerpc/8xx: Drop CONFIG_8xx_COPYBACK option Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 25/45] powerpc/8xx: Prepare handlers for _PAGE_HUGE for 512k pages Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 26/45] powerpc/8xx: Manage 512k huge pages as standard pages Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 27/45] powerpc/8xx: Only 8M pages are hugepte pages now Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 28/45] powerpc/8xx: MM_SLICE is not needed anymore Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 29/45] powerpc/8xx: Move PPC_PIN_TLB options into 8xx Kconfig Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 30/45] powerpc/8xx: Add function to set pinned TLBs Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 31/45] powerpc/8xx: Don't set IMMR map anymore at boot Christophe Leroy
2020-05-06 16:48 ` Christophe Leroy [this message]
2020-05-06 16:48 ` [PATCH v2 33/45] powerpc/8xx: Drop special handling of Linear and IMMR mappings in I/D TLB handlers Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 34/45] powerpc/8xx: Remove now unused TLB miss functions Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 35/45] powerpc/8xx: Move DTLB perf handling closer Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 36/45] powerpc/mm: Don't be too strict with _etext alignment on PPC32 Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 37/45] powerpc/8xx: Refactor kernel address boundary comparison Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 38/45] powerpc/8xx: Add a function to early map kernel via huge pages Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 39/45] powerpc/8xx: Map IMMR with a huge page Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 40/45] powerpc/8xx: Map linear memory with huge pages Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 41/45] powerpc/8xx: Allow STRICT_KERNEL_RwX with pinned TLB Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 42/45] powerpc/8xx: Allow large TLBs with DEBUG_PAGEALLOC Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 43/45] powerpc/8xx: Implement dedicated kasan_init_region() Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 44/45] powerpc/32s: Allow mapping with BATs with DEBUG_PAGEALLOC Christophe Leroy
2020-05-06 16:48 ` [PATCH v2 45/45] powerpc/32s: Implement dedicated kasan_init_region() Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f81a41eccde4eb1688eb1c9a9d5a170feba54b2d.1588783498.git.christophe.leroy@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).