From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Cc: "Oleg Nesterov" <oleg@redhat.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Cyrill Gorcunov" <gorcunov@gmail.com>,
"Kirill Tkhai" <ktkhai@virtuozzo.com>,
"Michal Koutný" <mkoutny@suse.com>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Roman Gushchin" <guro@fb.com>
Subject: [PATCH v2 5/6] proc: use down_read_killable mmap_sem for /proc/pid/map_files
Date: Sun, 09 Jun 2019 13:09:00 +0300 [thread overview]
Message-ID: <156007493995.3335.9595044802115356911.stgit@buzz> (raw)
In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz>
Do not stuck forever if something wrong.
Killable lock allows to cleanup stuck tasks and simplifies investigation.
It seems ->d_revalidate() could return any error (except ECHILD) to
abort validation and pass error as result of lookup sequence.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Reviewed-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Michal Hocko <mhocko@suse.com>
---
fs/proc/base.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9c8ca6cd3ce4..515ab29c2adf 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1962,9 +1962,12 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags)
goto out;
if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) {
- down_read(&mm->mmap_sem);
- exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end);
- up_read(&mm->mmap_sem);
+ status = down_read_killable(&mm->mmap_sem);
+ if (!status) {
+ exact_vma_exists = !!find_exact_vma(mm, vm_start,
+ vm_end);
+ up_read(&mm->mmap_sem);
+ }
}
mmput(mm);
@@ -2010,8 +2013,11 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
if (rc)
goto out_mmput;
+ rc = down_read_killable(&mm->mmap_sem);
+ if (rc)
+ goto out_mmput;
+
rc = -ENOENT;
- down_read(&mm->mmap_sem);
vma = find_exact_vma(mm, vm_start, vm_end);
if (vma && vma->vm_file) {
*path = vma->vm_file->f_path;
@@ -2107,7 +2113,10 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
if (!mm)
goto out_put_task;
- down_read(&mm->mmap_sem);
+ result = ERR_PTR(-EINTR);
+ if (down_read_killable(&mm->mmap_sem))
+ goto out_put_mm;
+
vma = find_exact_vma(mm, vm_start, vm_end);
if (!vma)
goto out_no_vma;
@@ -2118,6 +2127,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
out_no_vma:
up_read(&mm->mmap_sem);
+out_put_mm:
mmput(mm);
out_put_task:
put_task_struct(task);
@@ -2160,7 +2170,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
mm = get_task_mm(task);
if (!mm)
goto out_put_task;
- down_read(&mm->mmap_sem);
+
+ ret = down_read_killable(&mm->mmap_sem);
+ if (ret) {
+ mmput(mm);
+ goto out_put_task;
+ }
nr_files = 0;
next prev parent reply other threads:[~2019-06-09 10:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-09 10:08 [PATCH v2 0/6] mm: use down_read_killable for locking mmap_sem in proc Konstantin Khlebnikov
2019-06-09 10:08 ` [PATCH v2 1/6] proc: use down_read_killable mmap_sem for /proc/pid/maps Konstantin Khlebnikov
2019-06-09 10:08 ` [PATCH v2 2/6] proc: use down_read_killable mmap_sem for /proc/pid/smaps_rollup Konstantin Khlebnikov
2019-06-09 10:08 ` [PATCH v2 3/6] proc: use down_read_killable mmap_sem for /proc/pid/pagemap Konstantin Khlebnikov
2019-06-09 10:08 ` [PATCH v2 4/6] proc: use down_read_killable mmap_sem for /proc/pid/clear_refs Konstantin Khlebnikov
2019-06-09 10:09 ` Konstantin Khlebnikov [this message]
2019-06-12 23:14 ` [PATCH v2 5/6] proc: use down_read_killable mmap_sem for /proc/pid/map_files Andrei Vagin
2019-06-13 0:04 ` Andrew Morton
2019-06-13 6:48 ` Cyrill Gorcunov
2019-06-13 8:15 ` Konstantin Khlebnikov
2019-06-13 20:32 ` Andrei Vagin
2019-06-09 10:09 ` [PATCH v2 6/6] mm: use down_read_killable for locking mmap_sem in access_remote_vm Konstantin Khlebnikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=156007493995.3335.9595044802115356911.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=akpm@linux-foundation.org \
--cc=gorcunov@gmail.com \
--cc=guro@fb.com \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).