From nobody Mon Feb 9 19:26:53 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A174C04A6A for ; Thu, 27 Jul 2023 11:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbjG0L5B (ORCPT ); Thu, 27 Jul 2023 07:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233573AbjG0L44 (ORCPT ); Thu, 27 Jul 2023 07:56:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B0A2738 for ; Thu, 27 Jul 2023 04:56:52 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBTk351PczrS0M; Thu, 27 Jul 2023 19:55:55 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 19:56:50 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 1/4] mm/swapfile: fix wrong swap entry type for hwpoisoned swapcache page Date: Thu, 27 Jul 2023 19:56:40 +0800 Message-ID: <20230727115643.639741-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230727115643.639741-1-linmiaohe@huawei.com> References: <20230727115643.639741-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Hwpoisoned dirty swap cache page is kept in the swap cache and there's simple interception code in do_swap_page() to catch it. But when trying to swapoff, unuse_pte() will wrongly install a general sense of "future accesses are invalid" swap entry for hwpoisoned swap cache page due to unaware of such type of page. The user will receive SIGBUS signal without expected BUS_MCEERR_AR payload. BTW, typo 'hwposioned' is fixed. Fixes: 6b970599e807 ("mm: hwpoison: support recovery from ksm_might_need_to= _copy()") Signed-off-by: Miaohe Lin --- mm/ksm.c | 2 ++ mm/swapfile.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 97a9627116fa..74804158ee02 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2794,6 +2794,8 @@ struct page *ksm_might_need_to_copy(struct page *page, anon_vma->root =3D=3D vma->anon_vma->root) { return page; /* still no need to copy it */ } + if (PageHWPoison(page)) + return ERR_PTR(-EHWPOISON); if (!PageUptodate(page)) return page; /* let do_swap_page report the error */ =20 diff --git a/mm/swapfile.c b/mm/swapfile.c index e04eb9c0482d..0df94c4000ea 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1744,7 +1744,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_= t *pmd, struct page *swapcache; spinlock_t *ptl; pte_t *pte, new_pte, old_pte; - bool hwposioned =3D false; + bool hwpoisoned =3D PageHWPoison(page); int ret =3D 1; =20 swapcache =3D page; @@ -1752,7 +1752,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_= t *pmd, if (unlikely(!page)) return -ENOMEM; else if (unlikely(PTR_ERR(page) =3D=3D -EHWPOISON)) - hwposioned =3D true; + hwpoisoned =3D true; =20 pte =3D pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); if (unlikely(!pte || !pte_same_as_swp(ptep_get(pte), @@ -1763,11 +1763,11 @@ static int unuse_pte(struct vm_area_struct *vma, pm= d_t *pmd, =20 old_pte =3D ptep_get(pte); =20 - if (unlikely(hwposioned || !PageUptodate(page))) { + if (unlikely(hwpoisoned || !PageUptodate(page))) { swp_entry_t swp_entry; =20 dec_mm_counter(vma->vm_mm, MM_SWAPENTS); - if (hwposioned) { + if (hwpoisoned) { swp_entry =3D make_hwpoison_entry(swapcache); page =3D swapcache; } else { --=20 2.33.0