migrate: Skip hwpoisoned hugetlb folios during migration
Subsystems (2)
PATCH 1/1 migrate: Skip hwpoisoned hugetlb folios during migration
From: Kaitao Cheng <[email protected]>
Hugetlb migration does not check whether the source folio contains hwpoisoned memory before trying to move it. After the folio is unmapped, the move path can reach hugetlbfs_migrate_folio() and then migrate_huge_page_move_mapping(), which copies the source folio into the new folio.
That copy uses folio_mc_copy(), so architectures with recoverable machine-check copy support can fail the copy with -EHWPOISON. However, there is no reason to attempt the move once the source folio is already known to contain poisoned memory. Architectures without such copy_mc support also fall back to a normal copy, which can consume the poison.
Check folio_contain_hwpoisoned_page() after locking the source hugetlb folio and fail the migration with -EHWPOISON before unmapping or copying it. This covers both a hwpoisoned hugetlb head folio and large folios that only have the has_hwpoisoned summary flag set.
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/migrate.c +5 -0
@@ -1510,6 +1510,11 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, goto out_unlock; } +if (unlikely (folio_contain_hwpoisoned_page (src))) { + rc = -EHWPOISON ; + goto out_unlock; + } +if (folio_test_anon (src)) anon_vma =folio_get_anon_vma (src);
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 12 lines · On Wed, 1 Jul 2026 18:55:44 +0800 Kaitao Cheng <[email protected]> wrote:
Hugetlb migration does not check whether the source folio contains hwpoisoned memory before trying to move it. After the folio is unmapped, the move path can reach
hugetlbfs_migrate_folio()and thenmigrate_huge_page_move_mapping(), which copies the source folio into the new folio.That copy uses
folio_mc_copy(), so architectures with recoverable machine-check copy support can fail the copy with-EHWPOISON. However, there is no reason to attempt the move once the source folio is already known to contain poisoned memory. Architectures without suchcopy_mcsupport also fall back to a normal copy, which can consume the poison.
Quoted 4 lines
Check
folio_contain_hwpoisoned_page()after locking the source hugetlb folio and fail the migration with-EHWPOISONbefore unmapping or copying it. This covers both a hwpoisoned hugetlb head folio and large folios that only have thehas_hwpoisonedsummary flag set.
Thanks. I'll await reviewer input on this.
AI review suggests that a couple of other places may have the same issue:
https://sashiko.dev/#/patchset/[email protected]
Andrew Morton
maintainerQuoted 1 line · On Wed, 1 Jul 2026 18:55:44 +0800 Kaitao Cheng <[email protected]> wrote:
Date: Wed, 1 Jul 2026 18:55:44 +0800
Well.
Quoted 12 lines
Hugetlb migration does not check whether the source folio contains hwpoisoned memory before trying to move it. After the folio is unmapped, the move path can reach
hugetlbfs_migrate_folio()and thenmigrate_huge_page_move_mapping(), which copies the source folio into the new folio.That copy uses
folio_mc_copy(), so architectures with recoverable machine-check copy support can fail the copy with-EHWPOISON. However, there is no reason to attempt the move once the source folio is already known to contain poisoned memory. Architectures without suchcopy_mcsupport also fall back to a normal copy, which can consume the poison.
Quoted 4 lines
Check
folio_contain_hwpoisoned_page()after locking the source hugetlb folio and fail the migration with-EHWPOISONbefore unmapping or copying it. This covers both a hwpoisoned hugetlb head folio and large folios that only have thehas_hwpoisonedsummary flag set.
As always: please provide a description of the userspace-visible runtime effects of the bug.
Even better if you can present a reproducer.
Quoted 1 line
Fixes 290408d4a250 ("hugetlb: hugepage migration core")
Oct, 2010. So I'm assuming this isn't super-urgent.
otoh, now it's out there and known about, perhaps Bad Guys can find a way of triggering this, so the urgency becomes higher.
Anyway, please consider the Sashiko report
(https://sashiko.dev/#/patchset/[email protected])
then update the changelog with the above info. Decide whether we should cc:stable (and describe why) then resend?
Thanks.
Quoted 26 lines · Andrew Morton
Quoted 1 line · On Wed, 1 Jul 2026 18:55:44 +0800 Kaitao Cheng <[email protected]> wrote:
Date: Wed, 1 Jul 2026 18:55:44 +0800
Well.
Quoted 12 lines
Hugetlb migration does not check whether the source folio contains hwpoisoned memory before trying to move it. After the folio is unmapped, the move path can reach
hugetlbfs_migrate_folio()and thenmigrate_huge_page_move_mapping(), which copies the source folio into the new folio.That copy uses
folio_mc_copy(), so architectures with recoverable machine-check copy support can fail the copy with-EHWPOISON. However, there is no reason to attempt the move once the source folio is already known to contain poisoned memory. Architectures without suchcopy_mcsupport also fall back to a normal copy, which can consume the poison.Quoted 4 lines
Check
folio_contain_hwpoisoned_page()after locking the source hugetlb folio and fail the migration with-EHWPOISONbefore unmapping or copying it. This covers both a hwpoisoned hugetlb head folio and large folios that only have thehas_hwpoisonedsummary flag set.As always: please provide a description of the userspace-visible runtime effects of the bug.
Quoted 8 lines
Even better if you can present a reproducer.
Quoted 1 line
Fixes 290408d4a250 ("hugetlb: hugepage migration core")Oct, 2010. So I'm assuming this isn't super-urgent.
otoh, now it's out there and known about, perhaps Bad Guys can find a way of triggering this, so the urgency becomes higher.
In the subsequent discussion of the v2 patch, it became clear that the current fix can only narrow the race window and cannot fully resolve the issue. I do not currently have a complete solution in mind, so this issue is blocked for now.
v2: https://lore.kernel.org/all/[email protected]/#t
Quoted 6 lines
Anyway, please consider the Sashiko report
(https://sashiko.dev/#/patchset/[email protected])
then update the changelog with the above info. Decide whether we should cc:stable (and describe why) then resend?Thanks.
Signature · 2 lines
Thanks Kaitao Cheng