Skip to content

Commit 06a5e12

Browse files
Hugh Dickinstorvalds
authored andcommitted
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. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261529310.2275@eggly.anvils Fixes: f3f0e1d ("khugepaged: add support of collapse for tmpfs/shmem pages") Signed-off-by: Hugh Dickins <hughd@google.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> [4.8+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 87c460a commit 06a5e12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mm/khugepaged.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,15 @@ static void collapse_shmem(struct mm_struct *mm,
13991399
*/
14001400
VM_BUG_ON_PAGE(!PageLocked(page), page);
14011401
VM_BUG_ON_PAGE(!PageUptodate(page), page);
1402-
VM_BUG_ON_PAGE(PageTransCompound(page), page);
1402+
1403+
/*
1404+
* If file was truncated then extended, or hole-punched, before
1405+
* we locked the first page, then a THP might be there already.
1406+
*/
1407+
if (PageTransCompound(page)) {
1408+
result = SCAN_PAGE_COMPOUND;
1409+
goto out_unlock;
1410+
}
14031411

14041412
if (page_mapping(page) != mapping) {
14051413
result = SCAN_TRUNCATED;

0 commit comments

Comments
 (0)