[RFC PATCH v2 4/6] pagemap: introduce ->memory_failure()

Shiyang Ruan
2020-11-23T00:41:51Z

When memory-failure occurs, we call this function which is implemented
by each devices. For fsdax, pmem device implements it. Pmem device
will find out the block device where the error page located in, gets the
filesystem on this block device, and finally call ->storage_lost() to
handle the error in filesystem layer.

Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
---
drivers/nvdimm/pmem.c | 23 +++++++++++++++++++++++
include/linux/memremap.h | 3 +++
2 files changed, 26 insertions(+)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index d75a3f370f3c..1b1dbca090fa 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -390,9 +390,32 @@ static void pmem_release_disk(void *__pmem)
put_disk(pmem->disk);
}

+static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap,
+ struct mf_recover_controller *mfrc)
+{
+ struct pmem_device *pdev;
+ struct gendisk *disk;
+ loff_t disk_offset;
+ int rc = 0;
+
+ pdev = container_of(pgmap, struct pmem_device, pgmap);
+ disk = pdev->disk;
+ if (!disk)
+ return -ENXIO;
+
+ disk_offset = PFN_PHYS(mfrc->pfn) - pdev->phys_addr - pdev->data_offset;
+ if (disk->fops->block_lost) {
+ rc = disk->fops->block_lost(disk, NULL, disk_offset, mfrc);
+ if (rc == -ENODEV)
+ rc = -ENXIO;
+ }
+ return rc;
+}
+
static const struct dev_pagemap_ops fsdax_pagemap_ops = {
.kill = pmem_pagemap_kill,
.cleanup = pmem_pagemap_cleanup,
+ .memory_failure = pmem_pagemap_memory_failure,
};

static int pmem_attach_disk(struct device *dev,
diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 79c49e7f5c30..6aae0fe394ba 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -7,6 +7,7 @@

struct resource;
struct device;
+struct mf_recover_controller;

/**
* struct vmem_altmap - pre-allocated storage for vmemmap_populate
@@ -87,6 +88,8 @@ struct dev_pagemap_ops {
* the page back to a CPU accessible page.
*/
vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf);
+ int (*memory_failure)(struct dev_pagemap *pgmap,
+ struct mf_recover_controller *mfrc);
};

#define PGMAP_ALTMAP_VALID (1 << 0)
--
2.29.2