Support page table check on PowerPC
Subsystems (7)
v18 cover Support page table check on PowerPC
[I will be leaving IBM in about a month from now, and will also be on leave for most of that time starting tomorrow. I've cc'd my personal email, which I am going to use for any kernel development I do after I leave, and also Srish Srinivasan, who will be taking over some of my work.]
Support page table check on PowerPC. Page table check tracks the usage of of page table entries at each level to ensure that anonymous mappings have at most one writable consumer, and likewise that file-backed mappings are not simultaneously also anonymous mappings.
In order to support this infrastructure, a number of helpers or stubs must be defined or updated for all powerpc platforms. Additionally, we separate set_pte_at() and set_pte_at_unchecked(), to allow for internal, uninstrumented mappings.
On some PowerPC platforms, implementing {pte,pmd,pud}_user_accessible_page() requires the address. We revert previous changes that removed the address parameter from various interfaces, and add it to some other interfaces, in order to allow this.
For now, we don't allow page table check alongside HUGETLB_PAGE, due to the arch-specific complexity of set_huge_page_at(). (I'm sure I could figure this out, but I have to get this version on this list before I leave my job.)
This series was initially written by Rohan McLure, who has left IBM and is no longer working on powerpc.
v18:
* Rebase on mm-new
* Add instrumentation for pudp_invalidate()
* Add cleanup patch to use pte_advance_pfn()
* Move p{m,u}d_user_accessible_page() to a more sensible place in the code
* Disable when HUGETLB_PAGE is enabled
v17:
* Rebase on mm-new to fix build failure on commit 3f3806eff23f ("riscv: use an atomic xchg in pudp_huge_get_and_clear()")
* Remove patch 10 ("powerpc: mm: Add pud_pfn() stub"), as the original reasoning for the stub is now wrong (pud_pfn() is now used more broadly in generic code, and commit 35a76f5c0863 ("mm/arch: provide pud_pfn() fallback") now provides a generic fallback. This fixes the build failure on some powerpc platforms (0day)
v16:
* Rebase on mainline
v15:
* Rebase on mainline, including commit 91e40668e70a ("mm/page_table_check: Batch-check pmds/puds just like ptes") and associated arm64 changes
* Clarify/fix some commit messages
* Fix handling of address in a loop in __page_table_check_ptes_set()
v14:
* Fix a call to page_table_check_pud_set() that was missed (akpm)
v13:
* Rebase on mainline
* Don't use set_pte_at_unchecked() for early boot purposes (Pasha)
v12:
* Rename commits that revert changes to instead reflect that we are reinstating old behaviour due to it providing more flexibility
* Add return line to pud_pfn() stub
* Instrument ptep_get_and_clear() for nohash
v11:
* The pud_pfn() stub, which previously had no legitimate users on any powerpc platform, now has users in Book3s64 with transparent pages. Include a stub of the same name for each platform that does not define their own.
* Drop patch that standardised use of p*d_leaf(), as already included upstream in v6.9.
* Provide fallback definitions of p{m,u}d_user_accessible_page() that do not reference p*d_leaf(), p*d_pte(), as they are defined after powerpc/mm headers by linux/mm headers.
* Ensure that set_pte_at_unchecked() has the same checks as set_pte_at().
v10:
* Revert patches that removed address and mm parameters from page table check routines, including consuming code from arm64, x86_64 and riscv.
* Implement *_user_accessible_page() routines in terms of pte_user() where available (64-bit, book3s) but otherwise by checking the address (on platforms where the pte does not imply whether the mapping is for user or kernel)
* Internal set_pte_at() calls replaced with set_pte_at_unchecked(), which is identical, but prevents double instrumentation.
v9:
* Adapt to using the set_ptes() API, using __set_pte_at() where we need must avoid instrumentation.
* Use the logic of *_access_permitted() for implementing *_user_accessible_page(), which are required routines for page table check.
* Even though we no longer need p{m,u,4}d_leaf(), still default implement these to assist in refactoring out extant p{m,u,4}_is_leaf().
* Add p{m,u}_pte() stubs where asm-generic does not provide them, as page table check wants all *user_accessible_page() variants, and we would like to default implement the variants in terms of pte_user_accessible_page().
* Avoid the ugly pmdp_collapse_flush() macro nonsense! Just instrument its constituent calls instead for radix and hash.
v8:
* Fix linux/page_table_check.h include in asm/pgtable.h breaking 32-bit.
v7:
* Remove use of extern in set_pte prototypes
* Clean up pmdp_collapse_flush macro
* Replace set_pte_at with static inline function
* Fix commit message for patch 7
v6:
* Support huge pages and p{m,u}d accounting.
* Remove instrumentation from set_pte from kernel internal pages.
* 64s: Implement pmdp_collapse_flush in terms of __pmdp_collapse_flush as access to the mm_struct * is required.
v5: https://lore.kernel.org/linuxppc-dev/[email protected]/
---
Andrew Donnellan (2):
arm64/mm: Add addr parameter to __set_ptes_anysz() arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz()
Rohan McLure (10):
mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud[s]_set() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd[s]_set() mm/page_table_check: Provide addr parameter to page_table_check_ptes_set() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pte_clear()
mm: Provide address parameter to p{te,md,ud}_user_accessible_page() powerpc/mm: Implement *_user_accessible_page() for ptes
powerpc/mm: Use set_pte_at_unchecked() for internal usages
powerpc/mm: Support page table check
arch/arm64/include/asm/pgtable.h | 46 +++++++++---------- arch/arm64/mm/hugetlbpage.c | 17 +++---- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/book3s/32/pgtable.h | 12 ++++- arch/powerpc/include/asm/book3s/64/pgtable.h | 62 +++++++++++++++++++++---- arch/powerpc/include/asm/nohash/pgtable.h | 13 +++++- arch/powerpc/include/asm/pgtable.h | 10 ++++ arch/powerpc/mm/book3s64/hash_pgtable.c | 4 ++ arch/powerpc/mm/book3s64/pgtable.c | 25 ++++++---- arch/powerpc/mm/book3s64/radix_pgtable.c | 9 ++-- arch/powerpc/mm/pgtable.c | 12 +++++ arch/riscv/include/asm/pgtable.h | 22 ++++----- arch/x86/include/asm/pgtable.h | 22 ++++----- include/linux/page_table_check.h | 69 ++++++++++++++++------------ include/linux/pgtable.h | 10 ++-- mm/page_table_check.c | 41 +++++++++-------- 16 files changed, 245 insertions(+), 130 deletions(-)
---
base-commit: c224625ec6f8a0476ffffc09807f4d717ba9cc93
change-id: 20251105-pgtable_check_v18rebase-2a8f88819994
--
Andrew Donnellan OzLabs, ADL Canberra
[email protected] IBM Australia Limited
PATCH v18 1/12 arm64/mm: Add addr parameter to __set_ptes_anysz()
To provide support for page table check on powerpc, we need to reinstate the address parameter in several functions, including page_table_check_{ptes,pmds,puds}_set().
In preparation for this, add the addr parameter to arm64's __set_ptes_anysz() and change its callsites accordingly.
---
v15: new patch
v16: rebase
--- arch/arm64/include/asm/pgtable.h | 19 ++++++++----------- arch/arm64/mm/hugetlbpage.c | 10 +++++----- 2 files changed, 13 insertions(+), 16 deletions(-)
arch/arm64/include/asm/pgtable.h +8 -11
@@ -673,8 +673,8 @@ static inline pgprot_t pud_pgprot(pud_t pud)return __pgprot (pud_val (pfn_pud (pfn,__pgprot (0 ))) ^pud_val (pud)); } -static inline void __set_ptes_anysz (struct mm_struct *mm,pte_t *ptep, -pte_t pte,unsigned int nr, +static inline void __set_ptes_anysz (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr,unsigned long pgsize) {unsigned long stride = pgsize >>PAGE_SHIFT ;
@@ -709,26 +709,23 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, pte_t *ptep,__set_pte_complete (pte); } -static inline void __set_ptes (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr) { -__set_ptes_anysz (mm, ptep, pte, nr,PAGE_SIZE ); +__set_ptes_anysz (mm, addr, ptep, pte, nr,PAGE_SIZE ); } -static inline void __set_pmds (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_pmds (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd,unsigned int nr) { -__set_ptes_anysz (mm, (pte_t *)pmdp,pmd_pte (pmd), nr,PMD_SIZE ); +__set_ptes_anysz (mm, addr, (pte_t *)pmdp,pmd_pte (pmd), nr,PMD_SIZE ); }#define set_pmd_at (mm, addr, pmdp, pmd) __set_pmds(mm, addr, pmdp, pmd, 1) -static inline void __set_puds (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_puds (struct mm_struct *mm,unsigned long addr,pud_t *pudp,pud_t pud,unsigned int nr) { -__set_ptes_anysz (mm, (pte_t *)pudp,pud_pte (pud), nr,PUD_SIZE ); +__set_ptes_anysz (mm, addr, (pte_t *)pudp,pud_pte (pud), nr,PUD_SIZE ); }#define set_pud_at (mm, addr, pudp, pud) __set_puds(mm, addr, pudp, pud, 1)
arch/arm64/mm/hugetlbpage.c +5 -5
@@ -225,8 +225,8 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, ncontig =num_contig_ptes (sz, &pgsize);if (!pte_present (pte)) { -for (i =0 ; i < ncontig; i++, ptep++) -__set_ptes_anysz (mm, ptep, pte,1 , pgsize); +for (i =0 ; i < ncontig; i++, ptep++, addr += pgsize) +__set_ptes_anysz (mm, addr, ptep, pte,1 , pgsize);return ; }
@@ -234,7 +234,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,if (pte_cont (pte) &&pte_valid (__ptep_get (ptep)))clear_flush (mm, addr, ptep, pgsize, ncontig); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize); } pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -449,7 +449,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,if (pte_young (orig_pte)) pte =pte_mkyoung (pte); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize);return 1 ; }
@@ -473,7 +473,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm, pte =get_clear_contig_flush (mm, addr, ptep, pgsize, ncontig); pte =pte_wrprotect (pte); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize); } pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
Signature · 1 line
2.52.0
Re: [PATCH v18 01/12] arm64/mm: Add addr parameter to __set_ptes_anysz()
Quoted 9 lines · Andrew Donnellan
To provide support for page table check on powerpc, we need to reinstate the address parameter in several functions, including page_table_check_{ptes,pmds,puds}_set().
In preparation for this, add the addr parameter to arm64's
__set_ptes_anysz()and change its callsites accordingly.Signed-off-by Andrew Donnellan <[email protected]>
Quoted 103 lines
---
v15: new patch
v16: rebase--- arch/arm64/include/asm/pgtable.h | 19 ++++++++----------- arch/arm64/mm/hugetlbpage.c | 10 +++++----- 2 files changed, 13 insertions(+), 16 deletions(-)arch/arm64/include/asm/pgtable.h +8
-11@@ -673,8 +673,8 @@ static inline pgprot_t pud_pgprot(pud_t pud)return __pgprot (pud_val (pfn_pud (pfn,__pgprot (0 ))) ^pud_val (pud)); } -static inline void __set_ptes_anysz (struct mm_struct *mm,pte_t *ptep, -pte_t pte,unsigned int nr, +static inline void __set_ptes_anysz (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr,unsigned long pgsize) {unsigned long stride = pgsize >>PAGE_SHIFT ;@@ -709,26 +709,23 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, pte_t *ptep,__set_pte_complete (pte); } -static inline void __set_ptes (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr) { -__set_ptes_anysz (mm, ptep, pte, nr,PAGE_SIZE ); +__set_ptes_anysz (mm, addr, ptep, pte, nr,PAGE_SIZE ); } -static inline void __set_pmds (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_pmds (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd,unsigned int nr) { -__set_ptes_anysz (mm, (pte_t *)pmdp,pmd_pte (pmd), nr,PMD_SIZE ); +__set_ptes_anysz (mm, addr, (pte_t *)pmdp,pmd_pte (pmd), nr,PMD_SIZE ); }#define set_pmd_at (mm, addr, pmdp, pmd) __set_pmds(mm, addr, pmdp, pmd, 1) -static inline void __set_puds (struct mm_struct *mm, -unsigned long __always_unused addr, +static inline void __set_puds (struct mm_struct *mm,unsigned long addr,pud_t *pudp,pud_t pud,unsigned int nr) { -__set_ptes_anysz (mm, (pte_t *)pudp,pud_pte (pud), nr,PUD_SIZE ); +__set_ptes_anysz (mm, addr, (pte_t *)pudp,pud_pte (pud), nr,PUD_SIZE ); }#define set_pud_at (mm, addr, pudp, pud) __set_puds(mm, addr, pudp, pud, 1)arch/arm64/mm/hugetlbpage.c +5
-6@@ -225,8 +225,8 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, ncontig =num_contig_ptes (sz, &pgsize);if (!pte_present (pte)) { -for (i =0 ; i < ncontig; i++, ptep++) -__set_ptes_anysz (mm, ptep, pte,1 , pgsize); +for (i =0 ; i < ncontig; i++, ptep++, addr += pgsize) +__set_ptes_anysz (mm, addr, ptep, pte,1 , pgsize);return ; }@@ -234,7 +234,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,if (pte_cont (pte) &&pte_valid (__ptep_get (ptep)))clear_flush (mm, addr, ptep, pgsize, ncontig); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize); } pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,@@ -449,7 +449,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,if (pte_young (orig_pte)) pte =pte_mkyoung (pte); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize);return 1 ; }@@ -473,7 +473,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm, pte =get_clear_contig_flush (mm, addr, ptep, pgsize, ncontig); pte =pte_wrprotect (pte); -__set_ptes_anysz (mm, ptep, pte, ncontig, pgsize); +__set_ptes_anysz (mm, addr, ptep, pte, ncontig, pgsize); } pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, --2.52.0
PATCH v18 2/12 arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz()
In reply to Andrew DonnellanTo provide support for page table check on powerpc, we need to reinstate the address parameter in several functions, including page_table_check_{pte,pmd,pud}_clear().
In preparation for this, add the addr parameter to arm64's __ptep_get_and_clear_anysz() and change its callsites accordingly.
---
v15: new patch
--- arch/arm64/include/asm/pgtable.h | 5 +++-- arch/arm64/mm/hugetlbpage.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-)
arch/arm64/include/asm/pgtable.h +3 -2
@@ -1332,6 +1332,7 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */ static inline pte_t __ptep_get_and_clear_anysz (struct mm_struct *mm, +unsigned long address,pte_t *ptep,unsigned long pgsize) {
@@ -1359,7 +1360,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,static inline pte_t __ptep_get_and_clear (struct mm_struct *mm,unsigned long address,pte_t *ptep) { -return __ptep_get_and_clear_anysz (mm, ptep,PAGE_SIZE ); +return __ptep_get_and_clear_anysz (mm, address, ptep,PAGE_SIZE ); } static inline void __clear_full_ptes(struct mm_struct *mm, unsigned long addr,
@@ -1398,7 +1399,7 @@ static inline pte_t __get_and_clear_full_ptes(struct mm_struct *mm,static inline pmd_t pmdp_huge_get_and_clear (struct mm_struct *mm,unsigned long address,pmd_t *pmdp) { -return pte_pmd (__ptep_get_and_clear_anysz (mm, (pte_t *)pmdp,PMD_SIZE )); +return pte_pmd (__ptep_get_and_clear_anysz (mm, address, (pte_t *)pmdp,PMD_SIZE )); }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
arch/arm64/mm/hugetlbpage.c +4 -3
@@ -159,11 +159,12 @@ static pte_t get_clear_contig(struct mm_struct *mm,pte_t pte, tmp_pte;bool present; - pte =__ptep_get_and_clear_anysz (mm, ptep, pgsize); + pte =__ptep_get_and_clear_anysz (mm, addr, ptep, pgsize); present =pte_present (pte);while (--ncontig) { ptep++; - tmp_pte =__ptep_get_and_clear_anysz (mm, ptep, pgsize); + addr += pgsize; + tmp_pte =__ptep_get_and_clear_anysz (mm, addr, ptep, pgsize);if (present) {if (pte_dirty (tmp_pte)) pte =pte_mkdirty (pte);
@@ -207,7 +208,7 @@ static void clear_flush(struct mm_struct *mm,unsigned long i, saddr = addr;for (i =0 ; i < ncontig; i++, addr += pgsize, ptep++) -__ptep_get_and_clear_anysz (mm, ptep, pgsize); +__ptep_get_and_clear_anysz (mm, addr, ptep, pgsize);if (mm == &init_mm)flush_tlb_kernel_range (saddr, addr);
Signature · 1 line
2.52.0
Re: [PATCH v18 02/12] arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz()
Quoted 9 lines · Andrew Donnellan
To provide support for page table check on powerpc, we need to reinstate the address parameter in several functions, including page_table_check_{pte,pmd,pud}_clear().
In preparation for this, add the addr parameter to arm64's
__ptep_get_and_clear_anysz()and change its callsites accordingly.Signed-off-by Andrew Donnellan <[email protected]>
PATCH v18 3/12 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud[s]_set()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
This reverts commit 6d144436d954 ("mm/page_table_check: remove unused parameter in [__]page_table_check_pud_set").
Reinstate previously unused parameters for the purpose of supporting powerpc platforms, as many do not encode user/kernel ownership of the page in the pte, but instead in the address of the access.
Apply this to __page_table_check_puds_set(), page_table_check_puds_set() and the page_table_check_pud_set() wrapper macro.
---
v13: remove inaccurate comment on riscv in the commit message
v14: fix an x86 usage I missed (found by akpm)
v15: rebase, amend commit message
--- arch/arm64/include/asm/pgtable.h | 3 ++- arch/riscv/include/asm/pgtable.h | 4 ++-- arch/x86/include/asm/pgtable.h | 4 ++-- include/linux/page_table_check.h | 12 ++++++------ mm/page_table_check.c | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-)
arch/arm64/include/asm/pgtable.h +2 -1
@@ -688,7 +688,8 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, unsigned long addr,break ;#ifndef __PAGETABLE_PMD_FOLDEDcase PUD_SIZE : -page_table_check_puds_set (mm, (pud_t *)ptep,pte_pud (pte), nr); +page_table_check_puds_set (mm, addr, (pud_t *)ptep, +pte_pud (pte), nr);break ;#endif default :
arch/riscv/include/asm/pgtable.h +2 -2
@@ -951,7 +951,7 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,static inline void set_pud_at (struct mm_struct *mm,unsigned long addr,pud_t *pudp,pud_t pud) { -page_table_check_pud_set (mm, pudp, pud); +page_table_check_pud_set (mm, addr, pudp, pud);return __set_pte_at (mm, (pte_t *)pudp,pud_pte (pud)); }
@@ -1114,7 +1114,7 @@ static inline void update_mmu_cache_pud(struct vm_area_struct *vma,static inline pud_t pudp_establish (struct vm_area_struct *vma,unsigned long address,pud_t *pudp,pud_t pud) { -page_table_check_pud_set (vma->vm_mm, pudp, pud); +page_table_check_pud_set (vma->vm_mm, address, pudp, pud);return __pud (atomic_long_xchg ((atomic_long_t *)pudp,pud_val (pud))); }
arch/x86/include/asm/pgtable.h +2 -2
@@ -1221,7 +1221,7 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,static inline void set_pud_at (struct mm_struct *mm,unsigned long addr,pud_t *pudp,pud_t pud) { -page_table_check_pud_set (mm, pudp, pud); +page_table_check_pud_set (mm, addr, pudp, pud);native_set_pud (pudp, pud); }
@@ -1372,7 +1372,7 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,static inline pud_t pudp_establish (struct vm_area_struct *vma,unsigned long address,pud_t *pudp,pud_t pud) { -page_table_check_pud_set (vma->vm_mm, pudp, pud); +page_table_check_pud_set (vma->vm_mm, address, pudp, pud);if (IS_ENABLED (CONFIG_SMP )) {return xchg (pudp, pud); }else {
include/linux/page_table_check.h +6 -6
@@ -21,8 +21,8 @@ void __page_table_check_ptes_set(struct mm_struct *mm, pte_t *ptep, pte_t pte, unsigned int nr);void __page_table_check_pmds_set (struct mm_struct *mm,pmd_t *pmdp,pmd_t pmd,unsigned int nr); -void __page_table_check_puds_set (struct mm_struct *mm,pud_t *pudp,pud_t pud, -unsigned int nr); +void __page_table_check_puds_set (struct mm_struct *mm,unsigned long addr, +pud_t *pudp,pud_t pud,unsigned int nr);void __page_table_check_pte_clear_range (struct mm_struct *mm,unsigned long addr,pmd_t pmd);
@@ -86,12 +86,12 @@ static inline void page_table_check_pmds_set(struct mm_struct *mm, }static inline void page_table_check_puds_set (struct mm_struct *mm, -pud_t *pudp,pud_t pud,unsigned int nr) +unsigned long addr,pud_t *pudp,pud_t pud,unsigned int nr) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_puds_set (mm, pudp, pud, nr); +__page_table_check_puds_set (mm, addr, pudp, pud, nr); } static inline void page_table_check_pte_clear_range(struct mm_struct *mm,
@@ -137,7 +137,7 @@ static inline void page_table_check_pmds_set(struct mm_struct *mm, }static inline void page_table_check_puds_set (struct mm_struct *mm, -pud_t *pudp,pud_t pud,unsigned int nr) +unsigned long addr,pud_t *pudp,pud_t pud,unsigned int nr) { }
@@ -150,6 +150,6 @@ static inline void page_table_check_pte_clear_range(struct mm_struct *mm,#endif /* CONFIG_PAGE_TABLE_CHECK */ #define page_table_check_pmd_set (mm, pmdp, pmd) page_table_check_pmds_set(mm, pmdp, pmd, 1) -#define page_table_check_pud_set (mm, pudp, pud) page_table_check_puds_set(mm, pudp, pud, 1) +#define page_table_check_pud_set (mm, addr, pudp, pud) page_table_check_puds_set(mm, addr, pudp, pud, 1)#endif /* __LINUX_PAGE_TABLE_CHECK_H */
mm/page_table_check.c +2 -2
@@ -243,8 +243,8 @@ void __page_table_check_pmds_set(struct mm_struct *mm, pmd_t *pmdp, pmd_t pmd, }EXPORT_SYMBOL (__page_table_check_pmds_set); -void __page_table_check_puds_set (struct mm_struct *mm,pud_t *pudp,pud_t pud, -unsigned int nr) +void __page_table_check_puds_set (struct mm_struct *mm,unsigned long addr, +pud_t *pudp,pud_t pud,unsigned int nr) {unsigned long stride =PUD_SIZE >>PAGE_SHIFT ;unsigned int i;
Signature · 1 line
2.52.0
PATCH v18 4/12 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd[s]_set()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
This reverts commit a3b837130b58 ("mm/page_table_check: remove unused parameter in [__]page_table_check_pmd_set").
Reinstate previously unused parameters for the purpose of supporting powerpc platforms, as many do not encode user/kernel ownership of the page in the pte, but instead in the address of the access.
Apply this to __page_table_check_pmds_set(), page_table_check_pmd_set(), and the page_table_check_pmd_set() wrapper macro.
---
v13: remove inaccurate comment on riscv in the commit message
v14: rebase
v15: rebase, amend commit message
--- arch/arm64/include/asm/pgtable.h | 5 +++-- arch/riscv/include/asm/pgtable.h | 4 ++-- arch/x86/include/asm/pgtable.h | 4 ++-- include/linux/page_table_check.h | 12 ++++++------ mm/page_table_check.c | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-)
arch/arm64/include/asm/pgtable.h +3 -2
@@ -684,7 +684,8 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, unsigned long addr,page_table_check_ptes_set (mm, ptep, pte, nr);break ;case PMD_SIZE : -page_table_check_pmds_set (mm, (pmd_t *)ptep,pte_pmd (pte), nr); +page_table_check_pmds_set (mm, addr, (pmd_t *)ptep, +pte_pmd (pte), nr);break ;#ifndef __PAGETABLE_PMD_FOLDEDcase PUD_SIZE :
@@ -1489,7 +1490,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,static inline pmd_t pmdp_establish (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp,pmd_t pmd) { -page_table_check_pmd_set (vma->vm_mm, pmdp, pmd); +page_table_check_pmd_set (vma->vm_mm, address, pmdp, pmd);return __pmd (xchg_relaxed (&pmd_val (*pmdp),pmd_val (pmd))); }#endif
arch/riscv/include/asm/pgtable.h +2 -2
@@ -944,7 +944,7 @@ static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) { -page_table_check_pmd_set (mm, pmdp, pmd); +page_table_check_pmd_set (mm, addr, pmdp, pmd);return __set_pte_at (mm, (pte_t *)pmdp,pmd_pte (pmd)); }
@@ -1015,7 +1015,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,static inline pmd_t pmdp_establish (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp,pmd_t pmd) { -page_table_check_pmd_set (vma->vm_mm, pmdp, pmd); +page_table_check_pmd_set (vma->vm_mm, address, pmdp, pmd);return __pmd (atomic_long_xchg ((atomic_long_t *)pmdp,pmd_val (pmd))); }
arch/x86/include/asm/pgtable.h +2 -2
@@ -1214,7 +1214,7 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp)static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) { -page_table_check_pmd_set (mm, pmdp, pmd); +page_table_check_pmd_set (mm, addr, pmdp, pmd);set_pmd (pmdp, pmd); }
@@ -1357,7 +1357,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,static inline pmd_t pmdp_establish (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp,pmd_t pmd) { -page_table_check_pmd_set (vma->vm_mm, pmdp, pmd); +page_table_check_pmd_set (vma->vm_mm, address, pmdp, pmd);if (IS_ENABLED (CONFIG_SMP )) {return xchg (pmdp, pmd); }else {
include/linux/page_table_check.h +6 -6
@@ -19,8 +19,8 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd);void __page_table_check_pud_clear (struct mm_struct *mm,pud_t pud);void __page_table_check_ptes_set (struct mm_struct *mm,pte_t *ptep,pte_t pte,unsigned int nr); -void __page_table_check_pmds_set (struct mm_struct *mm,pmd_t *pmdp,pmd_t pmd, -unsigned int nr); +void __page_table_check_pmds_set (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp,pmd_t pmd,unsigned int nr);void __page_table_check_puds_set (struct mm_struct *mm,unsigned long addr,pud_t *pudp,pud_t pud,unsigned int nr); void __page_table_check_pte_clear_range(struct mm_struct *mm,
@@ -77,12 +77,12 @@ static inline void page_table_check_ptes_set(struct mm_struct *mm, }static inline void page_table_check_pmds_set (struct mm_struct *mm, -pmd_t *pmdp,pmd_t pmd,unsigned int nr) +unsigned long addr,pmd_t *pmdp,pmd_t pmd,unsigned int nr) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_pmds_set (mm, pmdp, pmd, nr); +__page_table_check_pmds_set (mm, addr, pmdp, pmd, nr); } static inline void page_table_check_puds_set(struct mm_struct *mm,
@@ -132,7 +132,7 @@ static inline void page_table_check_ptes_set(struct mm_struct *mm, }static inline void page_table_check_pmds_set (struct mm_struct *mm, -pmd_t *pmdp,pmd_t pmd,unsigned int nr) +unsigned long addr,pmd_t *pmdp,pmd_t pmd,unsigned int nr) { }
@@ -149,7 +149,7 @@ static inline void page_table_check_pte_clear_range(struct mm_struct *mm,#endif /* CONFIG_PAGE_TABLE_CHECK */ -#define page_table_check_pmd_set (mm, pmdp, pmd) page_table_check_pmds_set(mm, pmdp, pmd, 1) +#define page_table_check_pmd_set (mm, addr, pmdp, pmd) page_table_check_pmds_set(mm, addr, pmdp, pmd, 1)#define page_table_check_pud_set (mm, addr, pudp, pud) page_table_check_puds_set(mm, addr, pudp, pud, 1)#endif /* __LINUX_PAGE_TABLE_CHECK_H */
mm/page_table_check.c +2 -2
@@ -225,8 +225,8 @@ static inline void page_table_check_pmd_flags(pmd_t pmd) } } -void __page_table_check_pmds_set (struct mm_struct *mm,pmd_t *pmdp,pmd_t pmd, -unsigned int nr) +void __page_table_check_pmds_set (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp,pmd_t pmd,unsigned int nr) {unsigned long stride =PMD_SIZE >>PAGE_SHIFT ;unsigned int i;
Signature · 1 line
2.52.0
PATCH v18 5/12 mm/page_table_check: Provide addr parameter to page_table_check_ptes_set()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
To provide support for powerpc platforms, provide an addr parameter to the __page_table_check_ptes_set() and page_table_check_ptes_set() routines. This parameter is needed on some powerpc platforms which do not encode whether a mapping is for user or kernel in the pte. On such platforms, this can be inferred from the addr parameter.
---
v15: rebase, amend commit message
--- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- include/linux/page_table_check.h | 12 +++++++----- include/linux/pgtable.h | 2 +- mm/page_table_check.c | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -1
@@ -681,7 +681,7 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, unsigned long addr,switch (pgsize) {case PAGE_SIZE : -page_table_check_ptes_set (mm, ptep, pte, nr); +page_table_check_ptes_set (mm, addr, ptep, pte, nr);break ;case PMD_SIZE : page_table_check_pmds_set(mm, addr, (pmd_t *)ptep,
arch/riscv/include/asm/pgtable.h +1 -1
@@ -631,7 +631,7 @@ static inline void __set_pte_at(struct mm_struct *mm, pte_t *ptep, pte_t pteval)static inline void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval,unsigned int nr) { -page_table_check_ptes_set (mm, ptep, pteval, nr); +page_table_check_ptes_set (mm, addr, ptep, pteval, nr);for (;;) {__set_pte_at (mm, ptep, pteval);
include/linux/page_table_check.h +7 -5
@@ -17,8 +17,8 @@ void __page_table_check_zero(struct page *page, unsigned int order);void __page_table_check_pte_clear (struct mm_struct *mm,pte_t pte);void __page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd);void __page_table_check_pud_clear (struct mm_struct *mm,pud_t pud); -void __page_table_check_ptes_set (struct mm_struct *mm,pte_t *ptep,pte_t pte, -unsigned int nr); +void __page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr);void __page_table_check_pmds_set (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd,unsigned int nr); void __page_table_check_puds_set(struct mm_struct *mm, unsigned long addr,
@@ -68,12 +68,13 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm, pud_t pud) }static inline void page_table_check_ptes_set (struct mm_struct *mm, -pte_t *ptep,pte_t pte,unsigned int nr) +unsigned long addr,pte_t *ptep, +pte_t pte,unsigned int nr) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_ptes_set (mm, ptep, pte, nr); +__page_table_check_ptes_set (mm, addr, ptep, pte, nr); } static inline void page_table_check_pmds_set(struct mm_struct *mm,
@@ -127,7 +128,8 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm, pud_t pud) }static inline void page_table_check_ptes_set (struct mm_struct *mm, -pte_t *ptep,pte_t pte,unsigned int nr) +unsigned long addr,pte_t *ptep, +pte_t pte,unsigned int nr) { }
include/linux/pgtable.h +1 -1
@@ -429,7 +429,7 @@ static inline pte_t pte_advance_pfn(pte_t pte, unsigned long nr)static inline void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr) { -page_table_check_ptes_set (mm, ptep, pte, nr); +page_table_check_ptes_set (mm, addr, ptep, pte, nr);for (;;) {set_pte (ptep, pte);
mm/page_table_check.c +2 -2
@@ -196,8 +196,8 @@ static void page_table_check_pte_flags(pte_t pte) } } -void __page_table_check_ptes_set (struct mm_struct *mm,pte_t *ptep,pte_t pte, -unsigned int nr) +void __page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) {unsigned int i;
Signature · 1 line
2.52.0
PATCH v18 6/12 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
This reverts commit 931c38e16499 ("mm/page_table_check: remove unused parameter in [__]page_table_check_pud_clear").
Reinstate previously unused parameters for the purpose of supporting powerpc platforms, as many do not encode user/kernel ownership of the page in the pte, but instead in the address of the access.
---
v15: rebase
v17: rebase, fix conflict with riscv patch
--- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- include/linux/page_table_check.h | 11 +++++++---- include/linux/pgtable.h | 2 +- mm/page_table_check.c | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -1
@@ -1349,7 +1349,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,break ;#ifndef __PAGETABLE_PMD_FOLDEDcase PUD_SIZE : -page_table_check_pud_clear (mm,pte_pud (pte)); +page_table_check_pud_clear (mm, address,pte_pud (pte));break ;#endif default :
arch/riscv/include/asm/pgtable.h +1 -1
@@ -1093,7 +1093,7 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,pud_clear (pudp);#endif -page_table_check_pud_clear (mm, pud); +page_table_check_pud_clear (mm, address, pud);return pud; }
arch/x86/include/asm/pgtable.h +1 -1
@@ -1330,7 +1330,7 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, {pud_t pud =native_pudp_get_and_clear (pudp); -page_table_check_pud_clear (mm, pud); +page_table_check_pud_clear (mm, addr, pud);return pud; }
include/linux/page_table_check.h +7 -4
@@ -16,7 +16,8 @@ extern struct page_ext_operations page_table_check_ops;void __page_table_check_zero (struct page *page,unsigned int order);void __page_table_check_pte_clear (struct mm_struct *mm,pte_t pte);void __page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd); -void __page_table_check_pud_clear (struct mm_struct *mm,pud_t pud); +void __page_table_check_pud_clear (struct mm_struct *mm,unsigned long addr, +pud_t pud);void __page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr); void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,
@@ -59,12 +60,13 @@ static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd)__page_table_check_pmd_clear (mm, pmd); } -static inline void page_table_check_pud_clear (struct mm_struct *mm,pud_t pud) +static inline void page_table_check_pud_clear (struct mm_struct *mm, +unsigned long addr,pud_t pud) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_pud_clear (mm, pud); +__page_table_check_pud_clear (mm, addr, pud); } static inline void page_table_check_ptes_set(struct mm_struct *mm,
@@ -123,7 +125,8 @@ static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd) { } -static inline void page_table_check_pud_clear (struct mm_struct *mm,pud_t pud) +static inline void page_table_check_pud_clear (struct mm_struct *mm, +unsigned long addr,pud_t pud) { }
include/linux/pgtable.h +1 -1
@@ -801,7 +801,7 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,pud_t pud = *pudp;pud_clear (pudp); -page_table_check_pud_clear (mm, pud); +page_table_check_pud_clear (mm, address, pud);return pud; }
mm/page_table_check.c +3 -2
@@ -167,7 +167,8 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd) }EXPORT_SYMBOL (__page_table_check_pmd_clear); -void __page_table_check_pud_clear (struct mm_struct *mm,pud_t pud) +void __page_table_check_pud_clear (struct mm_struct *mm,unsigned long addr, +pud_t pud) {if (&init_mm == mm)return ;
@@ -253,7 +254,7 @@ void __page_table_check_puds_set(struct mm_struct *mm, unsigned long addr,return ;for (i =0 ; i < nr; i++) -__page_table_check_pud_clear (mm, *(pudp + i)); +__page_table_check_pud_clear (mm, addr +PUD_SIZE * i, *(pudp + i));if (pud_user_accessible_page (pud))page_table_check_set (pud_pfn (pud), stride * nr,pud_write (pud)); }
Signature · 1 line
2.52.0
PATCH v18 7/12 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
This reverts commit 1831414cd729 ("mm/page_table_check: remove unused parameter in [__]page_table_check_pmd_clear").
Reinstate previously unused parameters for the purpose of supporting powerpc platforms, as many do not encode user/kernel ownership of the page in the pte, but instead in the address of the access.
---
v15: rebase
--- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- include/linux/page_table_check.h | 11 +++++++---- include/linux/pgtable.h | 2 +- mm/page_table_check.c | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -1
@@ -1345,7 +1345,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,page_table_check_pte_clear (mm, pte);break ;case PMD_SIZE : -page_table_check_pmd_clear (mm,pte_pmd (pte)); +page_table_check_pmd_clear (mm, address,pte_pmd (pte));break ;#ifndef __PAGETABLE_PMD_FOLDEDcase PUD_SIZE :
arch/riscv/include/asm/pgtable.h +1 -1
@@ -999,7 +999,7 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, {pmd_t pmd =__pmd (atomic_long_xchg ((atomic_long_t *)pmdp,0 )); -page_table_check_pmd_clear (mm, pmd); +page_table_check_pmd_clear (mm, address, pmd);return pmd; }
arch/x86/include/asm/pgtable.h +1 -1
@@ -1319,7 +1319,7 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long {pmd_t pmd =native_pmdp_get_and_clear (pmdp); -page_table_check_pmd_clear (mm, pmd); +page_table_check_pmd_clear (mm, addr, pmd);return pmd; }
include/linux/page_table_check.h +7 -4
@@ -15,7 +15,8 @@ extern struct page_ext_operations page_table_check_ops;void __page_table_check_zero (struct page *page,unsigned int order);void __page_table_check_pte_clear (struct mm_struct *mm,pte_t pte); -void __page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd); +void __page_table_check_pmd_clear (struct mm_struct *mm,unsigned long addr, +pmd_t pmd);void __page_table_check_pud_clear (struct mm_struct *mm,unsigned long addr,pud_t pud); void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
@@ -52,12 +53,13 @@ static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte)__page_table_check_pte_clear (mm, pte); } -static inline void page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd) +static inline void page_table_check_pmd_clear (struct mm_struct *mm, +unsigned long addr,pmd_t pmd) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_pmd_clear (mm, pmd); +__page_table_check_pmd_clear (mm, addr, pmd); } static inline void page_table_check_pud_clear(struct mm_struct *mm,
@@ -121,7 +123,8 @@ static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) { } -static inline void page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd) +static inline void page_table_check_pmd_clear (struct mm_struct *mm, +unsigned long addr,pmd_t pmd) { }
include/linux/pgtable.h +1 -1
@@ -788,7 +788,7 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,pmd_t pmd = *pmdp;pmd_clear (pmdp); -page_table_check_pmd_clear (mm, pmd); +page_table_check_pmd_clear (mm, address, pmd);return pmd; }
mm/page_table_check.c +3 -2
@@ -156,7 +156,8 @@ void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) }EXPORT_SYMBOL (__page_table_check_pte_clear); -void __page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd) +void __page_table_check_pmd_clear (struct mm_struct *mm,unsigned long addr, +pmd_t pmd) {if (&init_mm == mm)return ;
@@ -238,7 +239,7 @@ void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,page_table_check_pmd_flags (pmd);for (i =0 ; i < nr; i++) -__page_table_check_pmd_clear (mm, *(pmdp + i)); +__page_table_check_pmd_clear (mm, addr +PMD_SIZE * i, *(pmdp + i));if (pmd_user_accessible_page (pmd))page_table_check_set (pmd_pfn (pmd), stride * nr,pmd_write (pmd)); }
Signature · 1 line
2.52.0
PATCH v18 8/12 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pte_clear()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
This reverts commit aa232204c468 ("mm/page_table_check: remove unused parameter in [__]page_table_check_pte_clear").
Reinstate previously unused parameters for the purpose of supporting powerpc platforms, as many do not encode user/kernel ownership of the page in the pte, but instead in the address of the access.
---
v13: fix an additional occurrence
v15: rebase, fix loop handling
--- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable.h | 4 ++-- include/linux/page_table_check.h | 11 +++++++---- include/linux/pgtable.h | 4 ++-- mm/page_table_check.c | 7 ++++--- 6 files changed, 17 insertions(+), 13 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -1
@@ -1342,7 +1342,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,switch (pgsize) {case PAGE_SIZE : -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, address, pte);break ;case PMD_SIZE :page_table_check_pmd_clear (mm, address,pte_pmd (pte));
arch/riscv/include/asm/pgtable.h +1 -1
@@ -662,7 +662,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, {pte_t pte =__pte (atomic_long_xchg ((atomic_long_t *)ptep,0 )); -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, address, pte);return pte; }
arch/x86/include/asm/pgtable.h +2 -2
@@ -1252,7 +1252,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) {pte_t pte =native_ptep_get_and_clear (ptep); -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, addr, pte);return pte; }
@@ -1268,7 +1268,7 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,* care about updates and native needs no locking */ pte =native_local_ptep_get_and_clear (ptep); -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, addr, pte); }else { pte =ptep_get_and_clear (mm, addr, ptep); }
include/linux/page_table_check.h +7 -4
@@ -14,7 +14,8 @@ extern struct static_key_true page_table_check_disabled;extern struct page_ext_operations page_table_check_ops;void __page_table_check_zero (struct page *page,unsigned int order); -void __page_table_check_pte_clear (struct mm_struct *mm,pte_t pte); +void __page_table_check_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t pte);void __page_table_check_pmd_clear (struct mm_struct *mm,unsigned long addr,pmd_t pmd); void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr,
@@ -45,12 +46,13 @@ static inline void page_table_check_free(struct page *page, unsigned int order)__page_table_check_zero (page, order); } -static inline void page_table_check_pte_clear (struct mm_struct *mm,pte_t pte) +static inline void page_table_check_pte_clear (struct mm_struct *mm, +unsigned long addr,pte_t pte) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_pte_clear (mm, pte); +__page_table_check_pte_clear (mm, addr, pte); } static inline void page_table_check_pmd_clear(struct mm_struct *mm,
@@ -119,7 +121,8 @@ static inline void page_table_check_free(struct page *page, unsigned int order) { } -static inline void page_table_check_pte_clear (struct mm_struct *mm,pte_t pte) +static inline void page_table_check_pte_clear (struct mm_struct *mm, +unsigned long addr,pte_t pte) { }
include/linux/pgtable.h +2 -2
@@ -634,7 +634,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, {pte_t pte =ptep_get (ptep);pte_clear (mm, address, ptep); -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, address, pte);return pte; }#endif
@@ -693,7 +693,7 @@ static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,* No need for ptep_get_and_clear(): page table check doesn't care about * any bits that could have been set by HW concurrently. */ -page_table_check_pte_clear (mm, pte); +page_table_check_pte_clear (mm, addr, pte); }#ifdef CONFIG_GUP_GET_PXX_LOW_HIGH
mm/page_table_check.c +4 -3
@@ -145,7 +145,8 @@ void __page_table_check_zero(struct page *page, unsigned int order)rcu_read_unlock (); } -void __page_table_check_pte_clear (struct mm_struct *mm,pte_t pte) +void __page_table_check_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t pte) {if (&init_mm == mm)return ;
@@ -209,7 +210,7 @@ void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,page_table_check_pte_flags (pte);for (i =0 ; i < nr; i++) -__page_table_check_pte_clear (mm,ptep_get (ptep + i)); +__page_table_check_pte_clear (mm, addr +PAGE_SIZE * i,ptep_get (ptep + i));if (pte_user_accessible_page (pte))page_table_check_set (pte_pfn (pte), nr,pte_write (pte)); }
@@ -275,7 +276,7 @@ void __page_table_check_pte_clear_range(struct mm_struct *mm,if (WARN_ON (!ptep))return ;for (i =0 ; i <PTRS_PER_PTE ; i++) { -__page_table_check_pte_clear (mm,ptep_get (ptep)); +__page_table_check_pte_clear (mm, addr,ptep_get (ptep)); addr +=PAGE_SIZE ; ptep++; }
Signature · 1 line
2.52.0
PATCH v18 9/12 mm: Provide address parameter to p{te,md,ud}_user_accessible_page()
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
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.
---
v15: rebase
--- arch/arm64/include/asm/pgtable.h | 6 +++--- arch/riscv/include/asm/pgtable.h | 6 +++--- arch/x86/include/asm/pgtable.h | 6 +++--- mm/page_table_check.c | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-)
arch/arm64/include/asm/pgtable.h +3 -3
@@ -1265,17 +1265,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)); }
arch/riscv/include/asm/pgtable.h +3 -3
@@ -956,17 +956,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); }
arch/x86/include/asm/pgtable.h +3 -3
@@ -1680,17 +1680,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); }
mm/page_table_check.c +6 -6
@@ -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 ); } }
@@ -211,7 +211,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);
@@ -241,7 +241,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);
@@ -257,7 +257,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);
Signature · 1 line
2.52.0
PATCH v18 10/12 powerpc/mm: Implement *_user_accessible_page() for ptes
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
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.
---
v18: move the definitions of p{m,u}d_user_accessible_page() to be next to
p{m,u}d_access_permitted()
---
arch/powerpc/include/asm/book3s/32/pgtable.h | 5 +++++
arch/powerpc/include/asm/book3s/64/pgtable.h | 17 +++++++++++++++++
arch/powerpc/include/asm/nohash/pgtable.h | 5 +++++
arch/powerpc/include/asm/pgtable.h | 8 ++++++++
4 files changed, 35 insertions(+)arch/powerpc/include/asm/book3s/32/pgtable.h +5 -0
@@ -437,6 +437,11 @@ static inline bool pte_access_permitted(pte_t pte, bool write)return true; } +static inline bool pte_user_accessible_page (pte_t pte,unsigned long addr) +{ +return pte_present (pte) && !is_kernel_addr (addr); +} +/* Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. *
arch/powerpc/include/asm/book3s/64/pgtable.h +17 -0
@@ -539,6 +539,11 @@ static inline bool pte_access_permitted(pte_t pte, bool write)return arch_pte_access_permitted (pte_val (pte), write,0 ); } +static inline bool pte_user_accessible_page (pte_t pte,unsigned long addr) +{ +return pte_present (pte) &&pte_user (pte); +} +/* * Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to.
@@ -909,6 +914,12 @@ static inline bool pud_access_permitted(pud_t pud, bool write)return pte_access_permitted (pud_pte (pud), write); } +#define pud_user_accessible_page pud_user_accessible_page +static inline bool pud_user_accessible_page (pud_t pud,unsigned long addr) +{ +return pud_leaf (pud) &&pte_user_accessible_page (pud_pte (pud), addr); +} +#define __p4d_raw (x) ((p4d_t) { __pgd_raw(x) })static inline __be64 p4d_raw (p4d_t x) {
@@ -1074,6 +1085,12 @@ static inline bool pmd_access_permitted(pmd_t pmd, bool write)return pte_access_permitted (pmd_pte (pmd), write); } +#define pmd_user_accessible_page pmd_user_accessible_page +static inline bool pmd_user_accessible_page (pmd_t pmd,unsigned long addr) +{ +return pmd_leaf (pmd) &&pte_user_accessible_page (pmd_pte (pmd), addr); +} +#ifdef CONFIG_TRANSPARENT_HUGEPAGE extern pmd_t pfn_pmd (unsigned long pfn,pgprot_t pgprot);extern pud_t pfn_pud (unsigned long pfn,pgprot_t pgprot);
arch/powerpc/include/asm/nohash/pgtable.h +5 -0
@@ -243,6 +243,11 @@ static inline bool pte_access_permitted(pte_t pte, bool write)return true; } +static inline bool pte_user_accessible_page (pte_t pte,unsigned long addr) +{ +return pte_present (pte) && !is_kernel_addr (addr); +} +/* Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. *
arch/powerpc/include/asm/pgtable.h +8 -0
@@ -202,6 +202,14 @@ static inline bool arch_supports_memmap_on_memory(unsigned long vmemmap_size)#endif /* CONFIG_PPC64 */ +#ifndef pmd_user_accessible_page +#define pmd_user_accessible_page (pmd, addr) false +#endif + +#ifndef pud_user_accessible_page +#define pud_user_accessible_page (pud, addr) false +#endif +#endif /* __ASSEMBLER__ */ #endif /* _ASM_POWERPC_PGTABLE_H */
Signature · 1 line
2.52.0
Re: [PATCH v18 10/12] powerpc/mm: Implement *_user_accessible_page() for ptes
On Fri, Dec 19, 2025 at 04:09:42AM +1100, Andrew Donnellan wrote:
Hi All,
...
Quoted 2 lines
Page table checking depends on architectures providing an implementation of p{te,md,ud}_user_accessible_page.
...
arch/powerpc/include/asm/book3s/32/pgtable.h static inline bool pte_access_permitted(pte_t pte, bool write) · line 443
Quoted 4 lines
arch/powerpc/include/asm/book3s/32/pgtable.h +4
-0+static inline bool pte_user_accessible_page (pte_t pte,unsigned long addr) +{ +return pte_present (pte) && !is_kernel_addr (addr); +}
We looked into implementing this for s390 and for us the only possible user vs kernel entry attribute is comparing mm to init_mm. The generic code already does that, but I am not sure whether such check alone is enough.
But it occured to me that we could implement e.g. ARCH_SUPPORTS_PTC_USER_PAGE that adds an extra field to struct page_table_check:
struct page_table_check {
atomic_t anon_map_count;
atomic_t file_map_count;
#ifdef CONFIG_ARCH_SUPPORTS_PTC_USER_PAGE
bool user_page;#endif
};
Page Table Extensions already used by PTC, so that would fit pretty natural. Once a page is mapped into a user process it would be marked as user_page, while p{te,md,ud}_user_accessible_page() could go generic:
static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr)
{
return pte_present(pte) && page_table_check_is_user_page(pte);
}...
I guess, many architectures without viable p.._user() support could benefit from that.
But I am not sure whether is it doable, so opinions are very welcomed!
Thanks!
PATCH v18 11/12 powerpc/mm: Use set_pte_at_unchecked() for internal usages
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
In the new set_ptes() API, set_pte_at() (a special case of set_ptes()) is intended to be instrumented by the page table check facility. There are however several other routines that constitute the API for setting page table entries, including set_pmd_at() among others. Such routines are themselves implemented in terms of set_ptes_at().
A future patch providing support for page table checking on powerpc must take care to avoid duplicate calls to page_table_check_p{te,md,ud}_set(). Allow for assignment of pte entries without instrumentation through the set_pte_at_unchecked() routine introduced in this patch.
Cause API-facing routines that call set_pte_at() to instead call set_pte_at_unchecked(), which will remain uninstrumented by page table check. set_ptes() is itself implemented by calls to __set_pte_at(), so this eliminates redundant code.
---
v13: don't use the unchecked version for early-boot kernel mappings (Pasha)
--- arch/powerpc/include/asm/pgtable.h | 2 ++ arch/powerpc/mm/book3s64/pgtable.c | 6 +++--- arch/powerpc/mm/book3s64/radix_pgtable.c | 6 +++--- arch/powerpc/mm/pgtable.c | 8 ++++++++ 4 files changed, 16 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/pgtable.h +2 -0
@@ -34,6 +34,8 @@ struct mm_struct;void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr);#define set_ptes set_ptes +void set_pte_at_unchecked (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte);#define update_mmu_cache (vma, addr, ptep) \ update_mmu_cache_range(NULL, vma, addr, ptep, 1)
arch/powerpc/mm/book3s64/pgtable.c +3 -3
@@ -127,7 +127,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,WARN_ON (!(pmd_leaf (pmd)));#endif trace_hugepage_set_pmd (addr,pmd_val (pmd)); -return set_pte_at (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd)); +return set_pte_at_unchecked (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd)); } void set_pud_at(struct mm_struct *mm, unsigned long addr,
@@ -144,7 +144,7 @@ void set_pud_at(struct mm_struct *mm, unsigned long addr,WARN_ON (!(pud_leaf (pud)));#endif trace_hugepage_set_pud (addr,pud_val (pud)); -return set_pte_at (mm, addr,pudp_ptep (pudp),pud_pte (pud)); +return set_pte_at_unchecked (mm, addr,pudp_ptep (pudp),pud_pte (pud)); }static void do_serialize (void *arg)
@@ -550,7 +550,7 @@ void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr,if (radix_enabled ())return radix__ptep_modify_prot_commit (vma, addr, ptep, old_pte, pte); -set_pte_at (vma->vm_mm, addr, ptep, pte); +set_pte_at_unchecked (vma->vm_mm, addr, ptep, pte); }#ifdef CONFIG_TRANSPARENT_HUGEPAGE
arch/powerpc/mm/book3s64/radix_pgtable.c +3 -3
@@ -1606,7 +1606,7 @@ void radix__ptep_modify_prot_commit(struct vm_area_struct *vma, (atomic_read(&mm->context.copros) > 0))radix__flush_tlb_page (vma, addr); -set_pte_at (mm, addr, ptep, pte); +set_pte_at_unchecked (mm, addr, ptep, pte); }int pud_set_huge (pud_t *pud,phys_addr_t addr,pgprot_t prot)
@@ -1617,7 +1617,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)if (!radix_enabled ())return 0 ; -set_pte_at (&init_mm,0 /* radix unused */ , ptep, new_pud); +set_pte_at_unchecked (&init_mm,0 /* radix unused */ , ptep, new_pud);return 1 ; }
@@ -1664,7 +1664,7 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)if (!radix_enabled ())return 0 ; -set_pte_at (&init_mm,0 /* radix unused */ , ptep, new_pmd); +set_pte_at_unchecked (&init_mm,0 /* radix unused */ , ptep, new_pmd);return 1 ; }
arch/powerpc/mm/pgtable.c +8 -0
@@ -224,6 +224,14 @@ void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, } } +void set_pte_at_unchecked (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte) +{ +VM_WARN_ON (pte_hw_valid (*ptep) && !pte_protnone (*ptep)); + pte =set_pte_filter (pte, addr); +__set_pte_at (mm, addr, ptep, pte,0 ); +} +void unmap_kernel_page (unsigned long va) {pmd_t *pmdp =pmd_off_k (va);
Signature · 1 line
2.52.0
PATCH v18 12/12 powerpc/mm: Support page table check
In reply to Andrew DonnellanFrom: Rohan McLure <[email protected]>
On creation and clearing of a page table mapping, instrument such calls by invoking page_table_check_pte_set and page_table_check_pte_clear respectively. These calls serve as a sanity check against illegal mappings.
Enable ARCH_SUPPORTS_PAGE_TABLE_CHECK on powerpc, except when HUGETLB_PAGE is enabled (powerpc has some weirdness in how it implements set_huge_pte_at(), which may require some further work).
See also:
riscv support in commit 3fee229a8eb9 ("riscv/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")
arm64 in commit 42b2547137f5 ("arm64/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")x86_64 in commit d283d422c6c4 ("x86: mm: add x86_64 support for page table check")
---
v18:
- instrument the new pudp_invalidate()
- don't allow with HUGETLB_PAGE, for now
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/book3s/32/pgtable.h | 7 ++++- arch/powerpc/include/asm/book3s/64/pgtable.h | 45 +++++++++++++++++++++------- arch/powerpc/include/asm/nohash/pgtable.h | 8 ++++- arch/powerpc/mm/book3s64/hash_pgtable.c | 4 +++ arch/powerpc/mm/book3s64/pgtable.c | 19 ++++++++---- arch/powerpc/mm/book3s64/radix_pgtable.c | 3 ++ arch/powerpc/mm/pgtable.c | 4 +++ 8 files changed, 73 insertions(+), 18 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -172,6 +172,7 @@ config PPC select ARCH_STACKWALK select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_DEBUG_PAGEALLOC if PPC_BOOK3S || PPC_8xx + select ARCH_SUPPORTS_PAGE_TABLE_CHECK if !HUGETLB_PAGE select ARCH_SUPPORTS_SCHED_MC if SMP select ARCH_SUPPORTS_SCHED_SMT if PPC64 && SMP select SCHED_MC if ARCH_SUPPORTS_SCHED_MC
arch/powerpc/include/asm/book3s/32/pgtable.h +6 -1
@@ -202,6 +202,7 @@ void unmap_kernel_page(unsigned long va);#ifndef __ASSEMBLER__#include <linux/sched.h> #include <linux/threads.h> +#include <linux/page_table_check.h> /* Bits to mask out from a PGD to get to the PUD page */ #define PGD_MASKED_BITS 0
@@ -315,7 +316,11 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm,static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) { -return __pte (pte_update (mm, addr, ptep, ~_PAGE_HASHPTE,0 ,0 )); +pte_t old_pte =__pte (pte_update (mm, addr, ptep, ~_PAGE_HASHPTE,0 ,0 )); + +page_table_check_pte_clear (mm, addr, old_pte); + +return old_pte; }#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/book3s/64/pgtable.h +35 -10
79 lines not on this page · raw message
arch/powerpc/include/asm/nohash/pgtable.h +7 -1
@@ -29,6 +29,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p#ifndef __ASSEMBLER__ +#include <linux/page_table_check.h> +extern int icache_44x_need_flush;#ifndef pte_huge_size
@@ -122,7 +124,11 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) { -return __pte (pte_update (mm, addr, ptep, ~0UL ,0 ,0 )); +pte_t old_pte =__pte (pte_update (mm, addr, ptep, ~0UL ,0 ,0 )); + +page_table_check_pte_clear (mm, addr, old_pte); + +return old_pte; }#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
arch/powerpc/mm/book3s64/hash_pgtable.c +4 -0
@@ -8,6 +8,7 @@#include <linux/sched.h> #include <linux/mm_types.h> #include <linux/mm.h> +#include <linux/page_table_check.h> #include <linux/stop_machine.h> #include <asm/sections.h>
@@ -230,6 +231,9 @@ pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long addres pmd = *pmdp;pmd_clear (pmdp); + +page_table_check_pmd_clear (vma->vm_mm, address, pmd); +/* * Wait for all pending hash_page to finish. This is needed * in case of subpage collapse. When we collapse normal pages
arch/powerpc/mm/book3s64/pgtable.c +13 -6
@@ -10,6 +10,7 @@#include <linux/pkeys.h> #include <linux/debugfs.h> #include <linux/proc_fs.h> +#include <linux/page_table_check.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
@@ -127,6 +128,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,WARN_ON (!(pmd_leaf (pmd)));#endif trace_hugepage_set_pmd (addr,pmd_val (pmd)); +page_table_check_pmd_set (mm, addr, pmdp, pmd);return set_pte_at_unchecked (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd)); }
@@ -144,6 +146,7 @@ void set_pud_at(struct mm_struct *mm, unsigned long addr,WARN_ON (!(pud_leaf (pud)));#endif trace_hugepage_set_pud (addr,pud_val (pud)); +page_table_check_pud_set (mm, addr, pudp, pud);return set_pte_at_unchecked (mm, addr,pudp_ptep (pudp),pud_pte (pud)); }
@@ -179,23 +182,27 @@ void serialize_against_pte_lookup(struct mm_struct *mm)pmd_t pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp) { -unsigned long old_pmd; +pmd_t old_pmd;VM_WARN_ON_ONCE (!pmd_present (*pmdp)); - old_pmd =pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT, _PAGE_INVALID); + old_pmd =__pmd (pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT, _PAGE_INVALID));flush_pmd_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); -return __pmd (old_pmd); +page_table_check_pmd_clear (vma->vm_mm, address, old_pmd); + +return old_pmd; }pud_t pudp_invalidate (struct vm_area_struct *vma,unsigned long address,pud_t *pudp) { -unsigned long old_pud; +pud_t old_pud;VM_WARN_ON_ONCE (!pud_present (*pudp)); - old_pud =pud_hugepage_update (vma->vm_mm, address, pudp, _PAGE_PRESENT, _PAGE_INVALID); + old_pud =__pud (pud_hugepage_update (vma->vm_mm, address, pudp, _PAGE_PRESENT, _PAGE_INVALID));flush_pud_tlb_range (vma, address, address +HPAGE_PUD_SIZE ); -return __pud (old_pud); +page_table_check_pud_clear (vma->vm_mm, address, old_pud); + +return old_pud; } pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,
arch/powerpc/mm/book3s64/radix_pgtable.c +3 -0
@@ -14,6 +14,7 @@#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/mm.h> +#include <linux/page_table_check.h> #include <linux/hugetlb.h> #include <linux/string_helpers.h> #include <linux/memory.h>
@@ -1474,6 +1475,8 @@ pmd_t radix__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long addre pmd = *pmdp;pmd_clear (pmdp); +page_table_check_pmd_clear (vma->vm_mm, address, pmd); +radix__flush_tlb_collapsed_pmd (vma->vm_mm, address);return pmd;
arch/powerpc/mm/pgtable.c +4 -0
@@ -22,6 +22,7 @@#include <linux/mm.h> #include <linux/percpu.h> #include <linux/hardirq.h> +#include <linux/page_table_check.h> #include <linux/hugetlb.h> #include <asm/tlbflush.h> #include <asm/tlb.h>
@@ -206,6 +207,9 @@ void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep,* and not hw_valid ptes. Hence there is no translation cache flush * involved that need to be batched. */ + +page_table_check_ptes_set (mm, addr, ptep, pte, nr); +for (;;) {/*
Signature · 1 line
2.52.0
Pasha Tatashin
maintainerQuoted 28 lines · Andrew Donnellan
[I will be leaving IBM in about a month from now, and will also be on leave for most of that time starting tomorrow. I've cc'd my personal email, which I am going to use for any kernel development I do after I leave, and also Srish Srinivasan, who will be taking over some of my work.]
Support page table check on PowerPC. Page table check tracks the usage of of page table entries at each level to ensure that anonymous mappings have at most one writable consumer, and likewise that file-backed mappings are not simultaneously also anonymous mappings.
In order to support this infrastructure, a number of helpers or stubs must be defined or updated for all powerpc platforms. Additionally, we separate
set_pte_at()andset_pte_at_unchecked(), to allow for internal, uninstrumented mappings.On some PowerPC platforms, implementing {pte,pmd,pud}_user_accessible_page() requires the address. We revert previous changes that removed the address parameter from various interfaces, and add it to some other interfaces, in order to allow this.
For now, we don't allow page table check alongside
HUGETLB_PAGE, due to the arch-specific complexity ofset_huge_page_at(). (I'm sure I could figure this out, but I have to get this version on this list before I leave my job.)This series was initially written by Rohan McLure, who has left IBM and is no longer working on powerpc.
Quoted 6 lines
v18:
* Rebase on mm-new
* Add instrumentation forpudp_invalidate()
* Add cleanup patch to usepte_advance_pfn()
* Move p{m,u}d_user_accessible_page() to a more sensible place in the code
* Disable whenHUGETLB_PAGEis enabled
Thank you. This series looks good to me.
Pasha
Quoted 1 line · Pasha Tatashin
Thank you. This series looks good to me.
Thanks for the review!
Maddy, Christophe: any further comments from the PPC side?
Do we think we can get this in in the current cycle? My last day at IBM is this Friday, if a further respin is needed then Srish will need to handle it as I don't have any access to powerpc hardware outside of work (happy to provide what help I can from the outside though).
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Christophe Leroy (CS GROUP)
reviewerLe 14/01/2026 à 06:00, Andrew Donnellan a écrit :
Quoted 6 lines · Pasha Tatashin
Quoted 1 line
Thank you. This series looks good to me.
Thanks for the review!
Maddy, Christophe: any further comments from the PPC side?
No further comments from my side.
Quoted 6 lines
Do we think we can get this in in the current cycle? My last day at IBM is this Friday, if a further respin is needed then Srish will need to handle it as I don't have any access to powerpc hardware outside of work (happy to provide what help I can from the outside though).
What is the merge plan ? I see all powerpc commits are acked by Maddy, will the series be merged by Andrew into the mm tree ?
By the way it doesn't apply on top of powerpc/merge branch:
$ b4 shazam [email protected] Grabbing thread from lore.kernel.org/all/[email protected]/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 17 messages in the thread Looking for additional code-review trailers on lore.kernel.org Analyzing 86 code-review messages Checking attestation on all messages, may take a moment... --- ✓ [PATCH v18 1/12] arm64/mm: Add addr parameter to __set_ptes_anysz() + Reviewed-by: Pasha Tatashin <[email protected]> (✗ DKIM/soleen.com) ✓ [PATCH v18 2/12] arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz() + Reviewed-by: Pasha Tatashin <[email protected]> (✗ DKIM/soleen.com) ✓ [PATCH v18 3/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud[s]_set() ✓ [PATCH v18 4/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd[s]_set() ✓ [PATCH v18 5/12] mm/page_table_check: Provide addr parameter to page_table_check_ptes_set() ✓ [PATCH v18 6/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear() ✓ [PATCH v18 7/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() ✓ [PATCH v18 8/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pte_clear() ✓ [PATCH v18 9/12] mm: Provide address parameter to p{te,md,ud}_user_accessible_page() ✓ [PATCH v18 10/12] powerpc/mm: Implement *_user_accessible_page() for ptes ✓ [PATCH v18 11/12] powerpc/mm: Use set_pte_at_unchecked() for internal usages ✓ [PATCH v18 12/12] powerpc/mm: Support page table check --- ✓ Signed: DKIM/ibm.com (From: [email protected]) --- Total patches: 12 --- Base: base-commit c224625ec6f8a0476ffffc09807f4d717ba9cc93 not known, ignoring Application de arm64/mm: Add addr parameter to __set_ptes_anysz() Application de arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz() Application de mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud[s]_set() Application de mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd[s]_set() Application de mm/page_table_check: Provide addr parameter to page_table_check_ptes_set() Application de mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear() Application de mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() l'application de la rustine a échoué à 0007 mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() erreur : l'application de la rustine a échoué : arch/riscv/include/asm/pgtable.h:999 erreur : arch/riscv/include/asm/pgtable.h : la rustine ne s'applique pas astuce : Utilisez 'git am --show-current-patch=diff' pour visualiser la rustine en échec astuce : Quand vous avez résolu ce problème, lancez "git am --continue". astuce : Si vous préférez plutôt sauter cette rustine, lancez "git am --skip". astuce : Pour restaurer la branche originale et arrêter d'appliquer des rustines, lancez "git am --abort". astuce : Disable this message with "git config set advice.mergeConflict false"
Christophe
Quoted 2 lines · Christophe Leroy (CS GROUP)
What is the merge plan ? I see all powerpc commits are acked by Maddy, will the series be merged by Andrew into the mm tree ?
This is what I was expecting - this revision is rebased on mm-new as it stood around when I sent it.
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Andrew Morton
maintainerQuoted 6 lines · On Thu, 15 Jan 2026 17:13:26 +1100 Andrew Donnellan <[email protected]> wrote:
Quoted 2 lines · Christophe Leroy (CS GROUP)
What is the merge plan ? I see all powerpc commits are acked by Maddy, will the series be merged by Andrew into the mm tree ?
This is what I was expecting - this revision is rebased on mm-new as it stood around when I sent it.
Ouch, sorry, I did not understand this. So we've lost 4 weeks testing :(
The core MM and ARM changes are trival, in the if-it-compiles-it-works category. Is the mm tree really the best place for this? It'll get more testing in the powerpc tree?
But if you're OK with it, I'm OK with it.
Quoted 1 line
By the way it doesn't apply on top of powerpc/merge branch:
I guess we'll be hearing from Mark when this hits linux-next. Hopefully the resolution isn't horrible.
As I'm adding this to mm.git's mm-new branch, Mark won't actually be seeing it. I'll aim to move this into mm-unstable (and hence linux-next) after just a single day.
Quoted 18 lines · Andrew Morton
Quoted 7 lines · On Thu, 15 Jan 2026 17:13:26 +1100 Andrew Donnellan <[email protected]> wrote:
Quoted 2 lines · Christophe Leroy (CS GROUP)
What is the merge plan ? I see all powerpc commits are acked by Maddy, will the series be merged by Andrew into the mm tree ?
This is what I was expecting - this revision is rebased on mm-new as it stood
around when I sent it.Ouch, sorry, I did not understand this. So we've lost 4 weeks testing :(
The core MM and ARM changes are trival, in the if-it-compiles-it-works category. Is the mm tree really the best place for this? It'll get more testing in the powerpc tree?
But if you're OK with it, I'm OK with it.
Quoted 8 lines
Quoted 1 line
By the way it doesn't apply on top of powerpc/merge branch:
I guess we'll be hearing from Mark when this hits linux-next. Hopefully the resolution isn't horrible.
As I'm adding this to mm.git's mm-new branch, Mark won't actually be seeing it. I'll aim to move this into mm-unstable (and hence linux-next) after just a single day.
Thanks, sorry for the confusion! *Hopefully* 18th time's the charm...
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Quoted 11 lines · On Fri, 19 Dec 2025 04:09:32 +1100 you wrote:
[I will be leaving IBM in about a month from now, and will also be on leave for most of that time starting tomorrow. I've cc'd my personal email, which I am going to use for any kernel development I do after I leave, and also Srish Srinivasan, who will be taking over some of my work.]
Support page table check on PowerPC. Page table check tracks the usage of of page table entries at each level to ensure that anonymous mappings have at most one writable consumer, and likewise that file-backed mappings are not simultaneously also anonymous mappings.
[...]
Here is the summary with links:
- [v18,01/12] arm64/mm: Add addr parameter to __set_ptes_anysz()
https://git.kernel.org/riscv/c/9ac4941aceb0 - [v18,02/12] arm64/mm: Add addr parameter to __ptep_get_and_clear_anysz() https://git.kernel.org/riscv/c/ee329c29fde8 - [v18,03/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud[s]_set() https://git.kernel.org/riscv/c/c4a0c5ff85b7 - [v18,04/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd[s]_set() https://git.kernel.org/riscv/c/6e2d8f9fc4ed - [v18,05/12] mm/page_table_check: Provide addr parameter to page_table_check_ptes_set() https://git.kernel.org/riscv/c/0a5ae4483177 - [v18,06/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear() https://git.kernel.org/riscv/c/2e6ac078ce5d - [v18,07/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() (no matching commit) - [v18,08/12] mm/page_table_check: Reinstate address parameter in [__]page_table_check_pte_clear() (no matching commit) - [v18,09/12] mm: Provide address parameter to p{te,md,ud}_user_accessible_page() https://git.kernel.org/riscv/c/d79f9c9cf703 - [v18,10/12] powerpc/mm: Implement *_user_accessible_page() for ptes https://git.kernel.org/riscv/c/2f5e576598c9 - [v18,11/12] powerpc/mm: Use set_pte_at_unchecked() for internal usages https://git.kernel.org/riscv/c/2360f523a49b - [v18,12/12] powerpc/mm: Support page table check https://git.kernel.org/riscv/c/641d47d4c963
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html