Skip to contentSkip to conversation

Radix pte update tlbflush optimizations.

PATCH Superseded Aneesh Kumar K.V 1 participant 9 messages Nov 25, 2016 – Nov 26, 2016 PowerPC

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover Radix pte update tlbflush optimizations.

Changes from V5:
Switch to use pte bits to track page size.

Aneesh Kumar K.V (7):
powerpc/mm: Rename hugetlb-radix.h to hugetlb.h powerpc/mm/hugetlb: Handle hugepage size supported by hash config powerpc/mm: Introduce _PAGE_GIGANTIC and _PAGE_LARGE software pte bits powerpc/mm: Add radix__tlb_flush_pte
powerpc/mm: update radix__ptep_set_access_flag to not do full mm tlb
flush
powerpc/mm: update radix__pte_update to not do full mm tlb flush powerpc/mm: Batch tlb flush when invalidating pte entries

 arch/powerpc/include/asm/book3s/32/pgtable.h       |  3 ++-
 .../asm/book3s/64/{hugetlb-radix.h => hugetlb.h}   | 21 ++++++++++++++--
 arch/powerpc/include/asm/book3s/64/pgtable.h       | 15 ++++++++++--
 arch/powerpc/include/asm/book3s/64/radix.h         | 28 ++++++++++------------
 .../powerpc/include/asm/book3s/64/tlbflush-radix.h |  2 ++
 arch/powerpc/include/asm/hugetlb.h                 |  2 +-
 arch/powerpc/include/asm/nohash/32/pgtable.h       |  3 ++-
 arch/powerpc/include/asm/nohash/64/pgtable.h       |  3 ++-
 arch/powerpc/mm/pgtable-book3s64.c                 |  3 ++-
 arch/powerpc/mm/pgtable.c                          |  2 +-
 arch/powerpc/mm/tlb-radix.c                        | 11 +++++++++
 11 files changed, 67 insertions(+), 26 deletions(-)
 rename arch/powerpc/include/asm/book3s/64/{hugetlb-radix.h => hugetlb.h} (55%)
Signature · 1 line
2.10.2
#1 lore raw

PATCH v6 1/7 powerpc/mm: Rename hugetlb-radix.h to hugetlb.h

We will start moving some book3s specific hugetlb functions there.

---
 arch/powerpc/include/asm/book3s/64/{hugetlb-radix.h => hugetlb.h} | 4 ++--
 arch/powerpc/include/asm/hugetlb.h                                | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
 rename arch/powerpc/include/asm/book3s/64/{hugetlb-radix.h => hugetlb.h} (90%)
arch/powerpc/include/asm/book3s/64/hugetlb.h renamed from arch/powerpc/include/asm/book3s/64/hugetlb-radix.h +2 -2
similarity index 90%
rename from arch/powerpc/include/asm/book3s/64/hugetlb-radix.h
rename to arch/powerpc/include/asm/book3s/64/hugetlb.h
index c45189aa7476..499268045306 100644
@@ -1,5 +1,5 @@
-#ifndef _ASM_POWERPC_BOOK3S_64_HUGETLB_RADIX_H
-#define _ASM_POWERPC_BOOK3S_64_HUGETLB_RADIX_H
+#ifndef _ASM_POWERPC_BOOK3S_64_HUGETLB_H
+#define _ASM_POWERPC_BOOK3S_64_HUGETLB_H
 /*
  * For radix we want generic code to handle hugetlb. But then if we want
  * both hash and radix to be enabled together we need to workaround the
arch/powerpc/include/asm/hugetlb.h +1 -1
index c5517f463ec7..c03e0a3dd4d8 100644
@@ -9,7 +9,7 @@ extern struct kmem_cache *hugepte_cache;
 
 #ifdef CONFIG_PPC_BOOK3S_64
 
-#include <asm/book3s/64/hugetlb-radix.h>
+#include <asm/book3s/64/hugetlb.h>
 /*
  * This should work for other subarchs too. But right now we use the
  * new format only for 64bit book3s
Signature · 1 line
2.10.2
#2 lore raw

PATCH v6 2/7 powerpc/mm/hugetlb: Handle hugepage size supported by hash config

In reply to Aneesh Kumar K.V

W.r.t hash page table config, we support 16MB and 16GB as the hugepage size. Update the hstate_get_psize to handle 16M and 16G.

---
 arch/powerpc/include/asm/book3s/64/hugetlb.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/include/asm/book3s/64/hugetlb.h +4 -0
index 499268045306..d9c283f95e05 100644
@@ -21,6 +21,10 @@ static inline int hstate_get_psize(struct hstate *hstate)
 		return MMU_PAGE_2M;
 	else if (shift == mmu_psize_defs[MMU_PAGE_1G].shift)
 		return MMU_PAGE_1G;
+	else if (shift == mmu_psize_defs[MMU_PAGE_16M].shift)
+		return MMU_PAGE_16M;
+	else if (shift == mmu_psize_defs[MMU_PAGE_16G].shift)
+		return MMU_PAGE_16G;
 	else {
 		WARN(1, "Wrong huge page shift\n");
 		return mmu_virtual_psize;
Signature · 1 line
2.10.2
#3 lore raw

PATCH v6 3/7 powerpc/mm: Introduce _PAGE_GIGANTIC and _PAGE_LARGE software pte bits

In reply to Aneesh Kumar K.V

This patch adds two new software defined pte bits. We use the reserved fields of ISA 3.0 pte definitions here, because we will only be using this on DD1 code paths. We can possibly look at removing this code later.

These two software bits will be used to differentiate between 64K, 2M and 1G ptes. We need to know the page size mapping pte so that we can do efficient tlb flush.

---
 arch/powerpc/include/asm/book3s/64/hugetlb.h | 13 +++++++++++++
 arch/powerpc/include/asm/book3s/64/pgtable.h | 10 ++++++++++
 arch/powerpc/include/asm/book3s/64/radix.h   |  2 +-
 3 files changed, 24 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/hugetlb.h +13 -0
index d9c283f95e05..f246dadaf1f9 100644
@@ -30,4 +30,17 @@ static inline int hstate_get_psize(struct hstate *hstate)
 		return mmu_virtual_psize;
 	}
 }
+
+#define arch_make_huge_pte arch_make_huge_pte
+static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
+				       struct page *page, int writable)
+{
+	unsigned long page_shift = huge_page_shift(hstate_vma(vma));
+
+	if (page_shift == mmu_psize_defs[MMU_PAGE_2M].shift ||
+	    page_shift == mmu_psize_defs[MMU_PAGE_16M].shift)
+		return __pte(pte_val(entry) | _PAGE_LARGE);
+	else
+		return __pte(pte_val(entry) | _PAGE_GIGANTIC);
+}
 #endif
arch/powerpc/include/asm/book3s/64/pgtable.h +10 -0
index 86870c11917b..e05028894a8e 100644
@@ -26,6 +26,11 @@
 #define _RPAGE_SW1		0x00800
 #define _RPAGE_SW2		0x00400
 #define _RPAGE_SW3		0x00200
+#define _RPAGE_RSV1		0x1000000000000000UL
+#define _RPAGE_RSV2		0x0800000000000000UL
+#define _RPAGE_RSV3		0x0400000000000000UL
+#define _RPAGE_RSV4		0x0200000000000000UL
+
 #ifdef CONFIG_MEM_SOFT_DIRTY
 #define _PAGE_SOFT_DIRTY	_RPAGE_SW3 /* software: software dirty tracking */
 #else
@@ -34,6 +39,11 @@
 #define _PAGE_SPECIAL		_RPAGE_SW2 /* software: special page */
 #define _PAGE_DEVMAP		_RPAGE_SW1
 #define __HAVE_ARCH_PTE_DEVMAP
+/*
+ * For DD1 only, we need to track whether the pte huge or gigantic.
+ */
+#define _PAGE_GIGANTIC	_RPAGE_RSV1
+#define _PAGE_LARGE	_RPAGE_RSV2
 
 
 #define _PAGE_PTE		(1ul << 62)	/* distinguishes PTEs from pointers */
arch/powerpc/include/asm/book3s/64/radix.h +1 -1
index 2a46dea8e1b1..de009387e258 100644
@@ -243,7 +243,7 @@ static inline int radix__pmd_trans_huge(pmd_t pmd)
 
 static inline pmd_t radix__pmd_mkhuge(pmd_t pmd)
 {
-	return __pmd(pmd_val(pmd) | _PAGE_PTE);
+	return __pmd(pmd_val(pmd) | _PAGE_PTE | _PAGE_LARGE);
 }
 static inline void radix__pmdp_huge_split_prepare(struct vm_area_struct *vma,
 					    unsigned long address, pmd_t *pmdp)
Signature · 1 line
2.10.2
#4 lore raw

PATCH v6 4/7 powerpc/mm: Add radix__tlb_flush_pte

In reply to Aneesh Kumar K.V

Now that we have page size details encoded in pte using software pte bits, use that to find page size needed for tlb flush.

---
 arch/powerpc/include/asm/book3s/64/tlbflush-radix.h |  2 ++
 arch/powerpc/mm/tlb-radix.c                         | 11 +++++++++++
 2 files changed, 13 insertions(+)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +2 -0
index a9e19cb2f7c5..e9bbd10ee7e9 100644
@@ -42,4 +42,6 @@ extern void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
 				     unsigned long page_size);
 extern void radix__flush_tlb_lpid(unsigned long lpid);
 extern void radix__flush_tlb_all(void);
+extern void radix__flush_tlb_pte(unsigned long old_pte, struct mm_struct *mm,
+				 unsigned long address);
 #endif
arch/powerpc/mm/tlb-radix.c +11 -0
index 3493cf4e0452..9a1084b45bb5 100644
@@ -428,3 +428,14 @@ void radix__flush_tlb_all(void)
 		     : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory");
 	asm volatile("eieio; tlbsync; ptesync": : :"memory");
 }
+
+void radix__flush_tlb_pte(unsigned long old_pte, struct mm_struct *mm,
+			  unsigned long address)
+{
+	if (old_pte & _PAGE_LARGE)
+		radix__flush_tlb_page_psize(mm, address, MMU_PAGE_2M);
+	else if (old_pte & _PAGE_GIGANTIC)
+		radix__flush_tlb_page_psize(mm, address, MMU_PAGE_1G);
+	else
+		radix__flush_tlb_page_psize(mm, address, mmu_virtual_psize);
+}
Signature · 1 line
2.10.2
#5 lore raw

PATCH v6 5/7 powerpc/mm: update radix__ptep_set_access_flag to not do full mm tlb flush

In reply to Aneesh Kumar K.V

When we are updating pte, we just need to flush the tlb mapping for that pte. Right now we do a full mm flush because we don't track page size. Now that we have page size details in pte use that to do the optimized flush

---
 arch/powerpc/include/asm/book3s/32/pgtable.h |  3 ++-
 arch/powerpc/include/asm/book3s/64/pgtable.h |  5 +++--
 arch/powerpc/include/asm/book3s/64/radix.h   | 11 +++--------
 arch/powerpc/include/asm/nohash/32/pgtable.h |  3 ++-
 arch/powerpc/include/asm/nohash/64/pgtable.h |  3 ++-
 arch/powerpc/mm/pgtable-book3s64.c           |  3 ++-
 arch/powerpc/mm/pgtable.c                    |  2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +2 -1
index 6b8b2d57fdc8..dc58980f3ad9 100644
@@ -224,7 +224,8 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
 
 
 static inline void __ptep_set_access_flags(struct mm_struct *mm,
-					   pte_t *ptep, pte_t entry)
+					   pte_t *ptep, pte_t entry,
+					   unsigned long address)
 {
 	unsigned long set = pte_val(entry) &
 		(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -2
index e05028894a8e..7f4356de5ce1 100644
@@ -590,10 +590,11 @@ static inline bool check_pte_access(unsigned long access, unsigned long ptev)
  */
 
 static inline void __ptep_set_access_flags(struct mm_struct *mm,
-					   pte_t *ptep, pte_t entry)
+					   pte_t *ptep, pte_t entry,
+					   unsigned long address)
 {
 	if (radix_enabled())
-		return radix__ptep_set_access_flags(mm, ptep, entry);
+		return radix__ptep_set_access_flags(mm, ptep, entry, address);
 	return hash__ptep_set_access_flags(ptep, entry);
 }
 
arch/powerpc/include/asm/book3s/64/radix.h +3 -8
index de009387e258..08eaceb430ee 100644
@@ -167,7 +167,8 @@ static inline unsigned long radix__pte_update(struct mm_struct *mm,
  * function doesn't need to invalidate tlb.
  */
 static inline void radix__ptep_set_access_flags(struct mm_struct *mm,
-						pte_t *ptep, pte_t entry)
+						pte_t *ptep, pte_t entry,
+						unsigned long address)
 {
 
 	unsigned long set = pte_val(entry) & (_PAGE_DIRTY | _PAGE_ACCESSED |
@@ -183,13 +184,7 @@ static inline void radix__ptep_set_access_flags(struct mm_struct *mm,
 		 * new value of pte
 		 */
 		new_pte = old_pte | set;
-
-		/*
-		 * For now let's do heavy pid flush
-		 * radix__flush_tlb_page_psize(mm, addr, mmu_virtual_psize);
-		 */
-		radix__flush_tlb_mm(mm);
-
+		radix__flush_tlb_pte(old_pte, mm, address);
 		__radix_pte_update(ptep, 0, new_pte);
 	} else
 		__radix_pte_update(ptep, 0, set);
arch/powerpc/include/asm/nohash/32/pgtable.h +2 -1
index c219ef7be53b..65073fbc6707 100644
@@ -268,7 +268,8 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
 
 
 static inline void __ptep_set_access_flags(struct mm_struct *mm,
-					   pte_t *ptep, pte_t entry)
+					   pte_t *ptep, pte_t entry,
+					   unsigned long address)
 {
 	unsigned long set = pte_val(entry) &
 		(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
arch/powerpc/include/asm/nohash/64/pgtable.h +2 -1
index 653a1838469d..ea1c0123b85c 100644
@@ -301,7 +301,8 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  * function doesn't need to flush the hash entry
  */
 static inline void __ptep_set_access_flags(struct mm_struct *mm,
-					   pte_t *ptep, pte_t entry)
+					   pte_t *ptep, pte_t entry,
+					   unsigned long address)
 {
 	unsigned long bits = pte_val(entry) &
 		(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
arch/powerpc/mm/pgtable-book3s64.c +2 -1
index f4f437cbabf1..ebf9782bacf9 100644
@@ -35,7 +35,8 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
 #endif
 	changed = !pmd_same(*(pmdp), entry);
 	if (changed) {
-		__ptep_set_access_flags(vma->vm_mm, pmdp_ptep(pmdp), pmd_pte(entry));
+		__ptep_set_access_flags(vma->vm_mm, pmdp_ptep(pmdp),
+					pmd_pte(entry), address);
 		flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
 	}
 	return changed;
arch/powerpc/mm/pgtable.c +1 -1
index 911fdfb63ec1..cb39c8bd2436 100644
@@ -224,7 +224,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
 	if (changed) {
 		if (!is_vm_hugetlb_page(vma))
 			assert_pte_locked(vma->vm_mm, address);
-		__ptep_set_access_flags(vma->vm_mm, ptep, entry);
+		__ptep_set_access_flags(vma->vm_mm, ptep, entry, address);
 		flush_tlb_page(vma, address);
 	}
 	return changed;
Signature · 1 line
2.10.2
#6 lore raw

PATCH v6 6/7 powerpc/mm: update radix__pte_update to not do full mm tlb flush

In reply to Aneesh Kumar K.V

When we are updating pte, we just need to flush the tlb mapping for that pte. Right now we do a full mm flush because we don't track page size. Now that we have page size details in pte use that to do the optimized flush

---
 arch/powerpc/include/asm/book3s/64/radix.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
arch/powerpc/include/asm/book3s/64/radix.h +1 -7
index 08eaceb430ee..c0d43766ec63 100644
@@ -145,13 +145,7 @@ static inline unsigned long radix__pte_update(struct mm_struct *mm,
 		 * new value of pte
 		 */
 		new_pte = (old_pte | set) & ~clr;
-
-		/*
-		 * For now let's do heavy pid flush
-		 * radix__flush_tlb_page_psize(mm, addr, mmu_virtual_psize);
-		 */
-		radix__flush_tlb_mm(mm);
-
+		radix__flush_tlb_pte(old_pte, mm, addr);
 		__radix_pte_update(ptep, 0, new_pte);
 	} else
 		old_pte = __radix_pte_update(ptep, clr, set);
Signature · 1 line
2.10.2
#7 lore raw

PATCH v6 7/7 powerpc/mm: Batch tlb flush when invalidating pte entries

In reply to Aneesh Kumar K.V

This will improve the task exit case, by batching tlb invalidates.

---
 arch/powerpc/include/asm/book3s/64/radix.h | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/book3s/64/radix.h +10 -3
index c0d43766ec63..98a0aee8b148 100644
@@ -140,13 +140,20 @@ static inline unsigned long radix__pte_update(struct mm_struct *mm,
 		unsigned long new_pte;
 
 		old_pte = __radix_pte_update(ptep, ~0, 0);
-		asm volatile("ptesync" : : : "memory");
 		/*
 		 * new value of pte
 		 */
 		new_pte = (old_pte | set) & ~clr;
-		radix__flush_tlb_pte(old_pte, mm, addr);
-		__radix_pte_update(ptep, 0, new_pte);
+		/*
+		 * If we are trying to clear the pte, we can skip
+		 * the below sequence and batch the tlb flush. The
+		 * tlb flush batching is done by mmu gather code
+		 */
+		if (new_pte) {
+			asm volatile("ptesync" : : : "memory");
+			radix__flush_tlb_pte(old_pte, mm, addr);
+			__radix_pte_update(ptep, 0, new_pte);
+		}
 	} else
 		old_pte = __radix_pte_update(ptep, clr, set);
 	asm volatile("ptesync" : : : "memory");
Signature · 1 line
2.10.2
#8 lore raw
In reply to Aneesh Kumar K.V
Quoted 2 lines · Aneesh Kumar K.V

Changes from V5:
Switch to use pte bits to track page size.

I am now testing a new version that will limit this new pte bit usage only on DD1.

Quoted 27 lines

Aneesh Kumar K.V (7):
powerpc/mm: Rename hugetlb-radix.h to hugetlb.h powerpc/mm/hugetlb: Handle hugepage size supported by hash config powerpc/mm: Introduce _PAGE_GIGANTIC and _PAGE_LARGE software pte bits powerpc/mm: Add radix__tlb_flush_pte
powerpc/mm: update radix__ptep_set_access_flag to not do full mm tlb
flush
powerpc/mm: update radix__pte_update to not do full mm tlb flush powerpc/mm: Batch tlb flush when invalidating pte entries

 arch/powerpc/include/asm/book3s/32/pgtable.h       |  3 ++-
 .../asm/book3s/64/{hugetlb-radix.h => hugetlb.h}   | 21 ++++++++++++++--
 arch/powerpc/include/asm/book3s/64/pgtable.h       | 15 ++++++++++--
 arch/powerpc/include/asm/book3s/64/radix.h         | 28 ++++++++++------------
 .../powerpc/include/asm/book3s/64/tlbflush-radix.h |  2 ++
 arch/powerpc/include/asm/hugetlb.h                 |  2 +-
 arch/powerpc/include/asm/nohash/32/pgtable.h       |  3 ++-
 arch/powerpc/include/asm/nohash/64/pgtable.h       |  3 ++-
 arch/powerpc/mm/pgtable-book3s64.c                 |  3 ++-
 arch/powerpc/mm/pgtable.c                          |  2 +-
 arch/powerpc/mm/tlb-radix.c                        | 11 +++++++++
 11 files changed, 67 insertions(+), 26 deletions(-)
 rename arch/powerpc/include/asm/book3s/64/{hugetlb-radix.h => hugetlb.h} (55%)
Signature · 1 line
2.10.2