Skip to content

Commit

Permalink
proc: use down_read_killable mmap_sem for /proc/pid/maps
Browse files Browse the repository at this point in the history
Do not remain stuck forever if something goes wrong.  Using a killable
lock permits cleanup of stuck tasks and simplifies investigation.

This function is also used for /proc/pid/smaps.

Link: http://lkml.kernel.org/r/156007493160.3335.14447544314127417266.stgit@buzz
Signed-off-by: Konstantin Khlebnikov <[email protected]>
Reviewed-by: Roman Gushchin <[email protected]>
Reviewed-by: Cyrill Gorcunov <[email protected]>
Reviewed-by: Kirill Tkhai <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Michal Koutný <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
koct9i authored and torvalds committed Jul 12, 2019
1 parent cbf800d commit 8a713e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion fs/proc/task_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ static void *m_start(struct seq_file *m, loff_t *ppos)
if (!mm || !mmget_not_zero(mm))
return NULL;

down_read(&mm->mmap_sem);
if (down_read_killable(&mm->mmap_sem)) {
mmput(mm);
return ERR_PTR(-EINTR);
}

hold_task_mempolicy(priv);
priv->tail_vma = get_gate_vma(mm);

Expand Down
6 changes: 5 additions & 1 deletion fs/proc/task_nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ static void *m_start(struct seq_file *m, loff_t *pos)
if (!mm || !mmget_not_zero(mm))
return NULL;

down_read(&mm->mmap_sem);
if (down_read_killable(&mm->mmap_sem)) {
mmput(mm);
return ERR_PTR(-EINTR);
}

/* start from the Nth VMA */
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p))
if (n-- == 0)
Expand Down

0 comments on commit 8a713e7

Please sign in to comment.