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.

powerpc/mm: implement *_user_accessible_page() for ptes

Page table checking depends on architectures providing an implementation
of p{te,md,ud}_user_accessible_page. With refactorisations made on
powerpc/mm, the pte_access_permitted() and similar methods verify whether
a userland page is accessible with the required permissions.

Since page table checking is the only user of
p{te,md,ud}_user_accessible_page(), implement these for all platforms,
using some of the same preliminary checks taken by pte_access_permitted()
on that platform.

Since commit 8e9bd41e4ce1 ("powerpc/nohash: Replace pte_user() by
pte_read()") pte_user() is no longer required to be present on all
platforms as it may be equivalent to or implied by pte_read(). Hence
implementations of pte_user_accessible_page() are specialised.

[ajd@linux.ibm.com: rebase and clean up]
Link: https://lkml.kernel.org/r/20251219-pgtable_check_v18rebase-v18-10-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: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
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: Ingo Molnar <mingo@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kevin Brodsky <kevin.brodsky@arm.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
2f5e5765 d79f9c9c

+35
+5
arch/powerpc/include/asm/book3s/32/pgtable.h
··· 437 437 return true; 438 438 } 439 439 440 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 441 + { 442 + return pte_present(pte) && !is_kernel_addr(addr); 443 + } 444 + 440 445 /* Conversion functions: convert a page and protection to a page entry, 441 446 * and a page entry and page directory to the page they refer to. 442 447 *
+17
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 539 539 return arch_pte_access_permitted(pte_val(pte), write, 0); 540 540 } 541 541 542 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 543 + { 544 + return pte_present(pte) && pte_user(pte); 545 + } 546 + 542 547 /* 543 548 * Conversion functions: convert a page and protection to a page entry, 544 549 * and a page entry and page directory to the page they refer to. ··· 914 909 return pte_access_permitted(pud_pte(pud), write); 915 910 } 916 911 912 + #define pud_user_accessible_page pud_user_accessible_page 913 + static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) 914 + { 915 + return pud_leaf(pud) && pte_user_accessible_page(pud_pte(pud), addr); 916 + } 917 + 917 918 #define __p4d_raw(x) ((p4d_t) { __pgd_raw(x) }) 918 919 static inline __be64 p4d_raw(p4d_t x) 919 920 { ··· 1083 1072 return false; 1084 1073 1085 1074 return pte_access_permitted(pmd_pte(pmd), write); 1075 + } 1076 + 1077 + #define pmd_user_accessible_page pmd_user_accessible_page 1078 + static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) 1079 + { 1080 + return pmd_leaf(pmd) && pte_user_accessible_page(pmd_pte(pmd), addr); 1086 1081 } 1087 1082 1088 1083 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
+5
arch/powerpc/include/asm/nohash/pgtable.h
··· 243 243 return true; 244 244 } 245 245 246 + static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) 247 + { 248 + return pte_present(pte) && !is_kernel_addr(addr); 249 + } 250 + 246 251 /* Conversion functions: convert a page and protection to a page entry, 247 252 * and a page entry and page directory to the page they refer to. 248 253 *
+8
arch/powerpc/include/asm/pgtable.h
··· 202 202 203 203 #endif /* CONFIG_PPC64 */ 204 204 205 + #ifndef pmd_user_accessible_page 206 + #define pmd_user_accessible_page(pmd, addr) false 207 + #endif 208 + 209 + #ifndef pud_user_accessible_page 210 + #define pud_user_accessible_page(pud, addr) false 211 + #endif 212 + 205 213 #endif /* __ASSEMBLER__ */ 206 214 207 215 #endif /* _ASM_POWERPC_PGTABLE_H */