powerpc/book3s/hash: Drop _PAGE_PRIVILEGED from PAGE_NONE
authorAneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org>
Mon, 4 Dec 2023 09:36:37 +0000 (15:06 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 7 Dec 2023 12:34:11 +0000 (23:34 +1100)
There used to be a dependency on _PAGE_PRIVILEGED with pte_savedwrite.
But that got dropped by
commit 6a56ccbcf6c6 ("mm/autonuma: use can_change_(pte|pmd)_writable() to replace savedwrite")

With the change in this patch numa fault pte (pte_protnone()) gets mapped as regular user pte
with RWX cleared (no-access) whereas earlier it used to be mapped _PAGE_PRIVILEGED.

Hash fault handling code gets some WARN_ON added in this patch because
those functions are not expected to get called with _PAGE_READ cleared.
commit 18061c17c8ec ("powerpc/mm: Update PROTFAULT handling in the page
fault path") explains the details.

Signed-off-by: "Aneesh Kumar K.V (IBM)" <aneesh.kumar@kernel.org>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231204093638.71503-1-aneesh.kumar@kernel.org
arch/powerpc/include/asm/book3s/64/pgtable.h
arch/powerpc/mm/book3s64/hash_utils.c

index cb77eddca54b9961c2f72c966f6ee27699e19d73..927d585652bc75c2e9d798ed439e5274dc7327ef 100644 (file)
 #define _PAGE_EXEC             0x00001 /* execute permission */
 #define _PAGE_WRITE            0x00002 /* write access allowed */
 #define _PAGE_READ             0x00004 /* read access allowed */
-#define _PAGE_NA               _PAGE_PRIVILEGED
-#define _PAGE_NAX              _PAGE_EXEC
-#define _PAGE_RO               _PAGE_READ
-#define _PAGE_ROX              (_PAGE_READ | _PAGE_EXEC)
-#define _PAGE_RW               (_PAGE_READ | _PAGE_WRITE)
-#define _PAGE_RWX              (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
 #define _PAGE_PRIVILEGED       0x00008 /* kernel access only */
 #define _PAGE_SAO              0x00010 /* Strong access order */
 #define _PAGE_NON_IDEMPOTENT   0x00020 /* non idempotent memory */
@@ -532,8 +526,8 @@ static inline bool pte_user(pte_t pte)
 static inline bool pte_access_permitted(pte_t pte, bool write)
 {
        /*
-        * _PAGE_READ is needed for any access and will be
-        * cleared for PROT_NONE
+        * _PAGE_READ is needed for any access and will be cleared for
+        * PROT_NONE. Execute-only mapping via PROT_EXEC also returns false.
         */
        if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
                return false;
index ad2afa08e62ed9ecf8ee33ca8f89e138c1b38d0c..0626a25b0d728be1a33aa36012327f1ddc71374f 100644 (file)
@@ -310,9 +310,16 @@ unsigned long htab_convert_pte_flags(unsigned long pteflags, unsigned long flags
                        else
                                rflags |= 0x3;
                }
+               VM_WARN_ONCE(!(pteflags & _PAGE_RWX), "no-access mapping request");
        } else {
                if (pteflags & _PAGE_RWX)
                        rflags |= 0x2;
+               /*
+                * We should never hit this in normal fault handling because
+                * a permission check (check_pte_access()) will bubble this
+                * to higher level linux handler even for PAGE_NONE.
+                */
+               VM_WARN_ONCE(!(pteflags & _PAGE_RWX), "no-access mapping request");
                if (!((pteflags & _PAGE_WRITE) && (pteflags & _PAGE_DIRTY)))
                        rflags |= 0x1;
        }