Skip to contentSkip to conversation

devirtualize kernel access to DAX

PATCH In review Christoph Hellwig 5 participants 33 messages Dec 9, 2021 – Dec 15, 2021

Subsystems (11)
VFS s390 virtio core Device mapper +7 more subsystems
lore
Share & tools
lore
#0 lore raw

Hi Dan,

this series cleans up a few loose end ends and then removes the copy_from_iter and copy_to_iter dax_operations methods in favor of straight calls.

Diffstat:

 drivers/dax/bus.c             |    3 +
 drivers/dax/super.c           |   40 ++++++++++++++-------
 drivers/md/dm-linear.c        |   20 ----------
 drivers/md/dm-log-writes.c    |   80 ------------------------------------------
 drivers/md/dm-stripe.c        |   20 ----------
 drivers/md/dm.c               |   52 ---------------------------
 drivers/nvdimm/pmem.c         |   27 +-------------
 drivers/s390/block/dcssblk.c  |   18 +--------
 fs/dax.c                      |    5 --
 fs/fuse/virtio_fs.c           |   20 +---------
 include/linux/dax.h           |   28 +++-----------
 include/linux/device-mapper.h |    4 --
 include/linux/uio.h           |   20 ----------
 13 files changed, 44 insertions(+), 293 deletions(-)
#1 lore raw

PATCH 1/5 uio: remove copy_from_iter_flushcache() and copy_mc_to_iter()

These two wrappers are never used.

---
 drivers/nvdimm/pmem.c |  4 ++--
 include/linux/uio.h   | 20 +-------------------
 2 files changed, 3 insertions(+), 21 deletions(-)
drivers/nvdimm/pmem.c +2 -2
index 4190c8c46ca88..8294f1c701baa 100644
@@ -302,8 +302,8 @@ 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
+ * 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()
  */
include/linux/uio.h +1 -19
index 6350354f97e90..494d552c1d663 100644
@@ -196,7 +196,7 @@ bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i)
 #ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
 /*
  * Note, users like pmem that depend on the stricter semantics of
- * copy_from_iter_flushcache() than copy_from_iter_nocache() must check for
+ * _copy_from_iter_flushcache() than _copy_from_iter_nocache() must check for
  * IS_ENABLED(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) before assuming that the
  * destination is flushed from the cache on return.
  */
@@ -211,24 +211,6 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i);
 #define _copy_mc_to_iter _copy_to_iter
 #endif
 
-static __always_inline __must_check
-size_t copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
-{
-	if (unlikely(!check_copy_size(addr, bytes, false)))
-		return 0;
-	else
-		return _copy_from_iter_flushcache(addr, bytes, i);
-}
-
-static __always_inline __must_check
-size_t copy_mc_to_iter(void *addr, size_t bytes, struct iov_iter *i)
-{
-	if (unlikely(!check_copy_size(addr, bytes, true)))
-		return 0;
-	else
-		return _copy_mc_to_iter(addr, bytes, i);
-}
-
 size_t iov_iter_zero(size_t bytes, struct iov_iter *);
 unsigned long iov_iter_alignment(const struct iov_iter *i);
 unsigned long iov_iter_gap_alignment(const struct iov_iter *i);
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 1/5] uio: remove copy_from_iter_flushcache() and copy_mc_to_iter()

Quoted 14 lines · Christoph Hellwig

These two wrappers are never used.

---
 drivers/nvdimm/pmem.c |  4 ++--
 include/linux/uio.h   | 20 +-------------------
 2 files changed, 3 insertions(+), 21 deletions(-)
drivers/nvdimm/pmem.c +0 -0
index 4190c8c46ca88..8294f1c701baa 100644

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

Quoted 10 lines
drivers/nvdimm/pmem.c +2 -2
@@ -302,8 +302,8 @@ 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
+ * 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()
  */

This comment change does not make sense since it is saying why pmem is using the "_" versions. However, I assume this whole comment goes away in a later patch.

include/linux/uio.h bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i) · line 202

Quoted 13 lines
include/linux/uio.h +1 -1
index 6350354f97e90..494d552c1d663 100644
@@ -196,7 +196,7 @@ bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i)
 #ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
 /*
  * Note, users like pmem that depend on the stricter semantics of
- * copy_from_iter_flushcache() than copy_from_iter_nocache() must check for
+ * _copy_from_iter_flushcache() than _copy_from_iter_nocache() must check for
  * IS_ENABLED(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) before assuming that the
  * destination is flushed from the cache on return.
  */

Same here.

Quoted 28 lines
include/linux/uio.h +0 -19
@@ -211,24 +211,6 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i);
 #define _copy_mc_to_iter _copy_to_iter
 #endif
 
-static __always_inline __must_check
-size_t copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
-{
-       if (unlikely(!check_copy_size(addr, bytes, false)))
-               return 0;
-       else
-               return _copy_from_iter_flushcache(addr, bytes, i);
-}
-
-static __always_inline __must_check
-size_t copy_mc_to_iter(void *addr, size_t bytes, struct iov_iter *i)
-{
-       if (unlikely(!check_copy_size(addr, bytes, true)))
-               return 0;
-       else
-               return _copy_mc_to_iter(addr, bytes, i);
-}
-
 size_t iov_iter_zero(size_t bytes, struct iov_iter *);
 unsigned long iov_iter_alignment(const struct iov_iter *i);
 unsigned long iov_iter_gap_alignment(const struct iov_iter *i);
--

2.30.2

#3 lore raw

Re: [PATCH 1/5] uio: remove copy_from_iter_flushcache() and copy_mc_to_iter()

Quoted 11 lines · Dan Williams
Quoted 7 lines

- * Use the 'no check' versions of copy_from_iter_flushcache() and
- * copy_mc_to_iter() to bypass HARDENED_USERCOPY overhead. Bounds
+ * 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()
*/

This comment change does not make sense since it is saying why pmem is using the "_" versions. However, I assume this whole comment goes away in a later patch.

It does not go away in this series.

#4 lore raw

PATCH 2/5 dax: simplify dax_synchronous and set_dax_synchronous

In reply to Christoph Hellwig

Remove the pointless wrappers.

---
 drivers/dax/super.c |  8 ++++----
 include/linux/dax.h | 12 ++----------
 2 files changed, 6 insertions(+), 14 deletions(-)
drivers/dax/super.c +4 -4
index e7152a6c4cc40..e18155f43a635 100644
@@ -208,17 +208,17 @@ bool dax_write_cache_enabled(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
 
-bool __dax_synchronous(struct dax_device *dax_dev)
+bool dax_synchronous(struct dax_device *dax_dev)
 {
 	return test_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__dax_synchronous);
+EXPORT_SYMBOL_GPL(dax_synchronous);
 
-void __set_dax_synchronous(struct dax_device *dax_dev)
+void set_dax_synchronous(struct dax_device *dax_dev)
 {
 	set_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__set_dax_synchronous);
+EXPORT_SYMBOL_GPL(set_dax_synchronous);
 
 bool dax_alive(struct dax_device *dax_dev)
 {
include/linux/dax.h +2 -10
index 87ae4c9b1d65b..3bd1fdb5d5f4b 100644
@@ -48,16 +48,8 @@ void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);
 bool dax_write_cache_enabled(struct dax_device *dax_dev);
-bool __dax_synchronous(struct dax_device *dax_dev);
-static inline bool dax_synchronous(struct dax_device *dax_dev)
-{
-	return  __dax_synchronous(dax_dev);
-}
-void __set_dax_synchronous(struct dax_device *dax_dev);
-static inline void set_dax_synchronous(struct dax_device *dax_dev)
-{
-	__set_dax_synchronous(dax_dev);
-}
+bool dax_synchronous(struct dax_device *dax_dev);
+void set_dax_synchronous(struct dax_device *dax_dev);
 /*
  * Check if given mapping is supported by the file / underlying device.
  */
Signature · 1 line
2.30.2
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] dax: simplify dax_synchronous and set_dax_synchronous

Quoted 47 lines

Remove the pointless wrappers.

---
 drivers/dax/super.c |  8 ++++----
 include/linux/dax.h | 12 ++----------
 2 files changed, 6 insertions(+), 14 deletions(-)
drivers/dax/super.c +4 -4
index e7152a6c4cc40..e18155f43a635 100644
@@ -208,17 +208,17 @@ bool dax_write_cache_enabled(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
 
-bool __dax_synchronous(struct dax_device *dax_dev)
+bool dax_synchronous(struct dax_device *dax_dev)
 {
        return test_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__dax_synchronous);
+EXPORT_SYMBOL_GPL(dax_synchronous);
 
-void __set_dax_synchronous(struct dax_device *dax_dev)
+void set_dax_synchronous(struct dax_device *dax_dev)
 {
        set_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__set_dax_synchronous);
+EXPORT_SYMBOL_GPL(set_dax_synchronous);
 
 bool dax_alive(struct dax_device *dax_dev)
 {
include/linux/dax.h +0 -5
index 87ae4c9b1d65b..3bd1fdb5d5f4b 100644
@@ -48,16 +48,8 @@ void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);
 bool dax_write_cache_enabled(struct dax_device *dax_dev);
-bool __dax_synchronous(struct dax_device *dax_dev);
-static inline bool dax_synchronous(struct dax_device *dax_dev)
-{
-       return  __dax_synchronous(dax_dev);
-}

include/linux/dax.h void put_dax(struct dax_device *dax_dev); · line 55

Quoted 10 lines
include/linux/dax.h +2 -5
-void __set_dax_synchronous(struct dax_device *dax_dev);
-static inline void set_dax_synchronous(struct dax_device *dax_dev)
-{
-       __set_dax_synchronous(dax_dev);
-}
+bool dax_synchronous(struct dax_device *dax_dev);
+void set_dax_synchronous(struct dax_device *dax_dev);
 /*
  * Check if given mapping is supported by the file / underlying device.
  */

Looks good to me.

Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] dax: simplify dax_synchronous and set_dax_synchronous

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Remove the pointless wrappers.

Looks good, not sure why those ever existed.

Quoted 57 lines
---
 drivers/dax/super.c |  8 ++++----
 include/linux/dax.h | 12 ++----------
 2 files changed, 6 insertions(+), 14 deletions(-)
drivers/dax/super.c +4 -4
index e7152a6c4cc40..e18155f43a635 100644
@@ -208,17 +208,17 @@ bool dax_write_cache_enabled(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
 
-bool __dax_synchronous(struct dax_device *dax_dev)
+bool dax_synchronous(struct dax_device *dax_dev)
 {
        return test_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__dax_synchronous);
+EXPORT_SYMBOL_GPL(dax_synchronous);
 
-void __set_dax_synchronous(struct dax_device *dax_dev)
+void set_dax_synchronous(struct dax_device *dax_dev)
 {
        set_bit(DAXDEV_SYNC, &dax_dev->flags);
 }
-EXPORT_SYMBOL_GPL(__set_dax_synchronous);
+EXPORT_SYMBOL_GPL(set_dax_synchronous);
 
 bool dax_alive(struct dax_device *dax_dev)
 {
include/linux/dax.h +2 -11
index 87ae4c9b1d65b..3bd1fdb5d5f4b 100644
@@ -48,16 +48,8 @@ void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);
 bool dax_write_cache_enabled(struct dax_device *dax_dev);
-bool __dax_synchronous(struct dax_device *dax_dev);
-static inline bool dax_synchronous(struct dax_device *dax_dev)
-{
-       return  __dax_synchronous(dax_dev);
-}
-void __set_dax_synchronous(struct dax_device *dax_dev);
-static inline void set_dax_synchronous(struct dax_device *dax_dev)
-{
-       __set_dax_synchronous(dax_dev);
-}
+bool dax_synchronous(struct dax_device *dax_dev);
+void set_dax_synchronous(struct dax_device *dax_dev);
 /*
  * Check if given mapping is supported by the file / underlying device.
  */
--

2.30.2

#7 lore raw

PATCH 3/5 dax: remove the DAXDEV_F_SYNC flag

In reply to Christoph Hellwig

Remove the DAXDEV_F_SYNC flag and thus the flags argument to alloc_dax and just let the drivers call set_dax_synchronous directly.

---
 drivers/dax/bus.c            | 3 ++-
 drivers/dax/super.c          | 6 +-----
 drivers/md/dm.c              | 2 +-
 drivers/nvdimm/pmem.c        | 7 +++----
 drivers/s390/block/dcssblk.c | 4 ++--
 fs/fuse/virtio_fs.c          | 2 +-
 include/linux/dax.h          | 8 ++------
 7 files changed, 12 insertions(+), 20 deletions(-)
drivers/dax/bus.c +2 -1
index 6683d42c32c56..da2a14d096d29 100644
@@ -1324,11 +1324,12 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
 	 * No dax_operations since there is no access to this device outside of
 	 * mmap of the resulting character device.
 	 */
-	dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC);
+	dax_dev = alloc_dax(dev_dax, NULL);
 	if (IS_ERR(dax_dev)) {
 		rc = PTR_ERR(dax_dev);
 		goto err_alloc_dax;
 	}
+	set_dax_synchronous(dax_dev);
 
 	/* a device_dax instance is dead while the driver is not attached */
 	kill_dax(dax_dev);
drivers/dax/super.c +1 -5
index e18155f43a635..e81d5ee57390f 100644
@@ -345,8 +345,7 @@ static struct dax_device *dax_dev_get(dev_t devt)
 	return dax_dev;
 }
 
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-		unsigned long flags)
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
 {
 	struct dax_device *dax_dev;
 	dev_t devt;
@@ -366,9 +365,6 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
 
 	dax_dev->ops = ops;
 	dax_dev->private = private;
-	if (flags & DAXDEV_F_SYNC)
-		set_dax_synchronous(dax_dev);
-
 	return dax_dev;
 
  err_dev:
drivers/md/dm.c +1 -1
index 4e997c02bb0a0..f4b972af10928 100644
@@ -1765,7 +1765,7 @@ static struct mapped_device *alloc_dev(int minor)
 	sprintf(md->disk->disk_name, "dm-%d", minor);
 
 	if (IS_ENABLED(CONFIG_FS_DAX)) {
-		md->dax_dev = alloc_dax(md, &dm_dax_ops, 0);
+		md->dax_dev = alloc_dax(md, &dm_dax_ops);
 		if (IS_ERR(md->dax_dev)) {
 			md->dax_dev = NULL;
 			goto bad;
drivers/nvdimm/pmem.c +3 -4
index 8294f1c701baa..85b3339286bd8 100644
@@ -402,7 +402,6 @@ static int pmem_attach_disk(struct device *dev,
 	struct gendisk *disk;
 	void *addr;
 	int rc;
-	unsigned long flags = 0UL;
 
 	pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
 	if (!pmem)
@@ -495,13 +494,13 @@ static int pmem_attach_disk(struct device *dev,
 	nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_range);
 	disk->bb = &pmem->bb;
 
-	if (is_nvdimm_sync(nd_region))
-		flags = DAXDEV_F_SYNC;
-	dax_dev = alloc_dax(pmem, &pmem_dax_ops, flags);
+	dax_dev = alloc_dax(pmem, &pmem_dax_ops);
 	if (IS_ERR(dax_dev)) {
 		rc = PTR_ERR(dax_dev);
 		goto out;
 	}
+	if (is_nvdimm_sync(nd_region))
+		set_dax_synchronous(dax_dev);
 	rc = dax_add_host(dax_dev, disk);
 	if (rc)
 		goto out_cleanup_dax;
drivers/s390/block/dcssblk.c +2 -2
index e65e83764d1ce..10823debc09bd 100644
@@ -686,13 +686,13 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
 	if (rc)
 		goto put_dev;
 
-	dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops,
-			DAXDEV_F_SYNC);
+	dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops);
 	if (IS_ERR(dev_info->dax_dev)) {
 		rc = PTR_ERR(dev_info->dax_dev);
 		dev_info->dax_dev = NULL;
 		goto put_dev;
 	}
+	set_dax_synchronous(dev_info->dax_dev);
 	rc = dax_add_host(dev_info->dax_dev, dev_info->gd);
 	if (rc)
 		goto out_dax;
fs/fuse/virtio_fs.c +1 -1
index 242cc1c0d7ed7..5c03a0364a9bb 100644
@@ -850,7 +850,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
 	dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len 0x%llx\n",
 		__func__, fs->window_kaddr, cache_reg.addr, cache_reg.len);
 
-	fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops, 0);
+	fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
 	if (IS_ERR(fs->dax_dev))
 		return PTR_ERR(fs->dax_dev);
 
include/linux/dax.h +2 -6
index 3bd1fdb5d5f4b..c04f46478e3b5 100644
@@ -6,9 +6,6 @@
 #include <linux/mm.h>
 #include <linux/radix-tree.h>
 
-/* Flag for synchronous flush */
-#define DAXDEV_F_SYNC (1UL << 0)
-
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -42,8 +39,7 @@ struct dax_operations {
 };
 
 #if IS_ENABLED(CONFIG_DAX)
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-		unsigned long flags);
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
 void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);
@@ -64,7 +60,7 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 }
 #else
 static inline struct dax_device *alloc_dax(void *private,
-		const struct dax_operations *ops, unsigned long flags)
+		const struct dax_operations *ops)
 {
 	/*
 	 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
Signature · 1 line
2.30.2
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] dax: remove the DAXDEV_F_SYNC flag

Quoted 5 lines · Christoph Hellwig

Remove the DAXDEV_F_SYNC flag and thus the flags argument to alloc_dax and just let the drivers call set_dax_synchronous directly.

Sure, looks good to me.

Quoted 163 lines
---
 drivers/dax/bus.c            | 3 ++-
 drivers/dax/super.c          | 6 +-----
 drivers/md/dm.c              | 2 +-
 drivers/nvdimm/pmem.c        | 7 +++----
 drivers/s390/block/dcssblk.c | 4 ++--
 fs/fuse/virtio_fs.c          | 2 +-
 include/linux/dax.h          | 8 ++------
 7 files changed, 12 insertions(+), 20 deletions(-)
drivers/dax/bus.c +2 -1
index 6683d42c32c56..da2a14d096d29 100644
@@ -1324,11 +1324,12 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
         * No dax_operations since there is no access to this device outside of
         * mmap of the resulting character device.
         */
-       dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC);
+       dax_dev = alloc_dax(dev_dax, NULL);
        if (IS_ERR(dax_dev)) {
                rc = PTR_ERR(dax_dev);
                goto err_alloc_dax;
        }
+       set_dax_synchronous(dax_dev);
 
        /* a device_dax instance is dead while the driver is not attached */
        kill_dax(dax_dev);
drivers/dax/super.c +1 -5
index e18155f43a635..e81d5ee57390f 100644
@@ -345,8 +345,7 @@ static struct dax_device *dax_dev_get(dev_t devt)
        return dax_dev;
 }
 
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-               unsigned long flags)
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
 {
        struct dax_device *dax_dev;
        dev_t devt;
@@ -366,9 +365,6 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
 
        dax_dev->ops = ops;
        dax_dev->private = private;
-       if (flags & DAXDEV_F_SYNC)
-               set_dax_synchronous(dax_dev);
-
        return dax_dev;
 
  err_dev:
drivers/md/dm.c +1 -1
index 4e997c02bb0a0..f4b972af10928 100644
@@ -1765,7 +1765,7 @@ static struct mapped_device *alloc_dev(int minor)
        sprintf(md->disk->disk_name, "dm-%d", minor);
 
        if (IS_ENABLED(CONFIG_FS_DAX)) {
-               md->dax_dev = alloc_dax(md, &dm_dax_ops, 0);
+               md->dax_dev = alloc_dax(md, &dm_dax_ops);
                if (IS_ERR(md->dax_dev)) {
                        md->dax_dev = NULL;
                        goto bad;
drivers/nvdimm/pmem.c +3 -4
index 8294f1c701baa..85b3339286bd8 100644
@@ -402,7 +402,6 @@ static int pmem_attach_disk(struct device *dev,
        struct gendisk *disk;
        void *addr;
        int rc;
-       unsigned long flags = 0UL;
 
        pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
        if (!pmem)
@@ -495,13 +494,13 @@ static int pmem_attach_disk(struct device *dev,
        nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_range);
        disk->bb = &pmem->bb;
 
-       if (is_nvdimm_sync(nd_region))
-               flags = DAXDEV_F_SYNC;
-       dax_dev = alloc_dax(pmem, &pmem_dax_ops, flags);
+       dax_dev = alloc_dax(pmem, &pmem_dax_ops);
        if (IS_ERR(dax_dev)) {
                rc = PTR_ERR(dax_dev);
                goto out;
        }
+       if (is_nvdimm_sync(nd_region))
+               set_dax_synchronous(dax_dev);
        rc = dax_add_host(dax_dev, disk);
        if (rc)
                goto out_cleanup_dax;
drivers/s390/block/dcssblk.c +2 -2
index e65e83764d1ce..10823debc09bd 100644
@@ -686,13 +686,13 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        if (rc)
                goto put_dev;
 
-       dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops,
-                       DAXDEV_F_SYNC);
+       dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops);
        if (IS_ERR(dev_info->dax_dev)) {
                rc = PTR_ERR(dev_info->dax_dev);
                dev_info->dax_dev = NULL;
                goto put_dev;
        }
+       set_dax_synchronous(dev_info->dax_dev);
        rc = dax_add_host(dev_info->dax_dev, dev_info->gd);
        if (rc)
                goto out_dax;
fs/fuse/virtio_fs.c +1 -1
index 242cc1c0d7ed7..5c03a0364a9bb 100644
@@ -850,7 +850,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
        dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len 0x%llx\n",
                __func__, fs->window_kaddr, cache_reg.addr, cache_reg.len);
 
-       fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops, 0);
+       fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
        if (IS_ERR(fs->dax_dev))
                return PTR_ERR(fs->dax_dev);
 
include/linux/dax.h +2 -7
index 3bd1fdb5d5f4b..c04f46478e3b5 100644
@@ -6,9 +6,6 @@
 #include <linux/mm.h>
 #include <linux/radix-tree.h>
 
-/* Flag for synchronous flush */
-#define DAXDEV_F_SYNC (1UL << 0)
-
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -42,8 +39,7 @@ struct dax_operations {
 };
 
 #if IS_ENABLED(CONFIG_DAX)
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-               unsigned long flags);
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
 void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);
@@ -64,7 +60,7 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 }
 #else
 static inline struct dax_device *alloc_dax(void *private,
-               const struct dax_operations *ops, unsigned long flags)
+               const struct dax_operations *ops)
 {
        /*
         * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
--

2.30.2

Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] dax: remove the DAXDEV_F_SYNC flag

In reply to Christoph Hellwig
Quoted 156 lines

Remove the DAXDEV_F_SYNC flag and thus the flags argument to alloc_dax and just let the drivers call set_dax_synchronous directly.

---
 drivers/dax/bus.c            | 3 ++-
 drivers/dax/super.c          | 6 +-----
 drivers/md/dm.c              | 2 +-
 drivers/nvdimm/pmem.c        | 7 +++----
 drivers/s390/block/dcssblk.c | 4 ++--
 fs/fuse/virtio_fs.c          | 2 +-
 include/linux/dax.h          | 8 ++------
 7 files changed, 12 insertions(+), 20 deletions(-)
drivers/dax/bus.c +2 -1
index 6683d42c32c56..da2a14d096d29 100644
@@ -1324,11 +1324,12 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
         * No dax_operations since there is no access to this device outside of
         * mmap of the resulting character device.
         */
-       dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC);
+       dax_dev = alloc_dax(dev_dax, NULL);
        if (IS_ERR(dax_dev)) {
                rc = PTR_ERR(dax_dev);
                goto err_alloc_dax;
        }
+       set_dax_synchronous(dax_dev);
 
        /* a device_dax instance is dead while the driver is not attached */
        kill_dax(dax_dev);
drivers/dax/super.c +1 -5
index e18155f43a635..e81d5ee57390f 100644
@@ -345,8 +345,7 @@ static struct dax_device *dax_dev_get(dev_t devt)
        return dax_dev;
 }
 
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-               unsigned long flags)
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
 {
        struct dax_device *dax_dev;
        dev_t devt;
@@ -366,9 +365,6 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
 
        dax_dev->ops = ops;
        dax_dev->private = private;
-       if (flags & DAXDEV_F_SYNC)
-               set_dax_synchronous(dax_dev);
-
        return dax_dev;
 
  err_dev:
drivers/md/dm.c +1 -1
index 4e997c02bb0a0..f4b972af10928 100644
@@ -1765,7 +1765,7 @@ static struct mapped_device *alloc_dev(int minor)
        sprintf(md->disk->disk_name, "dm-%d", minor);
 
        if (IS_ENABLED(CONFIG_FS_DAX)) {
-               md->dax_dev = alloc_dax(md, &dm_dax_ops, 0);
+               md->dax_dev = alloc_dax(md, &dm_dax_ops);
                if (IS_ERR(md->dax_dev)) {
                        md->dax_dev = NULL;
                        goto bad;
drivers/nvdimm/pmem.c +3 -4
index 8294f1c701baa..85b3339286bd8 100644
@@ -402,7 +402,6 @@ static int pmem_attach_disk(struct device *dev,
        struct gendisk *disk;
        void *addr;
        int rc;
-       unsigned long flags = 0UL;
 
        pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
        if (!pmem)
@@ -495,13 +494,13 @@ static int pmem_attach_disk(struct device *dev,
        nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_range);
        disk->bb = &pmem->bb;
 
-       if (is_nvdimm_sync(nd_region))
-               flags = DAXDEV_F_SYNC;
-       dax_dev = alloc_dax(pmem, &pmem_dax_ops, flags);
+       dax_dev = alloc_dax(pmem, &pmem_dax_ops);
        if (IS_ERR(dax_dev)) {
                rc = PTR_ERR(dax_dev);
                goto out;
        }
+       if (is_nvdimm_sync(nd_region))
+               set_dax_synchronous(dax_dev);
        rc = dax_add_host(dax_dev, disk);
        if (rc)
                goto out_cleanup_dax;
drivers/s390/block/dcssblk.c +2 -2
index e65e83764d1ce..10823debc09bd 100644
@@ -686,13 +686,13 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        if (rc)
                goto put_dev;
 
-       dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops,
-                       DAXDEV_F_SYNC);
+       dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops);
        if (IS_ERR(dev_info->dax_dev)) {
                rc = PTR_ERR(dev_info->dax_dev);
                dev_info->dax_dev = NULL;
                goto put_dev;
        }
+       set_dax_synchronous(dev_info->dax_dev);
        rc = dax_add_host(dev_info->dax_dev, dev_info->gd);
        if (rc)
                goto out_dax;
fs/fuse/virtio_fs.c +1 -1
index 242cc1c0d7ed7..5c03a0364a9bb 100644
@@ -850,7 +850,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
        dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len 0x%llx\n",
                __func__, fs->window_kaddr, cache_reg.addr, cache_reg.len);
 
-       fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops, 0);
+       fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
        if (IS_ERR(fs->dax_dev))
                return PTR_ERR(fs->dax_dev);
 
include/linux/dax.h +1 -5
index 3bd1fdb5d5f4b..c04f46478e3b5 100644
@@ -6,9 +6,6 @@
 #include <linux/mm.h>
 #include <linux/radix-tree.h>
 
-/* Flag for synchronous flush */
-#define DAXDEV_F_SYNC (1UL << 0)
-
 typedef unsigned long dax_entry_t;
 
 struct dax_device;
@@ -42,8 +39,7 @@ struct dax_operations {
 };
 
 #if IS_ENABLED(CONFIG_DAX)
-struct dax_device *alloc_dax(void *private, const struct dax_operations *ops,
-               unsigned long flags);
+struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
 void put_dax(struct dax_device *dax_dev);
 void kill_dax(struct dax_device *dax_dev);
 void dax_write_cache(struct dax_device *dax_dev, bool wc);

include/linux/dax.h static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, · line 66

Quoted 8 lines
include/linux/dax.h +1 -1
@@ -64,7 +60,7 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 }
 #else
 static inline struct dax_device *alloc_dax(void *private,
-               const struct dax_operations *ops, unsigned long flags)
+               const struct dax_operations *ops)
 {
        /*
         * Callers should check IS_ENABLED(CONFIG_DAX) to know if this

Looks good.

#10 lore raw

PATCH 4/5 dax: remove the copy_from_iter and copy_to_iter methods

In reply to Christoph Hellwig

These methods indirect the actual DAX read/write path. In the end pmem uses magic flush and mc safe variants and fuse and dcssblk use plain ones while device mapper picks redirects to the underlying device.

Add set_dax_virtual() and set_dax_nomcsafe() APIs for fuse to skip these special variants, then use them everywhere as they fall back to the plain ones on s390 anyway and remove an indirect call from the read/write path as well as a lot of boilerplate code.

---
 drivers/dax/super.c           | 36 ++++++++++++++--
 drivers/md/dm-linear.c        | 20 ---------
 drivers/md/dm-log-writes.c    | 80 -----------------------------------
 drivers/md/dm-stripe.c        | 20 ---------
 drivers/md/dm.c               | 50 ----------------------
 drivers/nvdimm/pmem.c         | 20 ---------
 drivers/s390/block/dcssblk.c  | 14 ------
 fs/dax.c                      |  5 ---
 fs/fuse/virtio_fs.c           | 19 +--------
 include/linux/dax.h           |  9 ++--
 include/linux/device-mapper.h |  4 --
 11 files changed, 37 insertions(+), 240 deletions(-)
drivers/dax/super.c +32 -4
index e81d5ee57390f..ff676a07480c8 100644
@@ -105,6 +105,10 @@ enum dax_device_flags {
 	DAXDEV_WRITE_CACHE,
 	/* flag to check if device supports synchronous flush */
 	DAXDEV_SYNC,
+	/* do not use uncached operations to write data */
+	DAXDEV_CACHED,
+	/* do not use mcsafe operations to read data */
+	DAXDEV_NOMCSAFE,
 };
 
 /**
@@ -146,9 +150,15 @@ size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 	if (!dax_alive(dax_dev))
 		return 0;
 
-	return dax_dev->ops->copy_from_iter(dax_dev, pgoff, addr, bytes, i);
+	/*
+	 * The userspace address for the memory copy has already been validated
+	 * via access_ok() in vfs_write, so use the 'no check' version to bypass
+	 * the HARDENED_USERCOPY overhead.
+	 */
+	if (test_bit(DAXDEV_CACHED, &dax_dev->flags))
+		return _copy_from_iter(addr, bytes, i);
+	return _copy_from_iter_flushcache(addr, bytes, i);
 }
-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)
@@ -156,9 +166,15 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 	if (!dax_alive(dax_dev))
 		return 0;
 
-	return dax_dev->ops->copy_to_iter(dax_dev, pgoff, addr, bytes, i);
+	/*
+	 * The userspace address for the memory copy has already been validated
+	 * via access_ok() in vfs_red, so use the 'no check' version to bypass
+	 * the HARDENED_USERCOPY overhead.
+	 */
+	if (test_bit(DAXDEV_NOMCSAFE, &dax_dev->flags))
+		return _copy_to_iter(addr, bytes, i);
+	return _copy_mc_to_iter(addr, bytes, i);
 }
-EXPORT_SYMBOL_GPL(dax_copy_to_iter);
 
 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 			size_t nr_pages)
@@ -220,6 +236,18 @@ void set_dax_synchronous(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(set_dax_synchronous);
 
+void set_dax_cached(struct dax_device *dax_dev)
+{
+	set_bit(DAXDEV_CACHED, &dax_dev->flags);
+}
+EXPORT_SYMBOL_GPL(set_dax_cached);
+
+void set_dax_nomcsafe(struct dax_device *dax_dev)
+{
+	set_bit(DAXDEV_NOMCSAFE, &dax_dev->flags);
+}
+EXPORT_SYMBOL_GPL(set_dax_nomcsafe);
+
 bool dax_alive(struct dax_device *dax_dev)
 {
 	lockdep_assert_held(&dax_srcu);
drivers/md/dm-linear.c +0 -20
index 90de42f6743ac..1b97a11d71517 100644
@@ -180,22 +180,6 @@ static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
 	return dax_direct_access(dax_dev, pgoff, nr_pages, 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)
-{
-	struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff);
-
-	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
-}
-
-static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
-{
-	struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff);
-
-	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
-}
-
 static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
 				      size_t nr_pages)
 {
@@ -206,8 +190,6 @@ static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
 
 #else
 #define linear_dax_direct_access NULL
-#define linear_dax_copy_from_iter NULL
-#define linear_dax_copy_to_iter NULL
 #define linear_dax_zero_page_range NULL
 #endif
 
@@ -225,8 +207,6 @@ static struct target_type linear_target = {
 	.prepare_ioctl = linear_prepare_ioctl,
 	.iterate_devices = linear_iterate_devices,
 	.direct_access = linear_dax_direct_access,
-	.dax_copy_from_iter = linear_dax_copy_from_iter,
-	.dax_copy_to_iter = linear_dax_copy_to_iter,
 	.dax_zero_page_range = linear_dax_zero_page_range,
 };
 
drivers/md/dm-log-writes.c +0 -80

104 lines not on this page · raw message

drivers/md/dm-stripe.c +0 -20
index 50dba3f39274c..e566115ec0bb8 100644
@@ -324,22 +324,6 @@ static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
 	return dax_direct_access(dax_dev, pgoff, nr_pages, 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)
-{
-	struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
-
-	return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
-}
-
-static size_t stripe_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
-{
-	struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
-
-	return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
-}
-
 static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
 				      size_t nr_pages)
 {
@@ -350,8 +334,6 @@ static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
 
 #else
 #define stripe_dax_direct_access NULL
-#define stripe_dax_copy_from_iter NULL
-#define stripe_dax_copy_to_iter NULL
 #define stripe_dax_zero_page_range NULL
 #endif
 
@@ -488,8 +470,6 @@ static struct target_type stripe_target = {
 	.iterate_devices = stripe_iterate_devices,
 	.io_hints = stripe_io_hints,
 	.direct_access = stripe_dax_direct_access,
-	.dax_copy_from_iter = stripe_dax_copy_from_iter,
-	.dax_copy_to_iter = stripe_dax_copy_to_iter,
 	.dax_zero_page_range = stripe_dax_zero_page_range,
 };
 
drivers/md/dm.c +0 -50

62 lines not on this page · raw message

drivers/nvdimm/pmem.c +0 -20
index 85b3339286bd8..b08f0642aa257 100644
@@ -301,28 +301,8 @@ static long pmem_dax_direct_access(struct dax_device *dax_dev,
 	return __pmem_direct_access(pmem, pgoff, nr_pages, kaddr, pfn);
 }
 
-/*
- * 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()
- */
-static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
-		void *addr, size_t bytes, struct iov_iter *i)
-{
-	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)
-{
-	return _copy_mc_to_iter(addr, bytes, i);
-}
-
 static const struct dax_operations pmem_dax_ops = {
 	.direct_access = pmem_dax_direct_access,
-	.copy_from_iter = pmem_copy_from_iter,
-	.copy_to_iter = pmem_copy_to_iter,
 	.zero_page_range = pmem_dax_zero_page_range,
 };
 
drivers/s390/block/dcssblk.c +0 -14
index 10823debc09bd..d614843caf6cc 100644
@@ -44,18 +44,6 @@ static const struct block_device_operations dcssblk_devops = {
 	.release 	= dcssblk_release,
 };
 
-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)
-{
-	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)
-{
-	return copy_to_iter(addr, bytes, i);
-}
-
 static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
 				       pgoff_t pgoff, size_t nr_pages)
 {
@@ -72,8 +60,6 @@ static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
 
 static const struct dax_operations dcssblk_dax_ops = {
 	.direct_access = dcssblk_dax_direct_access,
-	.copy_from_iter = dcssblk_dax_copy_from_iter,
-	.copy_to_iter = dcssblk_dax_copy_to_iter,
 	.zero_page_range = dcssblk_dax_zero_page_range,
 };
 
fs/dax.c +0 -5
index e0eecd8e3a8f8..cd03485867a74 100644
@@ -1260,11 +1260,6 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
 		if (map_len > end - pos)
 			map_len = end - pos;
 
-		/*
-		 * The userspace address for the memory copy has already been
-		 * validated via access_ok() in either vfs_read() or
-		 * vfs_write(), depending on which operation we are doing.
-		 */
 		if (iov_iter_rw(iter) == WRITE)
 			xfer = dax_copy_from_iter(dax_dev, pgoff, kaddr,
 					map_len, iter);
fs/fuse/virtio_fs.c +2 -17
index 5c03a0364a9bb..754319ce2a29b 100644
@@ -753,20 +753,6 @@ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	return nr_pages > max_nr_pages ? max_nr_pages : nr_pages;
 }
 
-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)
-{
-	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)
-{
-	return copy_to_iter(addr, bytes, i);
-}
-
 static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 				     pgoff_t pgoff, size_t nr_pages)
 {
@@ -783,8 +769,6 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 
 static const struct dax_operations virtio_fs_dax_ops = {
 	.direct_access = virtio_fs_direct_access,
-	.copy_from_iter = virtio_fs_copy_from_iter,
-	.copy_to_iter = virtio_fs_copy_to_iter,
 	.zero_page_range = virtio_fs_zero_page_range,
 };
 
@@ -853,7 +837,8 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
 	fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
 	if (IS_ERR(fs->dax_dev))
 		return PTR_ERR(fs->dax_dev);
-
+	set_dax_cached(fs->dax_dev);
+	set_dax_nomcsafe(fs->dax_dev);
 	return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
 					fs->dax_dev);
 }
include/linux/dax.h +3 -6
index c04f46478e3b5..d22cbf03d37d2 100644
@@ -28,12 +28,6 @@ struct dax_operations {
 	 */
 	bool (*dax_supported)(struct dax_device *, struct block_device *, int,
 			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 *);
-	/* 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 *);
 	/* zero_page_range: required operation. Zero page range   */
 	int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
 };
@@ -95,6 +89,9 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 }
 #endif
 
+void set_dax_cached(struct dax_device *dax_dev);
+void set_dax_nomcsafe(struct dax_device *dax_dev);
+
 struct writeback_control;
 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
 int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
include/linux/device-mapper.h +0 -4
index a7df155ea49b8..b26fecf6c8e87 100644
@@ -147,8 +147,6 @@ typedef int (*dm_busy_fn) (struct dm_target *ti);
  */
 typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff,
 		long nr_pages, 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);
 typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,
 		size_t nr_pages);
 
@@ -200,8 +198,6 @@ struct target_type {
 	dm_iterate_devices_fn iterate_devices;
 	dm_io_hints_fn io_hints;
 	dm_dax_direct_access_fn direct_access;
-	dm_dax_copy_iter_fn dax_copy_from_iter;
-	dm_dax_copy_iter_fn dax_copy_to_iter;
 	dm_dax_zero_page_range_fn dax_zero_page_range;
 
 	/* For internal device-mapper use. */
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 24 lines · Christoph Hellwig

These methods indirect the actual DAX read/write path. In the end pmem uses magic flush and mc safe variants and fuse and dcssblk use plain ones while device mapper picks redirects to the underlying device.

Add set_dax_virtual() and set_dax_nomcsafe() APIs for fuse to skip these special variants, then use them everywhere as they fall back to the plain ones on s390 anyway and remove an indirect call from the read/write path as well as a lot of boilerplate code.

---
 drivers/dax/super.c           | 36 ++++++++++++++--
 drivers/md/dm-linear.c        | 20 ---------
 drivers/md/dm-log-writes.c    | 80 -----------------------------------
 drivers/md/dm-stripe.c        | 20 ---------
 drivers/md/dm.c               | 50 ----------------------
 drivers/nvdimm/pmem.c         | 20 ---------
 drivers/s390/block/dcssblk.c  | 14 ------
 fs/dax.c                      |  5 ---
 fs/fuse/virtio_fs.c           | 19 +--------
 include/linux/dax.h           |  9 ++--
 include/linux/device-mapper.h |  4 --
 11 files changed, 37 insertions(+), 240 deletions(-)

[..]

Quoted 35 lines
fs/fuse/virtio_fs.c +0 -16
index 5c03a0364a9bb..754319ce2a29b 100644
@@ -753,20 +753,6 @@ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	return nr_pages > max_nr_pages ? max_nr_pages : nr_pages;
 }
 
-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)
-{
-	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)
-{
-	return copy_to_iter(addr, bytes, i);
-}
-
 static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 				     pgoff_t pgoff, size_t nr_pages)
 {
@@ -783,8 +769,6 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 
 static const struct dax_operations virtio_fs_dax_ops = {
 	.direct_access = virtio_fs_direct_access,
-	.copy_from_iter = virtio_fs_copy_from_iter,
-	.copy_to_iter = virtio_fs_copy_to_iter,
 	.zero_page_range = virtio_fs_zero_page_range,
 };
 

fs/fuse/virtio_fs.c static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) · line 840

Quoted 5 lines
fs/fuse/virtio_fs.c +1 -1
@@ -853,7 +837,8 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
 	fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
 	if (IS_ERR(fs->dax_dev))
 		return PTR_ERR(fs->dax_dev);
-
+	set_dax_cached(fs->dax_dev);

Looks good to me from virtiofs point of view.

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

fs/fuse/virtio_fs.c static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) · line 844

Quoted 4 lines
fs/fuse/virtio_fs.c +1 -0
+	set_dax_nomcsafe(fs->dax_dev);
 	return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
 					fs->dax_dev);
 }

Thanks
Vivek

#12 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 71 lines · Vivek Goyal
Quoted 24 lines · Christoph Hellwig

These methods indirect the actual DAX read/write path. In the end pmem uses magic flush and mc safe variants and fuse and dcssblk use plain ones while device mapper picks redirects to the underlying device.

Add set_dax_virtual() and set_dax_nomcsafe() APIs for fuse to skip these special variants, then use them everywhere as they fall back to the plain ones on s390 anyway and remove an indirect call from the read/write path as well as a lot of boilerplate code.

---
 drivers/dax/super.c           | 36 ++++++++++++++--
 drivers/md/dm-linear.c        | 20 ---------
 drivers/md/dm-log-writes.c    | 80 -----------------------------------
 drivers/md/dm-stripe.c        | 20 ---------
 drivers/md/dm.c               | 50 ----------------------
 drivers/nvdimm/pmem.c         | 20 ---------
 drivers/s390/block/dcssblk.c  | 14 ------
 fs/dax.c                      |  5 ---
 fs/fuse/virtio_fs.c           | 19 +--------
 include/linux/dax.h           |  9 ++--
 include/linux/device-mapper.h |  4 --
 11 files changed, 37 insertions(+), 240 deletions(-)

[..]

Quoted 35 lines
fs/fuse/virtio_fs.c +0 -16
index 5c03a0364a9bb..754319ce2a29b 100644
@@ -753,20 +753,6 @@ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
      return nr_pages > max_nr_pages ? max_nr_pages : nr_pages;
 }
 
-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)
-{
-     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)
-{
-     return copy_to_iter(addr, bytes, i);
-}
-
 static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
                                   pgoff_t pgoff, size_t nr_pages)
 {
@@ -783,8 +769,6 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 
 static const struct dax_operations virtio_fs_dax_ops = {
      .direct_access = virtio_fs_direct_access,
-     .copy_from_iter = virtio_fs_copy_from_iter,
-     .copy_to_iter = virtio_fs_copy_to_iter,
      .zero_page_range = virtio_fs_zero_page_range,
 };
 

fs/fuse/virtio_fs.c static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) · line 840

Quoted 5 lines
fs/fuse/virtio_fs.c +1 -1
@@ -853,7 +837,8 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
      fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
      if (IS_ERR(fs->dax_dev))
              return PTR_ERR(fs->dax_dev);
-
+     set_dax_cached(fs->dax_dev);

Looks good to me from virtiofs point of view.

Quoted 8 lines

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Quoted 10 lines

fs/fuse/virtio_fs.c static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) · line 844

Quoted 5 lines
fs/fuse/virtio_fs.c +1 -0
+     set_dax_nomcsafe(fs->dax_dev);
      return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
                                      fs->dax_dev);
 }

Thanks
Vivek

#13 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 5 lines · Dan Williams
Quoted 4 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Quoted 8 lines
Quoted 2 lines

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

maintainer
#14 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Vivek

#15 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

maintainer
#16 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

IOW.

	if (virtiofs_backed_by_pmem) {
		use_mc_safe_version
	else
		use_non_mc_safe_version
	}

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

Vivek

#17 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 65 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

Quoted 6 lines

But if we are not using pmem on host, then there is no point in using MC safe variant.

IOW.

        if (virtiofs_backed_by_pmem) {

No, PMEM should not be considered at all relative to whether to use MC or not, it is 100% a decision of whether you expect virtiofs users will balk more at unhandled machine checks or performance regressions on the platforms that set "enable_copy_mc_fragile()". See quirk_intel_brickland_xeon_ras_cap() and quirk_intel_purley_xeon_ras_cap() in arch/x86/kernel/quirks.c.

Quoted 10 lines
                use_mc_safe_version
        else
                use_non_mc_safe_version
        }

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

Quoted 6 lines

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

I assume you meant "not like", but again PMEM has no bearing on whether using that device will throw machine checks. I'm sure there are people that would make the opposite tradeoff.

maintainer
#18 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 69 lines · Dan Williams
Quoted 68 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

Quoted 8 lines
Quoted 3 lines

IOW.

        if (virtiofs_backed_by_pmem) {

No, PMEM should not be considered at all relative to whether to use MC or not, it is 100% a decision of whether you expect virtiofs users will balk more at unhandled machine checks or performance regressions on the platforms that set "enable_copy_mc_fragile()".

If we don't handle machine check, kernel will panic(), right? So that's the trade off. Whether get higher performance (on select platforms) and crash if MC happens OR get slower memcpy() performance (on select platoforms) and recover from MC. Hmm...

Quoted 14 lines

See
quirk_intel_brickland_xeon_ras_cap() and quirk_intel_purley_xeon_ras_cap() in arch/x86/kernel/quirks.c.

Quoted 10 lines
                use_mc_safe_version
        else
                use_non_mc_safe_version
        }

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

Quoted 8 lines
Quoted 6 lines

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

I assume you meant "not like",

Yes. It was a typo.

Quoted 3 lines

but again PMEM has no bearing on
whether using that device will throw machine checks. I'm sure there are people that would make the opposite tradeoff.

Why pmem driver does not have to make such trade off and it always uses machine check variant.

As you mentioned machine checks can happen with DRAM too. So why loading from page cache not use machine check variant (or given an option to user allow making a choice).

BTW, stefan mentioned that we could think of adding a device feature bit to signal whether to do MC safe memcpy() or not if it becomes really necessary. For now probably let us stick to performance variant and if users demand machine check handling, then either introduce it unconditionally or make it an opt-in based on device feature bit.

Thanks
Vivek

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#19 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 109 lines · Vivek Goyal
Quoted 69 lines · Dan Williams
Quoted 68 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

Quoted 8 lines
Quoted 3 lines

IOW.

        if (virtiofs_backed_by_pmem) {

No, PMEM should not be considered at all relative to whether to use MC or not, it is 100% a decision of whether you expect virtiofs users will balk more at unhandled machine checks or performance regressions on the platforms that set "enable_copy_mc_fragile()".

If we don't handle machine check, kernel will panic(), right? So that's the trade off. Whether get higher performance (on select platforms) and crash if MC happens OR get slower memcpy() performance (on select platoforms) and recover from MC. Hmm...

Quoted 14 lines

See
quirk_intel_brickland_xeon_ras_cap() and quirk_intel_purley_xeon_ras_cap() in arch/x86/kernel/quirks.c.

Quoted 10 lines
                use_mc_safe_version
        else
                use_non_mc_safe_version
        }

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

Quoted 8 lines
Quoted 6 lines

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

I assume you meant "not like",

Quoted 8 lines

Yes. It was a typo.

Quoted 3 lines

but again PMEM has no bearing on
whether using that device will throw machine checks. I'm sure there are people that would make the opposite tradeoff.

Why pmem driver does not have to make such trade off and it always uses machine check variant.

It certainly did. I can't find the thread now, but the end result was to accept the performance regression in favor of maximal MC handling protection.

Quoted 3 lines

As you mentioned machine checks can happen with DRAM too. So why loading from page cache not use machine check variant (or given an option to user allow making a choice).

...because regressing page cache operations is fraught, and x86 machine check architecture elicits strong feelings.

Quoted 6 lines

BTW, stefan mentioned that we could think of adding a device feature bit to signal whether to do MC safe memcpy() or not if it becomes really necessary. For now probably let us stick to performance variant and if users demand machine check handling, then either introduce it unconditionally or make it an opt-in based on device feature bit.

Sure, it's a reasonable choice.

maintainer
#20 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

In reply to Vivek Goyal
Quoted 80 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

IOW.

	if (virtiofs_backed_by_pmem) {
		use_mc_safe_version
	else
		use_non_mc_safe_version
	}

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

Quoted 6 lines

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

Reads from the page cache handle machine checks (filemap_read() -> raw_copy_to_user()). I think virtiofs should therefore always handle machine checks when reading from the DAX Window.

Stefan

maintainer
#21 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 85 lines · Stefan Hajnoczi
Quoted 84 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

IOW.

	if (virtiofs_backed_by_pmem) {
		use_mc_safe_version
	else
		use_non_mc_safe_version
	}

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

Quoted 6 lines
Quoted 2 lines

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

Reads from the page cache handle machine checks (filemap_read() -> raw_copy_to_user()). I think virtiofs should therefore always handle machine checks when reading from the DAX Window.

IIUC, raw_copy_to_user() does not handle recovery from machine check. For example, it can call copy_user_enhanced_fast_string() if cpu supports X86_FEATURE_ERMS. But equivalent machine check safe version is copy_mc_enhanced_fast_string() instead.

Hence, I don't think reading from page cache is using machine check safe variants by default. This copy_mc_to_user() path has to be taken explicitly for machine check safe variants. And currently only pmem driver seems to take it by calling _copy_mc_to_iter().

Thanks
Vivek

maintainer
#22 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 98 lines · Vivek Goyal
Quoted 85 lines · Stefan Hajnoczi
Quoted 84 lines · Vivek Goyal
Quoted 47 lines · Dan Williams
Quoted 37 lines · Vivek Goyal
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Dan Williams
Quoted 6 lines · Vivek Goyal

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

Quoted 8 lines
Quoted 5 lines

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver. However, if the guest sends any fsync/msync you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

Do we? The application can't really know what backend it is on, so it sounds like the current virtiofs implementation doesn't really, does it?

Agreed that application does not know what backend it is on. So virtiofs just offers regular posix API where applications have to do fsync/msync for data persistence. No support for mmap(MAP_SYNC). We don't offer persistent memory programming model on virtiofs. That's not the expectation. DAX is used only to bypass guest page cache.

With this assumption, I think we might not have to use flushcache version at all even if shared filesystem is on persistent memory on host.

- We mmap() host files into qemu address space. So any dax store in virtiofs should make corresponding pages dirty in page cache on host and when and fsync()/msync() comes later, it should flush all the data to PMEM.

- In case of file extending writes, virtiofs falls back to regular FUSE_WRITE path (and not use DAX), and in that case host pmem driver should make sure writes are flushed to pmem immediately.

Quoted 8 lines

Are there any other path I am missing. If not, looks like we might not have to use flushcache version in virtiofs at all as long as we are not offering guest applications user space flushes and MAP_SYNC support.

We still might have to use machine check safe variant though as loads might generate synchronous machine check. What's not clear to me is that if this MC safe variant should be used only in case of PMEM or should it be used in case of non-PMEM as well.

Quoted 5 lines

It should be used on any memory address that can throw exception on load, which is any physical address, in paths that can tolerate memcpy() returning an error code, most I/O paths, and can tolerate slower copy performance on older platforms that do not support MC recovery with fast string operations, to date that's only PMEM users.

Ok, So basically latest cpus can do fast string operations with MC recovery so that using MC safe variant is not a problem.

Then there is range of cpus which can do MC recovery but do slower versions of memcpy and that's where the issue is.

So if we knew that virtiofs dax window is backed by a pmem device then we should always use MC safe variant. Even if it means paying the price of slow version for the sake of correctness.

But if we are not using pmem on host, then there is no point in using MC safe variant.

IOW.

	if (virtiofs_backed_by_pmem) {
		use_mc_safe_version
	else
		use_non_mc_safe_version
	}

Now question is, how do we know if virtiofs dax window is backed by a pmem or not. I checked virtio_pmem driver and that does not seem to communicate anything like that. It just communicates start of the range and size of range, nothing else.

I don't have full handle on stack of modules of virtio_pmem, but my guess is it probably is using MC safe version always (because it does not know anthing about the backing storage).

Quoted 6 lines
Quoted 2 lines

/me will definitely like to pay penalty of slower memcpy if virtiofs device is not backed by a pmem.

Reads from the page cache handle machine checks (filemap_read() -> raw_copy_to_user()). I think virtiofs should therefore always handle machine checks when reading from the DAX Window.

IIUC, raw_copy_to_user() does not handle recovery from machine check. For example, it can call copy_user_enhanced_fast_string() if cpu supports X86_FEATURE_ERMS. But equivalent machine check safe version is copy_mc_enhanced_fast_string() instead.

Quoted 4 lines

Hence, I don't think reading from page cache is using machine check safe variants by default. This copy_mc_to_user() path has to be taken explicitly for machine check safe variants. And currently only pmem driver seems to take it by calling _copy_mc_to_iter().

Now I'm confused between copy_user_enhanced_fast_string() and copy_mc_enhanced_fast_string(). The code is very similar, the main difference being _ASM_EXTABLE_CPY() vs _ASM_EXTABLE_TYPE(..., ..., EX_TYPE_DEFAULT_MCE_SAFE).

Both return IN_KERNEL_RECOV from error_context() and set mce->kflags |= MCE_IN_KERNEL_RECOV. The difference is that copy_user_enhanced_fast_string() also sets mce->kflags |= MCE_IN_KERNEL_COPYIN in copy_user_enhanced_fast_string() whereas copy_mc_enhanced_fast_string() does not.

I must be missing something:

1. What is the purpose of the extable in copy_user_enhanced_fast_string() if that function cannot recover from MCEs?

2. Why is there a "Don't try to copy the tail if machine check happened" comment in .Lcopy_user_handle_tail?

Stefan

maintainer
#23 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

In reply to Dan Williams
Quoted 78 lines · Dan Williams
Quoted 77 lines · Vivek Goyal
Quoted 24 lines · Christoph Hellwig

These methods indirect the actual DAX read/write path. In the end pmem uses magic flush and mc safe variants and fuse and dcssblk use plain ones while device mapper picks redirects to the underlying device.

Add set_dax_virtual() and set_dax_nomcsafe() APIs for fuse to skip these special variants, then use them everywhere as they fall back to the plain ones on s390 anyway and remove an indirect call from the read/write path as well as a lot of boilerplate code.

---
 drivers/dax/super.c           | 36 ++++++++++++++--
 drivers/md/dm-linear.c        | 20 ---------
 drivers/md/dm-log-writes.c    | 80 -----------------------------------
 drivers/md/dm-stripe.c        | 20 ---------
 drivers/md/dm.c               | 50 ----------------------
 drivers/nvdimm/pmem.c         | 20 ---------
 drivers/s390/block/dcssblk.c  | 14 ------
 fs/dax.c                      |  5 ---
 fs/fuse/virtio_fs.c           | 19 +--------
 include/linux/dax.h           |  9 ++--
 include/linux/device-mapper.h |  4 --
 11 files changed, 37 insertions(+), 240 deletions(-)

[..]

Quoted 35 lines
fs/fuse/virtio_fs.c +0 -16
index 5c03a0364a9bb..754319ce2a29b 100644
@@ -753,20 +753,6 @@ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
      return nr_pages > max_nr_pages ? max_nr_pages : nr_pages;
 }
 
-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)
-{
-     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)
-{
-     return copy_to_iter(addr, bytes, i);
-}
-
 static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
                                   pgoff_t pgoff, size_t nr_pages)
 {
@@ -783,8 +769,6 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
 
 static const struct dax_operations virtio_fs_dax_ops = {
      .direct_access = virtio_fs_direct_access,
-     .copy_from_iter = virtio_fs_copy_from_iter,
-     .copy_to_iter = virtio_fs_copy_to_iter,
      .zero_page_range = virtio_fs_zero_page_range,
 };
 

fs/fuse/virtio_fs.c static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) · line 840

Quoted 5 lines
fs/fuse/virtio_fs.c +1 -1
@@ -853,7 +837,8 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
      fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops);
      if (IS_ERR(fs->dax_dev))
              return PTR_ERR(fs->dax_dev);
-
+     set_dax_cached(fs->dax_dev);

Looks good to me from virtiofs point of view.

Going forward, I am wondering should virtiofs use flushcache version as well. What if host filesystem is using DAX and mapping persistent memory pfn directly into qemu address space. I have never tested that.

Quoted 6 lines
Quoted 2 lines

Right now we are relying on applications to do fsync/msync on virtiofs for data persistence.

This sounds like it would need coordination with a paravirtualized driver that can indicate whether the host side is pmem or not, like the virtio_pmem driver.

Agreed. Let me check the details of virtio_pmem driver.

Quoted 3 lines

However, if the guest sends any fsync/msync
you would still need to go explicitly cache flush any dirty page because you can't necessarily trust that the guest did that already.

So host dax functionality will already take care of that, IIUC, right? I see a dax_flush() call in dax_writeback_one(). I am assuming that's the will take care of flushing dirty pages when guest issues fsync()/msync(). So probably don't have to do anything extra here.

I think qemu should map files using MAP_SYNC though in this case though. Any read/writes to virtiofs files will turn into host file load/store operations. So flushcache in guest makes more sense with MAP_SYNC which should make sure any filesystem metadata will already persist after fault completion. And later guest can do writes followed by flush and ensure data persists too.

IOW, I probably only need to do following.

- In virtiofs virtual device, add a notion of kind of dax window or memory it supports. So may be some kind of "writethrough" property of virtiofs dax cache.

- Use this property in virtiofs driver to decide whether to use plain copy_from_iter() or _copy_from_iter_flushcache().

- qemu should use mmap(MAP_SYNC) if host filesystem is on persistent memory.

Thanks
Vivek

#24 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

In reply to Christoph Hellwig
Quoted 30 lines · Christoph Hellwig

These methods indirect the actual DAX read/write path. In the end pmem uses magic flush and mc safe variants and fuse and dcssblk use plain ones while device mapper picks redirects to the underlying device.

Add set_dax_virtual() and set_dax_nomcsafe() APIs for fuse to skip these special variants, then use them everywhere as they fall back to the plain ones on s390 anyway and remove an indirect call from the read/write path as well as a lot of boilerplate code.

---
 drivers/dax/super.c           | 36 ++++++++++++++--
 drivers/md/dm-linear.c        | 20 ---------
 drivers/md/dm-log-writes.c    | 80 -----------------------------------
 drivers/md/dm-stripe.c        | 20 ---------
 drivers/md/dm.c               | 50 ----------------------
 drivers/nvdimm/pmem.c         | 20 ---------
 drivers/s390/block/dcssblk.c  | 14 ------
 fs/dax.c                      |  5 ---
 fs/fuse/virtio_fs.c           | 19 +--------
 include/linux/dax.h           |  9 ++--
 include/linux/device-mapper.h |  4 --
 11 files changed, 37 insertions(+), 240 deletions(-)
drivers/dax/super.c +0 -0
index e81d5ee57390f..ff676a07480c8 100644

drivers/dax/super.c enum dax_device_flags { · line 111

Quoted 7 lines
drivers/dax/super.c +4 -0
@@ -105,6 +105,10 @@ enum dax_device_flags {
        DAXDEV_WRITE_CACHE,
        /* flag to check if device supports synchronous flush */
        DAXDEV_SYNC,
+       /* do not use uncached operations to write data */
+       DAXDEV_CACHED,
+       /* do not use mcsafe operations to read data */
+       DAXDEV_NOMCSAFE,

Linus did not like the mcsafe name, and this brings it back. Let's flip the polarity to positively indicate which routine to use, and to match the 'nofault' style which says "copy and handle faults".

/* do not leave the caches dirty after writes */
DAXDEV_NOCACHE

/* handle CPU fetch exceptions during reads */
DAXDEV_NOMC

...and then flip the use cases around.

Otherwise, nice cleanup. In retrospect I took the feedback to push this decision to a driver a bit too literally, this is much better.

#25 lore raw

Re: [PATCH 4/5] dax: remove the copy_from_iter and copy_to_iter methods

Quoted 11 lines · Dan Williams

drivers/dax/super.c enum dax_device_flags { · line 111

Quoted 6 lines
        /* flag to check if device supports synchronous flush */
        DAXDEV_SYNC,
drivers/dax/super.c +4 -0
+       /* do not use uncached operations to write data */
+       DAXDEV_CACHED,
+       /* do not use mcsafe operations to read data */
+       DAXDEV_NOMCSAFE,

Linus did not like the mcsafe name, and this brings it back. Let's flip the polarity to positively indicate which routine to use, and to match the 'nofault' style which says "copy and handle faults".

Quoted 7 lines

/* do not leave the caches dirty after writes */
DAXDEV_NOCACHE

/* handle CPU fetch exceptions during reads */
DAXDEV_NOMC

...and then flip the use cases around.

Sure we can do that. But let's finish the discussion if we actually need the virtiofs special casing, as it seems pretty fishy in many aspects.

#26 lore raw

PATCH 5/5 dax: always use _copy_mc_to_iter in dax_copy_to_iter

In reply to Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs, it also isn't harmful at all. So just use _copy_mc_to_iter unconditionally to simplify the code.

---
 drivers/dax/super.c | 10 ----------
 fs/fuse/virtio_fs.c |  1 -
 include/linux/dax.h |  1 -
 3 files changed, 12 deletions(-)
drivers/dax/super.c +0 -10
index ff676a07480c8..fe783234ca669 100644
@@ -107,8 +107,6 @@ enum dax_device_flags {
 	DAXDEV_SYNC,
 	/* do not use uncached operations to write data */
 	DAXDEV_CACHED,
-	/* do not use mcsafe operations to read data */
-	DAXDEV_NOMCSAFE,
 };
 
 /**
@@ -171,8 +169,6 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 	 * via access_ok() in vfs_red, so use the 'no check' version to bypass
 	 * the HARDENED_USERCOPY overhead.
 	 */
-	if (test_bit(DAXDEV_NOMCSAFE, &dax_dev->flags))
-		return _copy_to_iter(addr, bytes, i);
 	return _copy_mc_to_iter(addr, bytes, i);
 }
 
@@ -242,12 +238,6 @@ void set_dax_cached(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(set_dax_cached);
 
-void set_dax_nomcsafe(struct dax_device *dax_dev)
-{
-	set_bit(DAXDEV_NOMCSAFE, &dax_dev->flags);
-}
-EXPORT_SYMBOL_GPL(set_dax_nomcsafe);
-
 bool dax_alive(struct dax_device *dax_dev)
 {
 	lockdep_assert_held(&dax_srcu);
fs/fuse/virtio_fs.c +0 -1
index 754319ce2a29b..d9c20b148ac19 100644
@@ -838,7 +838,6 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
 	if (IS_ERR(fs->dax_dev))
 		return PTR_ERR(fs->dax_dev);
 	set_dax_cached(fs->dax_dev);
-	set_dax_nomcsafe(fs->dax_dev);
 	return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
 					fs->dax_dev);
 }
include/linux/dax.h +0 -1
index d22cbf03d37d2..d267331bc37e7 100644
@@ -90,7 +90,6 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 #endif
 
 void set_dax_cached(struct dax_device *dax_dev);
-void set_dax_nomcsafe(struct dax_device *dax_dev);
 
 struct writeback_control;
 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
Signature · 1 line
2.30.2
maintainer
#27 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

Quoted 2 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs,

I was wondering about that. Is it completely pointless.

Typically we are just mapping host page cache into qemu address space. That shows as virtiofs device pfn in guest and that pfn is mapped into guest application address space in mmap() call.

Given on host its DRAM, so I would not expect machine check on load side so there was no need to use machine check safe variant. But what if host filesystem is on persistent memory and using DAX. In that case load in guest can trigger a machine check. Not sure if that machine check will actually travel into the guest and unblock read() operation or not.

But this sounds like a good change from virtiofs point of view, anyway.

Thanks
Vivek

Quoted 72 lines

it also isn't harmful at all. So just use _copy_mc_to_iter unconditionally to simplify the code.

---
 drivers/dax/super.c | 10 ----------
 fs/fuse/virtio_fs.c |  1 -
 include/linux/dax.h |  1 -
 3 files changed, 12 deletions(-)
drivers/dax/super.c +0 -10
index ff676a07480c8..fe783234ca669 100644
@@ -107,8 +107,6 @@ enum dax_device_flags {
 	DAXDEV_SYNC,
 	/* do not use uncached operations to write data */
 	DAXDEV_CACHED,
-	/* do not use mcsafe operations to read data */
-	DAXDEV_NOMCSAFE,
 };
 
 /**
@@ -171,8 +169,6 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 	 * via access_ok() in vfs_red, so use the 'no check' version to bypass
 	 * the HARDENED_USERCOPY overhead.
 	 */
-	if (test_bit(DAXDEV_NOMCSAFE, &dax_dev->flags))
-		return _copy_to_iter(addr, bytes, i);
 	return _copy_mc_to_iter(addr, bytes, i);
 }
 
@@ -242,12 +238,6 @@ void set_dax_cached(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(set_dax_cached);
 
-void set_dax_nomcsafe(struct dax_device *dax_dev)
-{
-	set_bit(DAXDEV_NOMCSAFE, &dax_dev->flags);
-}
-EXPORT_SYMBOL_GPL(set_dax_nomcsafe);
-
 bool dax_alive(struct dax_device *dax_dev)
 {
 	lockdep_assert_held(&dax_srcu);
fs/fuse/virtio_fs.c +0 -1
index 754319ce2a29b..d9c20b148ac19 100644
@@ -838,7 +838,6 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
 	if (IS_ERR(fs->dax_dev))
 		return PTR_ERR(fs->dax_dev);
 	set_dax_cached(fs->dax_dev);
-	set_dax_nomcsafe(fs->dax_dev);
 	return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
 					fs->dax_dev);
 }
include/linux/dax.h +0 -1
index d22cbf03d37d2..d267331bc37e7 100644
@@ -90,7 +90,6 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 #endif
 
 void set_dax_cached(struct dax_device *dax_dev);
-void set_dax_nomcsafe(struct dax_device *dax_dev);
 
 struct writeback_control;
 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
Signature · 1 line
2.30.2
#28 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

Quoted 5 lines · Vivek Goyal
Quoted 2 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs,

Quoted 8 lines

I was wondering about that. Is it completely pointless.

Typically we are just mapping host page cache into qemu address space. That shows as virtiofs device pfn in guest and that pfn is mapped into guest application address space in mmap() call.

Given on host its DRAM, so I would not expect machine check on load side so there was no need to use machine check safe variant.

That's a broken assumption, DRAM experiences multi-bit ECC errors. Machine checks, data aborts, etc existed before PMEM.

Quoted 84 lines

But what if host
filesystem is on persistent memory and using DAX. In that case load in guest can trigger a machine check. Not sure if that machine check will actually travel into the guest and unblock read() operation or not.

But this sounds like a good change from virtiofs point of view, anyway.

Thanks
Vivek

Quoted 72 lines

it also isn't harmful at all. So just use _copy_mc_to_iter unconditionally to simplify the code.

---
 drivers/dax/super.c | 10 ----------
 fs/fuse/virtio_fs.c |  1 -
 include/linux/dax.h |  1 -
 3 files changed, 12 deletions(-)
drivers/dax/super.c +0 -10
index ff676a07480c8..fe783234ca669 100644
@@ -107,8 +107,6 @@ enum dax_device_flags {
      DAXDEV_SYNC,
      /* do not use uncached operations to write data */
      DAXDEV_CACHED,
-     /* do not use mcsafe operations to read data */
-     DAXDEV_NOMCSAFE,
 };
 
 /**
@@ -171,8 +169,6 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
       * via access_ok() in vfs_red, so use the 'no check' version to bypass
       * the HARDENED_USERCOPY overhead.
       */
-     if (test_bit(DAXDEV_NOMCSAFE, &dax_dev->flags))
-             return _copy_to_iter(addr, bytes, i);
      return _copy_mc_to_iter(addr, bytes, i);
 }
 
@@ -242,12 +238,6 @@ void set_dax_cached(struct dax_device *dax_dev)
 }
 EXPORT_SYMBOL_GPL(set_dax_cached);
 
-void set_dax_nomcsafe(struct dax_device *dax_dev)
-{
-     set_bit(DAXDEV_NOMCSAFE, &dax_dev->flags);
-}
-EXPORT_SYMBOL_GPL(set_dax_nomcsafe);
-
 bool dax_alive(struct dax_device *dax_dev)
 {
      lockdep_assert_held(&dax_srcu);
fs/fuse/virtio_fs.c +0 -1
index 754319ce2a29b..d9c20b148ac19 100644
@@ -838,7 +838,6 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
      if (IS_ERR(fs->dax_dev))
              return PTR_ERR(fs->dax_dev);
      set_dax_cached(fs->dax_dev);
-     set_dax_nomcsafe(fs->dax_dev);
      return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax,
                                      fs->dax_dev);
 }
include/linux/dax.h +0 -2
index d22cbf03d37d2..d267331bc37e7 100644
@@ -90,7 +90,6 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
 #endif
 
 void set_dax_cached(struct dax_device *dax_dev);
-void set_dax_nomcsafe(struct dax_device *dax_dev);
 
 struct writeback_control;
 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
--

2.30.2

#29 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

Quoted 12 lines · Dan Williams
Quoted 11 lines · Vivek Goyal
Quoted 2 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs,

I was wondering about that. Is it completely pointless.

Typically we are just mapping host page cache into qemu address space. That shows as virtiofs device pfn in guest and that pfn is mapped into guest application address space in mmap() call.

Quoted 5 lines
Quoted 2 lines

Given on host its DRAM, so I would not expect machine check on load side so there was no need to use machine check safe variant.

That's a broken assumption, DRAM experiences multi-bit ECC errors. Machine checks, data aborts, etc existed before PMEM.

So the conclusion here is that we should always use the mc safe variant?

#30 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

Quoted 14 lines · Christoph Hellwig
Quoted 12 lines · Dan Williams
Quoted 11 lines · Vivek Goyal
Quoted 2 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs,

I was wondering about that. Is it completely pointless.

Typically we are just mapping host page cache into qemu address space. That shows as virtiofs device pfn in guest and that pfn is mapped into guest application address space in mmap() call.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Given on host its DRAM, so I would not expect machine check on load side so there was no need to use machine check safe variant.

That's a broken assumption, DRAM experiences multi-bit ECC errors. Machine checks, data aborts, etc existed before PMEM.

So the conclusion here is that we should always use the mc safe variant?

The proposal is one of the following:

1/ any paths not currently using the mc safe variant should continue not using it to avoid the performance regression on older platforms, i.e. drop this patch.

2/ add plumbing to switch to mcsafe variant, but only on newer platforms, incremental new patch

3/ always use the mc safe variant, keep this patch

We could go with 3/ and see who screams, because 3/ is smallest ongoing maintenance burden. However, I feel like 1/ is the path of least resistance until the platforms with the need to do 'careful' copying age out of use.

maintainer
#31 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

In reply to Dan Williams
Quoted 12 lines · Dan Williams
Quoted 11 lines · Vivek Goyal
Quoted 2 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs,

I was wondering about that. Is it completely pointless.

Typically we are just mapping host page cache into qemu address space. That shows as virtiofs device pfn in guest and that pfn is mapped into guest application address space in mmap() call.

Quoted 5 lines
Quoted 2 lines

Given on host its DRAM, so I would not expect machine check on load side so there was no need to use machine check safe variant.

That's a broken assumption, DRAM experiences multi-bit ECC errors. Machine checks, data aborts, etc existed before PMEM.

So we should use MC safe variant when loading from DRAM as well? (If needed platoform support is there).

Vivek

#32 lore raw

Re: [PATCH 5/5] dax: always use _copy_mc_to_iter in dax_copy_to_iter

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

While using the MC-safe copy routines is rather pointless on a virtual device like virtiofs, it also isn't harmful at all. So just use _copy_mc_to_iter unconditionally to simplify the code.

From a correctness perspective, yes, but from a performance perspective, see:

enable_copy_mc_fragile()

...on those platforms fast-string copy implementation is replaced with a manual unrolled copy. So this will cause a performance regression on those platforms.

How about let's keep this as is / still only use it for PMEM where end users are already dealing with the performance difference across platforms? I considered exporting an indicator of which backend routine has been selected from arch/x86/lib/copy_mc.c, but it got messy quickly so I fell back to just keeping the status quo.