Skip to contentSkip to conversation

mm-memory-failure-fix-folio-refcount-leak-and-min_order_for_split-locking.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Nov 10 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/memory-failure: fix folio refcount leak and min_order_for_split() locking
has been removed from the -mm tree. Its filename was
mm-memory-failure-fix-folio-refcount-leak-and-min_order_for_split-locking.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "David Hildenbrand (Arm)" <[email protected]>
Subject: mm/memory-failure: fix folio refcount leak and min_order_for_split() locking
Date: Fri, 30 Oct 2026 23:29:13 +0100

hwpoison code can end up calling min_order_for_split() without holding the folio lock. There isn't really something that would prevent concurrent truncation. Consequently folio->mapping can get set to NULL after checking for "!folio->mapping", and if the compiler reloads folio->mapping, mapping_min_folio_order() would try to dereference NULL.

While very unlikely to happen in practice, let's just enforce that min_order_for_split() is called with the folio lock held. We can significantly cleanup the calling hwpoison code, and just get rid of try_to_split_thp_page() to hold the folio lock for a bit longer.

Just work on folios now, which further cleans up the code. We just have to be careful about doing the page_folio() after splitting, which we have to do already either way. Do not change the way we split for now, this needs more thought and should be done separately.

Cleaning this up we fix another issue: in soft_offline_in_use_page(), we would currently have leaked a folio reference.

In min_order_for_split(), document and assert that we need the folio lock. Drop the questionable VM_BUG_ON_PAGE(!page_count(p), p) check entirely.

While updating the comment in soft_offline_in_use_page(), just drop the "NOTE" part that does not add any value to current code.

The folio->mapping problem was identified by Sashiko, and Li Youhong reported it by sending a proposal fix.

This likely does not really warrant CCing stable, but I expect little conflicts when doing the backport, so let's just CC stable because of the refcount leak.

---

 mm/huge_memory.c    |    4 ++
 mm/memory-failure.c |   63 ++++++++++++++----------------------------
 2 files changed, 25 insertions(+), 42 deletions(-)
mm/huge_memory.c renamed from mm/huge_memory.c~mm-memory-failure-fix-folio-refcount-leak-and-min_order_for_split-locking +4 -0
@@ -4551,10 +4551,14 @@ int folio_split(struct folio *folio, uns
  * If a file-backed folio is truncated, 0 will be returned. Any subsequent
  * split attempt should get -EBUSY from split checking code.
  *
+ * Context: @folio must be locked.
+ *
  * Return: @folio's minimum order for split
  */
 unsigned int min_order_for_split(struct folio *folio)
 {
+	VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
+
 	if (folio_test_anon(folio))
 		return 0;
 
mm/memory-failure.c renamed from mm/memory-failure.c~mm-memory-failure-fix-folio-refcount-leak-and-min_order_for_split-locking +21 -42

105 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are

mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-khugepaged-free-unused-page-table-when-setting-a-huge-pmd-fails.patch