From: John Hubbard <jhubbard@nvidia.com> Date: Wed, 3 Jun 2020 22:56:40 +0000 (-0700) Subject: mm/gup: might_lock_read(mmap_sem) in get_user_pages_fast() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=f81cd178ecfd0806c1d2859cfe0a162d80c81a69;p=linux.git mm/gup: might_lock_read(mmap_sem) in get_user_pages_fast() 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> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Matthew Wilcox <willy@infradead.org> Cc: Michel Lespinasse <walken@google.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Link: http://lkml.kernel.org/r/20200522010443.1290485-1-jhubbard@nvidia.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> --- diff --git a/mm/gup.c b/mm/gup.c index 0702c1a7e0413..61ee405ec5588 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2739,6 +2739,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;