aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@arm.com>2014-06-09 06:55:03 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2014-07-24 05:25:42 -0400
commit7f0b1bf04511348995d6fce38c87c98a3b5cb781 (patch)
tree87753459f2311e56a783cd4dcaceb768bf5ce494
parent383c2799113b00a5f12c820ff0fd3dfca9e5be89 (diff)
arm64: Fix barriers used for page table modifications
The architecture specification states that both DSB and ISB are required between page table modifications and subsequent memory accesses using the corresponding virtual address. When TLB invalidation takes place, the tlb_flush_* functions already have the necessary barriers. However, there are other functions like create_mapping() for which this is not the case. The patch adds the DSB+ISB instructions in the set_pte() function for valid kernel mappings. The invalid pte case is handled by tlb_flush_* and the user mappings in general have a corresponding update_mmu_cache() call containing a DSB. Even when update_mmu_cache() isn't called, the kernel can still cope with an unlikely spurious page fault by re-executing the instruction. In addition, the set_pmd, set_pud() functions gain an ISB for architecture compliance when block mappings are created. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Reported-by: Leif Lindholm <leif.lindholm@linaro.org> Acked-by: Steve Capper <steve.capper@linaro.org> Cc: Will Deacon <will.deacon@arm.com> Cc: <stable@vger.kernel.org>
-rw-r--r--arch/arm64/include/asm/cacheflush.h11
-rw-r--r--arch/arm64/include/asm/pgtable.h13
-rw-r--r--arch/arm64/include/asm/tlbflush.h5
3 files changed, 17 insertions, 12 deletions
diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h
index a5176cf32dad..f2defe1c380c 100644
--- a/arch/arm64/include/asm/cacheflush.h
+++ b/arch/arm64/include/asm/cacheflush.h
@@ -138,19 +138,10 @@ static inline void __flush_icache_all(void)
138#define flush_icache_page(vma,page) do { } while (0) 138#define flush_icache_page(vma,page) do { } while (0)
139 139
140/* 140/*
141 * flush_cache_vmap() is used when creating mappings (eg, via vmap, 141 * Not required on AArch64 (PIPT or VIPT non-aliasing D-cache).
142 * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT
143 * caches, since the direct-mappings of these pages may contain cached
144 * data, we need to do a full cache flush to ensure that writebacks
145 * don't corrupt data placed into these pages via the new mappings.
146 */ 142 */
147static inline void flush_cache_vmap(unsigned long start, unsigned long end) 143static inline void flush_cache_vmap(unsigned long start, unsigned long end)
148{ 144{
149 /*
150 * set_pte_at() called from vmap_pte_range() does not
151 * have a DSB after cleaning the cache line.
152 */
153 dsb(ish);
154} 145}
155 146
156static inline void flush_cache_vunmap(unsigned long start, unsigned long end) 147static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 73968c2180aa..ffe1ba0506d1 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -146,6 +146,8 @@ extern struct page *empty_zero_page;
146 146
147#define pte_valid_user(pte) \ 147#define pte_valid_user(pte) \
148 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER)) 148 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER))
149#define pte_valid_not_user(pte) \
150 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == PTE_VALID)
149 151
150static inline pte_t pte_wrprotect(pte_t pte) 152static inline pte_t pte_wrprotect(pte_t pte)
151{ 153{
@@ -192,6 +194,15 @@ static inline pte_t pte_mkspecial(pte_t pte)
192static inline void set_pte(pte_t *ptep, pte_t pte) 194static inline void set_pte(pte_t *ptep, pte_t pte)
193{ 195{
194 *ptep = pte; 196 *ptep = pte;
197
198 /*
199 * Only if the new pte is valid and kernel, otherwise TLB maintenance
200 * or update_mmu_cache() have the necessary barriers.
201 */
202 if (pte_valid_not_user(pte)) {
203 dsb(ishst);
204 isb();
205 }
195} 206}
196 207
197extern void __sync_icache_dcache(pte_t pteval, unsigned long addr); 208extern void __sync_icache_dcache(pte_t pteval, unsigned long addr);
@@ -311,6 +322,7 @@ static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
311{ 322{
312 *pmdp = pmd; 323 *pmdp = pmd;
313 dsb(ishst); 324 dsb(ishst);
325 isb();
314} 326}
315 327
316static inline void pmd_clear(pmd_t *pmdp) 328static inline void pmd_clear(pmd_t *pmdp)
@@ -343,6 +355,7 @@ static inline void set_pud(pud_t *pudp, pud_t pud)
343{ 355{
344 *pudp = pud; 356 *pudp = pud;
345 dsb(ishst); 357 dsb(ishst);
358 isb();
346} 359}
347 360
348static inline void pud_clear(pud_t *pudp) 361static inline void pud_clear(pud_t *pudp)
diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
index b9349c4513ea..3796ea6bb734 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -122,6 +122,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
122 for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) 122 for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
123 asm("tlbi vaae1is, %0" : : "r"(addr)); 123 asm("tlbi vaae1is, %0" : : "r"(addr));
124 dsb(ish); 124 dsb(ish);
125 isb();
125} 126}
126 127
127/* 128/*
@@ -131,8 +132,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,
131 unsigned long addr, pte_t *ptep) 132 unsigned long addr, pte_t *ptep)
132{ 133{
133 /* 134 /*
134 * set_pte() does not have a DSB, so make sure that the page table 135 * set_pte() does not have a DSB for user mappings, so make sure that
135 * write is visible. 136 * the page table write is visible.
136 */ 137 */
137 dsb(ishst); 138 dsb(ishst);
138} 139}