From patchwork Fri Dec 9 02:15:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13069155 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 AD2C3C4332F for ; Fri, 9 Dec 2022 01:58:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A2318E0005; Thu, 8 Dec 2022 20:58:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 352738E0001; Thu, 8 Dec 2022 20:58:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 240D38E0005; Thu, 8 Dec 2022 20:58:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 142C48E0001 for ; Thu, 8 Dec 2022 20:58:43 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E922C12085C for ; Fri, 9 Dec 2022 01:58:42 +0000 (UTC) X-FDA: 80221108884.30.4277831 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf16.hostedemail.com (Postfix) with ESMTP id B4B8618000E for ; Fri, 9 Dec 2022 01:58:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1670551121; 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: references; bh=wRn8+K1jmHpHnjnGO5QxMycdKELXRREIJsOUZlU+X+Y=; b=QpZR84Hk8HZGQC0SuG6qL5D3tQ45WiT/2QI7klV9iqfGa1QL9KAorC4aVpU9R84PB0qraC c9EKhBaSyBbMj15uyylxnTPDYKZUQMU8DffgTdxYFh+LdiP1TkIBtro1n2wCRT74scenYc r/GUZLRsF/VQ70pVoLakcplV/IEcSd8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670551121; a=rsa-sha256; cv=none; b=EB4Tzeg1lkND4f9hEIUdedajxYvsMSW4e5vZlquhRpuEwYUbOlh2bPUTM3zCfLpL5Al/hR j/iII0wZFKVJ262SjQUdHP1+KC8xJPyiEMlLjNiQjxpwXHnkRaYoM+rlvSJdK14xzdgmhC AP5Xn74pAlLS4unMA2H+KpXc6dREZJY= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NSvL2591vzJqNd; Fri, 9 Dec 2022 09:57:46 +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 09:58:36 +0800 From: Kefeng Wang To: , , CC: , , , Kefeng Wang Subject: [PATCH -next resend] mm: hwposion: support recovery from ksm_might_need_to_copy() Date: Fri, 9 Dec 2022 10:15:25 +0800 Message-ID: <20221209021525.196276-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B4B8618000E X-Rspam-User: X-Stat-Signature: ypdmobfwuindt7mmdfukq6omdhrqxza6 X-HE-Tag: 1670551120-233556 X-HE-Meta: U2FsdGVkX1/Zvs7dX4MrgxxxXlhz8FC5pOIQ+uxxJXg8BQqlWiOO/LT9y+eXbgeGyZnpxfOpzXBYf49rrg1MFu3y8kUX43oGe22dZMDtaXoLhE0MsW+hnYLjdLaPlrj83kTC1l7YPXOq67TLxyqv03kL+D5IM4kvu7DsuQ1YLksP1lZdjQTN9fEJhqQ4IuMvW7HM8gv8D15yOhRfd6ecYmemlPb9Bvb60B8e5kgA41VS01o4QJRicgUUVNqGcVa2xW2NynBQC6/2esRPykx6siQKpIPMsDdIW4LX9jz0m27qZ5XHOoHLuiPpDU5/iaw3YmoNXPQ+bqVDIxS4kv5mRdls4LRZVoKTZr3XzZGXlOGsEWxWz/SLEzDN8AIt1PNcMPXHjiyHnzJ+jYUObQ4jtLVALniHR241RQZdXwEsYuvesbv66wQRh+rmb8IgQb2QkqVvtvLEl9tTG5fgNqxmyjggtoAjk1SkupFkLYoJgZKQiyGjg/m2m0PqrhkeBtbeZnLqciAdTc9nCbqDmkVIlG9HHlBSJXdDgav0/Mc2yd535/SzKRzSLq+EZGEjmlKBwqQFCLpnfndBBjnnwV0Pui8C2rUXBiXATwidJVm0ShlOSO7ZO9u+D06/FvTK1Yqa/jKd6T46HClBIUiMZaf8typLRTHngB8Ug2XMKHDeYDVVTRDj+nNsJsGfTMezpvlrWXxDo4dADrcX+00qsIFTorJDz/oSzyoGZl5hXIY0/47s5Bnpajt7ahbmd+eK3eaykw+2hnbOWolYFE0pNvP0Myz8YCWl3mOBr+hkAie8pTIuwreWenXMBHkR+/+KaXqYCJW2jRB7mNF6JRqC8s3fSlHaruaU8jStGuz4Y9RLSxq13EsJVeKfuUWt95f/tBXLMeOoojAgagS2HP+zCrw6SU6izbpPNr0b 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 --- 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..8711488f5305 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; + } els 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);