mm: proc/task_mmu: Use walk_page_range_vma() for smaps
Subsystems (4)
PATCH 1/1 mm: proc/task_mmu: Use walk_page_range_vma() for smaps
From: Kalesh Singh <[email protected]>
Modify smap_gather_stats() to use walk_page_range_vma() instead of walk_page_range() when walking page tables.
walk_page_range() internally calls find_vma(), which asserts that mmap_lock is held. This assertion fails when reading /proc/pid/smaps under per-VMA locks (where mmap_lock is not held).
walk_page_range_vma() walks a range within a single VMA and does not use find_vma(). It relies on the VMA lock instead (when configured with PGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.
--- fs/proc/task_mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/proc/task_mmu.c +5 -5
@@ -1369,9 +1369,12 @@ static void smap_gather_stats(struct proc_maps_private *priv, struct mem_size_stats *mss, unsigned long start) {const struct mm_walk_ops *ops =get_smaps_walk_ops (priv); +unsigned long end = vma->vm_end; + + start = start ?: vma->vm_start;/* Invalid start */ -if (start >= vma->vm_end) +if (start >= end)return ;if (vma ==get_gate_vma (priv->lock_ctx.mm))
@@ -1401,10 +1404,7 @@ static void smap_gather_stats(struct proc_maps_private *priv, } } -if (!start) -walk_page_vma (vma, ops, mss); -else -walk_page_range (vma->vm_mm, start, vma->vm_end, ops, mss); +walk_page_range_vma (vma, start, end, ops, mss);reacquire_rcu (priv); }
base-commit: b95f03f04d475aa6719d15a636ddf32222d55657
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Quoted 30 lines · kaleshsingh via kernel-team
From: Kalesh Singh <[email protected]>
Modify
smap_gather_stats()to usewalk_page_range_vma()instead ofwalk_page_range()when walking page tables.
walk_page_range()internally callsfind_vma(), which asserts thatmmap_lockis held. This assertion fails when reading/proc/pid/smapsunder per-VMA locks (wheremmap_lockis not held).
walk_page_range_vma()walks a range within a single VMA and does not usefind_vma(). It relies on the VMA lock instead (when configured withPGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.Fixes ea3085dd7a4e ("fs/proc/task_mmu: read proc/pid/{smaps|numa_maps} under per-vma lock")Cc Andrew Morton <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Signed-off-by Kalesh Singh <[email protected]>--- fs/proc/task_mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)fs/proc/task_mmu.c +0
-0
fs/proc/task_mmu.c static void smap_gather_stats(struct proc_maps_private *priv, · line 1374
Quoted 6 lines
fs/proc/task_mmu.c +3
-0@@ -1369,9 +1369,12 @@ static void smap_gather_stats(struct proc_maps_private *priv, struct mem_size_stats *mss, unsigned long start) {const struct mm_walk_ops *ops =get_smaps_walk_ops (priv); +unsigned long end = vma->vm_end; + + start = start ?: vma->vm_start;
Doesn't overwriting start here break the !start && (!shmem_swapped || ... check below when smap_gather_stats is called with start = 0 as in show_smaps_rollup?
Quoted 26 lines
fs/proc/task_mmu.c +2
-5/* Invalid start */ -if (start >= vma->vm_end) +if (start >= end)return ;if (vma ==get_gate_vma (priv->lock_ctx.mm))@@ -1401,10 +1404,7 @@ static void smap_gather_stats(struct proc_maps_private *priv, } } -if (!start) -walk_page_vma (vma, ops, mss); -else -walk_page_range (vma->vm_mm, start, vma->vm_end, ops, mss); +walk_page_range_vma (vma, start, end, ops, mss);reacquire_rcu (priv); }base-commit:
b95f03f04d475aa6719d15a636ddf32222d55657--
2.55.0.229.g6434b31f56-googTo unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Quoted 28 lines · T.J. Mercier
Quoted 25 lines · kaleshsingh via kernel-team
From: Kalesh Singh <[email protected]>
Modify
smap_gather_stats()to usewalk_page_range_vma()instead ofwalk_page_range()when walking page tables.
walk_page_range()internally callsfind_vma(), which asserts thatmmap_lockis held. This assertion fails when reading/proc/pid/smapsunder per-VMA locks (wheremmap_lockis not held).
walk_page_range_vma()walks a range within a single VMA and does not usefind_vma(). It relies on the VMA lock instead (when configured withPGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.Fixes ea3085dd7a4e ("fs/proc/task_mmu: read proc/pid/{smaps|numa_maps} under per-vma lock")Cc Andrew Morton <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Signed-off-by Kalesh Singh <[email protected]>--- fs/proc/task_mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 15 lines
fs/proc/task_mmu.c static void smap_gather_stats(struct proc_maps_private *priv, · line 1374
Quoted 11 lines
fs/proc/task_mmu.c +3
-0@@ -1369,9 +1369,12 @@ static void smap_gather_stats(struct proc_maps_private *priv, struct mem_size_stats *mss, unsigned long start) {const struct mm_walk_ops *ops =get_smaps_walk_ops (priv); +unsigned long end = vma->vm_end; + + start = start ?: vma->vm_start;Doesn't overwriting start here break the !start && (!shmem_swapped || ... check below when
smap_gather_statsis called with start = 0 as inshow_smaps_rollup?
Hi Tj,
You are right, I should have updated it to start == vm_start. I will fix this in v2.
Thanks,
Kalesh
Quoted 27 lines
Quoted 27 lines
fs/proc/task_mmu.c +2
-5/* Invalid start */ -if (start >= vma->vm_end) +if (start >= end)return ;if (vma ==get_gate_vma (priv->lock_ctx.mm))@@ -1401,10 +1404,7 @@ static void smap_gather_stats(struct proc_maps_private *priv, } } -if (!start) -walk_page_vma (vma, ops, mss); -else -walk_page_range (vma->vm_mm, start, vma->vm_end, ops, mss); +walk_page_range_vma (vma, start, end, ops, mss);reacquire_rcu (priv); }base-commit:
b95f03f04d475aa6719d15a636ddf32222d55657--
2.55.0.229.g6434b31f56-googTo unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Andrew Morton
maintainerQuoted 8 lines · On Tue, 21 Jul 2026 05:19:02 +0000 [email protected] wrote:
From: Kalesh Singh <[email protected]>
Modify
smap_gather_stats()to usewalk_page_range_vma()instead ofwalk_page_range()when walking page tables.
walk_page_range()internally callsfind_vma(), which asserts thatmmap_lockis held. This assertion fails when reading/proc/pid/smapsunder per-VMA locks (wheremmap_lockis not held).
So the kernel is emitting a WARN trace under some situation?
I'm surprised. The offending patch is only six weeks old, but we'd
normally hear about this very promptly. Is a bug report available
somewhere?
Quoted 4 lines
walk_page_range_vma()walks a range within a single VMA and does not usefind_vma(). It relies on the VMA lock instead (when configured withPGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.
Sashiko said a thing:
https://sashiko.dev/#/patchset/[email protected]
Quoted 12 lines · Andrew Morton
Quoted 8 lines · On Tue, 21 Jul 2026 05:19:02 +0000 [email protected] wrote:
From: Kalesh Singh <[email protected]>
Modify
smap_gather_stats()to usewalk_page_range_vma()instead ofwalk_page_range()when walking page tables.
walk_page_range()internally callsfind_vma(), which asserts thatmmap_lockis held. This assertion fails when reading/proc/pid/smapsunder per-VMA locks (wheremmap_lockis not held).
Quoted 5 lines
So the kernel is emitting a WARN trace under some situation?
I'm surprised. The offending patch is only six weeks old, but we'd
normally hear about this very promptly. Is a bug report available
somewhere?
No, when reading smaps "start" is always false, so walk_page_range() is never called.
Kalesh, this is not a problem that ever happens in the upstream kernel. In Android kernel there was an out-of-tree change that caused this warning, which I pointed out and you fixed. However, the upstream kernel does not have this issue.
Quoted 9 lines
Quoted 5 lines
walk_page_range_vma()walks a range within a single VMA and does not usefind_vma(). It relies on the VMA lock instead (when configured withPGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.Sashiko said a thing:
https://sashiko.dev/#/patchset/[email protected]
Quoted 20 lines · Suren Baghdasaryan
Quoted 12 lines · Andrew Morton
Quoted 8 lines · On Tue, 21 Jul 2026 05:19:02 +0000 [email protected] wrote:
From: Kalesh Singh <[email protected]>
Modify
smap_gather_stats()to usewalk_page_range_vma()instead ofwalk_page_range()when walking page tables.
walk_page_range()internally callsfind_vma(), which asserts thatmmap_lockis held. This assertion fails when reading/proc/pid/smapsunder per-VMA locks (wheremmap_lockis not held).Quoted 5 lines
So the kernel is emitting a WARN trace under some situation?
I'm surprised. The offending patch is only six weeks old, but we'd
normally hear about this very promptly. Is a bug report available
somewhere?
Quoted 6 lines
No, when reading smaps "start" is always false, so
walk_page_range()is never called.
Kalesh, this is not a problem that ever happens in the upstream kernel. In Android kernel there was an out-of-tree change that caused this warning, which I pointed out and you fixed. However, the upstream kernel does not have this issue.
Hi Suren, thanks for the clarification.
Sorry for the confusion, Andrew. Please ignore this patch.
Thanks,
Kalesh
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
walk_page_range_vma()walks a range within a single VMA and does not usefind_vma(). It relies on the VMA lock instead (when configured withPGWALK_VMA_RDLOCK_VERIFY), making it compatible with per-VMA locks.Sashiko said a thing:
https://sashiko.dev/#/patchset/[email protected]