Skip to content

Commit 33a8f7f

Browse files
iridesakpm00
authored andcommitted
pagemap,pmem: introduce ->memory_failure()
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. Link: https://lkml.kernel.org/r/20220603053738.1218681-4-ruansy.fnst@fujitsu.com Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dan Williams <dan.j.wiliams@intel.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Goldwyn Rodrigues <rgoldwyn@suse.com> Cc: Goldwyn Rodrigues <rgoldwyn@suse.de> Cc: Jane Chu <jane.chu@oracle.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Ritesh Harjani <riteshh@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 00cc790 commit 33a8f7f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

drivers/nvdimm/pmem.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ static void pmem_release_disk(void *__pmem)
453453
blk_cleanup_disk(pmem->disk);
454454
}
455455

456+
static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap,
457+
unsigned long pfn, unsigned long nr_pages, int mf_flags)
458+
{
459+
struct pmem_device *pmem =
460+
container_of(pgmap, struct pmem_device, pgmap);
461+
u64 offset = PFN_PHYS(pfn) - pmem->phys_addr - pmem->data_offset;
462+
u64 len = nr_pages << PAGE_SHIFT;
463+
464+
return dax_holder_notify_failure(pmem->dax_dev, offset, len, mf_flags);
465+
}
466+
467+
static const struct dev_pagemap_ops fsdax_pagemap_ops = {
468+
.memory_failure = pmem_pagemap_memory_failure,
469+
};
470+
456471
static int pmem_attach_disk(struct device *dev,
457472
struct nd_namespace_common *ndns)
458473
{
@@ -514,6 +529,7 @@ static int pmem_attach_disk(struct device *dev,
514529
pmem->pfn_flags = PFN_DEV;
515530
if (is_nd_pfn(dev)) {
516531
pmem->pgmap.type = MEMORY_DEVICE_FS_DAX;
532+
pmem->pgmap.ops = &fsdax_pagemap_ops;
517533
addr = devm_memremap_pages(dev, &pmem->pgmap);
518534
pfn_sb = nd_pfn->pfn_sb;
519535
pmem->data_offset = le64_to_cpu(pfn_sb->dataoff);
@@ -527,6 +543,7 @@ static int pmem_attach_disk(struct device *dev,
527543
pmem->pgmap.range.end = res->end;
528544
pmem->pgmap.nr_range = 1;
529545
pmem->pgmap.type = MEMORY_DEVICE_FS_DAX;
546+
pmem->pgmap.ops = &fsdax_pagemap_ops;
530547
addr = devm_memremap_pages(dev, &pmem->pgmap);
531548
pmem->pfn_flags |= PFN_MAP;
532549
bb_range = pmem->pgmap.range;

include/linux/memremap.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ struct dev_pagemap_ops {
8787
* the page back to a CPU accessible page.
8888
*/
8989
vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf);
90+
91+
/*
92+
* Handle the memory failure happens on a range of pfns. Notify the
93+
* processes who are using these pfns, and try to recover the data on
94+
* them if necessary. The mf_flags is finally passed to the recover
95+
* function through the whole notify routine.
96+
*
97+
* When this is not implemented, or it returns -EOPNOTSUPP, the caller
98+
* will fall back to a common handler called mf_generic_kill_procs().
99+
*/
100+
int (*memory_failure)(struct dev_pagemap *pgmap, unsigned long pfn,
101+
unsigned long nr_pages, int mf_flags);
90102
};
91103

92104
#define PGMAP_ALTMAP_VALID (1 << 0)

mm/memory-failure.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,20 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags,
17481748
if (!pgmap_pfn_valid(pgmap, pfn))
17491749
goto out;
17501750

1751+
/*
1752+
* Call driver's implementation to handle the memory failure, otherwise
1753+
* fall back to generic handler.
1754+
*/
1755+
if (pgmap->ops->memory_failure) {
1756+
rc = pgmap->ops->memory_failure(pgmap, pfn, 1, flags);
1757+
/*
1758+
* Fall back to generic handler too if operation is not
1759+
* supported inside the driver/device/filesystem.
1760+
*/
1761+
if (rc != -EOPNOTSUPP)
1762+
goto out;
1763+
}
1764+
17511765
rc = mf_generic_kill_procs(pfn, flags, pgmap);
17521766
out:
17531767
/* drop pgmap ref acquired in caller */

0 commit comments

Comments
 (0)