powerpc/nohash: Add _PAGE_WRITE to supplement _PAGE_RW
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Mon, 25 Sep 2023 18:31:42 +0000 (20:31 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 19 Oct 2023 06:12:46 +0000 (17:12 +1100)
Several places, _PAGE_RW maps to write permission and don't
always imply read. To make it more clear, do as book3s/64 in
commit c7d54842deb1 ("powerpc/mm: Use _PAGE_READ to indicate
Read access") and use _PAGE_WRITE when more relevant.

For the time being _PAGE_WRITE is equivalent to _PAGE_RW but that
will change when _PAGE_READ gets added in following patches.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/1f79b88db54d030ada776dc9845e0e88345bfc28.1695659959.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/nohash/32/pte-40x.h
arch/powerpc/include/asm/nohash/32/pte-44x.h
arch/powerpc/include/asm/nohash/32/pte-85xx.h
arch/powerpc/include/asm/nohash/64/pgtable.h
arch/powerpc/include/asm/nohash/pgtable.h
arch/powerpc/include/asm/nohash/pte-e500.h
arch/powerpc/kernel/head_40x.S
arch/powerpc/kernel/head_44x.S
arch/powerpc/kernel/head_85xx.S
arch/powerpc/mm/nohash/e500.c

index 0b4e5f8ce3e8a92f131e04c209c58836e8768931..e28ef0f5781e7c2e6f77e1a44ef67fc818c5cc03 100644 (file)
@@ -49,6 +49,8 @@
 #define _PAGE_EXEC     0x200   /* hardware: EX permission */
 #define _PAGE_ACCESSED 0x400   /* software: R: page referenced */
 
+#define _PAGE_WRITE    _PAGE_RW
+
 /* No page size encoding in the linux PTE */
 #define _PAGE_PSIZE            0
 
index b7ed13cee13785d547328bad9b08471b9f044278..fc0c075006eadf5fa7a9e4c83c855319f73d010d 100644 (file)
@@ -75,6 +75,8 @@
 #define _PAGE_NO_CACHE 0x00000400              /* H: I bit */
 #define _PAGE_WRITETHRU        0x00000800              /* H: W bit */
 
+#define _PAGE_WRITE    _PAGE_RW
+
 /* No page size encoding in the linux PTE */
 #define _PAGE_PSIZE            0
 
index 16451df5ddb057b700c56e6ec0ed6366091a0e18..462acf69e302197fa9fd924671b3a89d1fcdfe17 100644 (file)
@@ -31,6 +31,8 @@
 #define _PAGE_WRITETHRU        0x00400 /* H: W bit */
 #define _PAGE_SPECIAL  0x00800 /* S: Special page */
 
+#define _PAGE_WRITE    _PAGE_RW
+
 #define _PAGE_KERNEL_RO                0
 #define _PAGE_KERNEL_ROX       _PAGE_EXEC
 #define _PAGE_KERNEL_RW                (_PAGE_DIRTY | _PAGE_RW)
index 36b9bad428ccc5cc6f518f9752933d432a25a434..2202c78730e8eb6b43ff886f217f384258b6c3a6 100644 (file)
@@ -149,7 +149,7 @@ static inline void p4d_set(p4d_t *p4dp, unsigned long val)
 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
                                           unsigned long addr, pte_t *ptep)
 {
-       pte_update(mm, addr, ptep, _PAGE_RW, 0, 1);
+       pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 1);
 }
 
 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
index 942f46e86b4b74fe3d3cadb2a5d4da5c44150cff..9a91efa6455b8a86286b993763c4152735b372ef 100644 (file)
@@ -84,7 +84,7 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
                                      pte_t *ptep)
 {
-       pte_update(mm, addr, ptep, _PAGE_RW, 0, 0);
+       pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 0);
 }
 #endif
 #define __HAVE_ARCH_PTEP_SET_WRPROTECT
@@ -122,6 +122,9 @@ static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
 #ifndef pte_mkwrite_novma
 static inline pte_t pte_mkwrite_novma(pte_t pte)
 {
+       /*
+        * write implies read, hence set both
+        */
        return __pte(pte_val(pte) | _PAGE_RW);
 }
 #endif
@@ -139,7 +142,7 @@ static inline pte_t pte_mkyoung(pte_t pte)
 #ifndef pte_wrprotect
 static inline pte_t pte_wrprotect(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~_PAGE_RW);
+       return __pte(pte_val(pte) & ~_PAGE_WRITE);
 }
 #endif
 
@@ -153,7 +156,7 @@ static inline pte_t pte_mkexec(pte_t pte)
 #ifndef pte_write
 static inline int pte_write(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_RW;
+       return pte_val(pte) & _PAGE_WRITE;
 }
 #endif
 #ifndef pte_read
index 9f9e3f02d41465337d69bc5a9dc0508a340205e6..b775c7d465a4137e9a312a3a332d3a4f09e3f8aa 100644 (file)
@@ -55,6 +55,8 @@
 #define _PAGE_KERNEL_ROX       (_PAGE_BAP_SR | _PAGE_BAP_SX)
 #define _PAGE_USER             (_PAGE_BAP_UR | _PAGE_BAP_SR) /* Can be read */
 
+#define _PAGE_WRITE    _PAGE_RW
+
 #define _PAGE_SPECIAL  _PAGE_SW0
 
 /* Base page size */
index b32e7b2ebdcfd20524c52903adaba4f22ce996bc..9f92f5c5e6aa74c3ef01adcedeb9edacb559d362 100644 (file)
@@ -316,9 +316,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
        andc.   r9, r9, r11             /* Check permission */
        bne     5f
 
-       rlwinm  r9, r11, 1, _PAGE_RW    /* dirty => rw */
-       and     r9, r9, r11             /* hwwrite = dirty & rw */
-       rlwimi  r11, r9, 0, _PAGE_RW    /* replace rw by hwwrite */
+       rlwinm  r9, r11, 1, _PAGE_WRITE /* dirty => w */
+       and     r9, r9, r11             /* hwwrite = dirty & w */
+       rlwimi  r11, r9, 0, _PAGE_WRITE /* replace w by hwwrite */
 
        /* Create TLB tag.  This is the faulting address plus a static
         * set of bits.  These are size, valid, E, U0.
@@ -400,9 +400,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
        andc.   r9, r9, r11             /* Check permission */
        bne     5f
 
-       rlwinm  r9, r11, 1, _PAGE_RW    /* dirty => rw */
-       and     r9, r9, r11             /* hwwrite = dirty & rw */
-       rlwimi  r11, r9, 0, _PAGE_RW    /* replace rw by hwwrite */
+       rlwinm  r9, r11, 1, _PAGE_WRITE /* dirty => w */
+       and     r9, r9, r11             /* hwwrite = dirty & w */
+       rlwimi  r11, r9, 0, _PAGE_WRITE /* replace w by hwwrite */
 
        /* Create TLB tag.  This is the faulting address plus a static
         * set of bits.  These are size, valid, E, U0.
index a3197c9f721cde70411537286035f752c3c643ad..858dabf8443297eba07df11db45d81c1b669b5bd 100644 (file)
@@ -342,7 +342,7 @@ interrupt_base:
        mtspr   SPRN_MMUCR,r12
 
        /* Mask of required permission bits. Note that while we
-        * do copy ESR:ST to _PAGE_RW position as trying to write
+        * do copy ESR:ST to _PAGE_WRITE position as trying to write
         * to an RO page is pretty common, we don't do it with
         * _PAGE_DIRTY. We could do it, but it's a fairly rare
         * event so I'd rather take the overhead when it happens
@@ -586,7 +586,7 @@ finish_tlb_load_44x:
 4:     mtspr   SPRN_MMUCR,r12          /* Set MMUCR */
 
        /* Mask of required permission bits. Note that while we
-        * do copy ESR:ST to _PAGE_RW position as trying to write
+        * do copy ESR:ST to _PAGE_WRITE position as trying to write
         * to an RO page is pretty common, we don't do it with
         * _PAGE_DIRTY. We could do it, but it's a fairly rare
         * event so I'd rather take the overhead when it happens
index 0f1641a31250ddd863bf0ddce41601ccea231bd9..1b122cba557b7954b2bdedef9a19159cfb8ac330 100644 (file)
@@ -471,7 +471,7 @@ END_BTB_FLUSH_SECTION
 
 4:
        /* Mask of required permission bits. Note that while we
-        * do copy ESR:ST to _PAGE_RW position as trying to write
+        * do copy ESR:ST to _PAGE_WRITE position as trying to write
         * to an RO page is pretty common, we don't do it with
         * _PAGE_DIRTY. We could do it, but it's a fairly rare
         * event so I'd rather take the overhead when it happens
index 5b7d7a932bfd43a53d8f4c4e7d90de34707413a7..921c3521ec113e1d99f79230b857d18bf8eb0d9a 100644 (file)
@@ -117,7 +117,7 @@ static void settlbcam(int index, unsigned long virt, phys_addr_t phys,
        TLBCAM[index].MAS2 |= (flags & _PAGE_ENDIAN) ? MAS2_E : 0;
 
        TLBCAM[index].MAS3 = (phys & MAS3_RPN) | MAS3_SR;
-       TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_SW : 0;
+       TLBCAM[index].MAS3 |= (flags & _PAGE_WRITE) ? MAS3_SW : 0;
        if (mmu_has_feature(MMU_FTR_BIG_PHYS))
                TLBCAM[index].MAS7 = (u64)phys >> 32;
 
@@ -125,7 +125,7 @@ static void settlbcam(int index, unsigned long virt, phys_addr_t phys,
        if (!is_kernel_addr(virt)) {
                TLBCAM[index].MAS3 |= MAS3_UR;
                TLBCAM[index].MAS3 |= (flags & _PAGE_EXEC) ? MAS3_UX : 0;
-               TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_UW : 0;
+               TLBCAM[index].MAS3 |= (flags & _PAGE_WRITE) ? MAS3_UW : 0;
        } else {
                TLBCAM[index].MAS3 |= (flags & _PAGE_EXEC) ? MAS3_SX : 0;
        }