aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2016-06-08 10:25:51 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-06-10 02:14:52 -0400
commita145abf12c9f7d30d8c330c9d8a97428cbf0589b (patch)
treefd6299b45426739853fc7b4da91fd62d7fdf3a74
parent36194812a4063dd2a72070aec3ee7890d135a587 (diff)
powerpc/mm/radix: Flush page walk cache when freeing page table
Even though a tlb_flush() does a flush with invalidate all cache, we can end up doing an RCU page table free before calling tlb_flush(). That means we can have page walk cache entries even after we free the page table pages. This can result in us doing wrong page table walk. Avoid this by doing pwc flush on every page table free. We can't batch the pwc flush, because the rcu call back function where we free the page table pages doesn't have information of the mmu gather. Thus we have to do a pwc on every page table page freed. Note: I also removed the dummy tlb_flush_pgtable call functions for hash 32. Fixes: 1a472c9dba6b ("powerpc/mm/radix: Add tlbflush routines") Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/include/asm/book3s/32/pgalloc.h1
-rw-r--r--arch/powerpc/include/asm/book3s/64/pgalloc.h16
-rw-r--r--arch/powerpc/include/asm/book3s/64/tlbflush-radix.h3
-rw-r--r--arch/powerpc/include/asm/book3s/64/tlbflush.h14
-rw-r--r--arch/powerpc/include/asm/book3s/pgalloc.h5
-rw-r--r--arch/powerpc/mm/tlb-radix.c41
6 files changed, 73 insertions, 7 deletions
diff --git a/arch/powerpc/include/asm/book3s/32/pgalloc.h b/arch/powerpc/include/asm/book3s/32/pgalloc.h
index a2350194fc76..8e21bb492dca 100644
--- a/arch/powerpc/include/asm/book3s/32/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/32/pgalloc.h
@@ -102,7 +102,6 @@ static inline void pgtable_free_tlb(struct mmu_gather *tlb,
102static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table, 102static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
103 unsigned long address) 103 unsigned long address)
104{ 104{
105 tlb_flush_pgtable(tlb, address);
106 pgtable_page_dtor(table); 105 pgtable_page_dtor(table);
107 pgtable_free_tlb(tlb, page_address(table), 0); 106 pgtable_free_tlb(tlb, page_address(table), 0);
108} 107}
diff --git a/arch/powerpc/include/asm/book3s/64/pgalloc.h b/arch/powerpc/include/asm/book3s/64/pgalloc.h
index 488279edb1f0..26eb2cb80c4e 100644
--- a/arch/powerpc/include/asm/book3s/64/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/64/pgalloc.h
@@ -110,6 +110,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
110static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, 110static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
111 unsigned long address) 111 unsigned long address)
112{ 112{
113 /*
114 * By now all the pud entries should be none entries. So go
115 * ahead and flush the page walk cache
116 */
117 flush_tlb_pgtable(tlb, address);
113 pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE); 118 pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE);
114} 119}
115 120
@@ -127,6 +132,11 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
127static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, 132static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
128 unsigned long address) 133 unsigned long address)
129{ 134{
135 /*
136 * By now all the pud entries should be none entries. So go
137 * ahead and flush the page walk cache
138 */
139 flush_tlb_pgtable(tlb, address);
130 return pgtable_free_tlb(tlb, pmd, PMD_CACHE_INDEX); 140 return pgtable_free_tlb(tlb, pmd, PMD_CACHE_INDEX);
131} 141}
132 142
@@ -198,7 +208,11 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
198static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table, 208static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
199 unsigned long address) 209 unsigned long address)
200{ 210{
201 tlb_flush_pgtable(tlb, address); 211 /*
212 * By now all the pud entries should be none entries. So go
213 * ahead and flush the page walk cache
214 */
215 flush_tlb_pgtable(tlb, address);
202 pgtable_free_tlb(tlb, table, 0); 216 pgtable_free_tlb(tlb, table, 0);
203} 217}
204 218
diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h b/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
index 13ef38828dfe..3fa94fcac628 100644
--- a/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
+++ b/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
@@ -18,16 +18,19 @@ extern void radix__local_flush_tlb_mm(struct mm_struct *mm);
18extern void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr); 18extern void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
19extern void radix___local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, 19extern void radix___local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
20 unsigned long ap, int nid); 20 unsigned long ap, int nid);
21extern void radix__local_flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr);
21extern void radix__tlb_flush(struct mmu_gather *tlb); 22extern void radix__tlb_flush(struct mmu_gather *tlb);
22#ifdef CONFIG_SMP 23#ifdef CONFIG_SMP
23extern void radix__flush_tlb_mm(struct mm_struct *mm); 24extern void radix__flush_tlb_mm(struct mm_struct *mm);
24extern void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr); 25extern void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
25extern void radix___flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, 26extern void radix___flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
26 unsigned long ap, int nid); 27 unsigned long ap, int nid);
28extern void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr);
27#else 29#else
28#define radix__flush_tlb_mm(mm) radix__local_flush_tlb_mm(mm) 30#define radix__flush_tlb_mm(mm) radix__local_flush_tlb_mm(mm)
29#define radix__flush_tlb_page(vma,addr) radix__local_flush_tlb_page(vma,addr) 31#define radix__flush_tlb_page(vma,addr) radix__local_flush_tlb_page(vma,addr)
30#define radix___flush_tlb_page(mm,addr,p,i) radix___local_flush_tlb_page(mm,addr,p,i) 32#define radix___flush_tlb_page(mm,addr,p,i) radix___local_flush_tlb_page(mm,addr,p,i)
33#define radix__flush_tlb_pwc(tlb, addr) radix__local_flush_tlb_pwc(tlb, addr)
31#endif 34#endif
32 35
33#endif 36#endif
diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush.h b/arch/powerpc/include/asm/book3s/64/tlbflush.h
index d98424ae356c..96e5769b18b0 100644
--- a/arch/powerpc/include/asm/book3s/64/tlbflush.h
+++ b/arch/powerpc/include/asm/book3s/64/tlbflush.h
@@ -72,5 +72,19 @@ static inline void flush_tlb_page(struct vm_area_struct *vma,
72#define flush_tlb_mm(mm) local_flush_tlb_mm(mm) 72#define flush_tlb_mm(mm) local_flush_tlb_mm(mm)
73#define flush_tlb_page(vma, addr) local_flush_tlb_page(vma, addr) 73#define flush_tlb_page(vma, addr) local_flush_tlb_page(vma, addr)
74#endif /* CONFIG_SMP */ 74#endif /* CONFIG_SMP */
75/*
76 * flush the page walk cache for the address
77 */
78static inline void flush_tlb_pgtable(struct mmu_gather *tlb, unsigned long address)
79{
80 /*
81 * Flush the page table walk cache on freeing a page table. We already
82 * have marked the upper/higher level page table entry none by now.
83 * So it is safe to flush PWC here.
84 */
85 if (!radix_enabled())
86 return;
75 87
88 radix__flush_tlb_pwc(tlb, address);
89}
76#endif /* _ASM_POWERPC_BOOK3S_64_TLBFLUSH_H */ 90#endif /* _ASM_POWERPC_BOOK3S_64_TLBFLUSH_H */
diff --git a/arch/powerpc/include/asm/book3s/pgalloc.h b/arch/powerpc/include/asm/book3s/pgalloc.h
index 54f591e9572e..c0a69ae92256 100644
--- a/arch/powerpc/include/asm/book3s/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/pgalloc.h
@@ -4,11 +4,6 @@
4#include <linux/mm.h> 4#include <linux/mm.h>
5 5
6extern void tlb_remove_table(struct mmu_gather *tlb, void *table); 6extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
7static inline void tlb_flush_pgtable(struct mmu_gather *tlb,
8 unsigned long address)
9{
10
11}
12 7
13#ifdef CONFIG_PPC64 8#ifdef CONFIG_PPC64
14#include <asm/book3s/64/pgalloc.h> 9#include <asm/book3s/64/pgalloc.h>
diff --git a/arch/powerpc/mm/tlb-radix.c b/arch/powerpc/mm/tlb-radix.c
index 71083621884e..ab2f60e812e2 100644
--- a/arch/powerpc/mm/tlb-radix.c
+++ b/arch/powerpc/mm/tlb-radix.c
@@ -128,6 +128,21 @@ void radix__local_flush_tlb_mm(struct mm_struct *mm)
128} 128}
129EXPORT_SYMBOL(radix__local_flush_tlb_mm); 129EXPORT_SYMBOL(radix__local_flush_tlb_mm);
130 130
131void radix__local_flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
132{
133 unsigned long pid;
134 struct mm_struct *mm = tlb->mm;
135
136 preempt_disable();
137
138 pid = mm->context.id;
139 if (pid != MMU_NO_CONTEXT)
140 _tlbiel_pid(pid, RIC_FLUSH_PWC);
141
142 preempt_enable();
143}
144EXPORT_SYMBOL(radix__local_flush_tlb_pwc);
145
131void radix___local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, 146void radix___local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
132 unsigned long ap, int nid) 147 unsigned long ap, int nid)
133{ 148{
@@ -183,6 +198,32 @@ no_context:
183} 198}
184EXPORT_SYMBOL(radix__flush_tlb_mm); 199EXPORT_SYMBOL(radix__flush_tlb_mm);
185 200
201void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
202{
203 unsigned long pid;
204 struct mm_struct *mm = tlb->mm;
205
206 preempt_disable();
207
208 pid = mm->context.id;
209 if (unlikely(pid == MMU_NO_CONTEXT))
210 goto no_context;
211
212 if (!mm_is_core_local(mm)) {
213 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
214
215 if (lock_tlbie)
216 raw_spin_lock(&native_tlbie_lock);
217 _tlbie_pid(pid, RIC_FLUSH_PWC);
218 if (lock_tlbie)
219 raw_spin_unlock(&native_tlbie_lock);
220 } else
221 _tlbiel_pid(pid, RIC_FLUSH_PWC);
222no_context:
223 preempt_enable();
224}
225EXPORT_SYMBOL(radix__flush_tlb_pwc);
226
186void radix___flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, 227void radix___flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
187 unsigned long ap, int nid) 228 unsigned long ap, int nid)
188{ 229{