linuxppc-dev.lists.ozlabs.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: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 30/45] powerpc/8xx: Add function to set pinned TLBs
Date: Mon, 11 May 2020 11:25:56 +0000 (UTC)	[thread overview]
Message-ID: <ece43d638800c538ec01a3f7f7eb91d9e27fb8ce.1589196133.git.christophe.leroy@csgroup.eu> (raw)
In-Reply-To: <cover.1589196133.git.christophe.leroy@csgroup.eu>

Pinned TLBs cannot be modified when the MMU is enabled.

Create a function to rewrite the pinned TLB entries with MMU off.

To set pinned TLB, we have to turn off MMU, disable pinning,
do a TLB flush (Either with tlbie and tlbia) then reprogam
the TLB entries, enable pinning and turn on MMU.

If using tlbie, it cleared entries in both instruction and data
TLB regardless whether pinning is disabled or not.
If using tlbia, it clears all entries of the TLB which has
disabled pinning.

To make it easy, just clear all entries in both TLBs, and
reprogram them.

The function takes two arguments, the top of the memory to
consider and whether data is RO under _sinittext.
When DEBUG_PAGEALLOC is set, the top is the end of kernel rodata.
Otherwise, that's the top of physical RAM.

Everything below _sinittext is set RX, over _sinittext that's RW.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v2: Function rewritten to manage all entries at once.
---
 arch/powerpc/include/asm/nohash/32/mmu-8xx.h |   2 +
 arch/powerpc/kernel/head_8xx.S               | 103 +++++++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/arch/powerpc/include/asm/nohash/32/mmu-8xx.h b/arch/powerpc/include/asm/nohash/32/mmu-8xx.h
index a092e6434bda..4d3ef3841b00 100644
--- a/arch/powerpc/include/asm/nohash/32/mmu-8xx.h
+++ b/arch/powerpc/include/asm/nohash/32/mmu-8xx.h
@@ -193,6 +193,8 @@
 
 #include <linux/mmdebug.h>
 
+void mmu_pin_tlb(unsigned long top, bool readonly);
+
 typedef struct {
 	unsigned int id;
 	unsigned int active;
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 423465b10c82..c9e3d54e6a6f 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -16,6 +16,7 @@
 
 #include <linux/init.h>
 #include <linux/magic.h>
+#include <linux/sizes.h>
 #include <asm/processor.h>
 #include <asm/page.h>
 #include <asm/mmu.h>
@@ -866,6 +867,108 @@ initial_mmu:
 	mtspr	SPRN_DER, r8
 	blr
 
+#ifdef CONFIG_PIN_TLB
+_GLOBAL(mmu_pin_tlb)
+	lis	r9, (1f - PAGE_OFFSET)@h
+	ori	r9, r9, (1f - PAGE_OFFSET)@l
+	mfmsr	r10
+	mflr	r11
+	li	r12, MSR_KERNEL & ~(MSR_IR | MSR_DR | MSR_RI)
+	rlwinm	r0, r10, 0, ~MSR_RI
+	rlwinm	r0, r0, 0, ~MSR_EE
+	mtmsr	r0
+	isync
+	.align	4
+	mtspr	SPRN_SRR0, r9
+	mtspr	SPRN_SRR1, r12
+	rfi
+1:
+	li	r5, 0
+	lis	r6, MD_TWAM@h
+	mtspr	SPRN_MI_CTR, r5
+	mtspr	SPRN_MD_CTR, r6
+	tlbia
+
+#ifdef CONFIG_PIN_TLB_TEXT
+	LOAD_REG_IMMEDIATE(r5, 28 << 8)
+	LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
+	LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG)
+	LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT)
+	LOAD_REG_ADDR(r9, _sinittext)
+	li	r0, 4
+	mtctr	r0
+
+2:	ori	r0, r6, MI_EVALID
+	mtspr	SPRN_MI_CTR, r5
+	mtspr	SPRN_MI_EPN, r0
+	mtspr	SPRN_MI_TWC, r7
+	mtspr	SPRN_MI_RPN, r8
+	addi	r5, r5, 0x100
+	addis	r6, r6, SZ_8M@h
+	addis	r8, r8, SZ_8M@h
+	cmplw	r6, r9
+	bdnzt	lt, 2b
+	lis	r0, MI_RSV4I@h
+	mtspr	SPRN_MI_CTR, r0
+#endif
+	LOAD_REG_IMMEDIATE(r5, 28 << 8 | MD_TWAM)
+#ifdef CONFIG_PIN_TLB_DATA
+	LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
+	LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG)
+#ifdef CONFIG_PIN_TLB_IMMR
+	li	r0, 3
+#else
+	li	r0, 4
+#endif
+	mtctr	r0
+	cmpwi	r4, 0
+	beq	4f
+	LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT)
+	LOAD_REG_ADDR(r9, _sinittext)
+
+2:	ori	r0, r6, MD_EVALID
+	mtspr	SPRN_MD_CTR, r5
+	mtspr	SPRN_MD_EPN, r0
+	mtspr	SPRN_MD_TWC, r7
+	mtspr	SPRN_MD_RPN, r8
+	addi	r5, r5, 0x100
+	addis	r6, r6, SZ_8M@h
+	addis	r8, r8, SZ_8M@h
+	cmplw	r6, r9
+	bdnzt	lt, 2b
+
+4:	LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT)
+2:	ori	r0, r6, MD_EVALID
+	mtspr	SPRN_MD_CTR, r5
+	mtspr	SPRN_MD_EPN, r0
+	mtspr	SPRN_MD_TWC, r7
+	mtspr	SPRN_MD_RPN, r8
+	addi	r5, r5, 0x100
+	addis	r6, r6, SZ_8M@h
+	addis	r8, r8, SZ_8M@h
+	cmplw	r6, r3
+	bdnzt	lt, 2b
+#endif
+#ifdef CONFIG_PIN_TLB_IMMR
+	LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID)
+	LOAD_REG_IMMEDIATE(r7, MD_SVALID | MD_PS512K | MD_GUARDED)
+	mfspr   r8, SPRN_IMMR
+	rlwinm	r8, r8, 0, 0xfff80000
+	ori	r8, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \
+			_PAGE_NO_CACHE | _PAGE_PRESENT
+	mtspr	SPRN_MD_CTR, r5
+	mtspr	SPRN_MD_EPN, r0
+	mtspr	SPRN_MD_TWC, r7
+	mtspr	SPRN_MD_RPN, r8
+#endif
+#if defined(CONFIG_PIN_TLB_IMMR) || defined(CONFIG_PIN_TLB_DATA)
+	lis	r0, (MD_RSV4I | MD_TWAM)@h
+	mtspr	SPRN_MI_CTR, r0
+#endif
+	mtspr	SPRN_SRR1, r10
+	mtspr	SPRN_SRR0, r11
+	rfi
+#endif /* CONFIG_PIN_TLB */
 
 /*
  * We put a few things here that have to be page-aligned.
-- 
2.25.0


  parent reply	other threads:[~2020-05-11 13:04 UTC|newest]

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