From patchwork Mon Jun 3 09:24:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13683600 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 C3A17C25B75 for ; Mon, 3 Jun 2024 10:46:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C516C6B0092; Mon, 3 Jun 2024 06:46:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD9C56B0093; Mon, 3 Jun 2024 06:46:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A05306B0095; Mon, 3 Jun 2024 06:46:08 -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 751266B0092 for ; Mon, 3 Jun 2024 06:46:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1BD381607DA for ; Mon, 3 Jun 2024 10:46:08 +0000 (UTC) X-FDA: 82189247616.15.76436A0 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf25.hostedemail.com (Postfix) with ESMTP id 3DA28A000E; Mon, 3 Jun 2024 10:46:04 +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=1717411566; 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=evrR0enGu4CVldhF9V8cpmPyJ0bXapKDS3IF6y1p7A8=; b=RBYEwjbZUxHoQ9TsVwVoLaAu17XdaB9vVR4QBZtspijocAlK86Kc2+Wg/k//M+2kj8c59W jBc7OUcpNj1FgXHe4GsFbqm++zPgt05Lw64Uj5ZwUqYYSIAtaCg1RKw+uFMLI2hTRWuEz1 qs0VqhWDWUWxkJNNdHo+xQK3B4FSQCk= 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=1717411566; a=rsa-sha256; cv=none; b=VhEC0alVip4ADtaTlcJiqYS4RWPsW3/QLHV2+pPcqlFfZFh0Aguq1athiJ/Artmh0Y4qn0 /yVuktmP+Vi2m4iEI0gmemsPKBQ21Rqkb/uwFCuhYw4W2xSA3LjRdNb+HMqrT1JPQ2Q/mm HpOUk8zGoFIGalN552qG51gh2NOgRWA= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Vt9Jv1Pm1zxNdS; Mon, 3 Jun 2024 18:42:07 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id BE39E180A9C; Mon, 3 Jun 2024 18:46:01 +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:46:00 +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 4/6] mm: migrate: support poisoned recover from migrate folio Date: Mon, 3 Jun 2024 17:24:37 +0800 Message-ID: <20240603092439.3360652-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240603092439.3360652-1-wangkefeng.wang@huawei.com> References: <20240603092439.3360652-1-wangkefeng.wang@huawei.com> 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-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3DA28A000E X-Stat-Signature: njbpqj84ycsu88tamh68iyer7bp99kty X-HE-Tag: 1717411564-368138 X-HE-Meta: U2FsdGVkX18egE1RYzXkTeG2FEN2sa03DUXmBnEogi09rbqTTr2fdelVWnh6K5kdwmtVS6sl8mNE8XcuKsyMkjjq5m6QAMYnX0WXO/UoxMqi+HDaHW4ByumdWDVwX0THL/YFiTyWjI2kQLnsj85wgaT46r2xAlCRGVo/g6XOa0UpZOpdWtJBiNV9FdvX19ga1zvkWn+SBmFk3C5GthSueTnysUM3lGDwIXUfu4pY4G2bj23kKoKl+lFD8to3VFbMx/UFv0/87pOOwQLCV28KNpB+atER04eZ8JaSS2QcnIsVq0v214FLpxOBgRopxMoQzQHtKiURn5GNxsx4c3gdQATV20Tp3HWk5rCx7hhPatHaUlEpANg0w/FGTeF9Jt9+BEI+en4lSR5xCGPI0ihNe4j19u20szURPGzuy4TEhmDPlKg/8YS1K3dr0sttvSG8MDG+Op0PZlYhx0tIADbPP/xBukU8fCwHOuBjBa17nBXfxuB5tdLUgBYwyw0FAsaB272eZViwnaf3jaRB3OzxvcZG+PU51juwBoJXnfWD2NOKQJmmDYasEB7jD2jz2NVwT/9jxYw4D1U7gWWB3sTlT0/6dfG0U9vEmesysBI6j3W/1vz41yQEPrKxAyA/DxE7vfTEq81SzOp30uoXB3Md4h7UsEtwDz/l4Fzfn9A0/oPtzpH3Sgt/OLC3ywCma9QsjrOvr7SDPGvMm6yQ4sh7+po5XqpE7ckbGVCtD6kQI/MQ7weS8IvhXf7eEgHYFBzehnvqBeAsdDUZHTcG2XPZR68xjZK5SNR83UAnLhmDT9Wbccb9ufm8HOVEouR0omTQ5BsqlZQvuuRi9ly/nxgP91/S9XdUvttau/wOqF8/zrb86X7n/pc1hkOh5ci/Ro48XwWMnrF0J+B3xAqhbZifGV+iAuHljauarhH8L72YigO59WV9r5K/a0RxGnIQIoP55wDZB9pceuF2uvktEfy LNt/e/4D 0I6Lq3+uMkogzLf+3xRnC2cIRyK0uYVMNDRtV+/Usj+SVpxcs4c+I4PZr4OgnqdtR+6r1lmgQCBPgf0V8ZaaeoAAhSS/Q2gYQpRaHsYV0ZXvdK4geqJTGB0qGzv0K5YvKto9aPbHUNAVO6mcRV+vuC11YctyTfkUrUFfxYSjFNBsaR0PjQtNrfsN9Z3lclfamBmd66+EbzcT5moKMYIlntwI12bf1SUirCQXc 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 Reviewed-by: Jane Chu --- mm/migrate.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index e930376c261a..28aa9da95781 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -663,16 +663,29 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, void *src_private, enum migrate_mode mode) { - int rc; + int ret, expected_cnt = folio_expected_refs(mapping, src); - rc = folio_migrate_mapping(mapping, dst, src, 0); - if (rc != MIGRATEPAGE_SUCCESS) - return rc; + if (!mapping) { + if (folio_ref_count(src) != expected_cnt) + return -EAGAIN; + } else { + if (!folio_ref_freeze(src, expected_cnt)) + return -EAGAIN; + } + + ret = folio_mc_copy(dst, src); + if (unlikely(ret)) { + if (mapping) + folio_ref_unfreeze(src, expected_cnt); + return ret; + } + + __folio_migrate_mapping(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; }