Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/migrate: Avoid copying hwpoisoned folios during migration
@ 2026-07-07  9:01 Kaitao Cheng
  2026-07-07 10:08 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 3+ messages in thread
From: Kaitao Cheng @ 2026-07-07  9:01 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Zi Yan, Matthew Brost,
	Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang,
	Alistair Popple
  Cc: Naoya Horiguchi, Andi Kleen, Muchun Song, linux-mm, linux-kernel,
	Kaitao Cheng

From: Kaitao Cheng <chengkaitao@kylinos.cn>

The generic folio migration path can copy the source folio after it has
been unmapped.  For normal and THP folios this goes through
move_to_new_folio(), then the filesystem or anonymous migration callback,
and commonly reaches folio_mc_copy().

folio_mc_copy() uses copy_mc_highpage(), but architectures without
copy_mc_to_kernel support fall back to copy_highpage().  If the source
folio already contains a hwpoisoned page, a normal copy can consume the
poisoned memory and trigger a synchronous machine check.

Check whether the source folio contains a hwpoisoned page in
move_to_new_folio(), before invoking any migration callback that may copy
from it.  Return -EHWPOISON so the folio is treated as a permanent
migration failure instead of being copied or retried as a transient
failure.

Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
---
Changes in v2:
- Move the hwpoison check from the hugetlb-specific migration path to
  move_to_new_folio(), so the normal and THP migration paths are covered.

Link to v1:
https://lore.kernel.org/all/20260701105544.97059-1-kaitao.cheng@linux.dev/
---
 mm/migrate.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/migrate.c b/mm/migrate.c
index 7301e424f8d8..f4f55a6fc23c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1098,6 +1098,9 @@ static int move_to_new_folio(struct folio *dst, struct folio *src,
 	VM_BUG_ON_FOLIO(!folio_test_locked(src), src);
 	VM_BUG_ON_FOLIO(!folio_test_locked(dst), dst);
 
+	if (unlikely(folio_contain_hwpoisoned_page(src)))
+		return -EHWPOISON;
+
 	if (!mapping)
 		rc = migrate_folio(mapping, dst, src, mode);
 	else if (mapping_inaccessible(mapping))
-- 
2.50.1 (Apple Git-155)



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-07 11:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07  9:01 [PATCH v2] mm/migrate: Avoid copying hwpoisoned folios during migration Kaitao Cheng
2026-07-07 10:08 ` David Hildenbrand (Arm)
2026-07-07 11:08   ` Huang, Ying

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox