From patchwork Tue Feb 6 11:21:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13547063 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 B2C51C4829A for ; Tue, 6 Feb 2024 11:22:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED3006B007B; Tue, 6 Feb 2024 06:21:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD7206B0098; Tue, 6 Feb 2024 06:21:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 844776B0087; Tue, 6 Feb 2024 06:21:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 138246B0099 for ; Tue, 6 Feb 2024 06:21:54 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CE87540682 for ; Tue, 6 Feb 2024 11:21:53 +0000 (UTC) X-FDA: 81761139306.06.E7727BC Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf27.hostedemail.com (Postfix) with ESMTP id 592A740019; Tue, 6 Feb 2024 11:21:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.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=1707218511; 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=7Vfi5mPP9Plx2/ma3bq2oRZ1jkmUJwNpM7DVX6FCJ7A=; b=X49FFN26r/P2nq2EsXoMw3DfXeykX+8JCvkVUaWDHhHmODyYTSw7qIYZqyuvppfXmD603H Ce4phCgeMy26MO3ik1FPmfdZQICGDIN+tS8lW4InzU/t9VUzFcRWg0C1vLLpm/gqx8lHwe 7JOyPS7/69FMKc2defJt6j527AuQOdM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707218511; a=rsa-sha256; cv=none; b=DUd+Ok2UXV4g5TP2V+XAuwrc/GP2ZivdD2NiHm2kB9696e9TejaTuTExHd2scBAZsJ+eGa tE5AU6v00HeZVMlWOWjnu/D/KRXVyl9tjq5sw2z2ny8g/V4CkofznN46wn8dgI1G/sYw2G MDEGMtFAUjVtI4/xKwIF4rPkOgnxaLw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.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.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TTgkv6Chsz29lQd; Tue, 6 Feb 2024 19:19:51 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 9CC921402C7; Tue, 6 Feb 2024 19:21:47 +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:46 +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 08/11] mm: migrate: support poisoned recover from migrate folio Date: Tue, 6 Feb 2024 19:21:31 +0800 Message-ID: <20240206112134.1479464-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240206112134.1479464-1-wangkefeng.wang@huawei.com> References: <20240206112134.1479464-1-wangkefeng.wang@huawei.com> 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-Rspamd-Queue-Id: 592A740019 X-Rspam-User: X-Stat-Signature: i7yozc3mttq9iqac9t4rqmebyzqynnp4 X-Rspamd-Server: rspam03 X-HE-Tag: 1707218509-91194 X-HE-Meta: U2FsdGVkX19jiyXkqNUuWiNHiMsKHtc/G8kc2a9U3QL8NjvLtGvb+v2XaPPXEcuP8CznGdFvGQh7pMEAMFL2kTEbznOZZwBZ2+pyWRvDpu/HTgkT3L6BQAI3C66owi4hE6NC6Tl7x2EVIqePZCuoAnulq4YemLCuxNnFKoFZrZaxIHjCh7BO7V8yVvXIRQ31MHktAmykBby4Ic3zAM6ZV70VZiAfEeY2g1IHp5HnvxzVWZNHepYyRvQIsEQUPbYfnM9mCoY0P4zVYhegOtxJNFcfyEjTdmF8cf+FSO4qGpII5ig2KtBRnd2e+7khKw8mWm4R8vtHbTUYYlrg4uucVTJoIxaLQQ6uEUJMyb+iUosGdRQasC+VEPGFS8yPqBKlsBGg+xLvb4wz/BrjgcJGsEQP71OqeK79dWkUvFbOuS+ADB5UlQJc5R+O1zKtTXnZo+FhHceqD0IofqKvyF0GQEyw7UaH7/VmkQbiLXQWLsSbp686r0BAi1JansDBmSmygoIAMfBFftItiOlbDSuds8L/9bFfba09UCL3rsVTVLCRkVynmIwyN2/eUaHY0i7R0bnC9DhJw2iSuF1jHVqvJXXOztXP+h+x5RSWYUKpdtRO7aHzlItoE4RCABc2iPes5oOVK8eWfQ7GaUJFZwUJB8zUnAWmXbig5I0ZcP4oEnHlg9gTC2O9Cn05KXRGkajwPxGg63Kuq57eSckQhIFuQEvKCpEWl+noFSj5gQRXAyszqByIFwDjjMbGhSrXNJPmzADJqItIjyxZe71MUwhCfFz7b6rfA33E5Ji9XQkeJBLh22ObPKsQrAN2yz4VUEMEJGKChPFXRG5vRvWG2/3FBK2wb9mm0J+a73eXfSQMOyfNIUkeYNBkzHDZLaXf1ev+b5W9qk9EgSKdBB0CM+DbBYM7KZrFkVm/7D48RFByENxe3+IbxB0uVlo0RTP+K5wbdPqe3y1wD5bCXHTNlnk 0wYh83fd sgwTEsB4ITMcVGvU32iCasIzZD1qMfzj/0lzwtpmz846SrDtaCe9+f99Atk/dSNZzx1PpKyJJIUK6esFmUkH1lshxQuQogRsuD5ptF5jr3ESREBolnwqi0MWqR16z+ejwrJIdHX6Zb/Zlaq/OaqFnSR4yDQ== 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, which is already used in other core-mm paths, eg, CoW, khugepaged, coredump, ksm copy, see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers. In order to support poisoned folio copy recover from migrate folio, we chose to make folio migration tolerant of memory failures and return error for folio migration, because folio migration is no guarantee of success, 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 Signed-off-by: Kefeng Wang --- mm/migrate.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 1db93b5eb819..6d99052848b4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -669,16 +669,25 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, void *src_private, enum migrate_mode mode) { - int rc; + int rc, expected_cnt = folio_expected_refs(mapping, src); - rc = folio_migrate_mapping(mapping, dst, src, 0); - if (rc != MIGRATEPAGE_SUCCESS) + rc = folio_refs_check_and_freeze(mapping, src, expected_cnt); + if (rc) return rc; + rc = folio_mc_copy(dst, src); + if (rc) { + if (mapping) + folio_ref_unfreeze(src, expected_cnt); + return rc; + } + + folio_replace_mapping_and_unfreeze(mapping, dst, src, expected_cnt); + if (src_private) folio_attach_private(dst, folio_detach_private(src)); - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; }