Skip to contentSkip to conversation

mm/huge_memory: fix folio split check for anon folios in swapcache.

PATCH Applied Zi Yan 4 participants 5 messages Nov 5, 2025 – Nov 6, 2025

Subsystems (3)
lore
Share & tools
lore

Zi Yan

author reviewer
#0 lore raw

PATCH 1/1 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. Fix the check.

Fixes 58729c04cf10 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()")
---
 mm/huge_memory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/huge_memory.c +4 -2
index 36fc4ff002c9..595811c78f42 100644
@@ -3674,7 +3674,8 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
 		/* order-1 is not supported for anonymous THP. */
 		VM_WARN_ONCE(warns && new_order == 1,
 				"Cannot split to order-1 folio");
-		return new_order != 1;
+		if (new_order == 1)
+			return false;
 	} else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
 	    !mapping_large_folio_support(folio->mapping)) {
 		/*
@@ -3705,7 +3706,8 @@ bool uniform_split_supported(struct folio *folio, unsigned int new_order,
 	if (folio_test_anon(folio)) {
 		VM_WARN_ONCE(warns && new_order == 1,
 				"Cannot split to order-1 folio");
-		return new_order != 1;
+		if (new_order == 1)
+			return false;
 	} else  if (new_order) {
 		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
 		    !mapping_large_folio_support(folio->mapping)) {
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#1 lore raw

On 05.11.25 17:29, Zi Yan wrote:

Nit: drop trailing "." in subject.

I'm sure Andrew can fix that up :)

Quoted 9 lines

Both uniform and non uniform split check missed the check to prevent splitting anon folios in swapcache to non-zero order. Fix the check.

Fixes 58729c04cf10 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()")

---

Thanks!

Signature · 3 lines
Cheers

David
maintainer
#2 lore raw
In reply to Zi Yan
Quoted 2 lines · On Wed, 5 Nov 2025 11:29:10 -0500 Zi Yan <[email protected]> wrote:

Both uniform and non uniform split check missed the check to prevent splitting anon folios in swapcache to non-zero order. Fix the check.

Please describe the possible userspace-visible effects of the bug especially when proposing a -stable backport.

Quoted 3 lines
Fixes 58729c04cf10 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()")

I was hopeful, but that's "from code inspection".

Quoted 2 lines
author reviewer
#3 lore raw
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Wed, 5 Nov 2025 11:29:10 -0500 Zi Yan <[email protected]> wrote:

Both uniform and non uniform split check missed the check to prevent splitting anon folios in swapcache to non-zero order. Fix the check.

Please describe the possible userspace-visible effects of the bug especially when proposing a -stable backport.

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.

Quoted 6 lines
Quoted 4 lines
Fixes 58729c04cf10 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()")

I was hopeful, but that's "from code inspection".

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.

Quoted 3 lines
Quoted 3 lines

Best Regards,
Yan, Zi

Reviewed-by on v1 1/1
#4 lore raw
In reply to Zi Yan
Quoted 8 lines · Zi Yan

Both uniform and non uniform split check missed the check to prevent splitting anon folios in swapcache to non-zero order. Fix the check.

Fixes 58729c04cf10 ("mm/huge_memory: add buddy allocator like (non-uniform) folio_split()")
Signature · 2 lines
Wei Yang
Help you, Help me