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/20251105162910.752266-1-ziy@nvidia.com Fixes: 58729c0 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()") Signed-off-by: Zi Yan <ziy@nvidia.com> Reported-by: "David Hildenbrand (Red Hat)" <david@kernel.org> Closes: https://lore.kernel.org/all/dc0ecc2c-4089-484f-917f-920fdca4c898@kernel.org/ Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Nico Pache <npache@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
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)