From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AC7938F22D for ; Tue, 7 Jul 2026 09:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783414964; cv=none; b=ZIjbzGa1GxqDFXe5xfzMnL+wSp0G19XzN11253HhsfTdqAF1zgOtWDWTKKlPz8wgSf5K4CfaUQgAmYnaWJS7iLGKASV7oV36Bztt/0cO6pr2moaLCoyo2EkIhC1LUxjlC/HdaDlXiixvheKmLNPj6n/RRUR2nEZbTnZqZLiuOwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783414964; c=relaxed/simple; bh=4thpqO2evPjrSSvtLalQRBqs4t35lAEA8Dt1PJYI0hM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=gXI34H5RBmK1wNBU+TuGPIQcp5IYIF+KS+JLMAy7Y2NoJQ/aPNsw7yuGu8kE9HgXO+xgX5Lg85rZ7sSsEr4zAsXuWsSTbD4jrs925UxBA8b62750Q6mrHmLRiweMnvElslUFNVr87k4e6tRvEA+61ElWzfOdZOFEv7OM/Oc0gYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=mQnCMUt9; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="mQnCMUt9" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783414959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Rx789viijXUmM3OKxnbqk3KcKhRqEoHeN7taWskeA2M=; b=mQnCMUt9hyZ7sE7pI1SC7pOHR7oinKvwkCqrkqNzKHrV9ykAL+pz3kXLPIbrnNZSbOcj9w L8d4qWdeTSKSCtsVd91QVqkRMlXT9wtn6J5M+FZYHf08GlghKXnWrIksih7RNkB4d7JKC2 8zRI/3lSXs4oFTSTPiZmbYt85TBy+Vw= From: Kaitao Cheng 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@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng Subject: [PATCH v2] mm/migrate: Avoid copying hwpoisoned folios during migration Date: Tue, 7 Jul 2026 17:01:36 +0800 Message-ID: <20260707090136.52904-1-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Kaitao Cheng 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 --- 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)