Skip to content

Commit b12835b

Browse files
stevecapperlinarogregkh
authored andcommitted
ARM: 8109/1: mm: Modify pte_write and pmd_write logic for LPAE
commit ded9477 upstream. 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> [hpy: Backported to 3.10 - adjust the context - ignore change related to pmd, because 3.10 does not support HugePage ] Signed-off-by: Hou Pengyang <houpengyang@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5012ebf commit b12835b

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

arch/arm/include/asm/pgtable-3level-hwdef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#define PTE_TYPE_PAGE (_AT(pteval_t, 3) << 0)
6969
#define PTE_BUFFERABLE (_AT(pteval_t, 1) << 2) /* AttrIndx[0] */
7070
#define PTE_CACHEABLE (_AT(pteval_t, 1) << 3) /* AttrIndx[1] */
71+
#define PTE_AP2 (_AT(pteval_t, 1) << 7) /* AP[2] */
7172
#define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
7273
#define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
7374
#define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */

arch/arm/include/asm/pgtable-3level.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171
#define L_PTE_PRESENT (_AT(pteval_t, 3) << 0) /* Present */
7272
#define L_PTE_FILE (_AT(pteval_t, 1) << 2) /* only when !PRESENT */
7373
#define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
74-
#define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
7574
#define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
7675
#define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
7776
#define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
78-
#define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
79-
#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
77+
#define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
78+
#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
8079
#define L_PTE_NONE (_AT(pteval_t, 1) << 57) /* PROT_NONE */
80+
#define L_PTE_RDONLY (_AT(pteval_t, 1) << 58) /* READ ONLY */
8181

8282
/*
8383
* To be used in assembly code with the upper page attributes.

arch/arm/mm/proc-v7-3level.S

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ ENTRY(cpu_v7_set_pte_ext)
7878
tst rh, #1 << (57 - 32) @ L_PTE_NONE
7979
bicne rl, #L_PTE_VALID
8080
bne 1f
81-
tst rh, #1 << (55 - 32) @ L_PTE_DIRTY
82-
orreq rl, #L_PTE_RDONLY
81+
82+
eor ip, rh, #1 << (55 - 32) @ toggle L_PTE_DIRTY in temp reg to
83+
@ test for !L_PTE_DIRTY || L_PTE_RDONLY
84+
tst ip, #1 << (55 - 32) | 1 << (58 - 32)
85+
orrne rl, #PTE_AP2
86+
biceq rl, #PTE_AP2
87+
8388
1: strd r2, r3, [r0]
8489
ALT_SMP(W(nop))
8590
ALT_UP (mcr p15, 0, r0, c7, c10, 1) @ flush_pte

0 commit comments

Comments
 (0)