FAILED: patch "[PATCH] mm/huge_memory: preserve PG_has_hwpoisoned if a folio is" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x fa5a061700364bc28ee1cb1095372f8033645dcb
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025112056-isolating-punisher-7be9@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fa5a061700364bc28ee1cb1095372f8033645dcb Mon Sep 17 00:00:00 2001
From: Zi Yan <[email protected]>
Date: Wed, 22 Oct 2025 23:05:21 -0400
Subject: [PATCH] mm/huge_memory: preserve PG_has_hwpoisoned if a folio is
split to >0 order
folio split clears PG_has_hwpoisoned, but the flag should be preserved in after-split folios containing pages with PG_hwpoisoned flag if the folio is split to >0 order folios. Scan all pages in a to-be-split folio to determine which after-split folios need the flag.
An alternatives is to change PG_has_hwpoisoned to PG_maybe_hwpoisoned to avoid the scan and set it on all after-split folios, but resulting false positive has undesirable negative impact. To remove false positive, caller of folio_test_has_hwpoisoned() and folio_contain_hwpoisoned_page() needs to do the scan. That might be causing a hassle for current and future callers and more costly than doing the scan in the split code. More details are discussed in [1].
This issue can be exposed via:
1. splitting a has_hwpoisoned folio to >0 order from debugfs interface;
2. truncating part of a has_hwpoisoned folio in truncate_inode_partial_folio().
And later accesses to a hwpoisoned page could be possible due to the missing has_hwpoisoned folio flag. This will lead to MCE errors.
mm/huge_memory.c +20 -3
@@ -3263,6 +3263,14 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) caller_pins; } +static bool page_range_has_hwpoisoned (struct page *page,long nr_pages) +{ +for (; nr_pages; page++, nr_pages--) +if (PageHWPoison (page)) +return true; +return false; +} +/* * It splits @folio into @new_order folios and copies the @folio metadata to * all the resulting folios.
@@ -3270,17 +3278,24 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins)static void __split_folio_to_order (struct folio *folio,int old_order,int new_order) { +/* Scan poisoned pages when split a poisoned folio to large folios */ +const bool handle_hwpoison =folio_test_has_hwpoisoned (folio) && new_order;long new_nr_pages =1 << new_order;long nr_pages =1 << old_order;long i; +folio_clear_has_hwpoisoned (folio); + +/* Check first new_nr_pages since the loop below skips them */ +if (handle_hwpoison && +page_range_has_hwpoisoned (folio_page (folio,0 ), new_nr_pages)) +folio_set_has_hwpoisoned (folio);/* * Skip the first new_nr_pages, since the new folio from them have all * the flags from the original folio. */ for (i = new_nr_pages; i < nr_pages; i += new_nr_pages) {struct page *new_head = &folio->page + i; -/* * Careful: new_folio is not a "real" folio before we cleared PageTail. * Don't pass it around before clear_compound_head().
@@ -3322,6 +3337,10 @@ static void __split_folio_to_order(struct folio *folio, int old_order, (1L << PG_dirty) | LRU_GEN_MASK | LRU_REFS_MASK)); +if (handle_hwpoison && +page_range_has_hwpoisoned (new_head, new_nr_pages)) +folio_set_has_hwpoisoned (new_folio); + new_folio->mapping = folio->mapping; new_folio->index = folio->index + i;
@@ -3422,8 +3441,6 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,if (folio_test_anon (folio))mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); -folio_clear_has_hwpoisoned (folio); -/* * split to new_order one order at a time. For uniform split, * folio is split to new_order directly.
Zi Yan
reviewerPATCH 1/1 mm/huge_memory: preserve PG_has_hwpoisoned if a folio is split to >0 order
folio split clears PG_has_hwpoisoned, but the flag should be preserved in after-split folios containing pages with PG_hwpoisoned flag if the folio is split to >0 order folios. Scan all pages in a to-be-split folio to determine which after-split folios need the flag.
An alternatives is to change PG_has_hwpoisoned to PG_maybe_hwpoisoned to avoid the scan and set it on all after-split folios, but resulting false positive has undesirable negative impact. To remove false positive, caller of folio_test_has_hwpoisoned() and folio_contain_hwpoisoned_page() needs to do the scan. That might be causing a hassle for current and future callers and more costly than doing the scan in the split code. More details are discussed in [1].
This issue can be exposed via:
1. splitting a has_hwpoisoned folio to >0 order from debugfs interface;
2. truncating part of a has_hwpoisoned folio in truncate_inode_partial_folio().
And later accesses to a hwpoisoned page could be possible due to the missing has_hwpoisoned folio flag. This will lead to MCE errors.
--- mm/huge_memory.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
mm/huge_memory.c +23 -2
@@ -3091,9 +3091,17 @@ static void lru_add_page_tail(struct folio *folio, struct page *tail, } } +static bool page_range_has_hwpoisoned (struct page *page,long nr_pages) +{ +for (; nr_pages; page++, nr_pages--) +if (PageHWPoison (page)) +return true; +return false; +} +static void __split_huge_page_tail (struct folio *folio,int tail,struct lruvec *lruvec,struct list_head *list, -unsigned int new_order) +unsigned int new_order,const bool handle_hwpoison) {struct page *head = &folio->page;struct page *page_tail = head + tail;
@@ -3170,6 +3178,11 @@ static void __split_huge_page_tail(struct folio *folio, int tail,folio_set_large_rmappable (new_folio); } +/* Set has_hwpoisoned flag on new_folio if any of its pages is HWPoison */ +if (handle_hwpoison && +page_range_has_hwpoisoned (page_tail,1 << new_order)) +folio_set_has_hwpoisoned (new_folio); +/* Finally unfreeze refcount. Additional reference from page cache. */ page_ref_unfreeze(page_tail, 1 + ((!folio_test_anon(folio) || folio_test_swapcache(folio)) ?
@@ -3194,6 +3207,8 @@ static void __split_huge_page(struct page *page, struct list_head *list, pgoff_t end, unsigned int new_order) { struct folio *folio = page_folio(page); +/* Scan poisoned pages when split a poisoned folio to large folios */ +const bool handle_hwpoison =folio_test_has_hwpoisoned (folio) && new_order;struct page *head = &folio->page;struct lruvec *lruvec;struct address_space *swap_cache =NULL ;
@@ -3217,8 +3232,14 @@ static void __split_huge_page(struct page *page, struct list_head *list,ClearPageHasHWPoisoned (head); +/* Check first new_nr pages since the loop below skips them */ +if (handle_hwpoison && +page_range_has_hwpoisoned (folio_page (folio,0 ), new_nr)) +folio_set_has_hwpoisoned (folio); +for (i = nr - new_nr; i >= new_nr; i -= new_nr) { -__split_huge_page_tail (folio, i, lruvec, list, new_order); +__split_huge_page_tail (folio, i, lruvec, list, new_order, + handle_hwpoison);/* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) {struct folio *tail =page_folio (head + i);
Signature · 1 line
2.51.0