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+bhOGpcVcB8ilTMNX+FTpd5wInHveyDFMBdoxv7bLp8dXO4fJHZyr6ogPfaazaL7lVhHx4Xi4FnuzQ+4fQUL53IgtAuI+qmmD/APdIoCpZvsMa7s7aU85VZtDne4b7gmkDqKw/qUB+opZl+xKOmAWBmWRDGSLNe/ZNCb+IG+pqh+3CHbbA3KiFYPW7sdeNPzuUEu5FGztHTCnqNhUMAaj4D4VR93Ez6hRX7pFDRz6xSu93p2YYxLl2AQmxU5JAaSGvLkYloi9EaYFn8NLeLJc9KeJUCwlkfV2DI26IJddEo7BLrghkstDZUvU1ZiYep5TnAvqzoq43b1GW/YneARw9QyJFcDB4qB6srmo8xwWsbdlg3CyqJm/L90cybyYd/zRicKTfwUNKLpimwfEhlv65d3y8wTlxz5hlWxarq8q+f0l7DPw9yB6goAuZthZJHY1B1aUwEMtQHGAgH98zJIqyXj7bOJvqon5xIO8IdOiNp+JSFlwurOZFiWbhtoM1FjM9y1j+mWFNzM5p5CqpH3Z5NEhZ3CTf6a5Ox61PbkrlxHmv6BbwSXVUBULStvanA/JF3h+wniNQrZiHQ833r/34ww9wV24nWHC80EKroWjcW9bPqSYu4IrzWUVr0imBJvL+HMc7bdG63z2fg+EgYDAamrlYtx8JeOG6CGVjGXkUs4s/Zgorm/kqgSHLyrMSfqO4eKELnKr1Kk/7a58TyYS4I0QgHOEyrAZRTn6bShvavwxtAHmifiOpjH8FFVlh9av+7HFZkCyAX48a6xIZrs9iDCuThzoKHVhZkfhHkleWht/DpMO/UDsZr39f1ytSuMKa06zfLD0VPYQWOZZpy4RrHJsq WDJg65ow HpyV13aZRmBC5ED1IaHf4ZN7nm/gVFBQjYbh6zznuuLBX9y6/AVt829EXLwQNPWf+/N6Q8JRog7DNoBg4qzhzEMOAew9dTeH4Oa8/fJAIRr5tCm+I812Dx8kM+4aJcyeqn9ueQgSNna/kd5/wO0J1CZ8kvn1D6wNsdm4WCzxyJqIrkQhknfrfdJklBA/Pi24HFCUWgKjU4Ew3+BkQwxcSZEpEiLMPo0a9J+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);