From patchwork Wed Jun 26 08:53:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712425 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 19A59C27C4F for ; Wed, 26 Jun 2024 08:54:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 855186B0088; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 803C16B0089; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67D9B6B008C; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 45F906B0088 for ; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 019A5A0C40 for ; Wed, 26 Jun 2024 08:54:42 +0000 (UTC) X-FDA: 82272429246.09.7FE28DF Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf25.hostedemail.com (Postfix) with ESMTP id 79D2EA0017; Wed, 26 Jun 2024 08:54:39 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392073; 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=/DYra3xJnyn4vFMbs0ipZVuO/+fEkjlheolaE/Ws6CA=; b=Do2uqg5nceuGv0UNQFtKPYAPfRLg3GOwbcJivGwAJecqmh4tud90gVOs8dk/qognXbB6Mq 6nd+wCDHVYUOQb5IFTJaEpZ27sglOPEvisQxO+uyN1msZ6fpj4iwKGhcsMyf67OIZy81Pk PDZFTxWtk/xQ4X3rK4rrXK6otBLKVi8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392073; a=rsa-sha256; cv=none; b=zas3pQaA2J4/ADOgZYiJa3rRduDOIBL8Wi6FJd+mhEdeiWR3EYTg0bWPIKfGvzbQ4Y8ZbS i1E2lDN29mxRF4iZhMxRPz/ROYbP7YAPFNJksDVDgB3IkkfnUh5O7ahPjJIZYPdokREyS3 gvf2uevSCHY+pnEjn8UsxoUpGnTvepI= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4W8FlC4dCFzxTJY; Wed, 26 Jun 2024 16:50:15 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 5DFA514011D; Wed, 26 Jun 2024 16:54:35 +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; Wed, 26 Jun 2024 16:54:34 +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 v5 0/6] mm: migrate: support poison recover from migrate folio Date: Wed, 26 Jun 2024 16:53:22 +0800 Message-ID: <20240626085328.608006-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: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 79D2EA0017 X-Stat-Signature: kb5j98rr3rsd1ds9sprtf89x1zzkd7ge X-HE-Tag: 1719392079-163829 X-HE-Meta: U2FsdGVkX1/xo4njg+4sPsUHel6IhlWOwGbXP7cwuBCw1lnwYp9JI4358qYOkdsqC0n5QW0+aX4xfzuvy7MAjNuVW3lbGSJuE9YO1JO/ETbo4UzxILWo82qTXCp3x6maUWM1zE4f9f79eRI5yP7U4J9b9tBvG85BRUP2JN5sp/eF3IgUnpn8B9/o6sOV+GOZGp8sSH+NoSr5d4v0seLzOH04bUqYLVy8WCvoGBur0/Qmipcf+FREkj4mZpzeSa74f/5EWwwR/M0jlez2tbCYe82UGapAZBEJ29rya38M9Ud5Pac7K8/Ep2udX59SJSWipheoyKO50ejOl8FmNbEhd8h5z9yHEKzXdz8bb/u24LosedLkl3i6d2lVgGwUnePQIyvGHrZbLR54oZjlweJsp7JlK0vPpWcovRyclwKLHxjzUgoMNWVPPu4VckPNJOTjPFWeEZaAsoKhosI/ReRBZJ9xGaxnkEoytTWhtau7E688CvEJP6YVhtU64nPckAuYUr0/N3C5BHr0mlNAO4WIlVdYoVNX8sYgwjyBir5o+8D0VAF04sbg05yJqnDqH4rKPNWyy/PZtxkg4/fWPiAX9NUNVagtVQXj+AESltd5F+WQzwBbDUXZOGrhQDaYhPKWhjgHcfBVGEMsoUZctZHmE0EYIuHMpKo6IJBa0CrxoHBvaZRHP1wZvDRaVQx3cKDqrSQBeOZEKQsJuz0wT0DEYUjtbR5ncdg4iuwsiR78h4sbuHD6BRmHKmCPTVRXAsX8/sHr60pKf3gbK7PUjAGrlimr7BWMfATtPy3b+KPyd2TUbkpHe74nXVhRmSh//xAe3tc6zWDR0Ghr8LcrXntnE98fbT2Wdw0HoLN+M+veUZFjn58SJGqiNqhflFb3V4jLGnNDGem4NihossHaupQf3YVCqKi3bL9BAgzPcxP1IvKKBxuf4c0S6/7z5qk8tHVcbFSJVZGGR8pCJOxpcxg 2TTTraaA vn0d1c029RxFC7ujmccu9/+RHSdxzHjYCG+B3VT9YQXIdyW/S116tjIig7Sm72B/w8LaW0CVtfYcJVX+XdCqAned/mZkozWRq5qmL2tYuG54orWKiwHyNOj6MBpDfOhTfUp5tLxGs7QwGeaMcqAxerfpnmZnd0fgMgyW7Z0MDBN/g2ZssNwonKgjEchYswlegaZTh2lAnPyLNEyXaE7lGR7MT63SNrn/044toHuFRHC063DRhmJR5F8+ZrA9Bbz+BPBA1/ALfVF6aggt9OgPH492ieRgWiBhS5ZQE4KHktAsxNyw= 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 v5: - revert to folio_ref_freeze() under xas_lock_irq(), since Hugh Dickins found issue when move freeze folio out of xas_lock_irq, thanks, and the fix patch[1] is same as my RFC version[2], so let's turn back to the old way, patch 2~4 are changed so drop the RB from v4. - revert v4 and rebased on next-20240625 [1] https://lore.kernel.org/linux-mm/07edaae7-ea5d-b6ae-3a10-f611946f9688@google.com/ [2] https://lore.kernel.org/linux-mm/20240129070934.3717659-7-wangkefeng.wang@huawei.com/ 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 poisoned 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 | 71 ++++++++++++++++++++++++----------------- mm/util.c | 17 ++++++++++ 9 files changed, 72 insertions(+), 42 deletions(-)