Skip to contentSkip to conversation

fs/proc/task_mmu: advance seq_file position on interrupted VMA lookup

PATCH Superseded Adrian Huang (Lenovo) 4 participants 7 messages Nov 12 – Nov 17

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/proc/task_mmu: advance seq_file position on interrupted VMA lookup

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

Update the position index when VMA lookup fails, as required by the seq_file interface. Also save the original position in priv->last_pos so that subsequent iteration can restart from the correct address without skipping or repeating a VMA.

Fixes 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock")
---
 fs/proc/task_mmu.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/proc/task_mmu.c +10 -0
index 22361607020d..164b4efc5e09 100644
@@ -221,6 +221,16 @@ static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppos)
 		if (PTR_ERR(vma) == -EAGAIN && fallback_to_mmap_lock(priv, *ppos))
 			goto retry;
 
+		/*
+		 * seq_file checks that the position advanced before it looks at
+		 * the returned pointer, so an error return that leaves *ppos
+		 * alone is reported as a buggy ->next. Advance it, and keep
+		 * last_pos at the pending position so m_start() would resume
+		 * the lookup from there.
+		 */
+		priv->last_pos = *ppos;
+		(*ppos)++;
+
 		return vma;
 	}
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines · On Thu, 12 Nov 2026 22:01:01 +0800 "Adrian Huang (Lenovo)"…

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

OK, but what's causing the interruption?

Quoted 9 lines

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

afaict "stress-ng -t" can send SIGALRM, but mmap_read_lock_killable() only responds to fatal signals.

So please clarify: exactly what is causing this to happen?

#2 lore raw
Quoted 15 lines · Andrew Morton
Quoted 3 lines · On Thu, 12 Nov 2026 22:01:01 +0800 "Adrian Huang (Lenovo)"…

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

OK, but what's causing the interruption?

Quoted 6 lines

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

Quoted 8 lines
Quoted 3 lines

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

afaict "stress-ng -t" can send SIGALRM, but mmap_read_lock_killable() only responds to fatal signals.

So please clarify: exactly what is causing this to happen?

Also I don't think stress-ng --vma 0 -t 60 command reads maps, smaps or smaps_rollup files by itself but I might be mistaken. It would be nice to get more details on how this gets reproduced.

Quoted 2 lines
#3 lore raw
Quoted 21 lines · Suren Baghdasaryan
Quoted 19 lines · Andrew Morton
Quoted 3 lines · On Thu, 12 Nov 2026 22:01:01 +0800 "Adrian Huang (Lenovo)"…

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

OK, but what's causing the interruption?

Quoted 9 lines

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60
Quoted 8 lines
Quoted 4 lines

afaict "stress-ng -t" can send SIGALRM, but mmap_read_lock_killable() only responds to fatal signals.

So please clarify: exactly what is causing this to happen?

Also I don't think stress-ng --vma 0 -t 60 command reads maps, smaps or smaps_rollup files by itself but I might be mistaken. It would be nice to get more details on how this gets reproduced.

Just after sending this I found
https://github.com/ColinIanKing/stress-ng/blob/master/stress-vma.c#L536,
so I stand corrected. Still, it would be nice to know how exactly this issue is reproduced.

Quoted 3 lines
Quoted 3 lines
#4 lore raw

Hi Andrew and Suren,

Quoted 28 lines · Suren Baghdasaryan
Quoted 26 lines · Suren Baghdasaryan
Quoted 23 lines · Andrew Morton
Quoted 3 lines · On Thu, 12 Nov 2026 22:01:01 +0800 "Adrian Huang (Lenovo)"…

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

OK, but what's causing the interruption?

Quoted 9 lines

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

afaict "stress-ng -t" can send SIGALRM, but mmap_read_lock_killable() only responds to fatal signals.

So please clarify: exactly what is causing this to happen?

Quoted 8 lines
Quoted 3 lines

Also I don't think stress-ng --vma 0 -t 60 command reads maps, smaps or smaps_rollup files by itself but I might be mistaken. It would be nice to get more details on how this gets reproduced.

Just after sending this I found
https://github.com/ColinIanKing/stress-ng/blob/master/stress-vma.c#L536,
so I stand corrected. Still, it would be nice to know how exactly this issue is reproduced.

The --vma stressor performs the following jobs:
* It creates a thread that repeatedly reads /proc/self/maps while other threads modify the process's VMAs[1][2].
* It sends SIGKILL (fatal signal) to its own threads approximately every 10 seconds[3]. This happens independently of the 60-second timeout for the command 'stress-ng --vma 0 -t 60'.

As a result, down_read_killable() in Linux kernel returns -EINTR.

This finding is based on code inspection and analysis. To validate the behavior, I collected ftrace logs and added debug patches to trace the relevant task PID/TID information. The full explanation is fairly detailed, so I have not included it here, but I can provide it if there's interest.

[1] https://github.com/ColinIanKing/stress-ng/blob/master/stress-vma.c#L748
[2] https://github.com/ColinIanKing/stress-ng/blob/master/stress-vma.c#L658
[3] https://github.com/ColinIanKing/stress-ng/blob/master/stress-vma.c#L768

-- Adrian

#5 lore raw
In reply to Adrian Huang (Lenovo)
Quoted 9 lines · Adrian Huang (Lenovo)

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

What does seq_read_iter() 'reporting' something mean? It feels like you're trying to make this into something bigger than it is.

What you mean to say is a rate-limited pr_info() output occurs, and when a process that _has received a fatal signal_ (!!) somehow continues long enough to try to output more data, you get an pr_info().

The relevant code from seq_read_iter():

		if (pos == m->index) {
			pr_info_ratelimited("buggy .next function %ps did not update position index\n",
					    m->op->next);
			m->index++;
		}

Anyway you should mention the fatal signal requirement clearly.

Quoted 4 lines

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

OK I could reproduce the output locally. It seems that this run results in fatal signals being sent to the processes triggering this output.

Quoted 4 lines

Update the position index when VMA lookup fails, as required by the seq_file interface. Also save the original position in priv->last_pos so that subsequent iteration can restart from the correct address without skipping or repeating a VMA.

We don't really care about skipping or repeating a VMA for a process that's about to die :)

We may as well do this but better to just hoist that to share code.

Quoted 2 lines
Fixes 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock")

This isn't really a bug, it's really cosmetic to be honest. So not sure if we need a cc: stable hmm.

Quoted 1 line

See attached suggested patch that makes the comment sane + hoists the shared bit (dropping a silly existing comment).

With that and an updated commit message should be ok.

Quoted 9 lines
---
 fs/proc/task_mmu.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/proc/task_mmu.c +0 -0
index 22361607020d..164b4efc5e09 100644

fs/proc/task_mmu.c static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppos) · line 230

Quoted 10 lines
fs/proc/task_mmu.c +7 -0
@@ -221,6 +221,16 @@ static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppos)
 		if (PTR_ERR(vma) == -EAGAIN && fallback_to_mmap_lock(priv, *ppos))
 			goto retry;
 
+		/*
+		 * seq_file checks that the position advanced before it looks at
+		 * the returned pointer, so an error return that leaves *ppos
+		 * alone is reported as a buggy ->next. Advance it, and keep
+		 * last_pos at the pending position so m_start() would resume
+		 * the lookup from there.
+		 */

We don't want (schloppy?) comments that go into painful detail about super specific elements of the code.

This is asking for bit rot and is too complicated to be in any way useful.

fs/proc/task_mmu.c static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppos) · line 231

Quoted 1 line
fs/proc/task_mmu.c +1 -0
+		priv->last_pos = *ppos;

This is duplicative with code below and strictly not necessary for the fix, better to hoist I think.

Quoted 8 lines
fs/proc/task_mmu.c +2 -1
+		(*ppos)++;
+
 		return vma;
 	}
 
--

2.43.0

Suggested:

----8<----
From 860d936c61bb641b72135e95c291aa6dfbf5fb0f Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (ARM)" <[email protected]>
Date: Mon, 16 Nov 2026 14:33:12 +0000
Subject: [PATCH] tmp

---
 fs/proc/task_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/proc/task_mmu.c +4 -3
index 22361607020d..564e52f7ddc6 100644
@@ -216,16 +216,17 @@ static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppos)
 
 retry:
 	vma = get_next_vma(priv, *ppos);
-	/* EINTR of EAGAIN is possible */
+	/* Store previous position to be able to restart if needed */
+	priv->last_pos = *ppos;
 	if (IS_ERR(vma)) {
 		if (PTR_ERR(vma) == -EAGAIN && fallback_to_mmap_lock(priv, *ppos))
 			goto retry;
 
+		/* Advance to avoid spurious buggy seq warning in dmesg */
+		(*ppos)++;
 		return vma;
 	}
 
-	/* Store previous position to be able to restart if needed */
-	priv->last_pos = *ppos;
 	if (vma) {
 		/*
 		 * Track the end of the reported vma to ensure position changes

--
2.56.0

#6 lore raw
Quoted 50 lines · Lorenzo Stoakes (ARM)
Quoted 9 lines · Adrian Huang (Lenovo)

Commit 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock") introduced the possibility of returning -EINTR from proc_get_vma() when the VMA lookup is interrupted.

When this happens in m_next(), proc_get_vma() returns an error pointer without updating the position index. Consequently, seq_read_iter() reports:

seq_file: buggy .next function m_next did not update position index

What does seq_read_iter() 'reporting' something mean? It feels like you're trying to make this into something bigger than it is.

What you mean to say is a rate-limited pr_info() output occurs, and when a process that _has received a fatal signal_ (!!) somehow continues long enough to try to output more data, you get an pr_info().

The relevant code from seq_read_iter():

                if (pos == m->index) {
                        pr_info_ratelimited("buggy .next function %ps did not update position index\n",
                                            m->op->next);
                        m->index++;
                }

Anyway you should mention the fatal signal requirement clearly.

Quoted 4 lines

The above buggy message is reproduced by the following command:

  # stress-ng --vma 0 -t 60

OK I could reproduce the output locally. It seems that this run results in fatal signals being sent to the processes triggering this output.

Quoted 4 lines

Update the position index when VMA lookup fails, as required by the seq_file interface. Also save the original position in priv->last_pos so that subsequent iteration can restart from the correct address without skipping or repeating a VMA.

We don't really care about skipping or repeating a VMA for a process that's about to die :)

We may as well do this but better to just hoist that to share code.

Quoted 2 lines
Fixes 5631da56c9a8 ("fs/proc/task_mmu: read proc/pid/maps under per-vma lock")
Quoted 7 lines

This isn't really a bug, it's really cosmetic to be honest. So not sure if we need a cc: stable hmm.

Quoted 1 line

See attached suggested patch that makes the comment sane + hoists the shared bit (dropping a silly existing comment).

Your suggested patch is better. I verified it on my side and it works as expected. Thanks.

-- Adrian