From patchwork Fri Sep 6 02:42:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13793156 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 F1290CE7AA5 for ; Fri, 6 Sep 2024 02:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84A9E6B0089; Thu, 5 Sep 2024 22:42:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7818C6B0092; Thu, 5 Sep 2024 22:42:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DC6A6B008A; Thu, 5 Sep 2024 22:42:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 171516B0089 for ; Thu, 5 Sep 2024 22:42:39 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BA6051A0D20 for ; Fri, 6 Sep 2024 02:42:38 +0000 (UTC) X-FDA: 82532765196.06.C55C5EE Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf18.hostedemail.com (Postfix) with ESMTP id 6827F1C0010 for ; Fri, 6 Sep 2024 02:42:36 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.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=1725590448; 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=PvT9d86Vd5m/uEFHN1TquoaZCkBXKwi3oHPofFcobQ4=; b=kRKZJTc0qtdxRWv4FU8BQ+lr8FVeZAAywv+rMDNFN15BRMJ8E0ZQrsoR/Fn5SG54W3mtpE 63C7USR7/cDGNgxSvQl1JWPmwLZQyGQOptGoHl96oCMWnv5Lv7oH5key2FAdfm+mlVUCjE 46UKgiMyTSZqx06n3cA3YRjn9nNcZeI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725590448; a=rsa-sha256; cv=none; b=lxhDBJxowXPONHiY8nw0GSznXd6wUtBQNlvRcmUjUnZSsrIC+pPxMnVZlQeosoUeQdoOyl U7jT8rTgRNH9/KL3ZwXR4U710usrS0VzRlR3y6DpQFgbk9ZAwK7lyjh7UfMP3i5OiAAfgv jTMW0V16Gy1v/hyf/BxfSboio77rxs0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4X0L7S1b65zpVTs; Fri, 6 Sep 2024 10:40:36 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 660E41400D8; Fri, 6 Sep 2024 10:42:31 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 6 Sep 2024 10:42:30 +0800 From: Kefeng Wang To: Andrew Morton CC: , Jane Chu , Miaohe Lin , Naoya Horiguchi , Tony Luck , Jiaqi Yan , David Hildenbrand , Kefeng Wang Subject: [PATCH 1/2] mm: support poison recovery from do_cow_fault() Date: Fri, 6 Sep 2024 10:42:00 +0800 Message-ID: <20240906024201.1214712-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240906024201.1214712-1-wangkefeng.wang@huawei.com> References: <20240906024201.1214712-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6827F1C0010 X-Stat-Signature: dmz3igrq5gb1e3kj8pj6bxpr9uqyguu1 X-Rspam-User: X-HE-Tag: 1725590556-745344 X-HE-Meta: U2FsdGVkX1+E3eS1jZ/vkcGiOWoH3OpHKPaW5F5s91ZURYYKwtb9H9OIqh92YeqeDsXo9oU5mASO0Hf2N54rx7owiZf727cjQt0IAKQZl2+4Y4IxIf7KJ/fwC/RWjkNVqim7yKURS5Vb75rFlEVIckph18f3gxEnLvzp/WqzvUUOcoQ/ndzIW57joyXWkiiodyLNs22cG4xgNalFxNHZmVbIP78b30ZhMpKGj3mksdsGNtjHms91VtIe3qQa4aU4dnW/mP0KDcUe1eRGh8LNg3scS8oakie3w7rc5q/NsOGb7FNnSLkIN4FO+tYO1Q9iJo0/RijeXwe+n9Et2ryOJ9T/+1EMzxfExZP424/04Ee0NGNRUYnOsIt9qJJMrZIzMozLqGwGNNUD6Xsx4swrnD9tQzl0vhd+Y1Po6iGE5Z13NdrDgM+jXteKotv6Mxi/Iyr+GdKDrSsI4dP9JR2UyV8F70++O5Od6s55gi8szsnVPlSLMLk8mh2qM682knqEAQU8t1Oj1TzKDU37MgMqZNg1oK/h1hNCZzDJQ5nuj2a9CkQpBVxsXBQF51xqe7SC/gTf4C46rXCqI9ieijotqePX5+YPwQuoe6eK2xI2ebfOy2Iqh/op+xinoalH1PV9Fe8+Nqoi202DKrxz3aG9ugvoLXydAGqIvJaus2cNuvJbRofvX22goCwWgWDcIPepDeLGP8XZlvAYE1TmS3uzjxwobxX5HiojxHs1yWnIEeZI0pLn0u7VzJmLoNlseRYuJ6O8km75xK7U1I96vxttfXWBLIFoP5pzUt4imIIhxvpGua78lwWlYTPzPFIzILPIXnZXtsp0w+7lJAj/bMNchbHcsZx5q5LDLU8YvSPTi2n/49BAARJNJCRNHHlXlFAKnmUQxYdsprIkgLS+7fHKgCs9FFvBlkL9GH/qF1ZKCwm8CTpyZJY3jycuLInN0P2NnJhLge4PyOYjmFxs+dL 1xeaWa/j CjV/jOPU9MqtVFwX2f37nNPKPVASXYVOxI0yibk3RnwAL97fNfDozS2iPR0WvHb18HfliLzShd3lpS8Ise6RDKT2wY2bkbsNV0TG4J4fLpDy0fu5DDrO8RluVFs+miBLszhC6opxORCdHqVn+enaJzcGdB7wtDai/T6+Sroz5+OceoxZ5ib24of2UjA7I+X5abBs0inlHIaXAZFjUfWubgr52Uz0YNOUR0+mxGn+FRcAHegKskIaCfeadl7oI/Gg8nc4L54l+Cj+6bSU= 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: List-Subscribe: List-Unsubscribe: Like commit a873dfe1032a ("mm, hwpoison: try to recover from copy-on write faults"), there is another path which could crash because it does not have recovery code where poison is consumed by the kernel in do_cow_fault(), a crash calltrace shown below on old kernel, but it could be happened in the lastest mainline code, CPU: 7 PID: 3248 Comm: mpi Kdump: loaded Tainted: G OE 5.10.0 #1 pc : copy_page+0xc/0xbc lr : copy_user_highpage+0x50/0x9c Call trace: copy_page+0xc/0xbc do_cow_fault+0x118/0x2bc do_fault+0x40/0x1a4 handle_pte_fault+0x154/0x230 __handle_mm_fault+0x1a8/0x38c handle_mm_fault+0xf0/0x250 do_page_fault+0x184/0x454 do_translation_fault+0xac/0xd4 do_mem_abort+0x44/0xbc Fix it by using copy_mc_user_highpage() to handle this case and return VM_FAULT_HWPOISON for cow fault. Signed-off-by: Kefeng Wang Reviewed-by: Jane Chu --- mm/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 42674c0748cb..d310c073a1b3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5089,7 +5089,10 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) if (ret & VM_FAULT_DONE_COW) return ret; - copy_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma); + if (copy_mc_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma)) { + ret = VM_FAULT_HWPOISON; + goto uncharge_out; + } __folio_mark_uptodate(folio); ret |= finish_fault(vmf); From patchwork Fri Sep 6 02:42:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13793154 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 DB9DACE7AA5 for ; Fri, 6 Sep 2024 02:42:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 737276B0085; Thu, 5 Sep 2024 22:42:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E6CB6B0088; Thu, 5 Sep 2024 22:42:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AE796B0089; Thu, 5 Sep 2024 22:42:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3D6EC6B0085 for ; Thu, 5 Sep 2024 22:42:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B65BF1405B6 for ; Fri, 6 Sep 2024 02:42:37 +0000 (UTC) X-FDA: 82532765154.08.FDBF034 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf07.hostedemail.com (Postfix) with ESMTP id 7511C40006 for ; Fri, 6 Sep 2024 02:42:35 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725590476; a=rsa-sha256; cv=none; b=fxHz6RiYZUzUDa7tCi/QkbMHHMfdL6VBVSMlnoZYfmnGXTpBnHXxSmE4J6vqbFS9/BCUfH 5uj+64+hUJ+uMfmKHnMtGyjSHsd2B4g122Ly/XMZFszRAmu0AldEZ6Ofaa4yVlJ8GKzqJI PoD7YYd713IedPOe8mX2i717wYJnqEM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 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=1725590476; 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=5OwamKPPxtFU1w3aPQQQRg7zEudLZEYUlH4GS4xSNM0=; b=3Zbc2XHKHZF/JRFglncsiVfFGkRLVFdOHW06asyTj/WZIAorUDD6cejPl3nEwrbL3jXwsk PA0F1DN+VQVbiOgGjJAVF+HkN80KlOZeozrsgZXlnwhOBQuEXEfcLvx1Y++C7MUbTE40HI zcUYSEJmUt53qBKFqItQ5ogha2yqNpQ= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4X0L9D6P1tz1S9sn; Fri, 6 Sep 2024 10:42:08 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id EF8491400DB; Fri, 6 Sep 2024 10:42:31 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 6 Sep 2024 10:42:31 +0800 From: Kefeng Wang To: Andrew Morton CC: , Jane Chu , Miaohe Lin , Naoya Horiguchi , Tony Luck , Jiaqi Yan , David Hildenbrand , Kefeng Wang Subject: [PATCH 2/2] mm: support poison recovery from copy_present_page() Date: Fri, 6 Sep 2024 10:42:01 +0800 Message-ID: <20240906024201.1214712-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240906024201.1214712-1-wangkefeng.wang@huawei.com> References: <20240906024201.1214712-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7511C40006 X-Stat-Signature: 83iaeefd3y3cr99wqhu4m7tyfh7bxrt8 X-Rspam-User: X-HE-Tag: 1725590555-794653 X-HE-Meta: U2FsdGVkX18WC8Ual4eHY0rxUk+HAOzbwC6TGAclczQZGRsq/O8sIqiu7cDtvYHRe+iUu4N1oRAs1VOl9jwEDG7mBzsUv77twkF9Xq6Sy2JieI3Ps/B/Ias/S+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ZEpEiLMPo0a9J+UOxiJGz3V/4ZqaYScL1NepwYFnXAkWPYRw 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: List-Subscribe: List-Unsubscribe: Similar to other poison recovery, use copy_mc_user_highpage() to avoid potentially kernel panic during copy page in copy_present_page() from fork, once copy failed due to hwpoison in source page, we need to break out of copy in copy_pte_range() and release prealloc folio, so copy_mc_user_highpage() is moved ahead before set *prealloc to NULL. Signed-off-by: Kefeng Wang Reviewed-by: Jane Chu Reviewed-by: Miaohe Lin --- mm/memory.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d310c073a1b3..6e7b78e49d1a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -926,8 +926,11 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma * We have a prealloc page, all good! Take it * over and copy the page & arm it. */ + + if (copy_mc_user_highpage(&new_folio->page, page, addr, src_vma)) + return -EHWPOISON; + *prealloc = NULL; - copy_user_highpage(&new_folio->page, page, addr, src_vma); __folio_mark_uptodate(new_folio); folio_add_new_anon_rmap(new_folio, dst_vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(new_folio, dst_vma); @@ -1166,8 +1169,9 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, /* * If we need a pre-allocated page for this pte, drop the * locks, allocate, and try again. + * If copy failed due to hwpoison in source page, break out. */ - if (unlikely(ret == -EAGAIN)) + if (unlikely(ret == -EAGAIN || ret == -EHWPOISON)) break; if (unlikely(prealloc)) { /* @@ -1197,7 +1201,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, goto out; } entry.val = 0; - } else if (ret == -EBUSY) { + } else if (ret == -EBUSY || unlikely(ret == -EHWPOISON)) { goto out; } else if (ret == -EAGAIN) { prealloc = folio_prealloc(src_mm, src_vma, addr, false);