Skip to content

Commit bbe98f9

Browse files
Hugh Dickinstorvalds
authored andcommitted
khugepaged: khugepaged_test_exit() check mmget_still_valid()
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 <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Song Liu <songliubraving@fb.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: <stable@vger.kernel.org> [4.8+] Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2008021217020.27773@eggly.anvils Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 18e7760 commit bbe98f9

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

mm/khugepaged.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static void insert_to_mm_slots_hash(struct mm_struct *mm,
431431

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

437437
static bool hugepage_vma_check(struct vm_area_struct *vma,
@@ -1100,9 +1100,6 @@ static void collapse_huge_page(struct mm_struct *mm,
11001100
* handled by the anon_vma lock + PG_lock.
11011101
*/
11021102
mmap_write_lock(mm);
1103-
result = SCAN_ANY_PROCESS;
1104-
if (!mmget_still_valid(mm))
1105-
goto out;
11061103
result = hugepage_vma_revalidate(mm, address, &vma);
11071104
if (result)
11081105
goto out;

0 commit comments

Comments
 (0)