Skip to content

Commit 6705cfd

Browse files
oleg-nesterovsfrothwell
authored andcommitted
fs/proc/task_mmu.c: simplify the vma_stop() logic
m_start() drops ->mmap_sem and does mmput() if it retuns vsyscall vma. This is because in this case m_stop()->vma_stop() obviously can't use gate_vma->vm_mm. Now that we have proc_maps_private->mm we can simplify this logic: - Change m_start() to return with ->mmap_sem held unless it returns IS_ERR_OR_NULL(). - Change vma_stop() to use priv->mm and avoid the ugly vma checks, this makes "vm_area_struct *vma" unnecessary. - This also allows m_start() to use vm_stop(). - Cleanup m_next() to follow the new locking rule. Note: m_stop() looks very ugly, and this temporary uglifies it even more. Fixed by the next change. Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Acked-by: Cyrill Gorcunov <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f58b75f commit 6705cfd

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

fs/proc/task_mmu.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,12 @@ static void release_task_mempolicy(struct proc_maps_private *priv)
129129
}
130130
#endif
131131

132-
static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
132+
static void vma_stop(struct proc_maps_private *priv)
133133
{
134-
if (vma && vma != priv->tail_vma) {
135-
struct mm_struct *mm = vma->vm_mm;
136-
release_task_mempolicy(priv);
137-
up_read(&mm->mmap_sem);
138-
mmput(mm);
139-
}
134+
struct mm_struct *mm = priv->mm;
135+
release_task_mempolicy(priv);
136+
up_read(&mm->mmap_sem);
137+
mmput(mm);
140138
}
141139

142140
static void *m_start(struct seq_file *m, loff_t *pos)
@@ -199,34 +197,38 @@ static void *m_start(struct seq_file *m, loff_t *pos)
199197
if (vma)
200198
return vma;
201199

202-
release_task_mempolicy(priv);
203200
/* End of vmas has been reached */
204201
m->version = (tail_vma != NULL)? 0: -1UL;
205-
up_read(&mm->mmap_sem);
206-
mmput(mm);
207-
return tail_vma;
202+
if (tail_vma)
203+
return tail_vma;
204+
205+
vma_stop(priv);
206+
return NULL;
208207
}
209208

210209
static void *m_next(struct seq_file *m, void *v, loff_t *pos)
211210
{
212211
struct proc_maps_private *priv = m->private;
213212
struct vm_area_struct *vma = v;
214213
struct vm_area_struct *tail_vma = priv->tail_vma;
214+
struct vm_area_struct *next;
215215

216216
(*pos)++;
217217
if (vma && (vma != tail_vma) && vma->vm_next)
218218
return vma->vm_next;
219-
vma_stop(priv, vma);
220-
return (vma != tail_vma)? tail_vma: NULL;
219+
220+
next = (vma != tail_vma)? tail_vma: NULL;
221+
if (!next)
222+
vma_stop(priv);
223+
return next;
221224
}
222225

223226
static void m_stop(struct seq_file *m, void *v)
224227
{
225228
struct proc_maps_private *priv = m->private;
226-
struct vm_area_struct *vma = v;
227229

228-
if (!IS_ERR(vma))
229-
vma_stop(priv, vma);
230+
if (!IS_ERR_OR_NULL(v))
231+
vma_stop(priv);
230232
if (priv->task)
231233
put_task_struct(priv->task);
232234
}

0 commit comments

Comments
 (0)