Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree
@ 2025-12-29 12:33 gregkh
  2025-12-30  2:48 ` [PATCH 6.18.y] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported() Sasha Levin
  2025-12-30  3:11 ` FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree Wei Yang
  0 siblings, 2 replies; 5+ messages in thread
From: gregkh @ 2025-12-29 12:33 UTC (permalink / raw)
  To: richard.weiyang, akpm, baohua, baolin.wang, david, dev.jain,
	lance.yang, liam.howlett, lorenzo.stoakes, npache, ryan.roberts,
	stable, ziy
  Cc: stable


The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 8a0e4bdddd1c998b894d879a1d22f1e745606215
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122925-victory-numeral-2346@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 8a0e4bdddd1c998b894d879a1d22f1e745606215 Mon Sep 17 00:00:00 2001
From: Wei Yang <richard.weiyang@gmail.com>
Date: Thu, 6 Nov 2025 03:41:55 +0000
Subject: [PATCH] mm/huge_memory: merge uniform_split_supported() and
 non_uniform_split_supported()

uniform_split_supported() and non_uniform_split_supported() share
significantly similar logic.

The only functional difference is that uniform_split_supported() includes
an additional check on the requested @new_order.

The reason for this check comes from the following two aspects:

  * some file system or swap cache just supports order-0 folio
  * the behavioral difference between uniform/non-uniform split

The behavioral difference between uniform split and non-uniform:

  * uniform split splits folio directly to @new_order
  * non-uniform split creates after-split folios with orders from
    folio_order(folio) - 1 to new_order.

This means for non-uniform split or !new_order split we should check the
file system and swap cache respectively.

This commit unifies the logic and merge the two functions into a single
combined helper, removing redundant code and simplifying the split
support checking mechanism.

Link: https://lkml.kernel.org/r/20251106034155.21398-3-richard.weiyang@gmail.com
Fixes: c010d47f107f ("mm: thp: split huge page to any lower order pages")
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: "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: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index b74708dc5b5f..19d4a5f52ca2 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -374,10 +374,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list
 		unsigned int new_order, bool unmapped);
 int min_order_for_split(struct folio *folio);
 int split_folio_to_list(struct folio *folio, struct list_head *list);
-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns);
-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns);
+bool folio_split_supported(struct folio *folio, unsigned int new_order,
+		enum split_type split_type, bool warns);
 int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
 		struct list_head *list);
 
@@ -408,7 +406,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_o
 static inline int try_folio_split_to_order(struct folio *folio,
 		struct page *page, unsigned int new_order)
 {
-	if (!non_uniform_split_supported(folio, new_order, /* warns= */ false))
+	if (!folio_split_supported(folio, new_order, SPLIT_TYPE_NON_UNIFORM, /* warns= */ false))
 		return split_huge_page_to_order(&folio->page, new_order);
 	return folio_split(folio, new_order, page, NULL);
 }
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 4118f330c55e..d79a4bb363de 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3593,8 +3593,8 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
 	return 0;
 }
 
-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns)
+bool folio_split_supported(struct folio *folio, unsigned int new_order,
+		enum split_type split_type, bool warns)
 {
 	if (folio_test_anon(folio)) {
 		/* order-1 is not supported for anonymous THP. */
@@ -3602,48 +3602,41 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
 				"Cannot split to order-1 folio");
 		if (new_order == 1)
 			return false;
-	} else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
-	    !mapping_large_folio_support(folio->mapping)) {
-		/*
-		 * No split if the file system does not support large folio.
-		 * Note that we might still have THPs in such mappings due to
-		 * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping
-		 * does not actually support large folios properly.
-		 */
-		VM_WARN_ONCE(warns,
-			"Cannot split file folio to non-0 order");
-		return false;
-	}
-
-	/* Only swapping a whole PMD-mapped folio is supported */
-	if (folio_test_swapcache(folio)) {
-		VM_WARN_ONCE(warns,
-			"Cannot split swapcache folio to non-0 order");
-		return false;
-	}
-
-	return true;
-}
-
-/* See comments in non_uniform_split_supported() */
-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns)
-{
-	if (folio_test_anon(folio)) {
-		VM_WARN_ONCE(warns && new_order == 1,
-				"Cannot split to order-1 folio");
-		if (new_order == 1)
-			return false;
-	} else  if (new_order) {
+	} else if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order) {
 		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
 		    !mapping_large_folio_support(folio->mapping)) {
+			/*
+			 * We can always split a folio down to a single page
+			 * (new_order == 0) uniformly.
+			 *
+			 * For any other scenario
+			 *   a) uniform split targeting a large folio
+			 *      (new_order > 0)
+			 *   b) any non-uniform split
+			 * we must confirm that the file system supports large
+			 * folios.
+			 *
+			 * Note that we might still have THPs in such
+			 * mappings, which is created from khugepaged when
+			 * CONFIG_READ_ONLY_THP_FOR_FS is enabled. But in that
+			 * case, the mapping does not actually support large
+			 * folios properly.
+			 */
 			VM_WARN_ONCE(warns,
 				"Cannot split file folio to non-0 order");
 			return false;
 		}
 	}
 
-	if (new_order && folio_test_swapcache(folio)) {
+	/*
+	 * swapcache folio could only be split to order 0
+	 *
+	 * non-uniform split creates after-split folios with orders from
+	 * folio_order(folio) - 1 to new_order, making it not suitable for any
+	 * swapcache folio split. Only uniform split to order-0 can be used
+	 * here.
+	 */
+	if ((split_type == SPLIT_TYPE_NON_UNIFORM || new_order) && folio_test_swapcache(folio)) {
 		VM_WARN_ONCE(warns,
 			"Cannot split swapcache folio to non-0 order");
 		return false;
@@ -3711,11 +3704,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
 	if (new_order >= old_order)
 		return -EINVAL;
 
-	if (split_type == SPLIT_TYPE_UNIFORM && !uniform_split_supported(folio, new_order, true))
-		return -EINVAL;
-
-	if (split_type == SPLIT_TYPE_NON_UNIFORM &&
-	    !non_uniform_split_supported(folio, new_order, true))
+	if (!folio_split_supported(folio, new_order, split_type, /* warn = */ true))
 		return -EINVAL;
 
 	is_hzp = is_huge_zero_folio(folio);


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 6.18.y] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported()
  2025-12-29 12:33 FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree gregkh
@ 2025-12-30  2:48 ` Sasha Levin
  2025-12-30  3:11 ` FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree Wei Yang
  1 sibling, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2025-12-30  2:48 UTC (permalink / raw)
  To: stable
  Cc: Wei Yang, Zi Yan, David Hildenbrand (Red Hat), Baolin Wang,
	Barry Song, Dev Jain, Lance Yang, Liam Howlett, Lorenzo Stoakes,
	Nico Pache, Ryan Roberts, Andrew Morton, Sasha Levin

From: Wei Yang <richard.weiyang@gmail.com>

[ Upstream commit 8a0e4bdddd1c998b894d879a1d22f1e745606215 ]

uniform_split_supported() and non_uniform_split_supported() share
significantly similar logic.

The only functional difference is that uniform_split_supported() includes
an additional check on the requested @new_order.

The reason for this check comes from the following two aspects:

  * some file system or swap cache just supports order-0 folio
  * the behavioral difference between uniform/non-uniform split

The behavioral difference between uniform split and non-uniform:

  * uniform split splits folio directly to @new_order
  * non-uniform split creates after-split folios with orders from
    folio_order(folio) - 1 to new_order.

This means for non-uniform split or !new_order split we should check the
file system and swap cache respectively.

This commit unifies the logic and merge the two functions into a single
combined helper, removing redundant code and simplifying the split
support checking mechanism.

Link: https://lkml.kernel.org/r/20251106034155.21398-3-richard.weiyang@gmail.com
Fixes: c010d47f107f ("mm: thp: split huge page to any lower order pages")
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: "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: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ split_type => uniform_split and replaced SPLIT_TYPE_NON_UNIFORM checks ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/linux/huge_mm.h |  8 ++---
 mm/huge_memory.c        | 71 +++++++++++++++++------------------------
 2 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 71ac78b9f834..240cbc676480 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -369,10 +369,8 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
 		unsigned int new_order);
 int min_order_for_split(struct folio *folio);
 int split_folio_to_list(struct folio *folio, struct list_head *list);
-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns);
-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns);
+bool folio_split_supported(struct folio *folio, unsigned int new_order,
+		bool uniform_split, bool warns);
 int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
 		struct list_head *list);
 /*
@@ -392,7 +390,7 @@ int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
 static inline int try_folio_split_to_order(struct folio *folio,
 		struct page *page, unsigned int new_order)
 {
-	if (!non_uniform_split_supported(folio, new_order, /* warns= */ false))
+	if (!folio_split_supported(folio, new_order, false, /* warns= */ false))
 		return split_huge_page_to_list_to_order(&folio->page, NULL,
 				new_order);
 	return folio_split(folio, new_order, page, NULL);
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 6cba1cb14b23..7a74198f05c6 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3515,8 +3515,8 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
 	return ret;
 }
 
-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns)
+bool folio_split_supported(struct folio *folio, unsigned int new_order,
+		bool uniform_split, bool warns)
 {
 	if (folio_test_anon(folio)) {
 		/* order-1 is not supported for anonymous THP. */
@@ -3524,48 +3524,41 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
 				"Cannot split to order-1 folio");
 		if (new_order == 1)
 			return false;
-	} else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
-	    !mapping_large_folio_support(folio->mapping)) {
-		/*
-		 * No split if the file system does not support large folio.
-		 * Note that we might still have THPs in such mappings due to
-		 * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping
-		 * does not actually support large folios properly.
-		 */
-		VM_WARN_ONCE(warns,
-			"Cannot split file folio to non-0 order");
-		return false;
-	}
-
-	/* Only swapping a whole PMD-mapped folio is supported */
-	if (folio_test_swapcache(folio)) {
-		VM_WARN_ONCE(warns,
-			"Cannot split swapcache folio to non-0 order");
-		return false;
-	}
-
-	return true;
-}
-
-/* See comments in non_uniform_split_supported() */
-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
-		bool warns)
-{
-	if (folio_test_anon(folio)) {
-		VM_WARN_ONCE(warns && new_order == 1,
-				"Cannot split to order-1 folio");
-		if (new_order == 1)
-			return false;
-	} else  if (new_order) {
+	} else if (!uniform_split || new_order) {
 		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
 		    !mapping_large_folio_support(folio->mapping)) {
+			/*
+			 * We can always split a folio down to a single page
+			 * (new_order == 0) uniformly.
+			 *
+			 * For any other scenario
+			 *   a) uniform split targeting a large folio
+			 *      (new_order > 0)
+			 *   b) any non-uniform split
+			 * we must confirm that the file system supports large
+			 * folios.
+			 *
+			 * Note that we might still have THPs in such
+			 * mappings, which is created from khugepaged when
+			 * CONFIG_READ_ONLY_THP_FOR_FS is enabled. But in that
+			 * case, the mapping does not actually support large
+			 * folios properly.
+			 */
 			VM_WARN_ONCE(warns,
 				"Cannot split file folio to non-0 order");
 			return false;
 		}
 	}
 
-	if (new_order && folio_test_swapcache(folio)) {
+	/*
+	 * swapcache folio could only be split to order 0
+	 *
+	 * non-uniform split creates after-split folios with orders from
+	 * folio_order(folio) - 1 to new_order, making it not suitable for any
+	 * swapcache folio split. Only uniform split to order-0 can be used
+	 * here.
+	 */
+	if ((!uniform_split || new_order) && folio_test_swapcache(folio)) {
 		VM_WARN_ONCE(warns,
 			"Cannot split swapcache folio to non-0 order");
 		return false;
@@ -3632,11 +3625,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
 	if (new_order >= folio_order(folio))
 		return -EINVAL;
 
-	if (uniform_split && !uniform_split_supported(folio, new_order, true))
-		return -EINVAL;
-
-	if (!uniform_split &&
-	    !non_uniform_split_supported(folio, new_order, true))
+	if (!folio_split_supported(folio, new_order, uniform_split, /* warn = */ true))
 		return -EINVAL;
 
 	is_hzp = is_huge_zero_folio(folio);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree
  2025-12-29 12:33 FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree gregkh
  2025-12-30  2:48 ` [PATCH 6.18.y] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported() Sasha Levin
@ 2025-12-30  3:11 ` Wei Yang
  2026-01-02 12:24   ` Greg KH
  1 sibling, 1 reply; 5+ messages in thread
From: Wei Yang @ 2025-12-30  3:11 UTC (permalink / raw)
  To: gregkh
  Cc: richard.weiyang, akpm, baohua, baolin.wang, david, dev.jain,
	lance.yang, liam.howlett, lorenzo.stoakes, npache, ryan.roberts,
	stable, ziy

On Mon, Dec 29, 2025 at 01:33:25PM +0100, gregkh@linuxfoundation.org wrote:
>
>The patch below does not apply to the 6.18-stable tree.
>If someone wants it applied there, or to any other stable or longterm
>tree, then please email the backport, including the original git commit
>id to <stable@vger.kernel.org>.
>
>To reproduce the conflict and resubmit, you may use the following commands:
>
>git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
>git checkout FETCH_HEAD
>git cherry-pick -x 8a0e4bdddd1c998b894d879a1d22f1e745606215
># <resolve conflicts, build, test, etc.>
>git commit -s
>git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122925-victory-numeral-2346@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..
>
>Possible dependencies:
>
>

Hi, Greg

This one is not a fix to some bug.

We found a real bug during the mail discussion, which is 

    commit cff47b9e39a6abf03dde5f4f156f841b0c54bba0
    Author: Wei Yang <richard.weiyang@gmail.com>
    Date:   Wed Nov 19 23:53:02 2025 +0000
    
        mm/huge_memory: fix NULL pointer deference when splitting folio

It looks has been back ported to 6.18.y and 6.12.y.

>
>thanks,
>
>greg k-h
>
>------------------ original commit in Linus's tree ------------------
>
>>From 8a0e4bdddd1c998b894d879a1d22f1e745606215 Mon Sep 17 00:00:00 2001
>From: Wei Yang <richard.weiyang@gmail.com>
>Date: Thu, 6 Nov 2025 03:41:55 +0000
>Subject: [PATCH] mm/huge_memory: merge uniform_split_supported() and
> non_uniform_split_supported()
>
>uniform_split_supported() and non_uniform_split_supported() share
>significantly similar logic.
>
>The only functional difference is that uniform_split_supported() includes
>an additional check on the requested @new_order.
>
>The reason for this check comes from the following two aspects:
>
>  * some file system or swap cache just supports order-0 folio
>  * the behavioral difference between uniform/non-uniform split
>
>The behavioral difference between uniform split and non-uniform:
>
>  * uniform split splits folio directly to @new_order
>  * non-uniform split creates after-split folios with orders from
>    folio_order(folio) - 1 to new_order.
>
>This means for non-uniform split or !new_order split we should check the
>file system and swap cache respectively.
>
>This commit unifies the logic and merge the two functions into a single
>combined helper, removing redundant code and simplifying the split
>support checking mechanism.
>
>Link: https://lkml.kernel.org/r/20251106034155.21398-3-richard.weiyang@gmail.com
>Fixes: c010d47f107f ("mm: thp: split huge page to any lower order pages")
>Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>Reviewed-by: Zi Yan <ziy@nvidia.com>
>Cc: Zi Yan <ziy@nvidia.com>
>Cc: "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: <stable@vger.kernel.org>

The Fixes tag and cc stable is not necessary here.

We didn't communicate well with Andrew, sorry for the confusion.

>Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>
>diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
>index b74708dc5b5f..19d4a5f52ca2 100644
>--- a/include/linux/huge_mm.h
>+++ b/include/linux/huge_mm.h
>@@ -374,10 +374,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list
> 		unsigned int new_order, bool unmapped);
> int min_order_for_split(struct folio *folio);
> int split_folio_to_list(struct folio *folio, struct list_head *list);
>-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
>-		bool warns);
>-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
>-		bool warns);
>+bool folio_split_supported(struct folio *folio, unsigned int new_order,
>+		enum split_type split_type, bool warns);
> int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
> 		struct list_head *list);
> 
>@@ -408,7 +406,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_o
> static inline int try_folio_split_to_order(struct folio *folio,
> 		struct page *page, unsigned int new_order)
> {
>-	if (!non_uniform_split_supported(folio, new_order, /* warns= */ false))
>+	if (!folio_split_supported(folio, new_order, SPLIT_TYPE_NON_UNIFORM, /* warns= */ false))
> 		return split_huge_page_to_order(&folio->page, new_order);
> 	return folio_split(folio, new_order, page, NULL);
> }
>diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>index 4118f330c55e..d79a4bb363de 100644
>--- a/mm/huge_memory.c
>+++ b/mm/huge_memory.c
>@@ -3593,8 +3593,8 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
> 	return 0;
> }
> 
>-bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
>-		bool warns)
>+bool folio_split_supported(struct folio *folio, unsigned int new_order,
>+		enum split_type split_type, bool warns)
> {
> 	if (folio_test_anon(folio)) {
> 		/* order-1 is not supported for anonymous THP. */
>@@ -3602,48 +3602,41 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
> 				"Cannot split to order-1 folio");
> 		if (new_order == 1)
> 			return false;
>-	} else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
>-	    !mapping_large_folio_support(folio->mapping)) {
>-		/*
>-		 * No split if the file system does not support large folio.
>-		 * Note that we might still have THPs in such mappings due to
>-		 * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping
>-		 * does not actually support large folios properly.
>-		 */
>-		VM_WARN_ONCE(warns,
>-			"Cannot split file folio to non-0 order");
>-		return false;
>-	}
>-
>-	/* Only swapping a whole PMD-mapped folio is supported */
>-	if (folio_test_swapcache(folio)) {
>-		VM_WARN_ONCE(warns,
>-			"Cannot split swapcache folio to non-0 order");
>-		return false;
>-	}
>-
>-	return true;
>-}
>-
>-/* See comments in non_uniform_split_supported() */
>-bool uniform_split_supported(struct folio *folio, unsigned int new_order,
>-		bool warns)
>-{
>-	if (folio_test_anon(folio)) {
>-		VM_WARN_ONCE(warns && new_order == 1,
>-				"Cannot split to order-1 folio");
>-		if (new_order == 1)
>-			return false;
>-	} else  if (new_order) {
>+	} else if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order) {
> 		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
> 		    !mapping_large_folio_support(folio->mapping)) {
>+			/*
>+			 * We can always split a folio down to a single page
>+			 * (new_order == 0) uniformly.
>+			 *
>+			 * For any other scenario
>+			 *   a) uniform split targeting a large folio
>+			 *      (new_order > 0)
>+			 *   b) any non-uniform split
>+			 * we must confirm that the file system supports large
>+			 * folios.
>+			 *
>+			 * Note that we might still have THPs in such
>+			 * mappings, which is created from khugepaged when
>+			 * CONFIG_READ_ONLY_THP_FOR_FS is enabled. But in that
>+			 * case, the mapping does not actually support large
>+			 * folios properly.
>+			 */
> 			VM_WARN_ONCE(warns,
> 				"Cannot split file folio to non-0 order");
> 			return false;
> 		}
> 	}
> 
>-	if (new_order && folio_test_swapcache(folio)) {
>+	/*
>+	 * swapcache folio could only be split to order 0
>+	 *
>+	 * non-uniform split creates after-split folios with orders from
>+	 * folio_order(folio) - 1 to new_order, making it not suitable for any
>+	 * swapcache folio split. Only uniform split to order-0 can be used
>+	 * here.
>+	 */
>+	if ((split_type == SPLIT_TYPE_NON_UNIFORM || new_order) && folio_test_swapcache(folio)) {
> 		VM_WARN_ONCE(warns,
> 			"Cannot split swapcache folio to non-0 order");
> 		return false;
>@@ -3711,11 +3704,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> 	if (new_order >= old_order)
> 		return -EINVAL;
> 
>-	if (split_type == SPLIT_TYPE_UNIFORM && !uniform_split_supported(folio, new_order, true))
>-		return -EINVAL;
>-
>-	if (split_type == SPLIT_TYPE_NON_UNIFORM &&
>-	    !non_uniform_split_supported(folio, new_order, true))
>+	if (!folio_split_supported(folio, new_order, split_type, /* warn = */ true))
> 		return -EINVAL;
> 
> 	is_hzp = is_huge_zero_folio(folio);

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree
  2025-12-30  3:11 ` FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree Wei Yang
@ 2026-01-02 12:24   ` Greg KH
  2026-01-03  1:32     ` Wei Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2026-01-02 12:24 UTC (permalink / raw)
  To: Wei Yang
  Cc: akpm, baohua, baolin.wang, david, dev.jain, lance.yang,
	liam.howlett, lorenzo.stoakes, npache, ryan.roberts, stable, ziy

On Tue, Dec 30, 2025 at 03:11:35AM +0000, Wei Yang wrote:
> On Mon, Dec 29, 2025 at 01:33:25PM +0100, gregkh@linuxfoundation.org wrote:
> >
> >The patch below does not apply to the 6.18-stable tree.
> >If someone wants it applied there, or to any other stable or longterm
> >tree, then please email the backport, including the original git commit
> >id to <stable@vger.kernel.org>.
> >
> >To reproduce the conflict and resubmit, you may use the following commands:
> >
> >git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
> >git checkout FETCH_HEAD
> >git cherry-pick -x 8a0e4bdddd1c998b894d879a1d22f1e745606215
> ># <resolve conflicts, build, test, etc.>
> >git commit -s
> >git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122925-victory-numeral-2346@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..
> >
> >Possible dependencies:
> >
> >
> 
> Hi, Greg
> 
> This one is not a fix to some bug.
> 
> We found a real bug during the mail discussion, which is 
> 
>     commit cff47b9e39a6abf03dde5f4f156f841b0c54bba0
>     Author: Wei Yang <richard.weiyang@gmail.com>
>     Date:   Wed Nov 19 23:53:02 2025 +0000
>     
>         mm/huge_memory: fix NULL pointer deference when splitting folio
> 
> It looks has been back ported to 6.18.y and 6.12.y.

I do not understand, should this not be applied?  Or should it be
applied?

confused,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree
  2026-01-02 12:24   ` Greg KH
@ 2026-01-03  1:32     ` Wei Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2026-01-03  1:32 UTC (permalink / raw)
  To: Greg KH
  Cc: Wei Yang, akpm, baohua, baolin.wang, david, dev.jain, lance.yang,
	liam.howlett, lorenzo.stoakes, npache, ryan.roberts, stable, ziy

On Fri, Jan 02, 2026 at 01:24:28PM +0100, Greg KH wrote:
>On Tue, Dec 30, 2025 at 03:11:35AM +0000, Wei Yang wrote:
>> On Mon, Dec 29, 2025 at 01:33:25PM +0100, gregkh@linuxfoundation.org wrote:
>> >
>> >The patch below does not apply to the 6.18-stable tree.
>> >If someone wants it applied there, or to any other stable or longterm
>> >tree, then please email the backport, including the original git commit
>> >id to <stable@vger.kernel.org>.
>> >
>> >To reproduce the conflict and resubmit, you may use the following commands:
>> >
>> >git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
>> >git checkout FETCH_HEAD
>> >git cherry-pick -x 8a0e4bdddd1c998b894d879a1d22f1e745606215
>> ># <resolve conflicts, build, test, etc.>
>> >git commit -s
>> >git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122925-victory-numeral-2346@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..
>> >
>> >Possible dependencies:
>> >
>> >
>> 
>> Hi, Greg
>> 
>> This one is not a fix to some bug.
>> 
>> We found a real bug during the mail discussion, which is 
>> 
>>     commit cff47b9e39a6abf03dde5f4f156f841b0c54bba0
>>     Author: Wei Yang <richard.weiyang@gmail.com>
>>     Date:   Wed Nov 19 23:53:02 2025 +0000
>>     
>>         mm/huge_memory: fix NULL pointer deference when splitting folio
>> 
>> It looks has been back ported to 6.18.y and 6.12.y.
>
>I do not understand, should this not be applied?  Or should it be
>applied?

Upstream commit

    cff47b9e39a6 2025-11-24 mm/huge_memory: fix NULL pointer deference when splitting folio

should be applied and already applied to 6.18.y and 6.12.y.

Upstream commit

    8a0e4bdddd1c 2025-11-24 mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported()

is not necessary to be back ported.

>
>confused,
>
>greg k-h

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-01-03  1:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29 12:33 FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree gregkh
2025-12-30  2:48 ` [PATCH 6.18.y] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported() Sasha Levin
2025-12-30  3:11 ` FAILED: patch "[PATCH] mm/huge_memory: merge uniform_split_supported() and" failed to apply to 6.18-stable tree Wei Yang
2026-01-02 12:24   ` Greg KH
2026-01-03  1:32     ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox