Skip to contentSkip to conversation

Dax poison recovery

PATCH Superseded Jane Chu 6 participants 21 messages Nov 6, 2021 – Nov 12, 2021

Subsystems (9)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Jane Chu

author
#0 lore raw

v2 cover Dax poison recovery

Up till now, the method commonly used for data recovery from dax media error has been a combination of hole-punch followed by a pwrite(2). The downside of this method is that it causes fragmentation of the pmem backend, which brings a host of very challenging issues.

This patch is an attempt to provide an alternative way for dax users to perform data recovery from pmem media error without fragmenting the pmem backend.

Dax media error may be manifested to user process via SIGBUS with .si_code BUS_MCEERR_AR when a load instruction consumes a poison in the media, or SIGBUS with .si_code BUS_ADRERR when a page fault handler fails to resolve due to existing poison record, or IO error returned from a block read or write.

With the patch in place, the way for user process to recover the data can be just a pwrite(2) to a page aligned range without the need to punch-a-hole. In case of BUS_MCEERR_AR, the range is incidated by the signal payload: .si_addr and .si_addr_lsb. In case of BUS_ADRERR, the range is the user mapping page size starting from .si_addr. If the clue of media error come from block IO error, the range is a stretch of the block IO range to page aligned range.

Changes from v1:
- instead of giving user the say to start dax data recovery, let dax-filesystem decide when to enter data recovery mode. Hence 99% of the non-dax usage of pwrite and its variants aren't aware of dax specific recovering.
- Instead of exporting dax_clear_error() API that does one thing, combine dax {poison-clearing, error-record-update, writing-good-data} in one tight operation to better protect data integrity.
- some semantics and format fixes

v1:
https://lore.kernel.org/lkml/[email protected]/T/

Jane Chu (2):
dax: Introduce normal and recovery dax operation modes dax,pmem: Implement pmem based dax data recovery

 drivers/dax/super.c             | 15 +++---
 drivers/md/dm-linear.c          | 14 +++---
 drivers/md/dm-log-writes.c      | 19 +++++---
 drivers/md/dm-stripe.c          | 14 +++---
 drivers/md/dm-target.c          |  2 +-
 drivers/md/dm-writecache.c      |  8 +--
 drivers/md/dm.c                 | 16 +++---
 drivers/nvdimm/pmem.c           | 86 +++++++++++++++++++++++++++++----
 drivers/nvdimm/pmem.h           |  2 +-
 drivers/s390/block/dcssblk.c    | 13 +++--
 fs/dax.c                        | 32 +++++++++---
 fs/fuse/dax.c                   |  4 +-
 fs/fuse/virtio_fs.c             | 12 +++--
 include/linux/dax.h             | 18 ++++---
 include/linux/device-mapper.h   |  5 +-
 tools/testing/nvdimm/pmem-dax.c |  2 +-
 16 files changed, 187 insertions(+), 75 deletions(-)
Signature · 1 line
2.18.4
author
#1 lore raw

PATCH v2 1/2 dax: Introduce normal and recovery dax operation modes

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

---
 drivers/dax/super.c             | 15 +++++++++------
 drivers/md/dm-linear.c          | 14 ++++++++------
 drivers/md/dm-log-writes.c      | 19 +++++++++++--------
 drivers/md/dm-stripe.c          | 14 ++++++++------
 drivers/md/dm-target.c          |  2 +-
 drivers/md/dm-writecache.c      |  8 +++++---
 drivers/md/dm.c                 | 14 ++++++++------
 drivers/nvdimm/pmem.c           | 11 ++++++-----
 drivers/nvdimm/pmem.h           |  2 +-
 drivers/s390/block/dcssblk.c    | 13 ++++++++-----
 fs/dax.c                        | 14 ++++++++------
 fs/fuse/dax.c                   |  4 ++--
 fs/fuse/virtio_fs.c             | 12 ++++++++----
 include/linux/dax.h             | 18 +++++++++++-------
 include/linux/device-mapper.h   |  5 +++--
 tools/testing/nvdimm/pmem-dax.c |  2 +-
 16 files changed, 98 insertions(+), 69 deletions(-)
drivers/dax/super.c +9 -6
index c0910687fbcb..90cae9d84b9c 100644
@@ -110,6 +110,7 @@ enum dax_device_flags {
  * @dax_dev: a dax_device instance representing the logical memory range
  * @pgoff: offset in pages from the start of the device to translate
  * @nr_pages: number of consecutive pages caller can handle relative to @pfn
+ * @mode: indicate whether dax operation is in normal or recovery mode
  * @kaddr: output parameter that returns a virtual address mapping of pfn
  * @pfn: output parameter that returns an absolute pfn translation of @pgoff
  *
@@ -117,7 +118,7 @@ enum dax_device_flags {
  * pages accessible at the device relative @pgoff.
  */
 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-		void **kaddr, pfn_t *pfn)
+		int mode, void **kaddr, pfn_t *pfn)
 {
 	long avail;
 
@@ -131,7 +132,7 @@ long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
 		return -EINVAL;
 
 	avail = dax_dev->ops->direct_access(dax_dev, pgoff, nr_pages,
-			kaddr, pfn);
+			mode, kaddr, pfn);
 	if (!avail)
 		return -ERANGE;
 	return min(avail, nr_pages);
@@ -139,22 +140,24 @@ long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
 EXPORT_SYMBOL_GPL(dax_direct_access);
 
 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i)
+		size_t bytes, struct iov_iter *i, int mode)
 {
 	if (!dax_alive(dax_dev))
 		return 0;
 
-	return dax_dev->ops->copy_from_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_dev->ops->copy_from_iter(dax_dev, pgoff, addr, bytes, i,
+						mode);
 }
 EXPORT_SYMBOL_GPL(dax_copy_from_iter);
 
 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i)
+		size_t bytes, struct iov_iter *i, int mode)
 {
 	if (!dax_alive(dax_dev))
 		return 0;
 
-	return dax_dev->ops->copy_to_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_dev->ops->copy_to_iter(dax_dev, pgoff, addr, bytes, i,
+						mode);
 }
 EXPORT_SYMBOL_GPL(dax_copy_to_iter);
 
drivers/md/dm-linear.c +8 -6
index 90de42f6743a..c73ac6b98801 100644
@@ -173,27 +173,29 @@ static struct dax_device *linear_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff)
 }
 
 static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff);
 
-	return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
+	return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn);
 }
 
 static size_t linear_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff);
 
-	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff);
 
-	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
drivers/md/dm-log-writes.c +11 -8
index df3cd78223fb..1e9847f904ef 100644
@@ -959,16 +959,18 @@ static struct dax_device *log_writes_dax_pgoff(struct dm_target *ti,
 }
 
 static long log_writes_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
-					 long nr_pages, void **kaddr, pfn_t *pfn)
+					 long nr_pages, int mode,
+					 void **kaddr, pfn_t *pfn)
 {
 	struct dax_device *dax_dev = log_writes_dax_pgoff(ti, &pgoff);
 
-	return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
+	return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn);
 }
 
 static size_t log_writes_dax_copy_from_iter(struct dm_target *ti,
-					    pgoff_t pgoff, void *addr, size_t bytes,
-					    struct iov_iter *i)
+					    pgoff_t pgoff, void *addr,
+					    size_t bytes, struct iov_iter *i,
+					    int mode)
 {
 	struct log_writes_c *lc = ti->private;
 	sector_t sector = pgoff * PAGE_SECTORS;
@@ -985,16 +987,17 @@ static size_t log_writes_dax_copy_from_iter(struct dm_target *ti,
 		return 0;
 	}
 dax_copy:
-	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static size_t log_writes_dax_copy_to_iter(struct dm_target *ti,
-					  pgoff_t pgoff, void *addr, size_t bytes,
-					  struct iov_iter *i)
+					  pgoff_t pgoff, void *addr,
+					  size_t bytes, struct iov_iter *i,
+					  int mode)
 {
 	struct dax_device *dax_dev = log_writes_dax_pgoff(ti, &pgoff);
 
-	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static int log_writes_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
drivers/md/dm-stripe.c +8 -6
index 50dba3f39274..4c098452268b 100644
@@ -317,27 +317,29 @@ static struct dax_device *stripe_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff)
 }
 
 static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
 
-	return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
+	return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn);
 }
 
 static size_t stripe_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
 
-	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static size_t stripe_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
 
-	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
+	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i, mode);
 }
 
 static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
drivers/md/dm-target.c +1 -1
index 64dd0b34fcf4..2de1073dbad6 100644
@@ -142,7 +142,7 @@ static void io_err_release_clone_rq(struct request *clone,
 }
 
 static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	return -EIO;
 }
drivers/md/dm-writecache.c +5 -3
index 0af464a863fe..b2e4ff922fe2 100644
@@ -286,7 +286,8 @@ static int persistent_memory_claim(struct dm_writecache *wc)
 
 	id = dax_read_lock();
 
-	da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, &wc->memory_map, &pfn);
+	da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, DAX_OP_NORMAL,
+				&wc->memory_map, &pfn);
 	if (da < 0) {
 		wc->memory_map = NULL;
 		r = da;
@@ -308,8 +309,9 @@ static int persistent_memory_claim(struct dm_writecache *wc)
 		i = 0;
 		do {
 			long daa;
-			daa = dax_direct_access(wc->ssd_dev->dax_dev, offset + i, p - i,
-						NULL, &pfn);
+			daa = dax_direct_access(wc->ssd_dev->dax_dev,
+						offset + i, p - i,
+						DAX_OP_NORMAL, NULL, &pfn);
 			if (daa <= 0) {
 				r = daa ? daa : -EINVAL;
 				goto err3;
drivers/md/dm.c +8 -6
index 282008afc465..dc354db22ef9 100644
@@ -1001,7 +1001,8 @@ static struct dm_target *dm_dax_get_live_target(struct mapped_device *md,
 }
 
 static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
-				 long nr_pages, void **kaddr, pfn_t *pfn)
+				 long nr_pages, int mode, void **kaddr,
+				 pfn_t *pfn)
 {
 	struct mapped_device *md = dax_get_private(dax_dev);
 	sector_t sector = pgoff * PAGE_SECTORS;
@@ -1019,7 +1020,7 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	if (len < 1)
 		goto out;
 	nr_pages = min(len, nr_pages);
-	ret = ti->type->direct_access(ti, pgoff, nr_pages, kaddr, pfn);
+	ret = ti->type->direct_access(ti, pgoff, nr_pages, mode, kaddr, pfn);
 
  out:
 	dm_put_live_table(md, srcu_idx);
@@ -1028,7 +1029,8 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 }
 
 static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
-				    void *addr, size_t bytes, struct iov_iter *i)
+				    void *addr, size_t bytes,
+				    struct iov_iter *i, int mode)
 {
 	struct mapped_device *md = dax_get_private(dax_dev);
 	sector_t sector = pgoff * PAGE_SECTORS;
@@ -1044,7 +1046,7 @@ static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 		ret = copy_from_iter(addr, bytes, i);
 		goto out;
 	}
-	ret = ti->type->dax_copy_from_iter(ti, pgoff, addr, bytes, i);
+	ret = ti->type->dax_copy_from_iter(ti, pgoff, addr, bytes, i, mode);
  out:
 	dm_put_live_table(md, srcu_idx);
 
@@ -1052,7 +1054,7 @@ static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 }
 
 static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
 	struct mapped_device *md = dax_get_private(dax_dev);
 	sector_t sector = pgoff * PAGE_SECTORS;
@@ -1068,7 +1070,7 @@ static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 		ret = copy_to_iter(addr, bytes, i);
 		goto out;
 	}
-	ret = ti->type->dax_copy_to_iter(ti, pgoff, addr, bytes, i);
+	ret = ti->type->dax_copy_to_iter(ti, pgoff, addr, bytes, i, mode);
  out:
 	dm_put_live_table(md, srcu_idx);
 
drivers/nvdimm/pmem.c +6 -5
index 0d6633987552..3dc99e0bf633 100644
@@ -255,7 +255,7 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
 
 /* see "strong" declaration in tools/testing/nvdimm/pmem-dax.c */
 __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset;
 
@@ -294,11 +294,12 @@ static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 }
 
 static long pmem_dax_direct_access(struct dax_device *dax_dev,
-		pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn)
+		pgoff_t pgoff, long nr_pages, int mode, void **kaddr,
+		pfn_t *pfn)
 {
 	struct pmem_device *pmem = dax_get_private(dax_dev);
 
-	return __pmem_direct_access(pmem, pgoff, nr_pages, kaddr, pfn);
+	return __pmem_direct_access(pmem, pgoff, nr_pages, mode, kaddr, pfn);
 }
 
 /*
@@ -308,13 +309,13 @@ static long pmem_dax_direct_access(struct dax_device *dax_dev,
  * dax_iomap_actor()
  */
 static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
 	return _copy_from_iter_flushcache(addr, bytes, i);
 }
 
 static size_t pmem_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
+		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
 	return _copy_mc_to_iter(addr, bytes, i);
 }
drivers/nvdimm/pmem.h +1 -1
index 59cfe13ea8a8..bda6a898ba81 100644
@@ -27,7 +27,7 @@ struct pmem_device {
 };
 
 long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn);
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn);
 
 #ifdef CONFIG_MEMORY_FAILURE
 static inline bool test_and_clear_pmem_poison(struct page *page)
drivers/s390/block/dcssblk.c +8 -5
index e65e83764d1c..fb9f768e12a1 100644
@@ -32,7 +32,7 @@ static int dcssblk_open(struct block_device *bdev, fmode_t mode);
 static void dcssblk_release(struct gendisk *disk, fmode_t mode);
 static void dcssblk_submit_bio(struct bio *bio);
 static long dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn);
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn);
 
 static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0";
 
@@ -45,13 +45,15 @@ static const struct block_device_operations dcssblk_devops = {
 };
 
 static size_t dcssblk_dax_copy_from_iter(struct dax_device *dax_dev,
-		pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i)
+		pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	return copy_from_iter(addr, bytes, i);
 }
 
 static size_t dcssblk_dax_copy_to_iter(struct dax_device *dax_dev,
-		pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i)
+		pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i,
+		int mode)
 {
 	return copy_to_iter(addr, bytes, i);
 }
@@ -62,7 +64,8 @@ static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
 	long rc;
 	void *kaddr;
 
-	rc = dax_direct_access(dax_dev, pgoff, nr_pages, &kaddr, NULL);
+	rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_OP_NORMAL,
+			       &kaddr, NULL);
 	if (rc < 0)
 		return rc;
 	memset(kaddr, 0, nr_pages << PAGE_SHIFT);
@@ -941,7 +944,7 @@ __dcssblk_direct_access(struct dcssblk_dev_info *dev_info, pgoff_t pgoff,
 
 static long
 dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	struct dcssblk_dev_info *dev_info = dax_get_private(dax_dev);
 
fs/dax.c +8 -6
index eb715363fd66..bea6df1498c3 100644
@@ -735,7 +735,8 @@ static int copy_cow_page_dax(struct block_device *bdev, struct dax_device *dax_d
 		return rc;
 
 	id = dax_read_lock();
-	rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL);
+	rc = dax_direct_access(dax_dev, pgoff, 1, DAX_OP_NORMAL, &kaddr,
+			       NULL);
 	if (rc < 0) {
 		dax_read_unlock(id);
 		return rc;
@@ -1036,7 +1037,7 @@ static int dax_iomap_pfn(const struct iomap *iomap, loff_t pos, size_t size,
 		return rc;
 	id = dax_read_lock();
 	length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size),
-				   NULL, pfnp);
+				   DAX_OP_NORMAL, NULL, pfnp);
 	if (length < 0) {
 		rc = length;
 		goto out;
@@ -1162,7 +1163,8 @@ s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap)
 	if (page_aligned)
 		rc = dax_zero_page_range(iomap->dax_dev, pgoff, 1);
 	else
-		rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &kaddr, NULL);
+		rc = dax_direct_access(iomap->dax_dev, pgoff, 1,
+				       DAX_OP_NORMAL, &kaddr, NULL);
 	if (rc < 0) {
 		dax_read_unlock(id);
 		return rc;
@@ -1231,7 +1233,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 			break;
 
 		map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
-				&kaddr, NULL);
+					    DAX_OP_NORMAL, &kaddr, NULL);
 		if (map_len < 0) {
 			ret = map_len;
 			break;
@@ -1250,10 +1252,10 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		 */
 		if (iov_iter_rw(iter) == WRITE)
 			xfer = dax_copy_from_iter(dax_dev, pgoff, kaddr,
-					map_len, iter);
+					map_len, iter, DAX_OP_NORMAL);
 		else
 			xfer = dax_copy_to_iter(dax_dev, pgoff, kaddr,
-					map_len, iter);
+					map_len, iter, DAX_OP_NORMAL);
 
 		pos += xfer;
 		length -= xfer;
fs/fuse/dax.c +2 -2
index 713818d74de6..755d8d4b7d34 100644
@@ -1241,8 +1241,8 @@ static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd)
 	INIT_DELAYED_WORK(&fcd->free_work, fuse_dax_free_mem_worker);
 
 	id = dax_read_lock();
-	nr_pages = dax_direct_access(fcd->dev, 0, PHYS_PFN(dax_size), NULL,
-				     NULL);
+	nr_pages = dax_direct_access(fcd->dev, 0, PHYS_PFN(dax_size),
+				     DAX_OP_NORMAL, NULL, NULL);
 	dax_read_unlock(id);
 	if (nr_pages < 0) {
 		pr_debug("dax_direct_access() returned %ld\n", nr_pages);
fs/fuse/virtio_fs.c +8 -4
index b4c7c7fa987f..fb5433a37a7b 100644
@@ -739,7 +739,8 @@ static void virtio_fs_cleanup_vqs(struct virtio_device *vdev,
  * offset.
  */
 static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
-				    long nr_pages, void **kaddr, pfn_t *pfn)
+				    long nr_pages, int mode, void **kaddr,
+				    pfn_t *pfn)
 {
 	struct virtio_fs *fs = dax_get_private(dax_dev);
 	phys_addr_t offset = PFN_PHYS(pgoff);
@@ -755,14 +756,16 @@ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 
 static size_t virtio_fs_copy_from_iter(struct dax_device *dax_dev,
 				       pgoff_t pgoff, void *addr,
-				       size_t bytes, struct iov_iter *i)
+				       size_t bytes, struct iov_iter *i,
+				       int mode)
 {
 	return copy_from_iter(addr, bytes, i);
 }
 
 static size_t virtio_fs_copy_to_iter(struct dax_device *dax_dev,
 				       pgoff_t pgoff, void *addr,
-				       size_t bytes, struct iov_iter *i)
+				       size_t bytes, struct iov_iter *i,
+				       int mode)
 {
 	return copy_to_iter(addr, bytes, i);
 }
@@ -773,7 +776,8 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 	long rc;
 	void *kaddr;
 
-	rc = dax_direct_access(dax_dev, pgoff, nr_pages, &kaddr, NULL);
+	rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_OP_NORMAL,
+			       &kaddr, NULL);
 	if (rc < 0)
 		return rc;
 	memset(kaddr, 0, nr_pages << PAGE_SHIFT);
include/linux/dax.h +11 -7
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
 /* Flag for synchronous flush */
 #define DAXDEV_F_SYNC (1UL << 0)
 
+/* dax operation mode dynamically set by caller */
+#define	DAX_OP_NORMAL		0
+#define	DAX_OP_RECOVERY		1
+
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
 	 * logical-page-offset into an absolute physical pfn. Return the
 	 * number of pages available for DAX at that pfn.
 	 */
-	long (*direct_access)(struct dax_device *, pgoff_t, long,
-			void **, pfn_t *);
+	long (*direct_access)(struct dax_device *, pgoff_t, long, int,
+				void **, pfn_t *);
 	/*
 	 * Validate whether this device is usable as an fsdax backing
 	 * device.
@@ -32,10 +36,10 @@ struct dax_operations {
 			sector_t, sector_t);
 	/* copy_from_iter: required operation for fs-dax direct-i/o */
 	size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-			struct iov_iter *);
+			struct iov_iter *, int);
 	/* copy_to_iter: required operation for fs-dax direct-i/o */
 	size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
-			struct iov_iter *);
+			struct iov_iter *, int);
 	/* zero_page_range: required operation. Zero page range   */
 	int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
 };
@@ -186,11 +190,11 @@ static inline void dax_read_unlock(int id)
 bool dax_alive(struct dax_device *dax_dev);
 void *dax_get_private(struct dax_device *dax_dev);
 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-		void **kaddr, pfn_t *pfn);
+		int mode, void **kaddr, pfn_t *pfn);
 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i);
+		size_t bytes, struct iov_iter *i, int mode);
 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i);
+		size_t bytes, struct iov_iter *i, int mode);
 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 			size_t nr_pages);
 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
include/linux/device-mapper.h +3 -2
index a7df155ea49b..6596a8e0ceed 100644
@@ -146,9 +146,10 @@ typedef int (*dm_busy_fn) (struct dm_target *ti);
  * >= 0 : the number of bytes accessible at the address
  */
 typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn);
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn);
 typedef size_t (*dm_dax_copy_iter_fn)(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i);
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode);
 typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,
 		size_t nr_pages);
 
tools/testing/nvdimm/pmem-dax.c +1 -1
index af19c85558e7..71c225630e7e 100644
@@ -8,7 +8,7 @@
 #include <nd.h>
 
 long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset;
 
Signature · 1 line
2.18.4
#2 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

Quoted 35 lines · Jane Chu

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

---
 drivers/dax/super.c             | 15 +++++++++------
 drivers/md/dm-linear.c          | 14 ++++++++------
 drivers/md/dm-log-writes.c      | 19 +++++++++++--------
 drivers/md/dm-stripe.c          | 14 ++++++++------
 drivers/md/dm-target.c          |  2 +-
 drivers/md/dm-writecache.c      |  8 +++++---
 drivers/md/dm.c                 | 14 ++++++++------
 drivers/nvdimm/pmem.c           | 11 ++++++-----
 drivers/nvdimm/pmem.h           |  2 +-
 drivers/s390/block/dcssblk.c    | 13 ++++++++-----
 fs/dax.c                        | 14 ++++++++------
 fs/fuse/dax.c                   |  4 ++--
 fs/fuse/virtio_fs.c             | 12 ++++++++----
 include/linux/dax.h             | 18 +++++++++++-------
 include/linux/device-mapper.h   |  5 +++--
 tools/testing/nvdimm/pmem-dax.c |  2 +-
 16 files changed, 98 insertions(+), 69 deletions(-)

<snip>

include/linux/dax.h line 14

Quoted 11 lines
include/linux/dax.h +3 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
 /* Flag for synchronous flush */
 #define DAXDEV_F_SYNC (1UL << 0)
 
+/* dax operation mode dynamically set by caller */
+#define	DAX_OP_NORMAL		0
+#define	DAX_OP_RECOVERY		1

Mostly looks ok to me, but since this is an operation mode, should this be an enum instead of an int?

Granted I also think six arguments is a lot... though I don't really see any better way to do this.

(Dunno, I spent all day running internal patches through the process gauntlet so this is the remaining 2% of my brain speaking...)

--D

Quoted 76 lines
include/linux/dax.h +8 -7
+
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
 	 * logical-page-offset into an absolute physical pfn. Return the
 	 * number of pages available for DAX at that pfn.
 	 */
-	long (*direct_access)(struct dax_device *, pgoff_t, long,
-			void **, pfn_t *);
+	long (*direct_access)(struct dax_device *, pgoff_t, long, int,
+				void **, pfn_t *);
 	/*
 	 * Validate whether this device is usable as an fsdax backing
 	 * device.
@@ -32,10 +36,10 @@ struct dax_operations {
 			sector_t, sector_t);
 	/* copy_from_iter: required operation for fs-dax direct-i/o */
 	size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-			struct iov_iter *);
+			struct iov_iter *, int);
 	/* copy_to_iter: required operation for fs-dax direct-i/o */
 	size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
-			struct iov_iter *);
+			struct iov_iter *, int);
 	/* zero_page_range: required operation. Zero page range   */
 	int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
 };
@@ -186,11 +190,11 @@ static inline void dax_read_unlock(int id)
 bool dax_alive(struct dax_device *dax_dev);
 void *dax_get_private(struct dax_device *dax_dev);
 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-		void **kaddr, pfn_t *pfn);
+		int mode, void **kaddr, pfn_t *pfn);
 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i);
+		size_t bytes, struct iov_iter *i, int mode);
 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
-		size_t bytes, struct iov_iter *i);
+		size_t bytes, struct iov_iter *i, int mode);
 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 			size_t nr_pages);
 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
include/linux/device-mapper.h +3 -2
index a7df155ea49b..6596a8e0ceed 100644
@@ -146,9 +146,10 @@ typedef int (*dm_busy_fn) (struct dm_target *ti);
  * >= 0 : the number of bytes accessible at the address
  */
 typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn);
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn);
 typedef size_t (*dm_dax_copy_iter_fn)(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i);
+		void *addr, size_t bytes, struct iov_iter *i,
+		int mode);
 typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,
 		size_t nr_pages);
 
tools/testing/nvdimm/pmem-dax.c +1 -1
index af19c85558e7..71c225630e7e 100644
@@ -8,7 +8,7 @@
 #include <nd.h>
 
 long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
-		long nr_pages, void **kaddr, pfn_t *pfn)
+		long nr_pages, int mode, void **kaddr, pfn_t *pfn)
 {
 	resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset;
 
Signature · 1 line
2.18.4
author
#3 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

Quoted 11 lines · Darrick J. Wong

<snip>

Quoted 8 lines
include/linux/dax.h +0 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
  /* Flag for synchronous flush */
  #define DAXDEV_F_SYNC (1UL << 0)
 
Quoted 6 lines

include/linux/dax.h line 14

Quoted 3 lines
include/linux/dax.h +3 -0
+/* dax operation mode dynamically set by caller */
+#define	DAX_OP_NORMAL		0
+#define	DAX_OP_RECOVERY		1

Mostly looks ok to me, but since this is an operation mode, should this be an enum instead of an int?

Yeah, I tried enum at first, and then noticed that the new dax enum type need to be introduced to device-mapper.h by either include dax.h or define a mirrored enum, and I wondered if that would be an over kill, so I ended up settle on #define.

Quoted 3 lines

Granted I also think six arguments is a lot... though I don't really see any better way to do this.

Dan has a suggestion, and that'll reduce the number of args to 5.

Quoted 3 lines

(Dunno, I spent all day running internal patches through the process gauntlet so this is the remaining 2% of my brain speaking...)

Thanks!
-jane

Quoted 3 lines

--D

#4 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

In reply to Jane Chu
Quoted 17 lines · Jane Chu

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

[..]

include/linux/dax.h line 13

Quoted 10 lines
include/linux/dax.h +2 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
 /* Flag for synchronous flush */
 #define DAXDEV_F_SYNC (1UL << 0)
 
+/* dax operation mode dynamically set by caller */
+#define        DAX_OP_NORMAL           0

Perhaps this should be called DAX_OP_FAILFAST?

include/linux/dax.h struct dax_operations { · line 29

Quoted 12 lines
include/linux/dax.h +3 -2
+#define        DAX_OP_RECOVERY         1
+
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
         * logical-page-offset into an absolute physical pfn. Return the
         * number of pages available for DAX at that pfn.
         */
-       long (*direct_access)(struct dax_device *, pgoff_t, long,
-                       void **, pfn_t *);
+       long (*direct_access)(struct dax_device *, pgoff_t, long, int,

Would be nice if that 'int' was an enum, but I'm not sure a new parameter is needed at all, see below...

include/linux/dax.h struct dax_operations { · line 39

Quoted 10 lines
include/linux/dax.h +2 -1
+                               void **, pfn_t *);
        /*
         * Validate whether this device is usable as an fsdax backing
         * device.
@@ -32,10 +36,10 @@ struct dax_operations {
                        sector_t, sector_t);
        /* copy_from_iter: required operation for fs-dax direct-i/o */
        size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

I'm not sure the flag is needed here as the "void *" could carry a flag in the pointer to indicate that is a recovery kaddr.

include/linux/dax.h struct dax_operations { · line 42

Quoted 4 lines
include/linux/dax.h +1 -1
        /* copy_to_iter: required operation for fs-dax direct-i/o */
        size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

Same comment here.

include/linux/dax.h static inline void dax_read_unlock(int id) · line 193

Quoted 9 lines
include/linux/dax.h +1 -1
        /* zero_page_range: required operation. Zero page range   */
        int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
 };
@@ -186,11 +190,11 @@ static inline void dax_read_unlock(int id)
 bool dax_alive(struct dax_device *dax_dev);
 void *dax_get_private(struct dax_device *dax_dev);
 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-               void **kaddr, pfn_t *pfn);
+               int mode, void **kaddr, pfn_t *pfn);

How about dax_direct_access() calling convention stays the same, but the kaddr is optionally updated to carry a flag in the lower unused bits. So:

void **kaddr = NULL; /* caller only cares about the pfn */

void *failfast = NULL;
void **kaddr = &failfast; /* caller wants -EIO not recovery */

void *recovery = (void *) DAX_OP_RECOVERY;
void **kaddr = &recovery; /* caller wants to carefully access page(s) containing poison */

author
#5 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

Quoted 27 lines · Dan Williams
Quoted 17 lines · Jane Chu

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

[..]

Quoted 8 lines
include/linux/dax.h +0 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
  /* Flag for synchronous flush */
  #define DAXDEV_F_SYNC (1UL << 0)
 
Quoted 4 lines

include/linux/dax.h line 13

Quoted 2 lines
include/linux/dax.h +2 -0
+/* dax operation mode dynamically set by caller */
+#define        DAX_OP_NORMAL           0

Perhaps this should be called DAX_OP_FAILFAST?

Sure.

Quoted 5 lines
Quoted 5 lines
include/linux/dax.h +2 -0
+#define        DAX_OP_RECOVERY         1
+
  typedef unsigned long dax_entry_t;
 
Quoted 11 lines

include/linux/dax.h struct dax_operations { · line 29

Quoted 8 lines
include/linux/dax.h +1 -2
  struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
          * logical-page-offset into an absolute physical pfn. Return the
          * number of pages available for DAX at that pfn.
          */
-       long (*direct_access)(struct dax_device *, pgoff_t, long,
-                       void **, pfn_t *);
+       long (*direct_access)(struct dax_device *, pgoff_t, long, int,

Would be nice if that 'int' was an enum, but I'm not sure a new parameter is needed at all, see below...

Let's do your suggestion below. :)

Quoted 14 lines

include/linux/dax.h struct dax_operations { · line 39

Quoted 11 lines
include/linux/dax.h +2 -1
+                               void **, pfn_t *);
         /*
          * Validate whether this device is usable as an fsdax backing
          * device.
@@ -32,10 +36,10 @@ struct dax_operations {
                         sector_t, sector_t);
         /* copy_from_iter: required operation for fs-dax direct-i/o */
         size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

I'm not sure the flag is needed here as the "void *" could carry a flag in the pointer to indicate that is a recovery kaddr.

Agreed.

Quoted 22 lines

include/linux/dax.h struct dax_operations { · line 42

Quoted 5 lines
include/linux/dax.h +1 -1
         /* copy_to_iter: required operation for fs-dax direct-i/o */
         size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

Same comment here.

include/linux/dax.h static inline void dax_read_unlock(int id) · line 193

Quoted 9 lines
include/linux/dax.h +1 -1
         /* zero_page_range: required operation. Zero page range   */
         int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
  };
@@ -186,11 +190,11 @@ static inline void dax_read_unlock(int id)
  bool dax_alive(struct dax_device *dax_dev);
  void *dax_get_private(struct dax_device *dax_dev);
  long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-               void **kaddr, pfn_t *pfn);
+               int mode, void **kaddr, pfn_t *pfn);

How about dax_direct_access() calling convention stays the same, but the kaddr is optionally updated to carry a flag in the lower unused bits. So:

Quoted 9 lines

void **kaddr = NULL; /* caller only cares about the pfn */

void *failfast = NULL;
void **kaddr = &failfast; /* caller wants -EIO not recovery */

void *recovery = (void *) DAX_OP_RECOVERY;
void **kaddr = &recovery; /* caller wants to carefully access page(s) containing poison */

Got it.

thanks!
-jane

#6 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

Quoted 69 lines · Jane Chu
Quoted 27 lines · Dan Williams
Quoted 17 lines · Jane Chu

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

[..]

Quoted 8 lines
include/linux/dax.h +0 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
  /* Flag for synchronous flush */
  #define DAXDEV_F_SYNC (1UL << 0)
 
Quoted 4 lines

include/linux/dax.h line 13

Quoted 2 lines
include/linux/dax.h +2 -0
+/* dax operation mode dynamically set by caller */
+#define        DAX_OP_NORMAL           0

Perhaps this should be called DAX_OP_FAILFAST?

Sure.

Quoted 5 lines
Quoted 5 lines
include/linux/dax.h +2 -0
+#define        DAX_OP_RECOVERY         1
+
  typedef unsigned long dax_entry_t;
 
Quoted 11 lines

include/linux/dax.h struct dax_operations { · line 29

Quoted 8 lines
include/linux/dax.h +1 -2
  struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
          * logical-page-offset into an absolute physical pfn. Return the
          * number of pages available for DAX at that pfn.
          */
-       long (*direct_access)(struct dax_device *, pgoff_t, long,
-                       void **, pfn_t *);
+       long (*direct_access)(struct dax_device *, pgoff_t, long, int,

Would be nice if that 'int' was an enum, but I'm not sure a new parameter is needed at all, see below...

Let's do your suggestion below. :)

Quoted 14 lines

include/linux/dax.h struct dax_operations { · line 39

Quoted 11 lines
include/linux/dax.h +2 -1
+                               void **, pfn_t *);
         /*
          * Validate whether this device is usable as an fsdax backing
          * device.
@@ -32,10 +36,10 @@ struct dax_operations {
                         sector_t, sector_t);
         /* copy_from_iter: required operation for fs-dax direct-i/o */
         size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

I'm not sure the flag is needed here as the "void *" could carry a flag in the pointer to indicate that is a recovery kaddr.

Quoted 1 line

Agreed.

Not sure if this is implied but I would like some macros or other helper functions to check these flags hidden in the addresses.

For me I'm a bit scared about having flags hidden in the address like this because I can't lead to some confusions IMO.

But if we have some macros or other calls which can make this more obvious of what is going on I think that would help.

Apologies if this was what you were already going to do... :-D

Ira

Quoted 38 lines
Quoted 23 lines

include/linux/dax.h struct dax_operations { · line 42

Quoted 6 lines
include/linux/dax.h +1 -1
         /* copy_to_iter: required operation for fs-dax direct-i/o */
         size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

Same comment here.

include/linux/dax.h static inline void dax_read_unlock(int id) · line 193

Quoted 9 lines
include/linux/dax.h +1 -1
         /* zero_page_range: required operation. Zero page range   */
         int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
  };
@@ -186,11 +190,11 @@ static inline void dax_read_unlock(int id)
  bool dax_alive(struct dax_device *dax_dev);
  void *dax_get_private(struct dax_device *dax_dev);
  long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
-               void **kaddr, pfn_t *pfn);
+               int mode, void **kaddr, pfn_t *pfn);

How about dax_direct_access() calling convention stays the same, but the kaddr is optionally updated to carry a flag in the lower unused bits. So:

Quoted 9 lines

void **kaddr = NULL; /* caller only cares about the pfn */

void *failfast = NULL;
void **kaddr = &failfast; /* caller wants -EIO not recovery */

void *recovery = (void *) DAX_OP_RECOVERY;
void **kaddr = &recovery; /* caller wants to carefully access page(s) containing poison */

Got it.

thanks!
-jane

#7 lore raw

Re: [PATCH v2 1/2] dax: Introduce normal and recovery dax operation modes

Quoted 73 lines · Ira Weiny
Quoted 69 lines · Jane Chu
Quoted 27 lines · Dan Williams
Quoted 17 lines · Jane Chu

Introduce DAX_OP_NORMAL and DAX_OP_RECOVERY operation modes to {dax_direct_access, dax_copy_from_iter, dax_copy_to_iter}. DAX_OP_NORMAL is the default or the existing mode, and DAX_OP_RECOVERY is a new mode for data recovery purpose.

When dax-FS suspects dax media error might be encountered on a read or write, it can enact the recovery mode read or write by setting DAX_OP_RECOVERY in the aforementioned APIs. A read in recovery mode attempts to fetch as much data as possible until the first poisoned page is encountered. A write in recovery mode attempts to clear poison(s) in a page-aligned range and then write the user provided data over.

DAX_OP_NORMAL should be used for all non-recovery code path.

[..]

Quoted 8 lines
include/linux/dax.h +0 -0
index 324363b798ec..931586df2905 100644
@@ -9,6 +9,10 @@
  /* Flag for synchronous flush */
  #define DAXDEV_F_SYNC (1UL << 0)
 
Quoted 4 lines

include/linux/dax.h line 13

Quoted 2 lines
include/linux/dax.h +2 -0
+/* dax operation mode dynamically set by caller */
+#define        DAX_OP_NORMAL           0

Perhaps this should be called DAX_OP_FAILFAST?

Sure.

Quoted 5 lines
Quoted 5 lines
include/linux/dax.h +2 -0
+#define        DAX_OP_RECOVERY         1
+
  typedef unsigned long dax_entry_t;
 
Quoted 11 lines

include/linux/dax.h struct dax_operations { · line 29

Quoted 8 lines
include/linux/dax.h +1 -2
  struct dax_device;
@@ -22,8 +26,8 @@ struct dax_operations {
          * logical-page-offset into an absolute physical pfn. Return the
          * number of pages available for DAX at that pfn.
          */
-       long (*direct_access)(struct dax_device *, pgoff_t, long,
-                       void **, pfn_t *);
+       long (*direct_access)(struct dax_device *, pgoff_t, long, int,

Would be nice if that 'int' was an enum, but I'm not sure a new parameter is needed at all, see below...

Let's do your suggestion below. :)

Quoted 14 lines

include/linux/dax.h struct dax_operations { · line 39

Quoted 11 lines
include/linux/dax.h +2 -1
+                               void **, pfn_t *);
         /*
          * Validate whether this device is usable as an fsdax backing
          * device.
@@ -32,10 +36,10 @@ struct dax_operations {
                         sector_t, sector_t);
         /* copy_from_iter: required operation for fs-dax direct-i/o */
         size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
-                       struct iov_iter *);
+                       struct iov_iter *, int);

I'm not sure the flag is needed here as the "void *" could carry a flag in the pointer to indicate that is a recovery kaddr.

Quoted 1 line

Agreed.

Quoted 8 lines

Not sure if this is implied but I would like some macros or other helper functions to check these flags hidden in the addresses.

For me I'm a bit scared about having flags hidden in the address like this because I can't lead to some confusions IMO.

But if we have some macros or other calls which can make this more obvious of what is going on I think that would help.

You could go further and mark it as an 'unsigned long __bitwise' type to get the compiler to help with enforcing accessors to strip off the flag bits.

author
#8 lore raw

PATCH v2 2/2 dax,pmem: Implement pmem based dax data recovery

In reply to Jane Chu

For /dev/pmem based dax, enable DAX_OP_RECOVERY mode for dax_direct_access to translate 'kaddr' over a range that may contain poison(s); and enable dax_copy_to_iter to read as much data as possible up till a poisoned page is encountered; and enable dax_copy_from_iter to clear poison among a page-aligned range, and then write the good data over.

---
 drivers/md/dm.c       |  2 ++
 drivers/nvdimm/pmem.c | 75 ++++++++++++++++++++++++++++++++++++++++---
 fs/dax.c              | 24 +++++++++++---
 3 files changed, 92 insertions(+), 9 deletions(-)
drivers/md/dm.c +2 -0
index dc354db22ef9..9b3dac916f22 100644
@@ -1043,6 +1043,7 @@ static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 	if (!ti)
 		goto out;
 	if (!ti->type->dax_copy_from_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);
 		ret = copy_from_iter(addr, bytes, i);
 		goto out;
 	}
@@ -1067,6 +1068,7 @@ static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 	if (!ti)
 		goto out;
 	if (!ti->type->dax_copy_to_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);
 		ret = copy_to_iter(addr, bytes, i);
 		goto out;
 	}
drivers/nvdimm/pmem.c +70 -5

97 lines not on this page · raw message

fs/dax.c +20 -4
index bea6df1498c3..7640be6b6a97 100644
@@ -1219,6 +1219,8 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		unsigned offset = pos & (PAGE_SIZE - 1);
 		const size_t size = ALIGN(length + offset, PAGE_SIZE);
 		const sector_t sector = dax_iomap_sector(iomap, pos);
+		long nr_page = PHYS_PFN(size);
+		int dax_mode = DAX_OP_NORMAL;
 		ssize_t map_len;
 		pgoff_t pgoff;
 		void *kaddr;
@@ -1232,8 +1234,13 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		if (ret)
 			break;
 
-		map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
-					    DAX_OP_NORMAL, &kaddr, NULL);
+		map_len = dax_direct_access(dax_dev, pgoff, nr_page, dax_mode,
+					    &kaddr, NULL);
+		if (unlikely(map_len == -EIO)) {
+			dax_mode = DAX_OP_RECOVERY;
+			map_len = dax_direct_access(dax_dev, pgoff, nr_page,
+						    dax_mode, &kaddr, NULL);
+		}
 		if (map_len < 0) {
 			ret = map_len;
 			break;
@@ -1252,11 +1259,20 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		 */
 		if (iov_iter_rw(iter) == WRITE)
 			xfer = dax_copy_from_iter(dax_dev, pgoff, kaddr,
-					map_len, iter, DAX_OP_NORMAL);
+					map_len, iter, dax_mode);
 		else
 			xfer = dax_copy_to_iter(dax_dev, pgoff, kaddr,
-					map_len, iter, DAX_OP_NORMAL);
+					map_len, iter, dax_mode);
 
+		/*
+		 * If dax data recovery is enacted via DAX_OP_RECOVERY,
+		 * recovery failure would be indicated by a -EIO return
+		 * in 'xfer' casted as (size_t).
+		 */
+		if ((ssize_t)xfer == -EIO) {
+			ret = -EIO;
+			break;
+		}
 		pos += xfer;
 		length -= xfer;
 		done += xfer;
Signature · 1 line
2.18.4
#9 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 27 lines · Jane Chu

For /dev/pmem based dax, enable DAX_OP_RECOVERY mode for dax_direct_access to translate 'kaddr' over a range that may contain poison(s); and enable dax_copy_to_iter to read as much data as possible up till a poisoned page is encountered; and enable dax_copy_from_iter to clear poison among a page-aligned range, and then write the good data over.

---
 drivers/md/dm.c       |  2 ++
 drivers/nvdimm/pmem.c | 75 ++++++++++++++++++++++++++++++++++++++++---
 fs/dax.c              | 24 +++++++++++---
 3 files changed, 92 insertions(+), 9 deletions(-)
drivers/md/dm.c +1 -0
index dc354db22ef9..9b3dac916f22 100644
@@ -1043,6 +1043,7 @@ static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 	if (!ti)
 		goto out;
 	if (!ti->type->dax_copy_from_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);
 		ret = copy_from_iter(addr, bytes, i);
 		goto out;
 	}

drivers/md/dm.c static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, · line 1071

Quoted 4 lines
drivers/md/dm.c +1 -0
@@ -1067,6 +1068,7 @@ static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 	if (!ti)
 		goto out;
 	if (!ti->type->dax_copy_to_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);

Maybe just return -EOPNOTSUPP here?

Warnings are kinda loud.

Quoted 31 lines
drivers/md/dm.c +0 -0
 		ret = copy_to_iter(addr, bytes, i);
 		goto out;
 	}
drivers/nvdimm/pmem.c +8 -5
index 3dc99e0bf633..8ae6aa678c51 100644
@@ -260,7 +260,7 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
 	resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset;
 
 	if (unlikely(is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512,
-					PFN_PHYS(nr_pages))))
+				 PFN_PHYS(nr_pages)) && mode == DAX_OP_NORMAL))
 		return -EIO;
 
 	if (kaddr)
@@ -303,20 +303,85 @@ static long pmem_dax_direct_access(struct dax_device *dax_dev,
 }
 
 /*
- * Use the 'no check' versions of copy_from_iter_flushcache() and
- * copy_mc_to_iter() to bypass HARDENED_USERCOPY overhead. Bounds
- * checking, both file offset and device offset, is handled by
- * dax_iomap_actor()
+ * Even though the 'no check' versions of copy_from_iter_flushcache()
+ * and copy_mc_to_iter() are used to bypass HARDENED_USERCOPY overhead,
+ * 'read'/'write' aren't always safe when poison is consumed. They happen
+ * to be safe because the 'read'/'write' range has been guaranteed
+ * be free of poison(s) by a prior call to dax_direct_access() on the
+ * caller stack.
+ * But on a data recovery code path, the 'read'/'write' range is expected

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 322

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+ * to contain poison(s), and so poison(s) is explicit checked, such that
+ * 'read' can fetch data from clean page(s) up till the first poison is
+ * encountered, and 'write' requires the range be page aligned in order
+ * to restore the poisoned page's memory type back to "rw" after clearing
+ * the poison(s).
+ * In the event of poison related failure, (size_t) -EIO is returned and
+ * caller may check the return value after casting it to (ssize_t).
+ *
+ * TODO: add support for CPUs that support MOVDIR64B instruction for
+ * faster poison clearing, and possibly smaller error blast radius.

I get that it's still early days yet for whatever pmem stuff is going on for 5.17, but I feel like this ought to be a separate function called by pmem_copy_from_iter, with this huge comment attached to that recovery function.

Quoted 12 lines
drivers/nvdimm/pmem.c +8 -0
  */
 static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
+	phys_addr_t pmem_off;
+	size_t len, lead_off;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 344

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+		if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+			if (lead_off || !(PAGE_ALIGNED(bytes))) {
+				dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+					addr, bytes);
+				return (size_t) -EIO;
+			}
+			pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+			if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+						BLK_STS_OK)
+				return (size_t) -EIO;

Looks reasonable enough to me, though you might want to restructure this to reduce the amount of indent.

FWIW I dislike how is_bad_pmem mixes units (sector_t vs. bytes), that was seriously confusing. But I guess that's a weird quirk of the badblocks API and .... ugh.

(I dunno, can we at least clean up the nvdimm parts and some day replace the badblocks backend with something that can handle more than 16 records? interval_tree is more than up to that task, I know, I use it for xfs online fsck...)

Quoted 28 lines
drivers/nvdimm/pmem.c +22 -0
+		}
+	}
+
 	return _copy_from_iter_flushcache(addr, bytes, i);
 }
 
 static size_t pmem_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
+	int num_bad;
+	size_t len, lead_off;
+	unsigned long bad_pfn;
+	bool bad_pmem = false;
+	size_t adj_len = bytes;
+	sector_t sector, first_bad;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		sector = PFN_PHYS(pgoff) / 512;
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));
+		if (pmem->bb.count)
+			bad_pmem = !!badblocks_check(&pmem->bb, sector,
+					len / 512, &first_bad, &num_bad);
+		if (bad_pmem) {
+			bad_pfn = PHYS_PFN(first_bad * 512);
+			if (bad_pfn == pgoff) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 382

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+				dev_warn(dev, "Found poison in page: pgoff(%#lx)\n",
+					pgoff);
+				return -EIO;
+			}
+			adj_len = PFN_PHYS(bad_pfn - pgoff) - lead_off;
+			dev_WARN_ONCE(dev, (adj_len > bytes),
+					"out-of-range first_bad?");
+		}
+		if (adj_len == 0)
+			return (size_t) -EIO;

Uh, are we supposed to adjust bytes here or something?

--D

Quoted 60 lines
drivers/nvdimm/pmem.c +2 -0
+	}
+
 	return _copy_mc_to_iter(addr, bytes, i);
 }
 
fs/dax.c +20 -4
index bea6df1498c3..7640be6b6a97 100644
@@ -1219,6 +1219,8 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		unsigned offset = pos & (PAGE_SIZE - 1);
 		const size_t size = ALIGN(length + offset, PAGE_SIZE);
 		const sector_t sector = dax_iomap_sector(iomap, pos);
+		long nr_page = PHYS_PFN(size);
+		int dax_mode = DAX_OP_NORMAL;
 		ssize_t map_len;
 		pgoff_t pgoff;
 		void *kaddr;
@@ -1232,8 +1234,13 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		if (ret)
 			break;
 
-		map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
-					    DAX_OP_NORMAL, &kaddr, NULL);
+		map_len = dax_direct_access(dax_dev, pgoff, nr_page, dax_mode,
+					    &kaddr, NULL);
+		if (unlikely(map_len == -EIO)) {
+			dax_mode = DAX_OP_RECOVERY;
+			map_len = dax_direct_access(dax_dev, pgoff, nr_page,
+						    dax_mode, &kaddr, NULL);
+		}
 		if (map_len < 0) {
 			ret = map_len;
 			break;
@@ -1252,11 +1259,20 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		 */
 		if (iov_iter_rw(iter) == WRITE)
 			xfer = dax_copy_from_iter(dax_dev, pgoff, kaddr,
-					map_len, iter, DAX_OP_NORMAL);
+					map_len, iter, dax_mode);
 		else
 			xfer = dax_copy_to_iter(dax_dev, pgoff, kaddr,
-					map_len, iter, DAX_OP_NORMAL);
+					map_len, iter, dax_mode);
 
+		/*
+		 * If dax data recovery is enacted via DAX_OP_RECOVERY,
+		 * recovery failure would be indicated by a -EIO return
+		 * in 'xfer' casted as (size_t).
+		 */
+		if ((ssize_t)xfer == -EIO) {
+			ret = -EIO;
+			break;
+		}
 		pos += xfer;
 		length -= xfer;
 		done += xfer;
Signature · 1 line
2.18.4
author
#10 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

On 11/5/2021 7:04 PM, Darrick J. Wong wrote:
<snip>

Quoted 21 lines
Quoted 14 lines
drivers/md/dm.c +1 -0
index dc354db22ef9..9b3dac916f22 100644
@@ -1043,6 +1043,7 @@ static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
  	if (!ti)
  		goto out;
  	if (!ti->type->dax_copy_from_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);
  		ret = copy_from_iter(addr, bytes, i);
  		goto out;
  	}

drivers/md/dm.c static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, · line 1071

Quoted 4 lines
drivers/md/dm.c +1 -0
@@ -1067,6 +1068,7 @@ static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
  	if (!ti)
  		goto out;
  	if (!ti->type->dax_copy_to_iter) {
+		WARN_ON(mode == DAX_OP_RECOVERY);

Maybe just return -EOPNOTSUPP here?

Quoted 2 lines

Warnings are kinda loud.

Indeed. Looks like the
"if (!ti->type->dax_copy_to_iter) {"
clause was to allow mixed dax targets in dm, such as dcss, fuse and virtio_fs targets. These targets either don't export .dax_copy_from/to_iter, or don't need to.
And their .dax_direct_access don't check poison, and can't repair poison anyway.

I think these targets may safely ignore the flag. However, returning -EOPNOTSUPP is helpful to catch future bug, such as someone add a method to detect poison, but didn't add a method to clear poison, in that case, we fail the call.

Dan, do you have a preference?

thanks!
-jane

author
#11 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

In reply to Darrick J. Wong

On 11/5/2021 7:04 PM, Darrick J. Wong wrote:
<snip>

Quoted 22 lines
Quoted 22 lines
drivers/nvdimm/pmem.c +14 -4
@@ -303,20 +303,85 @@ static long pmem_dax_direct_access(struct dax_device *dax_dev,
  }
 
  /*
- * Use the 'no check' versions of copy_from_iter_flushcache() and
- * copy_mc_to_iter() to bypass HARDENED_USERCOPY overhead. Bounds
- * checking, both file offset and device offset, is handled by
- * dax_iomap_actor()
+ * Even though the 'no check' versions of copy_from_iter_flushcache()
+ * and copy_mc_to_iter() are used to bypass HARDENED_USERCOPY overhead,
+ * 'read'/'write' aren't always safe when poison is consumed. They happen
+ * to be safe because the 'read'/'write' range has been guaranteed
+ * be free of poison(s) by a prior call to dax_direct_access() on the
+ * caller stack.
+ * But on a data recovery code path, the 'read'/'write' range is expected
+ * to contain poison(s), and so poison(s) is explicit checked, such that
+ * 'read' can fetch data from clean page(s) up till the first poison is
+ * encountered, and 'write' requires the range be page aligned in order
+ * to restore the poisoned page's memory type back to "rw" after clearing
+ * the poison(s).
+ * In the event of poison related failure, (size_t) -EIO is returned and
+ * caller may check the return value after casting it to (ssize_t).
Quoted 8 lines

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 322

Quoted 3 lines
drivers/nvdimm/pmem.c +3 -0
+ *
+ * TODO: add support for CPUs that support MOVDIR64B instruction for
+ * faster poison clearing, and possibly smaller error blast radius.

I get that it's still early days yet for whatever pmem stuff is going on for 5.17, but I feel like this ought to be a separate function called by pmem_copy_from_iter, with this huge comment attached to that recovery function.

Thanks, will refactor both functions.

Quoted 18 lines
Quoted 18 lines
drivers/nvdimm/pmem.c +13 -0
   */
  static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
  		void *addr, size_t bytes, struct iov_iter *i, int mode)
  {
+	phys_addr_t pmem_off;
+	size_t len, lead_off;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));
+		if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+			if (lead_off || !(PAGE_ALIGNED(bytes))) {
+				dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+					addr, bytes);
+				return (size_t) -EIO;
Quoted 8 lines

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 344

Quoted 5 lines
drivers/nvdimm/pmem.c +5 -0
+			}
+			pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+			if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+						BLK_STS_OK)
+				return (size_t) -EIO;

Looks reasonable enough to me, though you might want to restructure this to reduce the amount of indent.

Agreed.

Quoted 9 lines

FWIW I dislike how is_bad_pmem mixes units (sector_t vs. bytes), that was seriously confusing. But I guess that's a weird quirk of the badblocks API and .... ugh.

(I dunno, can we at least clean up the nvdimm parts and some day replace the badblocks backend with something that can handle more than 16 records? interval_tree is more than up to that task, I know, I use it for xfs online fsck...)

Let me look into this and get back to you.

Quoted 33 lines
Quoted 33 lines
drivers/nvdimm/pmem.c +26 -0
+		}
+	}
+
  	return _copy_from_iter_flushcache(addr, bytes, i);
  }
 
  static size_t pmem_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
  		void *addr, size_t bytes, struct iov_iter *i, int mode)
  {
+	int num_bad;
+	size_t len, lead_off;
+	unsigned long bad_pfn;
+	bool bad_pmem = false;
+	size_t adj_len = bytes;
+	sector_t sector, first_bad;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		sector = PFN_PHYS(pgoff) / 512;
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));
+		if (pmem->bb.count)
+			bad_pmem = !!badblocks_check(&pmem->bb, sector,
+					len / 512, &first_bad, &num_bad);
+		if (bad_pmem) {
+			bad_pfn = PHYS_PFN(first_bad * 512);
+			if (bad_pfn == pgoff) {
+				dev_warn(dev, "Found poison in page: pgoff(%#lx)\n",
+					pgoff);
+				return -EIO;
+			}
Quoted 8 lines

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 382

Quoted 6 lines
drivers/nvdimm/pmem.c +6 -0
+			adj_len = PFN_PHYS(bad_pfn - pgoff) - lead_off;
+			dev_WARN_ONCE(dev, (adj_len > bytes),
+					"out-of-range first_bad?");
+		}
+		if (adj_len == 0)
+			return (size_t) -EIO;

Uh, are we supposed to adjust bytes here or something?

Because we're trying to read as much data as possible... What is your concern here?

thanks!
-jane

Quoted 8 lines

--D

Quoted 5 lines
drivers/nvdimm/pmem.c +2 -0
+	}
+
  	return _copy_mc_to_iter(addr, bytes, i);
  }
 
#12 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

In reply to Jane Chu
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,

drivers/nvdimm/pmem.c +10 -0
 		void *addr, size_t bytes, struct iov_iter *i, int mode)
 {
+	phys_addr_t pmem_off;
+	size_t len, lead_off;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));
+		if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+			if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+				dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+					addr, bytes);
+				return (size_t) -EIO;
+			}
+			pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+			if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+						BLK_STS_OK)
+				return (size_t) -EIO;
+		}
+	}

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

#13 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

        rc = dax_direct_access(..., &kaddr, ...);
        if (unlikely(rc)) {
                kaddr = dax_mk_recovery(kaddr);
                dax_direct_access(..., &kaddr, ...);
                return dax_recovery_{read,write}(..., kaddr, ...);
        }
        return copy_{mc_to_iter,from_iter_flushcache}(...);

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access, dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

#14 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 4 lines · Dan Williams

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

This sound pretty sensible.

author
#15 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

In reply to Dan Williams
Quoted 36 lines · Dan Williams
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

Quoted 8 lines

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

         rc = dax_direct_access(..., &kaddr, ...);
         if (unlikely(rc)) {
                 kaddr = dax_mk_recovery(kaddr);

Sorry, what does dax_mk_recovery(kaddr) do?

Quoted 7 lines
                 dax_direct_access(..., &kaddr, ...);
                 return dax_recovery_{read,write}(..., kaddr, ...);
         }
         return copy_{mc_to_iter,from_iter_flushcache}(...);

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access,

again, sorry, what 'page permissions'? memory_failure_dev_pagemap() changes the poisoned page mem_type from 'rw' to 'uc-' (should be NP?), do you mean to reverse the change?

Quoted 5 lines

dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

How about to introduce 3 dax_recover_ APIs:
dax_recover_direct_access(): similar to dax_direct_access except
it ignores error list and return the kaddr, and hence is also optional, exported by device driver that has the ability to detect error;
dax_recovery_read(): optional, supported by pmem driver only,

      reads as much data as possible up to the poisoned page;

dax_recovery_write(): optional, supported by pmem driver only,
first clear-poison, then write.

Should we worry about the dm targets?

Both dax_recovery_read/write() are hooked up to dax_iomap_iter().

Thanks,
-jane

#16 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 43 lines · Jane Chu
Quoted 41 lines · Dan Williams
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

Quoted 5 lines
Quoted 3 lines
         rc = dax_direct_access(..., &kaddr, ...);
         if (unlikely(rc)) {
                 kaddr = dax_mk_recovery(kaddr);

Sorry, what does dax_mk_recovery(kaddr) do?

I was thinking this just does the hackery to set a flag bit in the pointer, something like:

return (void *) ((unsigned long) kaddr | DAX_RECOVERY)

Quoted 6 lines
Quoted 6 lines
                 dax_direct_access(..., &kaddr, ...);
                 return dax_recovery_{read,write}(..., kaddr, ...);
         }
         return copy_{mc_to_iter,from_iter_flushcache}(...);
Quoted 6 lines
Quoted 2 lines

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access,

again, sorry, what 'page permissions'? memory_failure_dev_pagemap() changes the poisoned page mem_type from 'rw' to 'uc-' (should be NP?), do you mean to reverse the change?

Right, the result of the conversation with Boris is that memory_failure() should mark the page as NP in call cases, so dax_direct_access() needs to create a UC mapping and dax_recover_{read,write}() would sink that operation and either return the page to NP after the access completes, or convert it to WB if the operation cleared the error.

Quoted 6 lines
Quoted 5 lines

dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

Quoted 7 lines

How about to introduce 3 dax_recover_ APIs:
dax_recover_direct_access(): similar to dax_direct_access except
it ignores error list and return the kaddr, and hence is also optional, exported by device driver that has the ability to detect error;
dax_recovery_read(): optional, supported by pmem driver only,

      reads as much data as possible up to the poisoned page;

It wouldn't be a property of the pmem driver, I expect it would be a flag on the dax device whether to attempt recovery or not. I.e. get away from this being a pmem callback and make this a native capability of a dax device.

Quoted 4 lines

dax_recovery_write(): optional, supported by pmem driver only,
first clear-poison, then write.

Should we worry about the dm targets?

The dm targets after Christoph's conversion should be able to do all the translation at direct access time and then dax_recovery_X can be done on the resulting already translated kaddr.

Quoted 1 line

Both dax_recovery_read/write() are hooked up to dax_iomap_iter().

Yes.

author
#17 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 48 lines · Dan Williams
Quoted 47 lines · Jane Chu
Quoted 44 lines · Dan Williams
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

          rc = dax_direct_access(..., &kaddr, ...);
          if (unlikely(rc)) {
                  kaddr = dax_mk_recovery(kaddr);
Quoted 6 lines
Quoted 1 line

Sorry, what does dax_mk_recovery(kaddr) do?

I was thinking this just does the hackery to set a flag bit in the pointer, something like:

return (void *) ((unsigned long) kaddr | DAX_RECOVERY)

Okay, how about call it dax_prep_recovery()?

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines

                  dax_direct_access(..., &kaddr, ...);
                  return dax_recovery_{read,write}(..., kaddr, ...);
          }
          return copy_{mc_to_iter,from_iter_flushcache}(...);
Quoted 6 lines
Quoted 2 lines

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access,

again, sorry, what 'page permissions'? memory_failure_dev_pagemap() changes the poisoned page mem_type from 'rw' to 'uc-' (should be NP?), do you mean to reverse the change?

Quoted 6 lines

Right, the result of the conversation with Boris is that memory_failure() should mark the page as NP in call cases, so dax_direct_access() needs to create a UC mapping and dax_recover_{read,write}() would sink that operation and either return the page to NP after the access completes, or convert it to WB if the operation cleared the error.

Okay, will add a patch to fix set_mce_nospec().

How about moving set_memory_uc() and set_memory_np() down to dax_recovery_read(), so that we don't split the set_memory_X calls over different APIs, because we can't enforce what follows dax_direct_access()?

Quoted 20 lines
Quoted 7 lines
Quoted 6 lines

dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

Quoted 7 lines

How about to introduce 3 dax_recover_ APIs:
dax_recover_direct_access(): similar to dax_direct_access except
it ignores error list and return the kaddr, and hence is also optional, exported by device driver that has the ability to detect error;
dax_recovery_read(): optional, supported by pmem driver only,
reads as much data as possible up to the poisoned page;

It wouldn't be a property of the pmem driver, I expect it would be a flag on the dax device whether to attempt recovery or not. I.e. get away from this being a pmem callback and make this a native capability of a dax device.

Quoted 8 lines
Quoted 4 lines

dax_recovery_write(): optional, supported by pmem driver only,
first clear-poison, then write.

Should we worry about the dm targets?

The dm targets after Christoph's conversion should be able to do all the translation at direct access time and then dax_recovery_X can be done on the resulting already translated kaddr.

I'm thinking about the mixed device dm where some provides dax_recovery_X, others don't, in which case we don't allow dax recovery because that causes confusion? or should we still allow recovery for part of the mixed devices?

Quoted 5 lines
Quoted 2 lines

Both dax_recovery_read/write() are hooked up to dax_iomap_iter().

Yes.

thanks!
-jane

#18 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 111 lines · Jane Chu
Quoted 48 lines · Dan Williams
Quoted 47 lines · Jane Chu
Quoted 44 lines · Dan Williams
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 346

Quoted 10 lines
drivers/nvdimm/pmem.c +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

          rc = dax_direct_access(..., &kaddr, ...);
          if (unlikely(rc)) {
                  kaddr = dax_mk_recovery(kaddr);
Quoted 6 lines
Quoted 1 line

Sorry, what does dax_mk_recovery(kaddr) do?

I was thinking this just does the hackery to set a flag bit in the pointer, something like:

return (void *) ((unsigned long) kaddr | DAX_RECOVERY)

Okay, how about call it dax_prep_recovery()?

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines

                  dax_direct_access(..., &kaddr, ...);
                  return dax_recovery_{read,write}(..., kaddr, ...);
          }
          return copy_{mc_to_iter,from_iter_flushcache}(...);
Quoted 6 lines
Quoted 2 lines

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access,

again, sorry, what 'page permissions'? memory_failure_dev_pagemap() changes the poisoned page mem_type from 'rw' to 'uc-' (should be NP?), do you mean to reverse the change?

Quoted 6 lines

Right, the result of the conversation with Boris is that memory_failure() should mark the page as NP in call cases, so dax_direct_access() needs to create a UC mapping and dax_recover_{read,write}() would sink that operation and either return the page to NP after the access completes, or convert it to WB if the operation cleared the error.

Okay, will add a patch to fix set_mce_nospec().

How about moving set_memory_uc() and set_memory_np() down to dax_recovery_read(), so that we don't split the set_memory_X calls over different APIs, because we can't enforce what follows dax_direct_access()?

Quoted 25 lines
Quoted 7 lines
Quoted 6 lines

dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

Quoted 7 lines

How about to introduce 3 dax_recover_ APIs:
dax_recover_direct_access(): similar to dax_direct_access except
it ignores error list and return the kaddr, and hence is also optional, exported by device driver that has the ability to detect error;
dax_recovery_read(): optional, supported by pmem driver only,
reads as much data as possible up to the poisoned page;

It wouldn't be a property of the pmem driver, I expect it would be a flag on the dax device whether to attempt recovery or not. I.e. get away from this being a pmem callback and make this a native capability of a dax device.

Quoted 4 lines

dax_recovery_write(): optional, supported by pmem driver only,
first clear-poison, then write.

Should we worry about the dm targets?

Quoted 8 lines
Quoted 3 lines

The dm targets after Christoph's conversion should be able to do all the translation at direct access time and then dax_recovery_X can be done on the resulting already translated kaddr.

I'm thinking about the mixed device dm where some provides dax_recovery_X, others don't, in which case we don't allow dax recovery because that causes confusion? or should we still allow recovery for part of the mixed devices?

I really don't like the all or nothing approach if it can be avoided. I would imagine that if recovery possible it best to support it even if the DM device happens to span a mix of devices with varying support for recovery.

Thanks,
Mike

author
#19 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

Quoted 123 lines · Mike Snitzer
Quoted 111 lines · Jane Chu
Quoted 48 lines · Dan Williams
Quoted 47 lines · Jane Chu
Quoted 44 lines · Dan Williams
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

(quoted diff) +10 -0
+     phys_addr_t pmem_off;
+     size_t len, lead_off;
+     struct pmem_device *pmem = dax_get_private(dax_dev);
+     struct device *dev = pmem->bb.dev;
+
+     if (unlikely(mode == DAX_OP_RECOVERY)) {
+             lead_off = (unsigned long)addr & ~PAGE_MASK;
+             len = PFN_PHYS(PFN_UP(lead_off + bytes));
+             if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+                     if (lead_off || !(PAGE_ALIGNED(bytes))) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+                             dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+                                     addr, bytes);
+                             return (size_t) -EIO;
+                     }
+                     pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+                     if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+                                             BLK_STS_OK)
+                             return (size_t) -EIO;
+             }
+     }
Quoted 8 lines

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

I think we just make error management a first class citizen of a dax-device and stop abstracting it behind a driver callback. That way the driver that registers the dax-device can optionally register error management as well. Then fsdax path can do:

           rc = dax_direct_access(..., &kaddr, ...);
           if (unlikely(rc)) {
                   kaddr = dax_mk_recovery(kaddr);
Quoted 6 lines
Quoted 1 line

Sorry, what does dax_mk_recovery(kaddr) do?

I was thinking this just does the hackery to set a flag bit in the pointer, something like:

return (void *) ((unsigned long) kaddr | DAX_RECOVERY)

Okay, how about call it dax_prep_recovery()?

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines

                   dax_direct_access(..., &kaddr, ...);
                   return dax_recovery_{read,write}(..., kaddr, ...);
           }
           return copy_{mc_to_iter,from_iter_flushcache}(...);
Quoted 6 lines
Quoted 2 lines

Where, the recovery version of dax_direct_access() has the opportunity to change the page permissions / use an alias mapping for the access,

again, sorry, what 'page permissions'? memory_failure_dev_pagemap() changes the poisoned page mem_type from 'rw' to 'uc-' (should be NP?), do you mean to reverse the change?

Quoted 6 lines

Right, the result of the conversation with Boris is that memory_failure() should mark the page as NP in call cases, so dax_direct_access() needs to create a UC mapping and dax_recover_{read,write}() would sink that operation and either return the page to NP after the access completes, or convert it to WB if the operation cleared the error.

Okay, will add a patch to fix set_mce_nospec().

How about moving set_memory_uc() and set_memory_np() down to dax_recovery_read(), so that we don't split the set_memory_X calls over different APIs, because we can't enforce what follows dax_direct_access()?

Quoted 25 lines
Quoted 7 lines
Quoted 6 lines

dax_recovery_read() allows reading the good cachelines out of a poisoned page, and dax_recovery_write() coordinates error list management and returning a poison page to full write-back caching operation when no more poisoned cacheline are detected in the page.

Quoted 7 lines

How about to introduce 3 dax_recover_ APIs:
dax_recover_direct_access(): similar to dax_direct_access except
it ignores error list and return the kaddr, and hence is also optional, exported by device driver that has the ability to detect error;
dax_recovery_read(): optional, supported by pmem driver only,
reads as much data as possible up to the poisoned page;

It wouldn't be a property of the pmem driver, I expect it would be a flag on the dax device whether to attempt recovery or not. I.e. get away from this being a pmem callback and make this a native capability of a dax device.

Quoted 4 lines

dax_recovery_write(): optional, supported by pmem driver only,
first clear-poison, then write.

Should we worry about the dm targets?

Quoted 8 lines
Quoted 3 lines

The dm targets after Christoph's conversion should be able to do all the translation at direct access time and then dax_recovery_X can be done on the resulting already translated kaddr.

I'm thinking about the mixed device dm where some provides dax_recovery_X, others don't, in which case we don't allow dax recovery because that causes confusion? or should we still allow recovery for part of the mixed devices?

Quoted 4 lines

I really don't like the all or nothing approach if it can be avoided. I would imagine that if recovery possible it best to support it even if the DM device happens to span a mix of devices with varying support for recovery.

Got it!

thanks!
-jane

Quoted 4 lines

Thanks,
Mike

author
#20 lore raw

Re: [PATCH v2 2/2] dax,pmem: Implement pmem based dax data recovery

In reply to Christoph Hellwig
Quoted 21 lines · Christoph Hellwig
Quoted 20 lines · Jane Chu

static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i, int mode)
{

drivers/nvdimm/pmem.c +17 -0
+	phys_addr_t pmem_off;
+	size_t len, lead_off;
+	struct pmem_device *pmem = dax_get_private(dax_dev);
+	struct device *dev = pmem->bb.dev;
+
+	if (unlikely(mode == DAX_OP_RECOVERY)) {
+		lead_off = (unsigned long)addr & ~PAGE_MASK;
+		len = PFN_PHYS(PFN_UP(lead_off + bytes));
+		if (is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, len)) {
+			if (lead_off || !(PAGE_ALIGNED(bytes))) {
+				dev_warn(dev, "Found poison, but addr(%p) and/or bytes(%#lx) not page aligned\n",
+					addr, bytes);
+				return (size_t) -EIO;
+			}
+			pmem_off = PFN_PHYS(pgoff) + pmem->data_offset;
+			if (pmem_clear_poison(pmem, pmem_off, bytes) !=
+						BLK_STS_OK)
Quoted 8 lines

drivers/nvdimm/pmem.c static long pmem_dax_direct_access(struct dax_device *dax_dev, · line 345

Quoted 3 lines
drivers/nvdimm/pmem.c +3 -0
+				return (size_t) -EIO;
+		}
+	}

This is in the wrong spot. As seen in my WIP series individual drivers really should not hook into copying to and from the iter, because it really is just one way to write to a nvdimm. How would dm-writecache clear the errors with this scheme?

How does dm-writecache detect and clear errors today?

Quoted 5 lines

So IMHO going back to the separate recovery method as in your previous patch really is the way to go. If/when the 64-bit store happens we need to figure out a good way to clear the bad block list for that.

Yeah, the separate .dax_clear_poison API may not be arbitrarily called though. It must be followed by a 'write' operation, and so, unless we bind the two operations together, how do we enforce that to avoid silent data corruption?

thanks!
-jane