From patchwork Mon Jun 3 09:24:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13683599 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 43AC5C27C44 for ; Mon, 3 Jun 2024 10:46:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 273C26B008C; Mon, 3 Jun 2024 06:46:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A0BD6B0095; Mon, 3 Jun 2024 06:46:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E71546B0093; Mon, 3 Jun 2024 06:46:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AC1ED6B008C for ; Mon, 3 Jun 2024 06:46:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 200A612020B for ; Mon, 3 Jun 2024 10:46:06 +0000 (UTC) X-FDA: 82189247532.02.8E1C114 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id EAD40120010; Mon, 3 Jun 2024 10:46:02 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1717411564; 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=AqUP9MQ4jV7RFAow4L055LmogfxoEzGenfLKQ8XAVZA=; b=lIQd/k++uzaY9byyTyIQCqNS+R/7UKHoJvy189CPoEGzfh38CGd44jX9/2a9tRtVVcOuMm 6QtkSliSI/IWZKbcB1z/0i2bVdHrTesLTz/RB0+GUEPU+ZtyPkQlvfXFXqMoYm3XnQc/WO MIzLXJvv1iTn6pOWqk1NrFfnkezlJHM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717411564; a=rsa-sha256; cv=none; b=16bfTaUg1RjgHkDpaTNkyiUnxYjCwCED2QSv0L5EEhmsRoApBeRjmbR+ad0z72QMLLjSpo JCpLFo9x1tAS2+91DzjvS3dVSQFNbIbvRIRpYv1ID3OcPjdYxTSV9tRMzdr/8OnyyyRWIc 9f+ytFaQZBe11LKW0WLLQJrMsphBSnw= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Vt9Jr3wZRzwRKN; Mon, 3 Jun 2024 18:42:04 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 8C6CE140417; Mon, 3 Jun 2024 18:45:58 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 18:45:57 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v4 0/6] mm: migrate: support poison recover from migrate folio Date: Mon, 3 Jun 2024 17:24:33 +0800 Message-ID: <20240603092439.3360652-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EAD40120010 X-Stat-Signature: nsnkjg6w866eda65dm8aero5jck9tum7 X-Rspam-User: X-HE-Tag: 1717411562-922674 X-HE-Meta: U2FsdGVkX192GePzwuXirtdAH86DnIYSALQ9MkIvo15EGNF43PKXw5vbxaXZLdduLrCAj1XMA0JvNIUb52NjptqS5hHyO7vc1PYMO2Z2jzpEWR340fjsV7WxF5AX+RQB4HAygZJqh7CXI68LMOgKIzN2GGjiHRRWDTV9DOkwXps+05LCE6Yk+aXcNemAk7+0cxOsJ5ArMGW/k+/Q42RjKkCwUWsnvyp4G80XCAW+HO/7nWPyXzFP+EddIsVosKpJYFPfAHl1/R9M/cocbbP086rjboBkiyLo+PtZ9ODGtEqbOeWda9JougsYt7LdgYQTJlTwBhQpHjRAgCXPGMzMXavvigpZ5VBAaIE/0WF6FJxEYQWXDIj5q5/PMRSh0U3ETZXYbG+qrx4TDDb2uyUFuFaUFWKnG+PFqqN4dKLgABCs9LTSRvBK2Mhw6i+g39L9DPK4sGqRC9IH5t9EnQOeZ0vS6G0mXIZiDuBZCOWhGwz/mw5vokjstmUu2v7WJuIrMuusxbPU88kmR14zlJP6/yLrYbgvrqYzF8vJk4JvsbewLaf2oukcNHwGj7kvUylLrJGYJfJSYkUE3nAsI1oQlCpAh4Z2L51EJJTSLBlif1I87lWSP7XthR+C5UU4KSBrgoUMxCXmzR4HuQ14up1dA7MVoKI56lhpZJR0WJ/gT6odFp/cM415wM5im3O8eeVBpyDKSs75qyrcyJHdSEb4bnuvVRd7B1wgktcDIeHtpGIW+IIM9QPhcYqy8cE4hxvBCw5HwC1p6lGkXJ6DCkUa8UZ+L4FSnjxcYeLXXHX2oj0hg4dz5oUwL4NHOzDaRcnm26ZAVl4ouBxqyeM5paSHcbfDrPqSnPRc6TOmj5Co05ibiQa3rjv5QVu21/bFMapyeYOtVjzFdtRgFqOIhu826wg2BIQ9RdMsXDwAldX1vhHllpZjf2B1T4JeS/Lb8Qw9xFPRb3tyekXSME9mQTW 7CG5vz9b gGzOtXSFTAu5HJkZXbR4fjHuPug9T+srCm6SooleXgZVafHNOL7UudQ+rpV6PL5u7Cbd8pmmGEaBV2f7zZnXTlLtAh3qCy65MDnYI3wDu2wunRT+FA9Q2PFalCPRpmJ/4d8z5EY6AvNFtvxLggcFhKkAULMWYF67Uy9g0uOY4Kq2ecLkLi6NW+KC0ihYk0+tbYPAYB7JfNCn8d930jZFifO2GTIXtdVPSUQ42bDqhYH42BQvVrXMBsh0k1LvjtedjqabS2leDE9NFQ6/1Ha/Druk18Q== 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: The folio migration is widely used in kernel, memory compaction, memory hotplug, soft offline page, numa balance, memory demote/promotion, etc, but once access a poisoned source folio when migrating, the kernel will panic. There is a mechanism in the kernel to recover from uncorrectable memory errors, ARCH_HAS_COPY_MC(eg, Machine Check Safe Memory Copy on x86), which is already used in NVDIMM or core-mm paths(eg, CoW, khugepaged, coredump, ksm copy), see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers. This series of patches provide the recovery mechanism from folio copy for the widely used folio migration. Please note, because folio migration is no guarantee of success, so we could chose to make folio migration tolerant of memory failures, adding folio_mc_copy() which is a #MC versions of folio_copy(), once accessing a poisoned source folio, we could return error and make the folio migration fail, and this could avoid the similar panic shown below. CPU: 1 PID: 88343 Comm: test_softofflin Kdump: loaded Not tainted 6.6.0 pc : copy_page+0x10/0xc0 lr : copy_highpage+0x38/0x50 ... Call trace: copy_page+0x10/0xc0 folio_copy+0x78/0x90 migrate_folio_extra+0x54/0xa0 move_to_new_folio+0xd8/0x1f0 migrate_folio_move+0xb8/0x300 migrate_pages_batch+0x528/0x788 migrate_pages_sync+0x8c/0x258 migrate_pages+0x440/0x528 soft_offline_in_use_page+0x2ec/0x3c0 soft_offline_page+0x238/0x310 soft_offline_page_store+0x6c/0xc0 dev_attr_store+0x20/0x40 sysfs_kf_write+0x4c/0x68 kernfs_fop_write_iter+0x130/0x1c8 new_sync_write+0xa4/0x138 vfs_write+0x238/0x2d8 ksys_write+0x74/0x110 v4: - return -EHWPOISON instead of -EFAULT in folio_mc_copy() and omit a ret variable, per Jane and Lance - return what folio_mc_copy() returns from callers, per Jane - move memory_failure_queue() into copy_mc_[user_]highpage() instead of calling it after each copy_mc_[user]_highpage caller, which avoids re-using the poisoned page, per Luck, Tony v3: - only folio migrate recover support part since the cleanup part has been merged to mm-unstable - don't introduce new folio_refs_check_and_freeze(), just move the check and freeze folio out, also update changelog 'mm: migrate: split folio_migrate_mapping()' - reorder patches and rebased on next-20240528 - https://lore.kernel.org/linux-mm/20240528134513.2283548-1-wangkefeng.wang@huawei.com/ Kefeng Wang (6): mm: move memory_failure_queue() into copy_mc_[user]_highpage() mm: add folio_mc_copy() mm: migrate: split folio_migrate_mapping() mm: migrate: support poisoned recover from migrate folio fs: hugetlbfs: support poison recover from hugetlbfs_migrate_folio() mm: migrate: remove folio_migrate_copy() fs/aio.c | 3 +- fs/hugetlbfs/inode.c | 2 +- include/linux/highmem.h | 6 +++ include/linux/migrate.h | 1 - include/linux/mm.h | 1 + mm/ksm.c | 1 - mm/memory.c | 12 ++--- mm/migrate.c | 107 ++++++++++++++++++++++------------------ mm/util.c | 17 +++++++ 9 files changed, 89 insertions(+), 61 deletions(-)