From: John Hubbard <jhubbard@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>, <jgg@ziepe.ca>
Cc: <Liam.Howlett@oracle.com>, <daniel.m.jordan@oracle.com>,
<dave@stgolabs.net>, <hughd@google.com>, <jglisse@redhat.com>,
<jhubbard@nvidia.com>, <ldufour@linux.ibm.com>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<peterz@infradead.org>, <rientjes@google.com>, <vbabka@suse.cz>,
<walken@google.com>, <willy@infradead.org>, <yinghan@google.com>
Subject: [PATCH] mm/gup: might_lock_read(mmap_sem) in get_user_pages_fast()
Date: Thu, 21 May 2020 18:04:43 -0700 [thread overview]
Message-ID: <20200522010443.1290485-1-jhubbard@nvidia.com> (raw)
Instead of scattering these assertions across the drivers,
do this assertion inside the core of get_user_pages_fast*()
functions. That also includes pin_user_pages_fast*()
routines.
Add a might_lock_read(mmap_sem) call to internal_get_user_pages_fast().
Suggested-by: Matthew Wilcox <willy@infradead.org>
Cc: Michel Lespinasse <walken@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
Hi Andrew,
This applies on top of [1], which in turn applies to
today's (20200521) linux-next.
As noted in the discussion [2], this will need changing from
mmap_sem to mmap_lock, after Michel Lespinasse's patchset
arrives.
[1]
https://lore.kernel.org/r/20200521233841.1279742-1-jhubbard@nvidia.com
[2] https://lore.kernel.org/linux-mm/20200520124817.GG31189@ziepe.ca/
thanks,
John Hubbard
NVIDIA
mm/gup.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/gup.c b/mm/gup.c
index ada6aa79576dc..3462c076e8ecf 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2728,6 +2728,9 @@ static int internal_get_user_pages_fast(unsigned long start, int nr_pages,
FOLL_FAST_ONLY)))
return -EINVAL;
+ if (!(gup_flags & FOLL_FAST_ONLY))
+ might_lock_read(¤t->mm->mmap_sem);
+
start = untagged_addr(start) & PAGE_MASK;
addr = start;
len = (unsigned long) nr_pages << PAGE_SHIFT;
--
2.26.2
next reply other threads:[~2020-05-22 1:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-22 1:04 John Hubbard [this message]
2020-05-22 1:16 ` [PATCH] mm/gup: might_lock_read(mmap_sem) in get_user_pages_fast() Matthew Wilcox
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=20200522010443.1290485-1-jhubbard@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.m.jordan@oracle.com \
--cc=dave@stgolabs.net \
--cc=hughd@google.com \
--cc=jgg@ziepe.ca \
--cc=jglisse@redhat.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=vbabka@suse.cz \
--cc=walken@google.com \
--cc=willy@infradead.org \
--cc=yinghan@google.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).