Commit 06a5e126 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

mm/khugepaged: collapse_shmem() do not crash on Compound

collapse_shmem()'s VM_BUG_ON_PAGE(PageTransCompound) was unsafe: before
it holds page lock of the first page, racing truncation then extension
might conceivably have inserted a hugepage there already.  Fail with the
SCAN_PAGE_COMPOUND result, instead of crashing (CONFIG_DEBUG_VM=y) or
otherwise mishandling the unexpected hugepage - though later we might
code up a more constructive way of handling it, with SCAN_SUCCESS.

Fixes: f3f0e1d2 ("khugepaged: add support of collapse for tmpfs/shmem pages")
Signed-off-by: default avatarHugh Dickins <>
Cc: Kirill A. Shutemov <>
Cc: Jerome Glisse <>
Cc: Konstantin Khlebnikov <>
Cc: Matthew Wilcox <>
Cc: <>	[4.8+]
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 87c460a0
......@@ -1399,7 +1399,15 @@ static void collapse_shmem(struct mm_struct *mm,
VM_BUG_ON_PAGE(!PageLocked(page), page);
VM_BUG_ON_PAGE(!PageUptodate(page), page);
VM_BUG_ON_PAGE(PageTransCompound(page), page);
* If file was truncated then extended, or hole-punched, before
* we locked the first page, then a THP might be there already.
if (PageTransCompound(page)) {
goto out_unlock;
if (page_mapping(page) != mapping) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment