From: Kaitao Cheng <kaitao.cheng@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>,
Andi Kleen <ak@linux.intel.com>,
Muchun Song <muchun.song@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Kaitao Cheng <chengkaitao@kylinos.cn>
Subject: [PATCH v2] mm/migrate: Avoid copying hwpoisoned folios during migration
Date: Tue, 7 Jul 2026 17:01:36 +0800 [thread overview]
Message-ID: <20260707090136.52904-1-kaitao.cheng@linux.dev> (raw)
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)
next reply other threads:[~2026-07-07 9:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 9:01 Kaitao Cheng [this message]
2026-07-07 10:08 ` [PATCH v2] mm/migrate: Avoid copying hwpoisoned folios during migration David Hildenbrand (Arm)
2026-07-07 11:08 ` Huang, Ying
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260707090136.52904-1-kaitao.cheng@linux.dev \
--to=kaitao.cheng@linux.dev \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=chengkaitao@kylinos.cn \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.brost@intel.com \
--cc=muchun.song@linux.dev \
--cc=nao.horiguchi@gmail.com \
--cc=rakie.kim@sk.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox