Skip to content

Commit

Permalink
khugepaged: khugepaged_test_exit() check mmget_still_valid()
Browse files Browse the repository at this point in the history
Move collapse_huge_page()'s mmget_still_valid() check into
khugepaged_test_exit() itself.  collapse_huge_page() is used for anon THP
only, and earned its mmget_still_valid() check because it inserts a huge
pmd entry in place of the page table's pmd entry; whereas
collapse_file()'s retract_page_tables() or collapse_pte_mapped_thp()
merely clears the page table's pmd entry.  But core dumping without mmap
lock must have been as open to mistaking a racily cleared pmd entry for a
page table at physical page 0, as exit_mmap() was.  And we certainly have
no interest in mapping as a THP once dumping core.

Fixes: 59ea6d0 ("coredump: fix race condition between collapse_huge_page() and core dumping")
Signed-off-by: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Mike Kravetz <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: <[email protected]>	[4.8+]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hugh Dickins authored and torvalds committed Aug 7, 2020
1 parent 18e7760 commit bbe98f9
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static void insert_to_mm_slots_hash(struct mm_struct *mm,

static inline int khugepaged_test_exit(struct mm_struct *mm)
{
return atomic_read(&mm->mm_users) == 0;
return atomic_read(&mm->mm_users) == 0 || !mmget_still_valid(mm);
}

static bool hugepage_vma_check(struct vm_area_struct *vma,
Expand Down Expand Up @@ -1100,9 +1100,6 @@ static void collapse_huge_page(struct mm_struct *mm,
* handled by the anon_vma lock + PG_lock.
*/
mmap_write_lock(mm);
result = SCAN_ANY_PROCESS;
if (!mmget_still_valid(mm))
goto out;
result = hugepage_vma_revalidate(mm, address, &vma);
if (result)
goto out;
Expand Down

0 comments on commit bbe98f9

Please sign in to comment.