[PATCH v18 00/12] Support page table check on PowerPC

Andrew Donnellan posted 12 patches 1 month, 2 weeks ago
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(-)
[PATCH v18 00/12] Support page table check on PowerPC
Posted by Andrew Donnellan 1 month, 2 weeks ago
[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)
Link: https://lore.kernel.org/all/20250909091335.183439-1-ajd@linux.ibm.com/

v16:
 * Rebase on mainline
Link: https://lore.kernel.org/all/20250813062614.51759-1-ajd@linux.ibm.com/

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()
Link: https://lore.kernel.org/all/20250625063753.77511-1-ajd@linux.ibm.com/

v14:
 * Fix a call to page_table_check_pud_set() that was missed (akpm)
Link: https://lore.kernel.org/all/20250411054354.511145-1-ajd@linux.ibm.com/

v13:
 * Rebase on mainline
 * Don't use set_pte_at_unchecked() for early boot purposes (Pasha)
Link: https://lore.kernel.org/linuxppc-dev/20250211161404.850215-1-ajd@linux.ibm.com/

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
Link: https://lore.kernel.org/linuxppc-dev/20240402051154.476244-1-rmclure@linux.ibm.com/

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().
Link: https://lore.kernel.org/linuxppc-dev/20240328045535.194800-14-rmclure@linux.ibm.com/ 

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.
Link: https://lore.kernel.org/linuxppc-dev/20240313042118.230397-9-rmclure@linux.ibm.com/T/

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.
Link: https://lore.kernel.org/linuxppc-dev/20231130025404.37179-2-rmclure@linux.ibm.com/

v8:
 * Fix linux/page_table_check.h include in asm/pgtable.h breaking
   32-bit.
Link: https://lore.kernel.org/linuxppc-dev/20230215231153.2147454-1-rmclure@linux.ibm.com/

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
Link: https://lore.kernel.org/linuxppc-dev/20230215020155.1969194-1-rmclure@linux.ibm.com/

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.
Link: https://lore.kernel.org/linuxppc-dev/20230214015939.1853438-1-rmclure@linux.ibm.com/

v5: https://lore.kernel.org/linuxppc-dev/20221118002146.25979-1-rmclure@linux.ibm.com/

---
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
ajd@linux.ibm.com   IBM Australia Limited
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Pasha Tatashin 1 month, 2 weeks ago
On Thu, Dec 18, 2025 at 12:10 PM Andrew Donnellan <ajd@linux.ibm.com> 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.
>
> 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

Thank you. This series looks good to me.

Pasha
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Andrew Donnellan 3 weeks, 3 days ago
On Thu, 2025-12-18 at 12:55 -0500, Pasha Tatashin wrote:
> 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).

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Christophe Leroy (CS GROUP) 3 weeks, 2 days ago

Le 14/01/2026 à 06:00, Andrew Donnellan a écrit :
> On Thu, 2025-12-18 at 12:55 -0500, Pasha Tatashin wrote:
>> 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.

> 
> 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 bf0def77b07a34c00928cedb46030ea17be4fceb.camel@linux.ibm.com
Grabbing thread from 
lore.kernel.org/all/bf0def77b07a34c00928cedb46030ea17be4fceb.camel@linux.ibm.com/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 <pasha.tatashin@soleen.com> (✗ 
DKIM/soleen.com)
   ✓ [PATCH v18 2/12] arm64/mm: Add addr parameter to 
__ptep_get_and_clear_anysz()
     + Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> (✗ 
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: ajd@linux.ibm.com)
---
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
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Andrew Donnellan 3 weeks, 2 days ago
On Wed, 2026-01-14 at 10:34 +0100, Christophe Leroy (CS GROUP) wrote:
> 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.

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Andrew Morton 3 weeks, 1 day ago
On Thu, 15 Jan 2026 17:13:26 +1100 Andrew Donnellan <ajd@linux.ibm.com> wrote:

> On Wed, 2026-01-14 at 10:34 +0100, Christophe Leroy (CS GROUP) wrote:
> > 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.

> 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.
Re: [PATCH v18 00/12] Support page table check on PowerPC
Posted by Andrew Donnellan 3 weeks, 1 day ago
On Thu, 2026-01-15 at 16:18 -0800, Andrew Morton wrote:
> On Thu, 15 Jan 2026 17:13:26 +1100 Andrew Donnellan <ajd@linux.ibm.com> wrote:
> 
> > On Wed, 2026-01-14 at 10:34 +0100, Christophe Leroy (CS GROUP) wrote:
> > > 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.
> 
> > 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...


-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited