Skip to content

Commit 7f3bfab

Browse files
thejhtorvalds
authored andcommitted
mm/gup: take mmap_lock in get_dump_page()
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]>
1 parent a07279c commit 7f3bfab

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mm/gup.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,19 +1547,23 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,
15471547
* NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found -
15481548
* allowing a hole to be left in the corefile to save diskspace.
15491549
*
1550-
* Called without mmap_lock, but after all other threads have been killed.
1550+
* Called without mmap_lock (takes and releases the mmap_lock by itself).
15511551
*/
15521552
#ifdef CONFIG_ELF_CORE
15531553
struct page *get_dump_page(unsigned long addr)
15541554
{
1555-
struct vm_area_struct *vma;
1555+
struct mm_struct *mm = current->mm;
15561556
struct page *page;
1557+
int locked = 1;
1558+
int ret;
15571559

1558-
if (__get_user_pages_locked(current->mm, addr, 1, &page, &vma, NULL,
1559-
FOLL_FORCE | FOLL_DUMP | FOLL_GET) < 1)
1560+
if (mmap_read_lock_killable(mm))
15601561
return NULL;
1561-
flush_cache_page(vma, addr, page_to_pfn(page));
1562-
return page;
1562+
ret = __get_user_pages_locked(mm, addr, 1, &page, NULL, &locked,
1563+
FOLL_FORCE | FOLL_DUMP | FOLL_GET);
1564+
if (locked)
1565+
mmap_read_unlock(mm);
1566+
return (ret == 1) ? page : NULL;
15631567
}
15641568
#endif /* CONFIG_ELF_CORE */
15651569

0 commit comments

Comments
 (0)