From patchwork Fri Dec 9 07:28:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13069335 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 711DEC4332F for ; Fri, 9 Dec 2022 07:12:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01E4C8E0003; Fri, 9 Dec 2022 02:12:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F10EC8E0001; Fri, 9 Dec 2022 02:12:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E00668E0003; Fri, 9 Dec 2022 02:12:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D04258E0001 for ; Fri, 9 Dec 2022 02:12:20 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A398F810A2 for ; Fri, 9 Dec 2022 07:12:20 +0000 (UTC) X-FDA: 80221899240.29.416553A Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf02.hostedemail.com (Postfix) with ESMTP id 73DDE80005 for ; Fri, 9 Dec 2022 07:12:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670569939; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XgPLd+iHHlrs52USbNQltXdZaLcuZOcleqibYghZXIw=; b=1pt29Cg4WSQOu5o1B0x7buFVo2Jh7LqtiJCTDGjflEPtriEbK8d9OuOObH2R1podSXrpVh /poRU05pSlGOKQDebdvvN170LoMbNzHQhouWU0jqWfLEjCceaWV1+mZfZyYIPtTFE9rQLa vTJoJME5AqD0vxcf8LEtX1PUge0ZbV4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670569939; a=rsa-sha256; cv=none; b=HVli6LxY7u57gxikxwRSubTLi7vX69jqnnVs7QXgayKCDDESnM86p5nDzaLtqSfrB7PL8/ NSo/LFjF8YruFCC6HUUS+5EJW6umqH9nYIwHt3fnKuvy7x0aHfs7VkdEKYT/GIzCK4054i I+Hl/UYVx8PnaZY8AGt4ZU2YdSyK5Ic= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NT2Dm2Lm1zJpCN; Fri, 9 Dec 2022 15:08:40 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 9 Dec 2022 15:11:38 +0800 From: Kefeng Wang To: , , CC: , , , Kefeng Wang Subject: [PATCH -next v2] mm: hwposion: support recovery from ksm_might_need_to_copy() Date: Fri, 9 Dec 2022 15:28:01 +0800 Message-ID: <20221209072801.193221-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221209021525.196276-1-wangkefeng.wang@huawei.com> References: <20221209021525.196276-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 73DDE80005 X-Rspam-User: X-Stat-Signature: 6ebtuprjq4wrttihmqz4ajtrek8wactf X-HE-Tag: 1670569937-681151 X-HE-Meta: U2FsdGVkX19XRH+6Xw2du7JLl87gFJhb0MBUTaRzMJ8i09jRbI8augDyC7VqjgBlvbyI0TNYF9G73SwVtdEaz22lZJDzctDwL6wVnULyOIL3iOLWjJ/I31h63X9qseFj5pH8EH4kGnjHSWN8I3n5/d6CkCp05tVfzdLyQo2Bj2eVfwvIALIllpfJ3O2mKzZp+e1yGpllRSkCOyXRLAY7h1KiZg6yVBIFfpXmzkc4s3aF8y1Lq2F/6iHB5T1FoJhCDmcyermtRwwjAZfwKssjgZhAE1I6dtopRskFGgyiA+O/L+jDSn5MJ0FQa+/vF+hWkIBqt0A+PTy9fWGW/yREoUbzxFE8Gdmh+xTlQkoUvjYY3hHjNasx5FFEHODKkzS8azDek8FPx6xpGhdINXpyb8Q+yjAEI4AflMvZYa0Ss6c6tqrDKtlrYeBl6qc++RaXvxtf1FWWqpGU1kvE1/W6ObSbBcT3VWi49iSXn4jkkRAsTpcmRbxnmOOo9LR4UqvOg6+0LTgsYreY8Ukl1idEePNfUExVmrEq1aLvENRkCf1r7kJ8x+EpvUSSomCFh4BmxuNQo5w0GqSvhfdVlSfxMngejRrrkGorYZjGCfY6nkcpfkEgsXElQrGNtgCsXfRx5/3/42b9ru1WhhtxJdJmkt4VBxYpyoB5lgsAWknUSV5miCAoyNWUXAA0T4lMJQi8AlRbKkAKpe3zNnG4hRGEqsOhCRevm61GX719x74j6JrzN06aL8iV6Lk2mUrg7svFHzYmNGy9O3I1JogS/DXsEpiwdyHPLjg0T+Y9MuZ1gDIA15ONGrtPIYrAfU+v9TtgcWEDUMoaQbFWSXsZPQTIPZ2NFIeTTemDR/bGs00PfHQE1aK7RyX1DnVBXVJbaEP8xPBBFg9jJTYnRdGkMzuTcr6RonZGZQ1l X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When the kernel copy a page from ksm_might_need_to_copy(), but runs into an uncorrectable error, it will crash since poisoned page is consumed by kernel, this is similar to Copy-on-write poison recovery, When an error is detected during the page copy, return VM_FAULT_HWPOISON, which help us to avoid system crash. Note, memory failure on a KSM page will be skipped, but still call memory_failure_queue() to be consistent with general memory failure process. Signed-off-by: Kefeng Wang --- v2: fix type error mm/ksm.c | 8 ++++++-- mm/memory.c | 3 +++ mm/swapfile.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index dd02780c387f..83e2f74ae7da 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2629,8 +2629,12 @@ struct page *ksm_might_need_to_copy(struct page *page, new_page = NULL; } if (new_page) { - copy_user_highpage(new_page, page, address, vma); - + if (copy_mc_user_highpage(new_page, page, address, vma)) { + put_page(new_page); + new_page = ERR_PTR(-EHWPOISON); + memory_failure_queue(page_to_pfn(page), 0); + return new_page; + } SetPageDirty(new_page); __SetPageUptodate(new_page); __SetPageLocked(new_page); diff --git a/mm/memory.c b/mm/memory.c index aad226daf41b..5b2c137dfb2a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3840,6 +3840,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (unlikely(!page)) { ret = VM_FAULT_OOM; goto out_page; + } else if (unlikely(PTR_ERR(page) == -EHWPOISON)) { + ret = VM_FAULT_HWPOISON; + goto out_page; } folio = page_folio(page); diff --git a/mm/swapfile.c b/mm/swapfile.c index 908a529bca12..d479811bc311 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1767,7 +1767,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, swapcache = page; page = ksm_might_need_to_copy(page, vma, addr); - if (unlikely(!page)) + if (IS_ERR_OR_NULL(page)) return -ENOMEM; pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);