* [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
2026-11-03 21:00 [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
@ 2026-11-03 21:00 ` Mani Tofigh via B4 Relay
2026-11-19 6:39 ` Miaohe Lin
2026-11-19 7:07 ` + mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch added to mm-new branch Andrew Morton
2026-11-03 21:00 ` [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
2026-11-19 7:06 ` [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Andrew Morton
2 siblings, 2 replies; 10+ messages in thread
From: Mani Tofigh via B4 Relay @ 2026-11-03 21:00 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, David Hildenbrand, Miaohe Lin,
Andrew Morton
Cc: Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan, Kaitao Cheng,
Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm, linux-kernel,
tz2294, stable, Mani Tofigh
From: Mani Tofigh <mt4022@columbia.edu>
If memory_failure() can't save the raw error page of a hugetlb folio,
it marks the folio raw_hwp_unreliable and unpoison_memory() refuses to
unpoison it, since we don't know which subpages are poisoned. Once the
folio is freed, __update_and_free_hugetlb_folio() leaks it on purpose.
If its hugetlb flag is cleared by then, e.g., without vmemmap
optimization, unpoison_memory() doesn't see a hugetlb folio anymore.
It treats the leaked folio as a normal page and clears PG_hwpoison on
its head, while the poisoned subpages are still unknown.
The leaked folio is still a large folio and raw_hwp_unreliable stays set
in folio->private. We now check it on any large folio before taking the
page, so unpoison_memory() refuses the folio whether it's still hugetlb
or not. With the fix, it returns -EBUSY for the leaked folio as it did
before the folio was freed.
Fixes: ac5fcde0a96a ("mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage")
Reported-by: Miaohe Lin <linmiaohe@huawei.com>
Closes: https://lore.kernel.org/all/ae6058ae-3703-a1d5-d82f-4102b46f227b@huawei.com/
Cc: stable@vger.kernel.org
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
---
mm/memory-failure.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index b215312f261b..496eacbefdf2 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -2809,6 +2809,15 @@ int unpoison_memory(unsigned long pfn)
goto unlock_mutex;
}
+ /*
+ * A hugetlb folio without reliable raw error info is leaked once it
+ * is freed, and its hugetlb flag may be cleared by then. Check the
+ * flag in folio->private, which stays set on the leaked folio.
+ */
+ if (folio_test_large(folio) &&
+ folio_test_hugetlb_raw_hwp_unreliable(folio))
+ goto unlock_mutex;
+
ghp = get_hwpoison_page(p, MF_UNPOISON);
if (!ghp) {
if (folio_test_hugetlb(folio)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
2026-11-03 21:00 ` [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio Mani Tofigh via B4 Relay
@ 2026-11-19 6:39 ` Miaohe Lin
2026-11-19 7:11 ` Andrew Morton
2026-11-19 7:07 ` + mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch added to mm-new branch Andrew Morton
1 sibling, 1 reply; 10+ messages in thread
From: Miaohe Lin @ 2026-11-19 6:39 UTC (permalink / raw)
To: mt4022
Cc: Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan, Kaitao Cheng,
Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm, linux-kernel,
tz2294, stable, Muchun Song, Oscar Salvador, David Hildenbrand,
Andrew Morton
On 2026/11/4 5:00, Mani Tofigh via B4 Relay wrote:
> From: Mani Tofigh <mt4022@columbia.edu>
>
> If memory_failure() can't save the raw error page of a hugetlb folio,
> it marks the folio raw_hwp_unreliable and unpoison_memory() refuses to
> unpoison it, since we don't know which subpages are poisoned. Once the
> folio is freed, __update_and_free_hugetlb_folio() leaks it on purpose.
> If its hugetlb flag is cleared by then, e.g., without vmemmap
> optimization, unpoison_memory() doesn't see a hugetlb folio anymore.
> It treats the leaked folio as a normal page and clears PG_hwpoison on
> its head, while the poisoned subpages are still unknown.
>
> The leaked folio is still a large folio and raw_hwp_unreliable stays set
> in folio->private. We now check it on any large folio before taking the
> page, so unpoison_memory() refuses the folio whether it's still hugetlb
> or not. With the fix, it returns -EBUSY for the leaked folio as it did
> before the folio was freed.
>
> Fixes: ac5fcde0a96a ("mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage")
> Reported-by: Miaohe Lin <linmiaohe@huawei.com>
> Closes: https://lore.kernel.org/all/ae6058ae-3703-a1d5-d82f-4102b46f227b@huawei.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
> ---
> mm/memory-failure.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index b215312f261b..496eacbefdf2 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -2809,6 +2809,15 @@ int unpoison_memory(unsigned long pfn)
> goto unlock_mutex;
> }
>
> + /*
> + * A hugetlb folio without reliable raw error info is leaked once it
> + * is freed, and its hugetlb flag may be cleared by then. Check the
> + * flag in folio->private, which stays set on the leaked folio.
> + */
> + if (folio_test_large(folio) &&
> + folio_test_hugetlb_raw_hwp_unreliable(folio))
It might be better to add a unpoison_pr_info here?
> + goto unlock_mutex;
Anyway, this patch LGTM:
Acked-by: Miaohe Lin <linmiaohe@huawei.com>
Thanks.
.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
2026-11-19 6:39 ` Miaohe Lin
@ 2026-11-19 7:11 ` Andrew Morton
2026-11-19 7:30 ` Miaohe Lin
0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2026-11-19 7:11 UTC (permalink / raw)
To: Miaohe Lin
Cc: mt4022, Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan,
Kaitao Cheng, Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm,
linux-kernel, tz2294, stable, Muchun Song, Oscar Salvador,
David Hildenbrand
On Thu, 19 Nov 2026 14:39:24 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
> > + /*
> > + * A hugetlb folio without reliable raw error info is leaked once it
> > + * is freed, and its hugetlb flag may be cleared by then. Check the
> > + * flag in folio->private, which stays set on the leaked folio.
> > + */
> > + if (folio_test_large(folio) &&
> > + folio_test_hugetlb_raw_hwp_unreliable(folio))
>
> It might be better to add a unpoison_pr_info here?
How does this look?
--- a/mm/memory-failure.c~mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio-fix
+++ a/mm/memory-failure.c
@@ -2818,8 +2818,12 @@ int unpoison_memory(unsigned long pfn)
* flag in folio->private, which stays set on the leaked folio.
*/
if (folio_test_large(folio) &&
- folio_test_hugetlb_raw_hwp_unreliable(folio))
+ folio_test_hugetlb_raw_hwp_unreliable(folio)) {
+ unpoison_pr_info("%#lx: cannot unpoison, poisoned subpages are unknown\n",
+ pfn, &unpoison_rs);
+
goto unlock_mutex;
+ }
ghp = get_hwpoison_page(p, MF_UNPOISON);
if (!ghp) {
_
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
2026-11-19 7:11 ` Andrew Morton
@ 2026-11-19 7:30 ` Miaohe Lin
0 siblings, 0 replies; 10+ messages in thread
From: Miaohe Lin @ 2026-11-19 7:30 UTC (permalink / raw)
To: Andrew Morton
Cc: mt4022, Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan,
Kaitao Cheng, Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm,
linux-kernel, tz2294, stable, Muchun Song, Oscar Salvador,
David Hildenbrand
On 2026/11/19 15:11, Andrew Morton wrote:
> On Thu, 19 Nov 2026 14:39:24 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>
>>> + /*
>>> + * A hugetlb folio without reliable raw error info is leaked once it
>>> + * is freed, and its hugetlb flag may be cleared by then. Check the
>>> + * flag in folio->private, which stays set on the leaked folio.
>>> + */
>>> + if (folio_test_large(folio) &&
>>> + folio_test_hugetlb_raw_hwp_unreliable(folio))
>>
>> It might be better to add a unpoison_pr_info here?
>
> How does this look?
>
> --- a/mm/memory-failure.c~mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio-fix
> +++ a/mm/memory-failure.c
> @@ -2818,8 +2818,12 @@ int unpoison_memory(unsigned long pfn)
> * flag in folio->private, which stays set on the leaked folio.
> */
> if (folio_test_large(folio) &&
> - folio_test_hugetlb_raw_hwp_unreliable(folio))
> + folio_test_hugetlb_raw_hwp_unreliable(folio)) {
> + unpoison_pr_info("%#lx: cannot unpoison, poisoned subpages are unknown\n",
> + pfn, &unpoison_rs);
> +
> goto unlock_mutex;
> + }
>
Looks good to me. Thanks Andrew.
> ghp = get_hwpoison_page(p, MF_UNPOISON);
> if (!ghp) {
> _
>
>
> .
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* + mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch added to mm-new branch
2026-11-03 21:00 ` [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio Mani Tofigh via B4 Relay
2026-11-19 6:39 ` Miaohe Lin
@ 2026-11-19 7:07 ` Andrew Morton
1 sibling, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2026-11-19 7:07 UTC (permalink / raw)
To: mm-commits, ziy, yuzhao, willy, tz2294, stable, rppt, osalvador,
nao.horiguchi, muchun.song, mike.kravetz, linmiaohe, kaitao.cheng,
jane.chu, david, mt4022, akpm
The patch titled
Subject: mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
has been added to the -mm mm-new branch. Its filename is
mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Mani Tofigh <mt4022@columbia.edu>
Subject: mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio
Date: Tue, 03 Nov 2026 16:00:49 -0500
Patch series "mm/hugetlb: clear the hugetlb flag before leaking a
hwpoisoned folio", v2.
If memory_failure() can't save the raw error page of a hugetlb folio,
the folio is marked raw_hwp_unreliable and leaked once it's freed. With
hugetlb_free_vmemmap=on it's leaked while it's still a hugetlb folio,
and dissolving it then loops forever, e.g., when offlining its memory
block. Patch 2 leaks it only after the hugetlb flag is cleared, as
without vmemmap optimization.
Miaohe pointed out that unpoison_memory() then doesn't see a hugetlb
folio anymore and unpoisons it. That already happens without vmemmap
optimization, so patch 1 fixes it on its own and goes first.
Patch 2 lets a raw_hwp_unreliable folio reach the add_hugetlb_folio()
rollback when restoring its vmemmap fails, as
dissolve_free_hugetlb_folio() already does. It relies on Kaitao's
"mm/hugetlb: preserve persistent flags when returning folios to the
pool" [1] to keep the flag there.
Reproducer:
https://github.com/manitofigh/files/blob/main/linux-repros/hugeoffline.c
This patch (of 2):
If memory_failure() can't save the raw error page of a hugetlb folio,
it marks the folio raw_hwp_unreliable and unpoison_memory() refuses to
unpoison it, since we don't know which subpages are poisoned. Once the
folio is freed, __update_and_free_hugetlb_folio() leaks it on purpose.
If its hugetlb flag is cleared by then, e.g., without vmemmap
optimization, unpoison_memory() doesn't see a hugetlb folio anymore.
It treats the leaked folio as a normal page and clears PG_hwpoison on
its head, while the poisoned subpages are still unknown.
The leaked folio is still a large folio and raw_hwp_unreliable stays set
in folio->private. We now check it on any large folio before taking the
page, so unpoison_memory() refuses the folio whether it's still hugetlb
or not. With the fix, it returns -EBUSY for the leaked folio as it did
before the folio was freed.
Link: https://lore.kernel.org/20261103-hugetlb-hwpoison-leak-v2-0-98085750c145@columbia.edu
Link: https://patch.msgid.link/20261103-hugetlb-hwpoison-leak-v2-1-98085750c145@columbia.edu
Link: https://lore.kernel.org/all/20261102024910.31486-3-kaitao.cheng@linux.dev/ [1]
Fixes: ac5fcde0a96a ("mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage")
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Miaohe Lin <linmiaohe@huawei.com>
Closes: https://lore.kernel.org/all/ae6058ae-3703-a1d5-d82f-4102b46f227b@huawei.com/
Acked-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Jane Chu <jane.chu@oracle.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Kaitao Cheng <kaitao.cheng@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Tal Zussman <tz2294@columbia.edu>
Cc: <stable@vger.kernel.org>
mm/memory-failure.c | 9 +++++++++
1 file changed, 9 insertions(+)
--- a/mm/memory-failure.c~mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio
+++ a/mm/memory-failure.c
@@ -2812,6 +2812,15 @@ int unpoison_memory(unsigned long pfn)
goto unlock_mutex;
}
+ /*
+ * A hugetlb folio without reliable raw error info is leaked once it
+ * is freed, and its hugetlb flag may be cleared by then. Check the
+ * flag in folio->private, which stays set on the leaked folio.
+ */
+ if (folio_test_large(folio) &&
+ folio_test_hugetlb_raw_hwp_unreliable(folio))
+ goto unlock_mutex;
+
ghp = get_hwpoison_page(p, MF_UNPOISON);
if (!ghp) {
guard(vmemmap_remap)();
_
Patches currently in -mm which might be from mt4022@columbia.edu are
mm-swapfile-drop-a-large-unmapped-swap-in-folio-in-unuse_pte.patch
mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch
mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio
2026-11-03 21:00 [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
2026-11-03 21:00 ` [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio Mani Tofigh via B4 Relay
@ 2026-11-03 21:00 ` Mani Tofigh via B4 Relay
2026-11-19 6:40 ` Miaohe Lin
2026-11-19 7:07 ` + mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch added to mm-new branch Andrew Morton
2026-11-19 7:06 ` [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Andrew Morton
2 siblings, 2 replies; 10+ messages in thread
From: Mani Tofigh via B4 Relay @ 2026-11-03 21:00 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, David Hildenbrand, Miaohe Lin,
Andrew Morton
Cc: Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan, Kaitao Cheng,
Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm, linux-kernel,
tz2294, stable, Mani Tofigh
From: Mani Tofigh <mt4022@columbia.edu>
If hugetlb_update_hwpoison() fails to allocate a raw_hwp_page, the folio
is marked raw_hwp_unreliable and __update_and_free_hugetlb_folio() leaks
it intentionally. With hugetlb_free_vmemmap=on, it's leaked before the
hugetlb flag is cleared, since commit 32c877191e02 ("hugetlb: do not
clear hugetlb dtor until allocating vmemmap") doesn't remove the flag
until the vmemmap is restored. The leaked folio is then a hugetlb folio
with refcount 0 and on no list (the same state as a hugetlb folio that
is being freed), but nothing is freeing it, and
dissolve_free_hugetlb_folio() keeps retrying on it. Offlining its
memory block then never completes, even on SIGKILL, and other tasks
block on the memory hotplug lock:
[ 3.271255] Memory failure: 0x20007: recovery action for free huge page: Failed
[ 41.729695] INFO: task hugeoffline:77 blocked for more than 20 seconds.
...
[ 41.733014] get_online_mems+0xc1/0xd0
[ 41.733026] soft_offline_page+0xfd/0x9b0
alloc_and_dissolve_hugetlb_folio() loops on it the same way. The
refcount is 0 since commit bd225530a4c7 ("mm/hugetlb_vmemmap: fix race
with speculative PFN walkers"). Before that these paths failed with
-EBUSY.
Check raw_hwp_unreliable after the hugetlb flag is cleared so that the
folio is leaked as a non-hugetlb folio, as without vmemmap
optimization. unpoison_memory() keeps refusing to unpoison it. With
the fix, offlining retries as it does for any page it can't isolate,
and stops on a signal.
Fixes: 32c877191e02 ("hugetlb: do not clear hugetlb dtor until allocating vmemmap")
Fixes: bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative PFN walkers")
Cc: stable@vger.kernel.org
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
---
This relies on Kaitao's "mm/hugetlb: preserve persistent flags when
returning folios to the pool" [1] (673b553e2bba in mm-new). The check
now comes after hugetlb_vmemmap_restore_folio(), so on a restore failure
add_hugetlb_folio() must keep raw_hwp_unreliable. It would be good to
take [1] to stable along with this one.
This changes the same lines as patch 07/15 of Matthew's "Use
generic_file_read_iter() in hugetlbfs" series [2]. On top of that
series, the check goes right after the folio_clear_hugetlb() call.
[1] https://lore.kernel.org/all/20261102024910.31486-3-kaitao.cheng@linux.dev/
[2] https://lore.kernel.org/all/20260805210557.1118966-8-willy@infradead.org/
Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/hugeoffline.c
---
mm/hugetlb.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 779b1de33c78..cdeb8923083f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1480,13 +1480,6 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
return;
}
- /*
- * If we don't know which subpages are hwpoisoned, we can't free
- * the hugepage, so it's leaked intentionally.
- */
- if (folio_test_hugetlb_raw_hwp_unreliable(folio))
- return;
-
/*
* If folio is not vmemmap optimized (!clear_flag), then the folio
* is no longer identified as a hugetlb page. hugetlb_vmemmap_restore_folio
@@ -1514,6 +1507,14 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
spin_unlock_irq(&hugetlb_lock);
}
+ /*
+ * If we don't know which subpages are hwpoisoned, we can't free
+ * the hugepage, so it's leaked intentionally, but only once it is
+ * no longer a hugetlb folio.
+ */
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio))
+ return;
+
/*
* Move PageHWPoison flag from head page to the raw error pages,
* which makes any healthy subpages reusable.
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio
2026-11-03 21:00 ` [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
@ 2026-11-19 6:40 ` Miaohe Lin
2026-11-19 7:07 ` + mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch added to mm-new branch Andrew Morton
1 sibling, 0 replies; 10+ messages in thread
From: Miaohe Lin @ 2026-11-19 6:40 UTC (permalink / raw)
To: mt4022
Cc: Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan, Kaitao Cheng,
Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm, linux-kernel,
tz2294, stable, Muchun Song, Oscar Salvador, David Hildenbrand,
Andrew Morton
On 2026/11/4 5:00, Mani Tofigh via B4 Relay wrote:
> From: Mani Tofigh <mt4022@columbia.edu>
>
> If hugetlb_update_hwpoison() fails to allocate a raw_hwp_page, the folio
> is marked raw_hwp_unreliable and __update_and_free_hugetlb_folio() leaks
> it intentionally. With hugetlb_free_vmemmap=on, it's leaked before the
> hugetlb flag is cleared, since commit 32c877191e02 ("hugetlb: do not
> clear hugetlb dtor until allocating vmemmap") doesn't remove the flag
> until the vmemmap is restored. The leaked folio is then a hugetlb folio
> with refcount 0 and on no list (the same state as a hugetlb folio that
> is being freed), but nothing is freeing it, and
> dissolve_free_hugetlb_folio() keeps retrying on it. Offlining its
> memory block then never completes, even on SIGKILL, and other tasks
> block on the memory hotplug lock:
>
> [ 3.271255] Memory failure: 0x20007: recovery action for free huge page: Failed
> [ 41.729695] INFO: task hugeoffline:77 blocked for more than 20 seconds.
> ...
> [ 41.733014] get_online_mems+0xc1/0xd0
> [ 41.733026] soft_offline_page+0xfd/0x9b0
>
> alloc_and_dissolve_hugetlb_folio() loops on it the same way. The
> refcount is 0 since commit bd225530a4c7 ("mm/hugetlb_vmemmap: fix race
> with speculative PFN walkers"). Before that these paths failed with
> -EBUSY.
>
> Check raw_hwp_unreliable after the hugetlb flag is cleared so that the
> folio is leaked as a non-hugetlb folio, as without vmemmap
> optimization. unpoison_memory() keeps refusing to unpoison it. With
> the fix, offlining retries as it does for any page it can't isolate,
> and stops on a signal.
>
> Fixes: 32c877191e02 ("hugetlb: do not clear hugetlb dtor until allocating vmemmap")
> Fixes: bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative PFN walkers")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Thanks.
.
^ permalink raw reply [flat|nested] 10+ messages in thread* + mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch added to mm-new branch
2026-11-03 21:00 ` [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
2026-11-19 6:40 ` Miaohe Lin
@ 2026-11-19 7:07 ` Andrew Morton
1 sibling, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2026-11-19 7:07 UTC (permalink / raw)
To: mm-commits, ziy, yuzhao, willy, tz2294, stable, rppt, osalvador,
nao.horiguchi, muchun.song, mike.kravetz, linmiaohe, kaitao.cheng,
jane.chu, david, mt4022, akpm
The patch titled
Subject: mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio
has been added to the -mm mm-new branch. Its filename is
mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Mani Tofigh <mt4022@columbia.edu>
Subject: mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio
Date: Tue, 03 Nov 2026 16:00:50 -0500
If hugetlb_update_hwpoison() fails to allocate a raw_hwp_page, the folio
is marked raw_hwp_unreliable and __update_and_free_hugetlb_folio() leaks
it intentionally. With hugetlb_free_vmemmap=on, it's leaked before the
hugetlb flag is cleared, since commit 32c877191e02 ("hugetlb: do not
clear hugetlb dtor until allocating vmemmap") doesn't remove the flag
until the vmemmap is restored. The leaked folio is then a hugetlb folio
with refcount 0 and on no list (the same state as a hugetlb folio that
is being freed), but nothing is freeing it, and
dissolve_free_hugetlb_folio() keeps retrying on it. Offlining its
memory block then never completes, even on SIGKILL, and other tasks
block on the memory hotplug lock:
[ 3.271255] Memory failure: 0x20007: recovery action for free huge page: Failed
[ 41.729695] INFO: task hugeoffline:77 blocked for more than 20 seconds.
...
[ 41.733014] get_online_mems+0xc1/0xd0
[ 41.733026] soft_offline_page+0xfd/0x9b0
alloc_and_dissolve_hugetlb_folio() loops on it the same way. The
refcount is 0 since commit bd225530a4c7 ("mm/hugetlb_vmemmap: fix race
with speculative PFN walkers"). Before that these paths failed with
-EBUSY.
Check raw_hwp_unreliable after the hugetlb flag is cleared so that the
folio is leaked as a non-hugetlb folio, as without vmemmap
optimization. unpoison_memory() keeps refusing to unpoison it. With
the fix, offlining retries as it does for any page it can't isolate,
and stops on a signal.
Link: https://patch.msgid.link/20261103-hugetlb-hwpoison-leak-v2-2-98085750c145@columbia.edu
Fixes: 32c877191e02 ("hugetlb: do not clear hugetlb dtor until allocating vmemmap")
Fixes: bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative PFN walkers")
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Jane Chu <jane.chu@oracle.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Kaitao Cheng <kaitao.cheng@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Tal Zussman <tz2294@columbia.edu>
Cc: <stable@vger.kernel.org>
mm/hugetlb.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
--- a/mm/hugetlb.c~mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio
+++ a/mm/hugetlb.c
@@ -1515,13 +1515,6 @@ static void __update_and_free_hugetlb_fo
}
/*
- * If we don't know which subpages are hwpoisoned, we can't free
- * the hugepage, so it's leaked intentionally.
- */
- if (folio_test_hugetlb_raw_hwp_unreliable(folio))
- return;
-
- /*
* If folio is not vmemmap optimized (!clear_flag), then the folio
* is no longer identified as a hugetlb page. hugetlb_vmemmap_restore_folio
* can only be passed hugetlb pages and will BUG otherwise.
@@ -1549,6 +1542,14 @@ static void __update_and_free_hugetlb_fo
}
/*
+ * If we don't know which subpages are hwpoisoned, we can't free
+ * the hugepage, so it's leaked intentionally, but only once it is
+ * no longer a hugetlb folio.
+ */
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio))
+ return;
+
+ /*
* Move PageHWPoison flag from head page to the raw error pages,
* which makes any healthy subpages reusable.
*/
_
Patches currently in -mm which might be from mt4022@columbia.edu are
mm-swapfile-drop-a-large-unmapped-swap-in-folio-in-unuse_pte.patch
mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio.patch
mm-hugetlb-clear-the-hugetlb-flag-before-leaking-a-hwpoisoned-folio.patch
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio
2026-11-03 21:00 [PATCH v2 0/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
2026-11-03 21:00 ` [PATCH v2 1/2] mm/memory-failure: don't unpoison a leaked raw_hwp_unreliable folio Mani Tofigh via B4 Relay
2026-11-03 21:00 ` [PATCH v2 2/2] mm/hugetlb: clear the hugetlb flag before leaking a hwpoisoned folio Mani Tofigh via B4 Relay
@ 2026-11-19 7:06 ` Andrew Morton
2 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2026-11-19 7:06 UTC (permalink / raw)
To: Mani Tofigh
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Miaohe Lin,
Naoya Horiguchi, Matthew Wilcox, Jane Chu, Zi Yan, Kaitao Cheng,
Mike Rapoport, Mike Kravetz, Yu Zhao, linux-mm, linux-kernel,
tz2294, stable
On Tue, 03 Nov 2026 16:00:48 -0500 Mani Tofigh <mt4022@columbia.edu> wrote:
> If memory_failure() can't save the raw error page of a hugetlb folio,
> the folio is marked raw_hwp_unreliable and leaked once it's freed. With
> hugetlb_free_vmemmap=on it's leaked while it's still a hugetlb folio,
> and dissolving it then loops forever, e.g., when offlining its memory
> block. Patch 2 leaks it only after the hugetlb flag is cleared, as
> without vmemmap optimization.
>
> Miaohe pointed out that unpoison_memory() then doesn't see a hugetlb
> folio anymore and unpoisons it. That already happens without vmemmap
> optimization, so patch 1 fixes it on its own and goes first.
>
> Patch 2 lets a raw_hwp_unreliable folio reach the add_hugetlb_folio()
> rollback when restoring its vmemmap fails, as
> dissolve_free_hugetlb_folio() already does. It relies on Kaitao's
> "mm/hugetlb: preserve persistent flags when returning folios to the
> pool" [1] (in mm-new) to keep the flag there.
Problem. [1] doesn't have cc:stable whereas your patches do. So we're
sending -stable people something which won't work.
I don't know if there's a way of expressing such a dependency for the
-stable machinery but fortunately [1] is still in development mode (ie,
in mm-unstable), so I can add a cc:stable to that along with an
explanatory note.
And I agree that these two patches are -stable material, especially
[2/2]. Having an offlining attempt lock up until reboot is not our
preferred user experience ;)
^ permalink raw reply [flat|nested] 10+ messages in thread