Skip to content

Commit fe44198

Browse files
lopsided98akpm00
authored andcommitted
proc: nommu: fix empty /proc/<pid>/maps
On no-MMU, /proc/<pid>/maps reads as an empty file. This happens because find_vma(mm, 0) always returns NULL (assuming no vma actually contains the zero address, which is normally the case). To fix this bug and improve the maintainability in the future, this patch makes the no-MMU implementation as similar as possible to the MMU implementation. The only remaining differences are the lack of hold/release_task_mempolicy and the extra code to shoehorn the gate vma into the iterator. This has been tested on top of 6.5.3 on an STM32F746. Link: https://lkml.kernel.org/r/20230915160055.971059-2-ben.wolsieffer@hefring.com Fixes: 0c563f1 ("proc: remove VMA rbtree use from nommu") Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Giulio Benetti <giulio.benetti@benettiengineering.com> Cc: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent c8be038 commit fe44198

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

fs/proc/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ struct proc_maps_private {
289289
struct inode *inode;
290290
struct task_struct *task;
291291
struct mm_struct *mm;
292-
#ifdef CONFIG_MMU
293292
struct vma_iterator iter;
294-
#endif
295293
#ifdef CONFIG_NUMA
296294
struct mempolicy *task_mempolicy;
297295
#endif

fs/proc/task_nommu.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,28 @@ static int show_map(struct seq_file *m, void *_p)
175175
return nommu_vma_show(m, _p);
176176
}
177177

178-
static void *m_start(struct seq_file *m, loff_t *pos)
178+
static struct vm_area_struct *proc_get_vma(struct proc_maps_private *priv,
179+
loff_t *ppos)
180+
{
181+
struct vm_area_struct *vma = vma_next(&priv->iter);
182+
183+
if (vma) {
184+
*ppos = vma->vm_start;
185+
} else {
186+
*ppos = -1UL;
187+
}
188+
189+
return vma;
190+
}
191+
192+
static void *m_start(struct seq_file *m, loff_t *ppos)
179193
{
180194
struct proc_maps_private *priv = m->private;
195+
unsigned long last_addr = *ppos;
181196
struct mm_struct *mm;
182-
struct vm_area_struct *vma;
183-
unsigned long addr = *pos;
184197

185-
/* See m_next(). Zero at the start or after lseek. */
186-
if (addr == -1UL)
198+
/* See proc_get_vma(). Zero at the start or after lseek. */
199+
if (last_addr == -1UL)
187200
return NULL;
188201

189202
/* pin the task and mm whilst we play with them */
@@ -205,12 +218,9 @@ static void *m_start(struct seq_file *m, loff_t *pos)
205218
return ERR_PTR(-EINTR);
206219
}
207220

208-
/* start the next element from addr */
209-
vma = find_vma(mm, addr);
210-
if (vma)
211-
return vma;
221+
vma_iter_init(&priv->iter, mm, last_addr);
212222

213-
return NULL;
223+
return proc_get_vma(priv, ppos);
214224
}
215225

216226
static void m_stop(struct seq_file *m, void *v)
@@ -227,12 +237,9 @@ static void m_stop(struct seq_file *m, void *v)
227237
priv->task = NULL;
228238
}
229239

230-
static void *m_next(struct seq_file *m, void *_p, loff_t *pos)
240+
static void *m_next(struct seq_file *m, void *_p, loff_t *ppos)
231241
{
232-
struct vm_area_struct *vma = _p;
233-
234-
*pos = vma->vm_end;
235-
return find_vma(vma->vm_mm, vma->vm_end);
242+
return proc_get_vma(m->private, ppos);
236243
}
237244

238245
static const struct seq_operations proc_pid_maps_ops = {

0 commit comments

Comments
 (0)