From mboxrd@z Thu Jan 1 00:00:00 1970 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 A2D03C4332F for ; Sun, 27 Feb 2022 12:07:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D36448D0003; Sun, 27 Feb 2022 07:07:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBDED8D0001; Sun, 27 Feb 2022 07:07:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5E568D0003; Sun, 27 Feb 2022 07:07:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id A4EB88D0001 for ; Sun, 27 Feb 2022 07:07:57 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5B9A98249980 for ; Sun, 27 Feb 2022 12:07:57 +0000 (UTC) X-FDA: 79188436194.30.6E3C32A Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf07.hostedemail.com (Postfix) with ESMTP id 5698440003 for ; Sun, 27 Feb 2022 12:07:56 +0000 (UTC) IronPort-Data: =?us-ascii?q?A9a23=3AoihylqIzAzMKJtFvFE+RrpQlxSXFcZb7ZxGrkP8?= =?us-ascii?q?bfHDs1jom1mNTy2QaDGGAaPbcZDP3eIojOomxoxsPv5OGn4NqS1BcGVNFFSwT8?= =?us-ascii?q?ZWfbTi6wuYcBwvLd4ubChsPA/w2MrEsF+hpCC+MzvuRGuK59yMkj/nRHuOU5NP?= =?us-ascii?q?sYUideyc1EU/Ntjozw4bVsqYw6TSIK1vlVeHa+qUzC3f5s9JACV/43orYwP9ZU?= =?us-ascii?q?FsejxtD1rA2TagjUFYzDBD5BrpHTU26ByOQroW5goeHq+j/ILGRpgs1/j8mDJW?= =?us-ascii?q?rj7T6blYXBLXVOGBiiFIPA+773EcE/Xd0j87XN9JFAatToy+UltZq2ZNDs4esY?= =?us-ascii?q?Qk0PKzQg/lbWB5de817FfQcouecfibv7aR/yGWDKRMA2c5GAEgoPIEw9PxwBGZ?= =?us-ascii?q?U//0EbjsKa3irh+m26LO9RPNliskqII/sJox3kn1py3fbS+knRZTCSqDRzd5ew?= =?us-ascii?q?Do0wMtJGJ72a8gGbjxgRBfNeRtCPhEQEp1WtOOpgGTvNjhdgFGLrKE0pW/Jw2R?= =?us-ascii?q?Z1qbhMd/QUtiLXtlO2EKZoH/WuWj0HHkyNNef4T6e7jSgi4fnnyr9VcQZFKCQ8?= =?us-ascii?q?eRji1megGcUDXU+UVq9vOn8hFWyVsxSL2QK9Sc066s/7kqmSp/6RRLQiHqFuAM?= =?us-ascii?q?MHtldCes37CmTxafOpQWUHG4JSnhGctNOnMs3QyE6k0+HhPv3CjF19r6YU3SQ8?= =?us-ascii?q?vGTtzzaBMS/BQfufgddFU1cvYal+9p103ryoh9YOPbdprXI9fvYnlhmdBQDuog?= =?us-ascii?q?=3D?= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3Ay1DMO6tCJ8KxxxpMoZCf2uqu7skCW4Mji2hC?= =?us-ascii?q?6mlwRA09TyXGra2TdaUgvyMc1gx7ZJhBo7+90ci7MBfhHPtOjbX5Uo3SOTUO1F?= =?us-ascii?q?HYTr2KjrGSuwEIeReOj9K1vJ0IG8YeNDSZNykdsS+Q2mmF+rgbsbq6GPfCv5a4?= =?us-ascii?q?854hd3AbV4hQqyNCTiqLGEx/QwdLQbI/CZqn/8JC4x6tY24eYMiXDmQMG7Grna?= =?us-ascii?q?y4qLvWJTo9QzI34giHij2lrJb8Dhijxx8bFxdC260r/2TpmxHwoo+jr/a44BnB?= =?us-ascii?q?0HK71eUkpPLRjv94QOCcgMkcLTvhziyyYp56ZrGEtDcp5Mmy9VcDirD30mEdFv?= =?us-ascii?q?U2z0mUUnC+oBPr1QWl+i0p8WXexViRhmamidDlRQg9F9FKietiA2zkAnIbzZlB?= =?us-ascii?q?OZ9wrimkX8I9N2KLoM293am9a/hSrDv8nZJ4+tRjwkC2UuMlGcBsRMIkjQ9o+a?= =?us-ascii?q?w7bVjHAbAcYZJT5f7nlYtrmHOhHg7kVzpUsa2RtkpaJGb7fqFFgL3h7wRr?= X-IronPort-AV: E=Sophos;i="5.88,333,1635177600"; d="scan'208";a="122037684" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Feb 2022 20:07:51 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 1074E4D169F3; Sun, 27 Feb 2022 20:07:51 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sun, 27 Feb 2022 20:07:53 +0800 Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sun, 27 Feb 2022 20:07:52 +0800 Received: from irides.mr.mr (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Sun, 27 Feb 2022 20:07:50 +0800 From: Shiyang Ruan To: , , , , CC: , , , , , Christoph Hellwig Subject: [PATCH v11 3/8] pagemap,pmem: Introduce ->memory_failure() Date: Sun, 27 Feb 2022 20:07:42 +0800 Message-ID: <20220227120747.711169-4-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220227120747.711169-1-ruansy.fnst@fujitsu.com> References: <20220227120747.711169-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-yoursite-MailScanner-ID: 1074E4D169F3.A5262 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5698440003 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=fujitsu.com (policy=none); spf=none (imf07.hostedemail.com: domain of ruansy.fnst@fujitsu.com has no SPF policy when checking 183.91.158.132) smtp.mailfrom=ruansy.fnst@fujitsu.com X-Stat-Signature: jxwh36cd6uwufjsnoya9jodc9m8jkc4r X-HE-Tag: 1645963676-746468 Content-Transfer-Encoding: quoted-printable 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: When memory-failure occurs, we call this function which is implemented by each kind of devices. For the fsdax case, pmem device driver implements it. Pmem device driver will find out the filesystem in which the corrupted page located in. With dax_holder notify support, we are able to notify the memory failure from pmem driver to upper layers. If there is something not support in the notify routine, memory_failure will fall back to the generic hanlder. Signed-off-by: Shiyang Ruan Reviewed-by: Christoph Hellwig Reviewed-by: Dan Williams --- drivers/nvdimm/pmem.c | 16 ++++++++++++++++ include/linux/memremap.h | 12 ++++++++++++ mm/memory-failure.c | 15 +++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 58d95242a836..cb915d144244 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -366,6 +366,20 @@ static void pmem_release_disk(void *__pmem) blk_cleanup_disk(pmem->disk); } =20 +static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap, + phys_addr_t addr, u64 len, int mf_flags) +{ + struct pmem_device *pmem =3D + container_of(pgmap, struct pmem_device, pgmap); + u64 offset =3D addr - pmem->phys_addr - pmem->data_offset; + + return dax_holder_notify_failure(pmem->dax_dev, offset, len, mf_flags); +} + +static const struct dev_pagemap_ops fsdax_pagemap_ops =3D { + .memory_failure =3D pmem_pagemap_memory_failure, +}; + static int pmem_attach_disk(struct device *dev, struct nd_namespace_common *ndns) { @@ -427,6 +441,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pfn_flags =3D PFN_DEV; if (is_nd_pfn(dev)) { pmem->pgmap.type =3D MEMORY_DEVICE_FS_DAX; + pmem->pgmap.ops =3D &fsdax_pagemap_ops; addr =3D devm_memremap_pages(dev, &pmem->pgmap); pfn_sb =3D nd_pfn->pfn_sb; pmem->data_offset =3D le64_to_cpu(pfn_sb->dataoff); @@ -440,6 +455,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pgmap.range.end =3D res->end; pmem->pgmap.nr_range =3D 1; pmem->pgmap.type =3D MEMORY_DEVICE_FS_DAX; + pmem->pgmap.ops =3D &fsdax_pagemap_ops; addr =3D devm_memremap_pages(dev, &pmem->pgmap); pmem->pfn_flags |=3D PFN_MAP; bb_range =3D pmem->pgmap.range; diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 1fafcc38acba..50d57118d935 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -77,6 +77,18 @@ struct dev_pagemap_ops { * the page back to a CPU accessible page. */ vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); + + /* + * Handle the memory failure happens on a range of pfns. Notify the + * processes who are using these pfns, and try to recover the data on + * them if necessary. The mf_flags is finally passed to the recover + * function through the whole notify routine. + * + * When this is not implemented, or it returns -EOPNOTSUPP, the caller + * will fall back to a common handler called mf_generic_kill_procs(). + */ + int (*memory_failure)(struct dev_pagemap *pgmap, phys_addr_t addr, + u64 len, int mf_flags); }; =20 #define PGMAP_ALTMAP_VALID (1 << 0) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 98b6144e4b9b..8dd2f58c1aa8 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1663,6 +1663,21 @@ static int memory_failure_dev_pagemap(unsigned lon= g pfn, int flags, if (!pgmap_pfn_valid(pgmap, pfn)) goto out; =20 + /* + * Call driver's implementation to handle the memory failure, otherwise + * fall back to generic handler. + */ + if (pgmap->ops->memory_failure) { + rc =3D pgmap->ops->memory_failure(pgmap, PFN_PHYS(pfn), PAGE_SIZE, + flags); + /* + * Fall back to generic handler too if operation is not + * supported inside the driver/device/filesystem. + */ + if (rc !=3D -EOPNOTSUPP) + goto out; + } + rc =3D mf_generic_kill_procs(pfn, flags, pgmap); out: /* drop pgmap ref acquired in caller */ --=20 2.35.1