From patchwork Mon Jan 29 07:09:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13535070 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 3AE4AC47DDF for ; Mon, 29 Jan 2024 07:10:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 960D16B009A; Mon, 29 Jan 2024 02:10:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F4406B008C; Mon, 29 Jan 2024 02:10:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 338786B008C; Mon, 29 Jan 2024 02:10:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id ED95B6B00A0 for ; Mon, 29 Jan 2024 02:10:02 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C0A041401CE for ; Mon, 29 Jan 2024 07:10:02 +0000 (UTC) X-FDA: 81731474244.24.AFA7A42 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf14.hostedemail.com (Postfix) with ESMTP id 4561B10001A; Mon, 29 Jan 2024 07:09:57 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.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=1706512200; 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=LZ6Y5L3dRmfa/dBtMJdnlibq2kcHoOr9a3q5ildHcpI=; b=2QTLS1sXzjPP3r9Nq3wpWOHlVTEkIpTDBVDaWtOEio2HdwbBOr0YZO0I6BQl4uSZUe+fHP avYRogI+oUE9l+qNqspONaR9je8f/NHkqPdsHsQX+xSof76HAwA3CSufEklN+PqDkAjr8J xZgRzlx/tcliitperxQggvfxzoEpl0A= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706512200; a=rsa-sha256; cv=none; b=t0d7uSuYIEtbFaozbJz+3VJ7DcWuuJ5o0gRuDy5JQgR7qQZRK0QnUlyaX/sQ/orR1a6WAz swASC9Z9FG3wdnce+J8Hk+ymL2gkWN6ativPp2TEMxesE/r3yBuaQo9mcF3+3rAwdsLHad EYNBYwQcLSDs5BmaiF2f5gfBz+131zQ= Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TNfY112ytz1xmk8; Mon, 29 Jan 2024 15:08:53 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id C3D1918002F; Mon, 29 Jan 2024 15:09:50 +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; Mon, 29 Jan 2024 15:09:50 +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 rfc 7/9] fs: hugetlbfs: support poison recover from hugetlbfs_migrate_folio() Date: Mon, 29 Jan 2024 15:09:32 +0800 Message-ID: <20240129070934.3717659-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240129070934.3717659-1-wangkefeng.wang@huawei.com> References: <20240129070934.3717659-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: 4561B10001A X-Rspam-User: X-Stat-Signature: d3ffe3xobzwgydjmua56hsoj1m43e5y6 X-Rspamd-Server: rspam01 X-HE-Tag: 1706512197-397312 X-HE-Meta: U2FsdGVkX1+R/CjfS8e0d/0ZQX6v+o9+Irok2VEPHo/pSU1/BSwTzPhaIz7m17fvtjedDJlSwIHT8VfJ8Zq8P+zwDXbc5BV0svmnZKzkf2jUNuXdOn33mhwypUqCQU78MpQ5Ija6W/oAhXT0zv7FNB+guPjZo8KtNqccoyZjAIlLtOuF8FfGAmVgdk4t8vGTtrMKF18tovXByF5IlBsDOXLHFdIXegx+BR7npSFmD1bRage/BCz7q+KkUReLcTIwbJDh41jNES8/YRYRShFmfM1UfDjhgnIUIIS1E5dB6t6SMqz3jwOQOw8tRWv1wJs4PdYMqyGgqJArxUEqSL0qInGXeWgUO9WuyISFKkpBcxOOpH5exb03B3PTg3fqee6CeQYLHgzNst7arDnBZXhn9JOvQnKS+G0MLsyqZZRFBC4jjmvyDt76veLgHP5P70cdtn+1/R8Mr4C9oZqfJ1uEgbNC+XbfqT3aI4+c0BfPuHsgMpRBaNFXlNxBkJ+xz2NXHx7kJD7UNJowtp1gfwBm7fqD2Ssw7u5rpq4Qsp7ZqKP43J+PfWt5dTDrvUb3nADmOOpSSyjpECvBFUkLEYU38/b1MFMhYcuNP9+N9Dv1IayhuxJHtyz2Cx3Q7vpS/BwbWc/WWuXt2a5JGqAVL1tNOCeUX5xEhYbsvROfE/gTY1ZvLRR2WpCp+7a8AlFMN749yOssCq2iIHhBaNSO7JlTNPGfFNuaIatzxsqIJoVdoZw/JGL1HVAYB+NYA2bLD750sW2AAWYgw64UovTFDm4rT7u2PuOKPVju6V9l9AFrQHwpByfFB7g66OD7PEvXtd3LAgmHElBVz0BjHoTEJsExpiD14nxo7e99iT7dP1ZfI/SmXkbp4zsVdwJBYe1dIHzIpJBU7Acr3uxLK+v8YNHT9ne8HU+Y+RqYWiDIvu9ekNik+DGh6DD+oHvZQu0/CuDRHKQ9AnhJKtGi1ma1S6d ViDVLRph WTJf9VFysVlVLFVI7aXHXSIiU4njjIawfpU9Spc56hskXta8Tp4oq9YwLofRKs8O2IUljaRkHVwhKMvik4w26UJiTRwqeEkWY8GItM+ROuXGZZtU1vb3lIwtTT2AAG6thfMWwU+1sZjti3Dvx8b3EgJ92AHO9Wzgy8I13Zn4gYBLkoXyWBTE8yLM475KDsS8FzHKCd4NbSrVOjJo= 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: This is similar to __migrate_folio(), use folio_mc_copy() to avoid panic when copy poisoned folio. Signed-off-by: Kefeng Wang --- fs/hugetlbfs/inode.c | 10 +++++++++- include/linux/migrate.h | 1 + mm/migrate.c | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 52839ffdd9a1..3871968d1780 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1119,6 +1119,14 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, { int rc; + /* Check whether src does not have extra refs before we do more work */ + if (folio_ref_count(src) != folio_expected_refs(mapping, src)) + return -EAGAIN; + + rc = folio_mc_copy(dst, src); + if (rc) + return rc; + rc = migrate_huge_page_move_mapping(mapping, dst, src); if (rc != MIGRATEPAGE_SUCCESS) return rc; @@ -1129,7 +1137,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, hugetlb_set_folio_subpool(src, NULL); } - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; } diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 517f70b70620..ab387ea66365 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -79,6 +79,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio); void folio_migrate_copy(struct folio *newfolio, struct folio *folio); int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); +int folio_expected_refs(struct address_space *mapping, struct folio *folio); #else diff --git a/mm/migrate.c b/mm/migrate.c index 99286394b5e5..097d67c82f8b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -375,8 +375,7 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd_t *pmd) } #endif -static int folio_expected_refs(struct address_space *mapping, - struct folio *folio) +int folio_expected_refs(struct address_space *mapping, struct folio *folio) { int refs = 1; if (!mapping)