]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: provide address parameter to p{te,md,ud}_user_accessible_page()
authorRohan McLure <rmclure@linux.ibm.com>
Wed, 13 Aug 2025 06:26:10 +0000 (16:26 +1000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 18 Aug 2025 05:08:56 +0000 (22:08 -0700)
On several powerpc platforms, a page table entry may not imply whether the
relevant mapping is for userspace or kernelspace.  Instead, such platforms
infer this by the address which is being accessed.

Add an additional address argument to each of these routines in order to
provide support for page table check on powerpc.

[ajd@linux.ibm.com: rebase on arm64 changes]
Link: https://lkml.kernel.org/r/20250813062614.51759-10-ajd@linux.ibm.com
Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Acked-by: Ingo Molnar <mingo@kernel.org> [x86]
Acked-by: Alexandre Ghiti <alexghiti@rivosinc.com> [riscv]
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Nicholas Miehlbradt <nicholas@linux.ibm.com>
Cc: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/arm64/include/asm/pgtable.h
arch/riscv/include/asm/pgtable.h
arch/x86/include/asm/pgtable.h
mm/page_table_check.c

index 2203ebac81d9f938ed026b332846a58103e1e77e..254265e9a4239e2d7c87b3d5aab988f9b508fbd5 100644 (file)
@@ -1290,17 +1290,17 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
 #endif
 
 #ifdef CONFIG_PAGE_TABLE_CHECK
-static inline bool pte_user_accessible_page(pte_t pte)
+static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr)
 {
        return pte_valid(pte) && (pte_user(pte) || pte_user_exec(pte));
 }
 
-static inline bool pmd_user_accessible_page(pmd_t pmd)
+static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr)
 {
        return pmd_valid(pmd) && !pmd_table(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd));
 }
 
-static inline bool pud_user_accessible_page(pud_t pud)
+static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr)
 {
        return pud_valid(pud) && !pud_table(pud) && (pud_user(pud) || pud_user_exec(pud));
 }
index 31728fa3b8b3c4291425dbcfe2789f99d70ce016..d5685ad09ace48e1fa0756263560825d77b79146 100644 (file)
@@ -817,17 +817,17 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
 }
 
 #ifdef CONFIG_PAGE_TABLE_CHECK
-static inline bool pte_user_accessible_page(pte_t pte)
+static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr)
 {
        return pte_present(pte) && pte_user(pte);
 }
 
-static inline bool pmd_user_accessible_page(pmd_t pmd)
+static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr)
 {
        return pmd_leaf(pmd) && pmd_user(pmd);
 }
 
-static inline bool pud_user_accessible_page(pud_t pud)
+static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr)
 {
        return pud_leaf(pud) && pud_user(pud);
 }
index 63350b76c0c61cb6869e729e431eafac9e7d6d5e..b977cebb5f4484bc3e20cd9da66ee737f216328c 100644 (file)
@@ -1679,17 +1679,17 @@ static inline bool arch_has_hw_nonleaf_pmd_young(void)
 #endif
 
 #ifdef CONFIG_PAGE_TABLE_CHECK
-static inline bool pte_user_accessible_page(pte_t pte)
+static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr)
 {
        return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
 }
 
-static inline bool pmd_user_accessible_page(pmd_t pmd)
+static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr)
 {
        return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) && (pmd_val(pmd) & _PAGE_USER);
 }
 
-static inline bool pud_user_accessible_page(pud_t pud)
+static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr)
 {
        return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) && (pud_val(pud) & _PAGE_USER);
 }
index 1c33439b9c0b73fb0302a885beaf83fce90e3972..abc2232ceb39d9a0e22c094112dc4532ac14d28f 100644 (file)
@@ -151,7 +151,7 @@ void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
        if (&init_mm == mm)
                return;
 
-       if (pte_user_accessible_page(pte)) {
+       if (pte_user_accessible_page(pte, addr)) {
                page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT);
        }
 }
@@ -163,7 +163,7 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr,
        if (&init_mm == mm)
                return;
 
-       if (pmd_user_accessible_page(pmd)) {
+       if (pmd_user_accessible_page(pmd, addr)) {
                page_table_check_clear(pmd_pfn(pmd), PMD_SIZE >> PAGE_SHIFT);
        }
 }
@@ -175,7 +175,7 @@ void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr,
        if (&init_mm == mm)
                return;
 
-       if (pud_user_accessible_page(pud)) {
+       if (pud_user_accessible_page(pud, addr)) {
                page_table_check_clear(pud_pfn(pud), PUD_SIZE >> PAGE_SHIFT);
        }
 }
@@ -208,7 +208,7 @@ void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
 
        for (i = 0; i < nr; i++)
                __page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i));
-       if (pte_user_accessible_page(pte))
+       if (pte_user_accessible_page(pte, addr))
                page_table_check_set(pte_pfn(pte), nr, pte_write(pte));
 }
 EXPORT_SYMBOL(__page_table_check_ptes_set);
@@ -234,7 +234,7 @@ void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,
 
        for (i = 0; i < nr; i++)
                __page_table_check_pmd_clear(mm, addr + PMD_SIZE * i, *(pmdp + i));
-       if (pmd_user_accessible_page(pmd))
+       if (pmd_user_accessible_page(pmd, addr))
                page_table_check_set(pmd_pfn(pmd), stride * nr, pmd_write(pmd));
 }
 EXPORT_SYMBOL(__page_table_check_pmds_set);
@@ -250,7 +250,7 @@ void __page_table_check_puds_set(struct mm_struct *mm, unsigned long addr,
 
        for (i = 0; i < nr; i++)
                __page_table_check_pud_clear(mm, addr + PUD_SIZE * i, *(pudp + i));
-       if (pud_user_accessible_page(pud))
+       if (pud_user_accessible_page(pud, addr))
                page_table_check_set(pud_pfn(pud), stride * nr, pud_write(pud));
 }
 EXPORT_SYMBOL(__page_table_check_puds_set);