diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-05 00:30:28 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-05 00:30:28 -0400 |
commit | a1fde08c74e90accd62d4cfdbf580d2ede938fe7 (patch) | |
tree | bdf58078fd37484729e350acb066dc1b1fa890ee /mm | |
parent | 5895198c56d131cc696556a45f7ff0ea99ac297b (diff) |
VM: skip the stack guard page lookup in get_user_pages only for mlock
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>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memory.c | 7 | ||||
-rw-r--r-- | mm/mlock.c | 5 |
2 files changed, 4 insertions, 8 deletions
diff --git a/mm/memory.c b/mm/memory.c index 607098d47e74..27f425378112 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -1359,7 +1359,7 @@ split_fallthrough: | |||
1359 | */ | 1359 | */ |
1360 | mark_page_accessed(page); | 1360 | mark_page_accessed(page); |
1361 | } | 1361 | } |
1362 | if (flags & FOLL_MLOCK) { | 1362 | if ((flags & FOLL_MLOCK) && (vma->vm_flags & VM_LOCKED)) { |
1363 | /* | 1363 | /* |
1364 | * The preliminary mapping check is mainly to avoid the | 1364 | * The preliminary mapping check is mainly to avoid the |
1365 | * pointless overhead of lock_page on the ZERO_PAGE | 1365 | * pointless overhead of lock_page on the ZERO_PAGE |
@@ -1552,10 +1552,9 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, | |||
1552 | } | 1552 | } |
1553 | 1553 | ||
1554 | /* | 1554 | /* |
1555 | * If we don't actually want the page itself, | 1555 | * For mlock, just skip the stack guard page. |
1556 | * and it's the stack guard page, just skip it. | ||
1557 | */ | 1556 | */ |
1558 | if (!pages && stack_guard_page(vma, start)) | 1557 | if ((gup_flags & FOLL_MLOCK) && stack_guard_page(vma, start)) |
1559 | goto next_page; | 1558 | goto next_page; |
1560 | 1559 | ||
1561 | do { | 1560 | do { |
diff --git a/mm/mlock.c b/mm/mlock.c index 6b55e3efe0df..516b2c2ddd5a 100644 --- a/mm/mlock.c +++ b/mm/mlock.c | |||
@@ -162,7 +162,7 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, | |||
162 | VM_BUG_ON(end > vma->vm_end); | 162 | VM_BUG_ON(end > vma->vm_end); |
163 | VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); | 163 | VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); |
164 | 164 | ||
165 | gup_flags = FOLL_TOUCH; | 165 | gup_flags = FOLL_TOUCH | FOLL_MLOCK; |
166 | /* | 166 | /* |
167 | * We want to touch writable mappings with a write fault in order | 167 | * We want to touch writable mappings with a write fault in order |
168 | * to break COW, except for shared mappings because these don't COW | 168 | * to break COW, except for shared mappings because these don't COW |
@@ -178,9 +178,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, | |||
178 | if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) | 178 | if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) |
179 | gup_flags |= FOLL_FORCE; | 179 | gup_flags |= FOLL_FORCE; |
180 | 180 | ||
181 | if (vma->vm_flags & VM_LOCKED) | ||
182 | gup_flags |= FOLL_MLOCK; | ||
183 | |||
184 | return __get_user_pages(current, mm, addr, nr_pages, gup_flags, | 181 | return __get_user_pages(current, mm, addr, nr_pages, gup_flags, |
185 | NULL, NULL, nonblocking); | 182 | NULL, NULL, nonblocking); |
186 | } | 183 | } |