Re: [PATCH v2 0/6] mm: add basic PTE const type-safety
From: Anshuman Khandual
Date: Wed Aug 05 2026 - 06:43:12 EST
On Mon, Aug 03, 2026 at 05:43:54PM +0100, Pedro Falcato wrote:
> Since forever, MM code has thrown pte_t * around with no concern for const
> safety, or typesafety of any kind. This is confusing. Attempt to address it
> by:
> 1) Making sure pte_get*() helpers can cope with const pte_t * arguments
> 2) Constifying the pte_offset_map_ro_nolock() return type, which by definition
> already pledges that users will not write to it.
>
> These two simple steps were already able to uncover code smell from
> khugepaged + do_swap_page().
>
> Separate steps could include introducing pte_offset_map_ro_lock() for more
> widespread usage of this.
>
> Benefits of this include less confusion and better type-safety. It could also
> futurely aid in efforts such as [0] which may want semantic annotation of these
> accesses.
>
> Based on mm-unstable and compile-tested on a handful of architectures.
>
> No functional changes intended.
Even though the pte accesses should always be type-safe, this series does
not really address the problem completely and instead changes things only
for a small set of pte access sites. So just wondering how much beneficial
this series really is ?
>
> [CC list editorially trimmed for brevity reasons; apologies if you're not on it]
>
> Link: https://lore.kernel.org/linux-mm/20260526-kpkeys-v8-0-eaaacdacc67c@xxxxxxx/#t [0]
> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> Cc: Will Deacon <will@xxxxxxxxxx>
> Cc: "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>
> Cc: Helge Deller <deller@xxxxxx>
> Cc: Madhavan Srinivasan <maddy@xxxxxxxxxxxxx>
> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
> Cc: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> Cc: "Liam R. Howlett" <liam@xxxxxxxxxxxxx>
> Cc: Vlastimil Babka <vbabka@xxxxxxxxxx>
> Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxx>
> Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: Zi Yan <ziy@xxxxxxxxxx>
> Cc: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
> Cc: Nico Pache <npache@xxxxxxxxxx>
> Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
> Cc: Dev Jain <dev.jain@xxxxxxx>
> Cc: Barry Song <baohua@xxxxxxxxxx>
> Cc: Lance Yang <lance.yang@xxxxxxxxx>
> Cc: Usama Arif <usama.arif@xxxxxxxxx>
> Cc: Kevin Brodsky <kevin.brodsky@xxxxxxx>
> Cc: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Cc: linux-parisc@xxxxxxxxxxxxxxx
> Cc: linuxppc-dev@xxxxxxxxxxxxxxxx
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-fsdevel@xxxxxxxxxxxxxxx
>
> v2:
> - Small fixups on the arm64 side
> - Re-order patches in a way such that bisection is preserved
> - Pick up Helge's patch dropping parisc ptep_get()
> - Constify s390's ptep_get() as well
>
> Helge Deller (1):
> parisc: Drop own implementations for ptep_get() and
> ptep_test_and_clear_young()
>
> Pedro Falcato (5):
> mm/arm64: constify pte_get*() and contpte get logic
> mm/powerpc/8xx: constify ptep_get() argument
> mm/s390: constify ptep_get() argument
> mm: constify generic pte_get*()
> mm: constify the pte_offset_map_ro_nolock() return value
>
> arch/arm64/include/asm/pgtable.h | 10 +++++-----
> arch/arm64/mm/contpte.c | 11 ++++++++---
> arch/parisc/include/asm/pgtable.h | 20 --------------------
> arch/powerpc/include/asm/nohash/32/pte-8xx.h | 2 +-
> arch/powerpc/mm/pgtable.c | 2 +-
> arch/s390/include/asm/pgtable.h | 2 +-
> include/linux/mm.h | 4 ++--
> include/linux/pgtable.h | 8 ++++----
> mm/filemap.c | 2 +-
> mm/khugepaged.c | 2 +-
> mm/pgtable-generic.c | 4 ++--
> 11 files changed, 26 insertions(+), 41 deletions(-)
>
> --
> 2.55.0
>