Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp64119pxb; Thu, 27 Jan 2022 15:10:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6lQKtN1wAORvxHGYjJwxC1c1KKwwwYmegud6ZCuVe9fJy0DB8wmUVFQ6Kl63W0dPYUCfa X-Received: by 2002:a17:907:1626:: with SMTP id hb38mr4653102ejc.306.1643325034993; Thu, 27 Jan 2022 15:10:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643325034; cv=none; d=google.com; s=arc-20160816; b=G/TTZ2aWlb9JgwoQIzGlL0XYw4or45LNoa00ydBTH/a4raF+DYJyeWjt7rL0iLKPLx bFoA35Z1uV7WLQ/Xu8MhtcJXq27+7n41vvrTQNZIQQmPzt9IB8gkeSctuGT8JWbSXOd5 9x7yPvL3oZewjY2tpeCeXIXriI/BQv9KiwIig7FrL0BnBh4XLJVRP+1uRmT3M1gVoewY MacmoWLbr5RgTt9ydJ1g8O0CDsRT/nEBt92vSuiJF2SYVxi5PFj7fM0QOiMd0Uw3lijl twi/UGh35TjV/PqY31E0CalwCjKwsxC6SpxCTI1b+xIWS/AyMt8GynygjT8e4L/UoZ37 QDIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-hdrordr:ironport-data; bh=MG67lw+t5CEWwR+hJddbCfrIGE7gWZ4PyKPKQ07xjMk=; b=q10p0UGciw+dpdoEAb1+98PSW8zIGQ6cDxqMwrsjL+a3lcnuOMipwae7PqyD4QiKwI LrIGEO0UThJ9ss01T7vAg6qjmnXaxVceBJiJLZQe0pbyyp8Y+aeFxyjce+NRxl6FhXsK MMjLn4VdgU+Sze/2mxui8gO5TZumQwVbCObchGNrrsw7Kr9TIZd7891Z2ZvaKA4YFQHl pNhgJjdmx4UD54dWB24NhI8nCq5zM3b+6kYPrFeFexiCYjEfg7D2DCKsOEHd4HPvdj2i Od9plGTxEX3m6OSVi9p4e20XZi98il3D+z7oJA8x4DeazBWSHbO3KJJnjc4THR4TDHH4 j61A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt5si2111269ejc.884.2022.01.27.15.10.10; Thu, 27 Jan 2022 15:10:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241262AbiA0MlY (ORCPT + 99 others); Thu, 27 Jan 2022 07:41:24 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:35635 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241260AbiA0MlQ (ORCPT ); Thu, 27 Jan 2022 07:41:16 -0500 IronPort-Data: =?us-ascii?q?A9a23=3AQId7TaMWpPLb+5nvrR3alsFynXyQoLVcMsFnjC/?= =?us-ascii?q?WdQOxgjknhjQBymMZXG3Sbv6KNjPyfYt+bNnnpktU65fRm99gGjLY11k3ESsS9?= =?us-ascii?q?pCt6fd1j6vIF3rLaJWFFSqL1u1GAjX7BJ1yHi+0SiuFaOC79yElj/7QH9IQNca?= =?us-ascii?q?fUsxPbV49IMseoUI78wIJqtYAbemRW2thi/uryyHsEAPNNwpPD44hw/nrRCWDE?= =?us-ascii?q?xjFkGhwUlQWPZintbJF/pUfJMp3yaqZdxMUTmTId9NWSdovzJnhlo/Y1xwrTN2?= =?us-ascii?q?4kLfnaVBMSbnXVeSMoiMOHfH83V4Z/Wpvuko4HKN0hUN/kSiAmctgjttLroCYR?= =?us-ascii?q?xorP7HXhaIWVBww/yRWZPceqeaceybu2SCU5wicG5f2+N1iBV83MaUW4OFyBnt?= =?us-ascii?q?E9OBeIzcIBjiDjOKewbS1UOBgi80vas7xM+s3tnhmizOfEvciRZHKRr7i5NlE0?= =?us-ascii?q?TN2jcdLdd7SZdUebzVHbxnaZRBLfFANB/oWmOaum2m6djhwq0ycrqlx5HLcpCR?= =?us-ascii?q?3zrTsNd/9ft2RWd4Tmkeeu3KA82nnajkaP9y3zSGZtH6h7sfNlCX2HokSCZW/7?= =?us-ascii?q?PdhhFDVzWsWYDUSVF2msby3kUKzRd9bA1Ib9zBorqUo8kGvCN7nUHWQpH+Cow5?= =?us-ascii?q?ZWNdKFeA+wB+Cx7CS4AuDAGUACDlbZ7QOsM4wWCxvxlGSt83mCCYps7CPT3+Zs?= =?us-ascii?q?LCOoluP1YI9RYMZTXZcC1JbvJ+4+8du5i8jh+1LSMad5uAZ0xmtq9xSkBUDug?= =?us-ascii?q?=3D=3D?= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3A6+OKzqwZVW8khNUkpm59KrPwEL1zdoMgy1kn?= =?us-ascii?q?xilNoH1uA6ilfqWV8cjzuiWbtN9vYhsdcLy7WZVoIkmskKKdg7NhXotKNTOO0A?= =?us-ascii?q?SVxepZnOnfKlPbexHWx6p00KdMV+xEAsTsMF4St63HyTj9P9E+4NTvysyVuds?= =?us-ascii?q?=3D?= X-IronPort-AV: E=Sophos;i="5.88,320,1635177600"; d="scan'208";a="120913269" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Jan 2022 20:41:07 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id EFDAD4D15A5E; Thu, 27 Jan 2022 20:41:01 +0800 (CST) Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 27 Jan 2022 20:41:02 +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; Thu, 27 Jan 2022 20:40:59 +0800 From: Shiyang Ruan To: , , , , CC: , , , , , Christoph Hellwig Subject: [PATCH v10 3/9] pagemap,pmem: Introduce ->memory_failure() Date: Thu, 27 Jan 2022 20:40:52 +0800 Message-ID: <20220127124058.1172422-4-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127124058.1172422-1-ruansy.fnst@fujitsu.com> References: <20220127124058.1172422-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: EFDAD4D15A5E.A503C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/nvdimm/pmem.c | 16 ++++++++++++++++ include/linux/memremap.h | 12 ++++++++++++ mm/memory-failure.c | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 58d95242a836..0a6e8698d086 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); } +static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap, + unsigned long pfn, u64 len, int mf_flags) +{ + struct pmem_device *pmem = + container_of(pgmap, struct pmem_device, pgmap); + u64 offset = PFN_PHYS(pfn) - 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 = { + .memory_failure = 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 = PFN_DEV; if (is_nd_pfn(dev)) { pmem->pgmap.type = MEMORY_DEVICE_FS_DAX; + pmem->pgmap.ops = &fsdax_pagemap_ops; addr = devm_memremap_pages(dev, &pmem->pgmap); pfn_sb = nd_pfn->pfn_sb; pmem->data_offset = le64_to_cpu(pfn_sb->dataoff); @@ -440,6 +455,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pgmap.range.end = res->end; pmem->pgmap.nr_range = 1; pmem->pgmap.type = MEMORY_DEVICE_FS_DAX; + pmem->pgmap.ops = &fsdax_pagemap_ops; addr = devm_memremap_pages(dev, &pmem->pgmap); pmem->pfn_flags |= PFN_MAP; bb_range = pmem->pgmap.range; diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 1fafcc38acba..f739318b496f 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, unsigned long pfn, + u64 len, int mf_flags); }; #define PGMAP_ALTMAP_VALID (1 << 0) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 98b6144e4b9b..b2d13eba1071 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1663,6 +1663,20 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, if (!pgmap_pfn_valid(pgmap, pfn)) goto out; + /* + * Call driver's implementation to handle the memory failure, otherwise + * fall back to generic handler. + */ + if (pgmap->ops->memory_failure) { + rc = pgmap->ops->memory_failure(pgmap, pfn, PAGE_SIZE, flags); + /* + * Fall back to generic handler too if operation is not + * supported inside the driver/device/filesystem. + */ + if (rc != -EOPNOTSUPP) + goto out; + } + rc = mf_generic_kill_procs(pfn, flags, pgmap); out: /* drop pgmap ref acquired in caller */ -- 2.34.1