Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: provide address parameter to p{te,md,ud}_user_accessible_page()

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/20251219-pgtable_check_v18rebase-v18-9-755bc151a50b@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: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Donet Tom <donettom@linux.ibm.com>
Cc: Guo Weikang <guoweikang.kernel@gmail.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Magnus Lindholm <linmag7@gmail.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Miehlbradt <nicholas@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: Thomas Huth <thuth@redhat.com>
Cc: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Rohan McLure and committed by
Andrew Morton
d79f9c9c d7b4b67e

+15 -15
+3 -3
arch/arm64/include/asm/pgtable.h
··· 1265 1265 #endif 1266 1266 1267 1267 #ifdef CONFIG_PAGE_TABLE_CHECK 1268 - static inline bool pte_user_accessible_page(pte_t pte) 1268 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 1269 1269 { 1270 1270 return pte_valid(pte) && (pte_user(pte) || pte_user_exec(pte)); 1271 1271 } 1272 1272 1273 - static inline bool pmd_user_accessible_page(pmd_t pmd) 1273 + static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) 1274 1274 { 1275 1275 return pmd_valid(pmd) && !pmd_table(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); 1276 1276 } 1277 1277 1278 - static inline bool pud_user_accessible_page(pud_t pud) 1278 + static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) 1279 1279 { 1280 1280 return pud_valid(pud) && !pud_table(pud) && (pud_user(pud) || pud_user_exec(pud)); 1281 1281 }
+3 -3
arch/riscv/include/asm/pgtable.h
··· 958 958 } 959 959 960 960 #ifdef CONFIG_PAGE_TABLE_CHECK 961 - static inline bool pte_user_accessible_page(pte_t pte) 961 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 962 962 { 963 963 return pte_present(pte) && pte_user(pte); 964 964 } 965 965 966 - static inline bool pmd_user_accessible_page(pmd_t pmd) 966 + static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) 967 967 { 968 968 return pmd_leaf(pmd) && pmd_user(pmd); 969 969 } 970 970 971 - static inline bool pud_user_accessible_page(pud_t pud) 971 + static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) 972 972 { 973 973 return pud_leaf(pud) && pud_user(pud); 974 974 }
+3 -3
arch/x86/include/asm/pgtable.h
··· 1680 1680 #endif 1681 1681 1682 1682 #ifdef CONFIG_PAGE_TABLE_CHECK 1683 - static inline bool pte_user_accessible_page(pte_t pte) 1683 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 1684 1684 { 1685 1685 return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER); 1686 1686 } 1687 1687 1688 - static inline bool pmd_user_accessible_page(pmd_t pmd) 1688 + static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) 1689 1689 { 1690 1690 return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) && (pmd_val(pmd) & _PAGE_USER); 1691 1691 } 1692 1692 1693 - static inline bool pud_user_accessible_page(pud_t pud) 1693 + static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) 1694 1694 { 1695 1695 return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) && (pud_val(pud) & _PAGE_USER); 1696 1696 }
+6 -6
mm/page_table_check.c
··· 151 151 if (&init_mm == mm) 152 152 return; 153 153 154 - if (pte_user_accessible_page(pte)) { 154 + if (pte_user_accessible_page(pte, addr)) { 155 155 page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT); 156 156 } 157 157 } ··· 163 163 if (&init_mm == mm) 164 164 return; 165 165 166 - if (pmd_user_accessible_page(pmd)) { 166 + if (pmd_user_accessible_page(pmd, addr)) { 167 167 page_table_check_clear(pmd_pfn(pmd), PMD_SIZE >> PAGE_SHIFT); 168 168 } 169 169 } ··· 175 175 if (&init_mm == mm) 176 176 return; 177 177 178 - if (pud_user_accessible_page(pud)) { 178 + if (pud_user_accessible_page(pud, addr)) { 179 179 page_table_check_clear(pud_pfn(pud), PUD_SIZE >> PAGE_SHIFT); 180 180 } 181 181 } ··· 211 211 212 212 for (i = 0; i < nr; i++) 213 213 __page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i)); 214 - if (pte_user_accessible_page(pte)) 214 + if (pte_user_accessible_page(pte, addr)) 215 215 page_table_check_set(pte_pfn(pte), nr, pte_write(pte)); 216 216 } 217 217 EXPORT_SYMBOL(__page_table_check_ptes_set); ··· 241 241 242 242 for (i = 0; i < nr; i++) 243 243 __page_table_check_pmd_clear(mm, addr + PMD_SIZE * i, *(pmdp + i)); 244 - if (pmd_user_accessible_page(pmd)) 244 + if (pmd_user_accessible_page(pmd, addr)) 245 245 page_table_check_set(pmd_pfn(pmd), stride * nr, pmd_write(pmd)); 246 246 } 247 247 EXPORT_SYMBOL(__page_table_check_pmds_set); ··· 257 257 258 258 for (i = 0; i < nr; i++) 259 259 __page_table_check_pud_clear(mm, addr + PUD_SIZE * i, *(pudp + i)); 260 - if (pud_user_accessible_page(pud)) 260 + if (pud_user_accessible_page(pud, addr)) 261 261 page_table_check_set(pud_pfn(pud), stride * nr, pud_write(pud)); 262 262 } 263 263 EXPORT_SYMBOL(__page_table_check_puds_set);