Skip to content

Commit

Permalink
mm/gup: take mmap_lock in get_dump_page()
Browse files Browse the repository at this point in the history
Properly take the mmap_lock before calling into the GUP code from
get_dump_page(); and play nice, allowing the GUP code to drop the
mmap_lock if it has to sleep.

As Linus pointed out, we don't actually need the VMA because
__get_user_pages() will flush the dcache for us if necessary.

Signed-off-by: Jann Horn <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Acked-by: Linus Torvalds <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: "Eric W . Biederman" <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Hugh Dickins <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
thejh authored and torvalds committed Oct 16, 2020
1 parent a07279c commit 7f3bfab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,19 +1547,23 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,
* NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found -
* allowing a hole to be left in the corefile to save diskspace.
*
* Called without mmap_lock, but after all other threads have been killed.
* Called without mmap_lock (takes and releases the mmap_lock by itself).
*/
#ifdef CONFIG_ELF_CORE
struct page *get_dump_page(unsigned long addr)
{
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
struct page *page;
int locked = 1;
int ret;

if (__get_user_pages_locked(current->mm, addr, 1, &page, &vma, NULL,
FOLL_FORCE | FOLL_DUMP | FOLL_GET) < 1)
if (mmap_read_lock_killable(mm))
return NULL;
flush_cache_page(vma, addr, page_to_pfn(page));
return page;
ret = __get_user_pages_locked(mm, addr, 1, &page, NULL, &locked,
FOLL_FORCE | FOLL_DUMP | FOLL_GET);
if (locked)
mmap_read_unlock(mm);
return (ret == 1) ? page : NULL;
}
#endif /* CONFIG_ELF_CORE */

Expand Down

0 comments on commit 7f3bfab

Please sign in to comment.