From patchwork Tue Feb 6 11:21:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13547059 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 48B4CC4829A for ; Tue, 6 Feb 2024 11:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F3BD6B0080; Tue, 6 Feb 2024 06:21:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 509276B0075; Tue, 6 Feb 2024 06:21:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 910E46B0083; Tue, 6 Feb 2024 06:21:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 19E046B0081 for ; Tue, 6 Feb 2024 06:21:52 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6C3471A0C28 for ; Tue, 6 Feb 2024 11:21:51 +0000 (UTC) X-FDA: 81761139222.23.7FFFF72 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf13.hostedemail.com (Postfix) with ESMTP id 9FB0220015; Tue, 6 Feb 2024 11:21:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 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=1707218509; 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=0mLapenz9gVgO/or1L1D5VRu24w4SeHrs42p+8fC8Yg=; b=zMMCthKgYY6lGY6Z+Z5saf15NBp1Db5seH8uRxS1Q6WKnpppNHng6xBqcXapEBjvXVtGGa A7ejQ1Fr244Bf5ml2I+upY8c9mUXE+rbR6GdygLvkahG1dDCYYHX9ni8Iv22beXgFi86Gh FGV91V1nVMxNqfqiAjfs3FyDI9wU8wU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707218509; a=rsa-sha256; cv=none; b=GJzWRrnvUaizYxTy4Di6F8QOhAZ3t5Az55Gnh1fxX8UohQJmcABwNTZRXxVwYi4VgG3m7f 89YeICgU1RiwR4VRQtHYyQH154VVRGDPQfwyvIKwaqAjHZ2lyxWo2gopAAyAeN0/DnXorQ EyhH23TxM5cDkzuPSG9z9vB5ggyF8Jk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TTgkp6Hdkz29lQp; Tue, 6 Feb 2024 19:19:46 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 9EB29140412; Tue, 6 Feb 2024 19:21:42 +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_128_GCM_SHA256) id 15.1.2507.35; Tue, 6 Feb 2024 19:21:41 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Naoya Horiguchi , Miaohe Lin , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Kefeng Wang Subject: [PATCH rfcv2 00/11] mm: migrate: support poison recover from migrate folio Date: Tue, 6 Feb 2024 19:21:23 +0800 Message-ID: <20240206112134.1479464-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: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-Stat-Signature: p95dujjjrb51wgyxina9gpz4npzrfe4p X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9FB0220015 X-Rspam-User: X-HE-Tag: 1707218507-566341 X-HE-Meta: U2FsdGVkX1/BftCpExajSoy9Dojlq5BQmSaW0QcMKUHeLsfnemuYnOuFMWYCDipg2pORWgs0RLxyI+USCMSN3rSF5eSdNS1DNnx637lwdR9Muc7EOYlQCoTzxWhBYMQqWc53xgWcybA9hBtGoV/P1ilfXfLPbhCfQl3JdIKy7BFTIZUJH5X+fI+rIygIrZTneFO6zdmwfFLcm+AbfyjxWxQKQ/FzXhmNphMk6JAWxDMNPGMFZ4B+fKYWM0E/yVoHfBzAzMUiZ0K/hx5dzwTF7oEtinhUHM2UxVFO4YfJ9HjftA/XH4Srp3FZj3Dz901ZJxeTFD+uWIqyFpU89nA6v0Nrv3Yi1NZCqvjvw69VpwHg5CMHpy1QD9DIqGRAZE50aPYz0ASUIk4Omj8QSQbW/qlhWYqSd7pfTEfWxqb34qOPWAKjihx+nl4bP9VqMUPq4MIU4ZhSlJuKteVuKPKzBJ1TKpbNLlswe5grfvemZCTPo4hwr3bZ/gHbvzmTN+ry40CPCkYHEUFyWg9CdFcUVMwpXf2QeeNuKIaUMcVxU0P72dg/Eenk/zN6HTy0A2NRFILh4qd/GxpJjRFzJ4UlUhMK08sBjeqBi7Ewn07CsKdJHYy+q05DU80tHfzmMXI/H/E2rdcI2AEagJKYtMdtyIlC7L6gVdHNBd4WGm5pY2HjgUo+F7kS1RGE9hjHzNaCWtVnIL7uDlkdHNBIWz4Vkxjwc5mwn74Dkdk/HMvXGJyJS+yrfBA3yKYorv9Vqkmpn1pB3X2BymM12lxULeI7XMncGC10iP9Mi9LN5pUqexjvh2+eB/m1CoILgeQfPsocY1BDVpmnk9DxOGBqEtSRIFtdyLvyw5wwSXhYTyrptdcfEikRM/EzWb/pv0hav+Kf4Z6J3dsR8xTNBzhhrnndipiaJBIiWsKn89SqPaoBJ3LOjaCI4kum/CHBH57/jkd/ufe7qbDxWznztDZkjOw phDbZOWi p558CAZqrxhXS5wR0gQdHXOVR26T1RdFkopizunL95tnizSMNIZ0fyB0hNv8G0FrrD5JdDts+rdCr+kJp9X4U7WpJGudAOJhzBh/CoORnZo0JBo2iB7gwyY6qtA== 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 kerenl will panic. There is a mechanism in the kernel to recover from uncorrectable memory errors, ARCH_HAS_COPY_MC(Machine Check Safe Memory Copy), 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 rfcv2: - Separate __migrate_device_pages() cleanup from patch "remove migrate_folio_extra()", suggested by Matthew - Split folio_migrate_mapping(), move refcount check/freeze out of folio_migrate_mapping(), suggested by Matthew - add RB Kefeng Wang (11): mm: migrate: simplify __buffer_migrate_folio() mm: migrate_device: use more folio in __migrate_device_pages() mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY mm: migrate: remove migrate_folio_extra() mm: remove MIGRATE_SYNC_NO_COPY mode mm: migrate: split folio_migrate_mapping() mm: add folio_mc_copy() 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: add explicit check for large folio in aio_migrate_folio() fs/aio.c | 15 ++-- fs/hugetlbfs/inode.c | 5 +- include/linux/migrate.h | 3 - include/linux/migrate_mode.h | 5 -- include/linux/mm.h | 1 + mm/balloon_compaction.c | 8 -- mm/migrate.c | 157 +++++++++++++++++------------------ mm/migrate_device.c | 28 +++---- mm/util.c | 20 +++++ mm/zsmalloc.c | 8 -- 10 files changed, 115 insertions(+), 135 deletions(-)