From: Sumit Semwal <sumit.semwal@linaro.org>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Alexey Dobriyan <adobriyan@gmail.com>,
Jonathan Corbet <corbet@lwn.net>
Cc: "Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Kees Cook" <keescook@chromium.org>,
"Michal Hocko" <mhocko@suse.com>,
"Colin Cross" <ccross@google.com>,
"Alexey Gladkov" <gladkov.alexey@gmail.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
"Michel Lespinasse" <walken@google.com>,
"Michal Koutný" <mkoutny@suse.com>,
"Song Liu" <songliubraving@fb.com>,
"Huang Ying" <ying.huang@intel.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Yang Shi" <yang.shi@linux.alibaba.com>,
chenqiwu <chenqiwu@xiaomi.com>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"John Hubbard" <jhubbard@nvidia.com>,
"Mike Christie" <mchristi@redhat.com>,
"Bart Van Assche" <bvanassche@acm.org>,
"Amit Pundir" <amit.pundir@linaro.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Christian Brauner" <christian.brauner@ubuntu.com>,
"Daniel Jordan" <daniel.m.jordan@oracle.com>,
"Adrian Reber" <areber@redhat.com>,
"Nicolas Viennot" <Nicolas.Viennot@twosigma.com>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Thomas Cedeno" <thomascedeno@google.com>,
linux-fsdevel@vger.kernel.org,
"John Stultz" <john.stultz@linaro.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>
Subject: [PATCH v6 2/3] mm: memory: Add access_remote_vm_locked variant
Date: Tue, 1 Sep 2020 14:49:00 +0530 [thread overview]
Message-ID: <20200901091901.19779-3-sumit.semwal@linaro.org> (raw)
In-Reply-To: <20200901091901.19779-1-sumit.semwal@linaro.org>
This allows accessing a remote vm while the mmap_lock is already
held by the caller.
While adding support for anonymous vma naming, show_map_vma()
needs to access the remote vm to get the name of the anonymous vma.
Since show_map_vma() already holds the mmap_lock, so this _locked
variant was required.
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
---
include/linux/mm.h | 2 ++
mm/memory.c | 49 ++++++++++++++++++++++++++++++++++++++++------
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ca6e6a81576b..e9212c0bb5ac 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1708,6 +1708,8 @@ extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
void *buf, int len, unsigned int gup_flags);
extern int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
unsigned long addr, void *buf, int len, unsigned int gup_flags);
+extern int access_remote_vm_locked(struct mm_struct *mm, unsigned long addr,
+ void *buf, int len, unsigned int gup_flags);
long get_user_pages_remote(struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
diff --git a/mm/memory.c b/mm/memory.c
index 602f4283122f..207be99390e9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4726,17 +4726,17 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
/*
* Access another process' address space as given in mm. If non-NULL, use the
* given task for page fault accounting.
+ * This variant assumes that the mmap_lock is already held by the caller, so
+ * doesn't take the mmap_lock.
*/
-int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
- unsigned long addr, void *buf, int len, unsigned int gup_flags)
+int __access_remote_vm_locked(struct task_struct *tsk, struct mm_struct *mm,
+ unsigned long addr, void *buf, int len,
+ unsigned int gup_flags)
{
struct vm_area_struct *vma;
void *old_buf = buf;
int write = gup_flags & FOLL_WRITE;
- if (mmap_read_lock_killable(mm))
- return 0;
-
/* ignore errors, just check how much was successfully transferred */
while (len) {
int bytes, ret, offset;
@@ -4785,9 +4785,46 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
buf += bytes;
addr += bytes;
}
+ return buf - old_buf;
+}
+
+/*
+ * Access another process' address space as given in mm. If non-NULL, use the
+ * given task for page fault accounting.
+ */
+int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
+ unsigned long addr, void *buf, int len, unsigned int gup_flags)
+{
+ int ret;
+
+ if (mmap_read_lock_killable(mm))
+ return 0;
+
+ ret = __access_remote_vm_locked(tsk, mm, addr, buf, len, gup_flags);
mmap_read_unlock(mm);
- return buf - old_buf;
+ return ret;
+}
+
+/**
+ * access_remote_vm_locked - access another process' address space, without
+ * taking the mmap_lock. This allows nested calls from callers that already have
+ * taken the lock.
+ *
+ * @mm: the mm_struct of the target address space
+ * @addr: start address to access
+ * @buf: source or destination buffer
+ * @len: number of bytes to transfer
+ * @gup_flags: flags modifying lookup behaviour
+ *
+ * The caller must hold a reference on @mm, as well as hold the mmap_lock
+ *
+ * Return: number of bytes copied from source to destination.
+ */
+int access_remote_vm_locked(struct mm_struct *mm, unsigned long addr, void *buf,
+ int len, unsigned int gup_flags)
+{
+ return __access_remote_vm_locked(NULL, mm, addr, buf, len, gup_flags);
}
/**
--
2.28.0
prev parent reply other threads:[~2020-09-01 9:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 9:18 [PATCH v6 0/3] Anonymous VMA naming patches Sumit Semwal
2020-09-01 9:19 ` Sumit Semwal [this message]
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=20200901091901.19779-3-sumit.semwal@linaro.org \
--to=sumit.semwal@linaro.org \
--cc=Nicolas.Viennot@twosigma.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=amit.pundir@linaro.org \
--cc=areber@redhat.com \
--cc=bvanassche@acm.org \
--cc=ccross@google.com \
--cc=chenqiwu@xiaomi.com \
--cc=christian.brauner@ubuntu.com \
--cc=corbet@lwn.net \
--cc=daniel.m.jordan@oracle.com \
--cc=gladkov.alexey@gmail.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=john.stultz@linaro.org \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mchehab+huawei@kernel.org \
--cc=mchristi@redhat.com \
--cc=mhocko@suse.com \
--cc=mkoutny@suse.com \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
--cc=thomascedeno@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=walken@google.com \
--cc=willy@infradead.org \
--cc=yang.shi@linux.alibaba.com \
--cc=ying.huang@intel.com \
/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).