Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm: page_isolation: do not take slab pages for free" failed to apply to 6.18-stable tree

PATCH New [email protected] 2 participants 4 messages Nov 24

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

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 <[email protected]>.

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 213268869301f747d19ca00a391757a6cf2d4fa8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112414-subtract-calculus-aa18@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

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

From 213268869301f747d19ca00a391757a6cf2d4fa8 Mon Sep 17 00:00:00 2001
From: Josef Bacik <[email protected]>
Date: Tue, 3 Nov 2026 17:16:49 +0100
Subject: [PATCH] mm: page_isolation: do not take slab pages for free

page_is_unmovable() regards a page with a reference count of zero as free or about to be freed. Since slab allocates frozen pages, they will be wrongly considered to be freed if order 0 (higher-order compound pages are caught earlier).

If such slabs are the only unmovable pages of a memory block, memory offlining now isolates the block, this can lead to offline_pages() looping without progress.

Thus detect the slab pages as removable to return -EBUSY, as would happen before commit 9aec2fb0fd5e ("slab: allocate frozen pages").

mm/memory_hotplug.c +7 -0
index c9cc42e54f05..0ab9a6e09222 100644
@@ -1832,6 +1832,13 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
 		if (PageOffline(page) && page_count(page))
 			return -EBUSY;
 
+		/*
+		 * A page that was allocated, but was not a slab page yet, when
+		 * its pageblock was isolated.
+		 */
+		if (PageSlab(page))
+			return -EBUSY;
+
 		folio = page_folio(page);
 		if (!folio_test_hugetlb(folio))
 			continue;
mm/page_isolation.c +7 -0
index 5aaad037384e..f4f0571607ab 100644
@@ -74,6 +74,13 @@ bool page_is_unmovable(struct zone *zone, struct page *page,
 		return false;
 	}
 
+	/*
+	 * Slab pages are frozen: do not take their reference count of zero
+	 * for that of a free page.
+	 */
+	if (PageSlab(page))
+		return true;
+
 	/*
 	 * We can't use page_count without pin a page
 	 * because another CPU can free compound page.
maintainer
#1 lore raw

PATCH 1/3 mm: page_isolation: introduce page_is_unmovable()

From: Kefeng Wang <[email protected]>

[ Upstream commit c83109e95c9d78e41b39e65b6490e511f4b8fba2 ]

Patch series "mm: accelerate gigantic folio allocation".

Optimize pfn_range_valid_contig() and replace_free_hugepage_folios() in alloc_contig_frozen_pages() to speed up gigantic folio allocation. The allocation time for 120*1G folios drops from 3.605s to 0.431s.

This patch (of 5):

Factor out the check if a page is unmovable into a new helper, and will be reused in the following patch.

No functional change intended, the minor changes are as follows,
1) Avoid unnecessary calls by checking CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
2) Directly call PageCompound since PageTransCompound may be dropped
3) Using folio_test_hugetlb()

Stable-dep-of: 213268869301 ("mm: page_isolation: do not take slab pages for free")

---
 include/linux/page-isolation.h |   2 +
 mm/page_isolation.c            | 187 +++++++++++++++++----------------
 2 files changed, 101 insertions(+), 88 deletions(-)
include/linux/page-isolation.h +2 -0
index 3e2f960e166ca..6f8638c9904ff 100644
@@ -67,4 +67,6 @@ void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
 
 int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
 			enum pb_isolate_mode mode);
+bool page_is_unmovable(struct zone *zone, struct page *page,
+			enum pb_isolate_mode mode, unsigned long *step);
 #endif
mm/page_isolation.c +99 -88

208 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/3 mm/memory_hotplug: fix possible race in scan_movable_pages()

From: "David Hildenbrand (Arm)" <[email protected]>

[ Upstream commit 89e69c7d187eca8a040d4db0e080f79b5b32163d ]

Patch series "mm: memory hot(un)plug and SPARSEMEM cleanups", v2.

Some cleanups around memory hot(un)plug and SPARSEMEM. In essence, we can limit CONFIG_MEMORY_HOTPLUG to CONFIG_SPARSEMEM_VMEMMAP, remove some dead code, and move all the hotplug bits over to mm/sparse-vmemmap.c.

Some further/related cleanups around other unnecessary code (memory hole handling and complicated usemap allocation).

I have some further sparse.c cleanups lying around, and I'm planning on getting rid of bootmem_info.c entirely.

This patch (of 15):

If a hugetlb folio gets freed while we are in scan_movable_pages(), folio_nr_pages() could return 0, resulting in or'ing "0 - 1 = -1" to the PFN, resulting in PFN = -1. We're not holding any locks or references that would prevent that.

for_each_valid_pfn() would then search for the next valid PFN, and could return a PFN that is outside of the range of the original requested range. do_migrate_page() would then try to migrate quite a big range, which is certainly undesirable.

To fix it, simply test for valid folio_nr_pages() values. While at it, as PageHuge() really just does a page_folio() internally, we can just use folio_test_hugetlb() on the folio directly.

scan_movable_pages() is expected to be fast, and we try to avoid taking locks or grabbing references. We cannot use folio_try_get() as that does not work for free hugetlb folios. We could grab the hugetlb_lock, but that just adds complexity.

The race is unlikely to trigger in practice, so we won't be CCing stable.

Fixes 16540dae959d ("mm/hugetlb: mm/memory_hotplug: use a folio in scan_movable_pages()")
Cc Axel Rasmussen <[email protected]>
Cc Liam Howlett <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Sidhartha Kumar <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Wei Xu <[email protected]>
Cc Yuanchu Xie <[email protected]>

Stable-dep-of: 213268869301 ("mm: page_isolation: do not take slab pages for free")

---
 mm/memory_hotplug.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +8 -3
index bdc064c026ec1..e62c196dfdfb8 100644
@@ -1782,6 +1782,7 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
 	unsigned long pfn;
 
 	for_each_valid_pfn(pfn, start, end) {
+		unsigned long nr_pages;
 		struct page *page;
 		struct folio *folio;
 
@@ -1798,9 +1799,9 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
 		if (PageOffline(page) && page_count(page))
 			return -EBUSY;
 
-		if (!PageHuge(page))
-			continue;
 		folio = page_folio(page);
+		if (!folio_test_hugetlb(folio))
+			continue;
 		/*
 		 * This test is racy as we hold no reference or lock.  The
 		 * hugetlb page could have been free'ed and head is no longer
@@ -1810,7 +1811,11 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
 		 */
 		if (folio_test_hugetlb_migratable(folio))
 			goto found;
-		pfn |= folio_nr_pages(folio) - 1;
+		nr_pages = folio_nr_pages(folio);
+		if (unlikely(nr_pages < 1 || nr_pages > MAX_FOLIO_NR_PAGES ||
+			     !is_power_of_2(nr_pages)))
+			continue;
+		pfn |= nr_pages - 1;
 	}
 	return -ENOENT;
 found:
Signature · 1 line
2.53.0
maintainer
#3 lore raw

PATCH 3/3 mm: page_isolation: do not take slab pages for free

In reply to Sasha Levin

From: Josef Bacik <[email protected]>

[ Upstream commit 213268869301f747d19ca00a391757a6cf2d4fa8 ]

page_is_unmovable() regards a page with a reference count of zero as free or about to be freed. Since slab allocates frozen pages, they will be wrongly considered to be freed if order 0 (higher-order compound pages are caught earlier).

If such slabs are the only unmovable pages of a memory block, memory offlining now isolates the block, this can lead to offline_pages() looping without progress.

Thus detect the slab pages as removable to return -EBUSY, as would happen before commit 9aec2fb0fd5e ("slab: allocate frozen pages").

---
 mm/memory_hotplug.c | 7 +++++++
 mm/page_isolation.c | 7 +++++++
 2 files changed, 14 insertions(+)
mm/memory_hotplug.c +7 -0
index e62c196dfdfb8..1f29e1a64d181 100644
@@ -1799,6 +1799,13 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
 		if (PageOffline(page) && page_count(page))
 			return -EBUSY;
 
+		/*
+		 * A page that was allocated, but was not a slab page yet, when
+		 * its pageblock was isolated.
+		 */
+		if (PageSlab(page))
+			return -EBUSY;
+
 		folio = page_folio(page);
 		if (!folio_test_hugetlb(folio))
 			continue;
mm/page_isolation.c +7 -0
index 7a32350eb8c2d..63c29a5527486 100644
@@ -66,6 +66,13 @@ bool page_is_unmovable(struct zone *zone, struct page *page,
 		return false;
 	}
 
+	/*
+	 * Slab pages are frozen: do not take their reference count of zero
+	 * for that of a free page.
+	 */
+	if (PageSlab(page))
+		return true;
+
 	/*
 	 * We can't use page_count without pin a page
 	 * because another CPU can free compound page.
Signature · 1 line
2.53.0