aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Capper <steve.capper@linaro.org>2014-07-18 11:16:15 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2014-07-24 09:27:08 -0400
commitded9477984690d026e46dd75e8157392cea3f13f (patch)
tree8faee3f6c299d1979290ce459687cf51c7e91e4c
parentf2950706871c4b6e8c0f0d7c3f62d35930b8de63 (diff)
ARM: 8109/1: mm: Modify pte_write and pmd_write logic for LPAE
For LPAE, we have the following means for encoding writable or dirty ptes: L_PTE_DIRTY L_PTE_RDONLY !pte_dirty && !pte_write 0 1 !pte_dirty && pte_write 0 1 pte_dirty && !pte_write 1 1 pte_dirty && pte_write 1 0 So we can't distinguish between writeable clean ptes and read only ptes. This can cause problems with ptes being incorrectly flagged as read only when they are writeable but not dirty. This patch renumbers L_PTE_RDONLY from AP[2] to a software bit #58, and adds additional logic to set AP[2] whenever the pte is read only or not dirty. That way we can distinguish between clean writeable ptes and read only ptes. HugeTLB pages will use this new logic automatically. We need to add some logic to Transparent HugePages to ensure that they correctly interpret the revised pgprot permissions (L_PTE_RDONLY has moved and no longer matches PMD_SECT_AP2). In the process of revising THP, the names of the PMD software bits have been prefixed with L_ to make them easier to distinguish from their hardware bit counterparts. Signed-off-by: Steve Capper <steve.capper@linaro.org> Reviewed-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/include/asm/pgtable-3level-hwdef.h3
-rw-r--r--arch/arm/include/asm/pgtable-3level.h41
-rw-r--r--arch/arm/mm/dump.c4
-rw-r--r--arch/arm/mm/proc-v7-3level.S9
4 files changed, 35 insertions, 22 deletions
diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
index 626989fec4d3..9fd61c72a33a 100644
--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
@@ -43,7 +43,7 @@
43#define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2) 43#define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
44#define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3) 44#define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
45#define PMD_SECT_USER (_AT(pmdval_t, 1) << 6) /* AP[1] */ 45#define PMD_SECT_USER (_AT(pmdval_t, 1) << 6) /* AP[1] */
46#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7) /* AP[2] */ 46#define PMD_SECT_AP2 (_AT(pmdval_t, 1) << 7) /* read only */
47#define PMD_SECT_S (_AT(pmdval_t, 3) << 8) 47#define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
48#define PMD_SECT_AF (_AT(pmdval_t, 1) << 10) 48#define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
49#define PMD_SECT_nG (_AT(pmdval_t, 1) << 11) 49#define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
@@ -72,6 +72,7 @@
72#define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1) 72#define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1)
73#define PTE_BUFFERABLE (_AT(pteval_t, 1) << 2) /* AttrIndx[0] */ 73#define PTE_BUFFERABLE (_AT(pteval_t, 1) << 2) /* AttrIndx[0] */
74#define PTE_CACHEABLE (_AT(pteval_t, 1) << 3) /* AttrIndx[1] */ 74#define PTE_CACHEABLE (_AT(pteval_t, 1) << 3) /* AttrIndx[1] */
75#define PTE_AP2 (_AT(pteval_t, 1) << 7) /* AP[2] */
75#define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */ 76#define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
76#define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */ 77#define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
77#define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */ 78#define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
index 34f371c4bbb2..06e0bc0f8b00 100644
--- a/arch/arm/include/asm/pgtable-3level.h
+++ b/arch/arm/include/asm/pgtable-3level.h
@@ -79,18 +79,19 @@
79#define L_PTE_PRESENT (_AT(pteval_t, 3) << 0) /* Present */ 79#define L_PTE_PRESENT (_AT(pteval_t, 3) << 0) /* Present */
80#define L_PTE_FILE (_AT(pteval_t, 1) << 2) /* only when !PRESENT */ 80#define L_PTE_FILE (_AT(pteval_t, 1) << 2) /* only when !PRESENT */
81#define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */ 81#define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
82#define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
83#define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */ 82#define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
84#define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */ 83#define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
85#define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */ 84#define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
86#define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */ 85#define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
87#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */ 86#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
88#define L_PTE_NONE (_AT(pteval_t, 1) << 57) /* PROT_NONE */ 87#define L_PTE_NONE (_AT(pteval_t, 1) << 57) /* PROT_NONE */
88#define L_PTE_RDONLY (_AT(pteval_t, 1) << 58) /* READ ONLY */
89 89
90#define PMD_SECT_VALID (_AT(pmdval_t, 1) << 0) 90#define L_PMD_SECT_VALID (_AT(pmdval_t, 1) << 0)
91#define PMD_SECT_DIRTY (_AT(pmdval_t, 1) << 55) 91#define L_PMD_SECT_DIRTY (_AT(pmdval_t, 1) << 55)
92#define PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56) 92#define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
93#define PMD_SECT_NONE (_AT(pmdval_t, 1) << 57) 93#define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
94#define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
94 95
95/* 96/*
96 * To be used in assembly code with the upper page attributes. 97 * To be used in assembly code with the upper page attributes.
@@ -214,24 +215,25 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
214#define pmd_young(pmd) (pmd_isset((pmd), PMD_SECT_AF)) 215#define pmd_young(pmd) (pmd_isset((pmd), PMD_SECT_AF))
215 216
216#define __HAVE_ARCH_PMD_WRITE 217#define __HAVE_ARCH_PMD_WRITE
217#define pmd_write(pmd) (pmd_isclear((pmd), PMD_SECT_RDONLY)) 218#define pmd_write(pmd) (pmd_isclear((pmd), L_PMD_SECT_RDONLY))
219#define pmd_dirty(pmd) (pmd_isset((pmd), L_PMD_SECT_DIRTY))
218 220
219#define pmd_hugewillfault(pmd) (!pmd_young(pmd) || !pmd_write(pmd)) 221#define pmd_hugewillfault(pmd) (!pmd_young(pmd) || !pmd_write(pmd))
220#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) 222#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd))
221 223
222#ifdef CONFIG_TRANSPARENT_HUGEPAGE 224#ifdef CONFIG_TRANSPARENT_HUGEPAGE
223#define pmd_trans_huge(pmd) (pmd_val(pmd) && !pmd_table(pmd)) 225#define pmd_trans_huge(pmd) (pmd_val(pmd) && !pmd_table(pmd))
224#define pmd_trans_splitting(pmd) (pmd_isset((pmd), PMD_SECT_SPLITTING)) 226#define pmd_trans_splitting(pmd) (pmd_isset((pmd), L_PMD_SECT_SPLITTING))
225#endif 227#endif
226 228
227#define PMD_BIT_FUNC(fn,op) \ 229#define PMD_BIT_FUNC(fn,op) \
228static inline pmd_t pmd_##fn(pmd_t pmd) { pmd_val(pmd) op; return pmd; } 230static inline pmd_t pmd_##fn(pmd_t pmd) { pmd_val(pmd) op; return pmd; }
229 231
230PMD_BIT_FUNC(wrprotect, |= PMD_SECT_RDONLY); 232PMD_BIT_FUNC(wrprotect, |= L_PMD_SECT_RDONLY);
231PMD_BIT_FUNC(mkold, &= ~PMD_SECT_AF); 233PMD_BIT_FUNC(mkold, &= ~PMD_SECT_AF);
232PMD_BIT_FUNC(mksplitting, |= PMD_SECT_SPLITTING); 234PMD_BIT_FUNC(mksplitting, |= L_PMD_SECT_SPLITTING);
233PMD_BIT_FUNC(mkwrite, &= ~PMD_SECT_RDONLY); 235PMD_BIT_FUNC(mkwrite, &= ~L_PMD_SECT_RDONLY);
234PMD_BIT_FUNC(mkdirty, |= PMD_SECT_DIRTY); 236PMD_BIT_FUNC(mkdirty, |= L_PMD_SECT_DIRTY);
235PMD_BIT_FUNC(mkyoung, |= PMD_SECT_AF); 237PMD_BIT_FUNC(mkyoung, |= PMD_SECT_AF);
236 238
237#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) 239#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT))
@@ -245,8 +247,8 @@ PMD_BIT_FUNC(mkyoung, |= PMD_SECT_AF);
245 247
246static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) 248static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
247{ 249{
248 const pmdval_t mask = PMD_SECT_USER | PMD_SECT_XN | PMD_SECT_RDONLY | 250 const pmdval_t mask = PMD_SECT_USER | PMD_SECT_XN | L_PMD_SECT_RDONLY |
249 PMD_SECT_VALID | PMD_SECT_NONE; 251 L_PMD_SECT_VALID | L_PMD_SECT_NONE;
250 pmd_val(pmd) = (pmd_val(pmd) & ~mask) | (pgprot_val(newprot) & mask); 252 pmd_val(pmd) = (pmd_val(pmd) & ~mask) | (pgprot_val(newprot) & mask);
251 return pmd; 253 return pmd;
252} 254}
@@ -257,8 +259,13 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
257 BUG_ON(addr >= TASK_SIZE); 259 BUG_ON(addr >= TASK_SIZE);
258 260
259 /* create a faulting entry if PROT_NONE protected */ 261 /* create a faulting entry if PROT_NONE protected */
260 if (pmd_val(pmd) & PMD_SECT_NONE) 262 if (pmd_val(pmd) & L_PMD_SECT_NONE)
261 pmd_val(pmd) &= ~PMD_SECT_VALID; 263 pmd_val(pmd) &= ~L_PMD_SECT_VALID;
264
265 if (pmd_write(pmd) && pmd_dirty(pmd))
266 pmd_val(pmd) &= ~PMD_SECT_AP2;
267 else
268 pmd_val(pmd) |= PMD_SECT_AP2;
262 269
263 *pmdp = __pmd(pmd_val(pmd) | PMD_SECT_nG); 270 *pmdp = __pmd(pmd_val(pmd) | PMD_SECT_nG);
264 flush_pmd_entry(pmdp); 271 flush_pmd_entry(pmdp);
diff --git a/arch/arm/mm/dump.c b/arch/arm/mm/dump.c
index c508f41a43bc..59424937e52b 100644
--- a/arch/arm/mm/dump.c
+++ b/arch/arm/mm/dump.c
@@ -126,8 +126,8 @@ static const struct prot_bits section_bits[] = {
126 .val = PMD_SECT_USER, 126 .val = PMD_SECT_USER,
127 .set = "USR", 127 .set = "USR",
128 }, { 128 }, {
129 .mask = PMD_SECT_RDONLY, 129 .mask = L_PMD_SECT_RDONLY,
130 .val = PMD_SECT_RDONLY, 130 .val = L_PMD_SECT_RDONLY,
131 .set = "ro", 131 .set = "ro",
132 .clear = "RW", 132 .clear = "RW",
133#elif __LINUX_ARM_ARCH__ >= 6 133#elif __LINUX_ARM_ARCH__ >= 6
diff --git a/arch/arm/mm/proc-v7-3level.S b/arch/arm/mm/proc-v7-3level.S
index 564f4b934ceb..e4c8acfc1323 100644
--- a/arch/arm/mm/proc-v7-3level.S
+++ b/arch/arm/mm/proc-v7-3level.S
@@ -87,8 +87,13 @@ ENTRY(cpu_v7_set_pte_ext)
87 tst rh, #1 << (57 - 32) @ L_PTE_NONE 87 tst rh, #1 << (57 - 32) @ L_PTE_NONE
88 bicne rl, #L_PTE_VALID 88 bicne rl, #L_PTE_VALID
89 bne 1f 89 bne 1f
90 tst rh, #1 << (55 - 32) @ L_PTE_DIRTY 90
91 orreq rl, #L_PTE_RDONLY 91 eor ip, rh, #1 << (55 - 32) @ toggle L_PTE_DIRTY in temp reg to
92 @ test for !L_PTE_DIRTY || L_PTE_RDONLY
93 tst ip, #1 << (55 - 32) | 1 << (58 - 32)
94 orrne rl, #PTE_AP2
95 biceq rl, #PTE_AP2
96
921: strd r2, r3, [r0] 971: strd r2, r3, [r0]
93 ALT_SMP(W(nop)) 98 ALT_SMP(W(nop))
94 ALT_UP (mcr p15, 0, r0, c7, c10, 1) @ flush_pte 99 ALT_UP (mcr p15, 0, r0, c7, c10, 1) @ flush_pte