Re: [PATCH v2 2/4] mm: make folio_walk_start()'s locking asserts scalable
From: David Hildenbrand (Arm)
Date: Sun Nov 22 2026 - 11:29:08 EST
On 11/2/26 14:29, xu.xin@xxxxxxxxx wrote:
> From: Xu Xin <xu.xin@xxxxxxxxx>
>
> Add an additional member 'walk_lock' to folio_walk to indicate
> locking requirements for the walk. Similar to commit 49b0638502da0
> ("mm: enable page walking API to lock vmas during the walk").
> But no change is made on any existing locking behavior,
> all existing folio_walk_start() callers are currently still
> under mmap_read_lock() protection.
>
> This change is prepared for the later patch to enable VMA locking
> asserts. folio_walk_start now operate under write-locked mmap_lock.
> With introduction of vma locks at the next patch, the vmas have to
> be locked as well during such walks to prevent concurrent page
> faults in these areas.
>
> No functional change intended.
>
> Signed-off-by: Xu Xin <xu.xin@xxxxxxxxx>
> ---
> arch/s390/mm/fault.c | 4 +++-
> include/linux/pagewalk.h | 1 +
> kernel/events/uprobes.c | 4 +++-
> mm/huge_memory.c | 4 +++-
> mm/ksm.c | 4 +++-
> mm/migrate.c | 8 ++++++--
> mm/pagewalk.c | 10 +++++++++-
> mm/rmap.c | 4 +++-
> 8 files changed, 31 insertions(+), 8 deletions(-)
>
> diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
> index 46d828926009..968f128a5232 100644
> --- a/arch/s390/mm/fault.c
> +++ b/arch/s390/mm/fault.c
> @@ -412,7 +412,9 @@ __context_unsafe(/* folio_walk_end() not instrumented */)
> unsigned long addr = get_fault_address(regs);
> struct mm_struct *mm = current->mm;
> struct vm_area_struct *vma;
> - struct folio_walk fw;
> + struct folio_walk fw = {
> + .walk_lock = PGWALK_RDLOCK,
> + };
> struct folio *folio;
> int rc;
>
> diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h
> index 1c397be0d092..455428eaf1fc 100644
> --- a/include/linux/pagewalk.h
> +++ b/include/linux/pagewalk.h
> @@ -184,6 +184,7 @@ struct folio_walk {
> };
> /* private */
> spinlock_t *ptl;
Ah, Sashiko is right here that this belongs into the public part and should get
kerneldoc.
But, "struct folio_walk" is currently filled out exclusively by
folio_walk_start(), and I'd like to keep it like that.
Also, I don't enjoy that we are reusing PGWALK_* stuff here.
Why not add a second function variant that targets the per-vma lock and branches
internally to a common helper?
diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h
index b41d7265c01bc..13f911e1db5d2 100644
--- a/include/linux/pagewalk.h
+++ b/include/linux/pagewalk.h
@@ -191,6 +191,10 @@ struct folio *folio_walk_start(struct folio_walk *fw,
struct vm_area_struct *vma, unsigned long addr,
folio_walk_flags_t flags);
+struct folio *folio_walk_start_vma_rdlock(struct folio_walk *fw,
+ struct vm_area_struct *vma, unsigned long addr,
+ folio_walk_flags_t flags);
+
Or something like that.
That also means that we don't have to touch any existing helpers and we won't
even have to store that type.
But now I wonder: do we need that *at all* ? It's effectively a parameter just
to do safety checks.
I'd just document locking requirements (mmap lock or per-vma read lock must be
held) and call it a day.
--
Cheers,
David