VM: skip the stack guard page lookup in get_user_pages only for mlock
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 5 May 2011 04:30:28 +0000 (21:30 -0700)
committerSteve Conklin <sconklin@canonical.com>
Thu, 2 Jun 2011 19:23:17 +0000 (14:23 -0500)
commitb6c12606aa71a8c94288f872bbde94509ea49f4c
tree1a993f45e752d77f72a7ea337b80d43ad247999e
parent57bd324dbd799b271cad945224df5a21b151297b
VM: skip the stack guard page lookup in get_user_pages only for mlock

BugLink: http://bugs.launchpad.net/bugs/780546

commit a1fde08c74e90accd62d4cfdbf580d2ede938fe7 upstream.

The logic in __get_user_pages() used to skip the stack guard page lookup
whenever the caller wasn't interested in seeing what the actual page
was.  But Michel Lespinasse points out that there are cases where we
don't care about the physical page itself (so 'pages' may be NULL), but
do want to make sure a page is mapped into the virtual address space.

So using the existence of the "pages" array as an indication of whether
to look up the guard page or not isn't actually so great, and we really
should just use the FOLL_MLOCK bit.  But because that bit was only set
for the VM_LOCKED case (and not all vma's necessarily have it, even for
mlock()), we couldn't do that originally.

Fix that by moving the VM_LOCKED check deeper into the call-chain, which
actually simplifies many things.  Now mlock() gets simpler, and we can
also check for FOLL_MLOCK in __get_user_pages() and the code ends up
much more straightforward.

Reported-and-reviewed-by: Michel Lespinasse <walken@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
mm/memory.c
mm/mlock.c