Skip to content

Commit f1d47ca

Browse files
x-y-zakpm00
authored andcommitted
mm/huge_memory: fix folio split check for anon folios in swapcache
Both uniform and non uniform split check missed the check to prevent splitting anon folios in swapcache to non-zero order. Splitting anon folios in swapcache to non-zero order can cause data corruption since swapcache only support PMD order and order-0 entries. This can happen when one use split_huge_pages under debugfs to split anon folios in swapcache. In-tree callers do not perform such an illegal operation. Only debugfs interface could trigger it. I will put adding a test case on my TODO list. Fix the check. Link: https://lkml.kernel.org/r/[email protected] Fixes: 58729c0 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()") Signed-off-by: Zi Yan <[email protected]> Reported-by: "David Hildenbrand (Red Hat)" <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Acked-by: David Hildenbrand (Red Hat) <[email protected]> Cc: Baolin Wang <[email protected]> Cc: Barry Song <[email protected]> Cc: Dev Jain <[email protected]> Cc: Lance Yang <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Nico Pache <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Wei Yang <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3470715 commit f1d47ca

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

mm/huge_memory.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,7 +3522,8 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
35223522
/* order-1 is not supported for anonymous THP. */
35233523
VM_WARN_ONCE(warns && new_order == 1,
35243524
"Cannot split to order-1 folio");
3525-
return new_order != 1;
3525+
if (new_order == 1)
3526+
return false;
35263527
} else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
35273528
!mapping_large_folio_support(folio->mapping)) {
35283529
/*
@@ -3553,7 +3554,8 @@ bool uniform_split_supported(struct folio *folio, unsigned int new_order,
35533554
if (folio_test_anon(folio)) {
35543555
VM_WARN_ONCE(warns && new_order == 1,
35553556
"Cannot split to order-1 folio");
3556-
return new_order != 1;
3557+
if (new_order == 1)
3558+
return false;
35573559
} else if (new_order) {
35583560
if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
35593561
!mapping_large_folio_support(folio->mapping)) {

0 commit comments

Comments
 (0)