Skip to contentSkip to conversation

dax,pmem: Provide a dax operation to zero range of memory

RFC PATCH Superseded Vivek Goyal 4 participants 25 messages Feb 3, 2020 – Feb 7, 2020

Subsystems (8)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover dax,pmem: Provide a dax operation to zero range of memory

Hi,

This is V2 of patches. I posted V1 here.

https://lore.kernel.org/linux-fsdevel/[email protected]/

Changes since V1.
- Took care of feedback from Christoph.
- Made ->zero_page_range() mandatory operation.
- Provided a generic helper to zero range for non-pmem drivers.
- Merged __dax_zero_page_range() and iomap_dax_zero()
- Made changes to dm drivers.
- Limited range zeroing to with-in single page.
- Tested patches with real hardware.

description
-----------
This is an RFC patch series to provide a dax operation to zero a range of memory. It will also clear poison in the process.

Motivation from this patch comes from Christoph's feedback that he will rather prefer a dax way to zero a range instead of relying on having to call blkdev_issue_zeroout() in __dax_zero_page_range().

https://lkml.org/lkml/2019/8/26/361

My motivation for this change is virtiofs DAX support. There we use DAX but we don't have a block device. So any dax code which has the assumption that there is always a block device associated is a problem. So this is more of a cleanup of one of the places where dax has this dependency on block device and if we add a dax operation for zeroing a range, it can help with not having to call blkdev_issue_zeroout() in dax path.

Thanks
Vivek

Vivek Goyal (5):
dax, pmem: Add a dax operation zero_page_range s390,dax: Add dax zero_page_range operation to dcssblk driver dm,dax: Add dax zero_page_range operation dax,iomap: Start using dax native zero_page_range() dax,iomap: Add helper dax_iomap_zero() to zero a range

 drivers/dax/super.c           | 20 ++++++++++++
 drivers/md/dm-linear.c        | 18 +++++++++++
 drivers/md/dm-log-writes.c    | 17 ++++++++++
 drivers/md/dm-stripe.c        | 23 ++++++++++++++
 drivers/md/dm.c               | 30 ++++++++++++++++++
 drivers/nvdimm/pmem.c         | 50 +++++++++++++++++++++++++++++
 drivers/s390/block/dcssblk.c  |  7 ++++
 fs/dax.c                      | 60 ++++++++++++++---------------------
 fs/iomap/buffered-io.c        |  9 +-----
 include/linux/dax.h           | 17 ++++++----
 include/linux/device-mapper.h |  3 ++
 11 files changed, 204 insertions(+), 50 deletions(-)
Signature · 1 line
2.18.1
#1 lore raw

PATCH v2 1/5 dax, pmem: Add a dax operation zero_page_range

Add a dax operation zero_page_range, to zero a range of memory. This will also clear any poison in the range being zeroed.

As of now, zeroing of up to one page is allowed in a single call. There are no callers which are trying to zero more than a page in a single call.

Once we grow the callers which zero more than a page in single call, we can add that support. Primary reason for not doing that yet is that this will add little complexity in dm implementation where a range might be spanning multiple underlying targets and one will have to split the range into multiple sub ranges and call zero_page_range() on individual targets.

---
 drivers/dax/super.c   | 20 +++++++++++++++++
 drivers/nvdimm/pmem.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 fs/dax.c              | 15 +++++++++++++
 include/linux/dax.h   |  6 ++++++
 4 files changed, 91 insertions(+)
drivers/dax/super.c +20 -0
index 26a654dbc69a..371744256fe5 100644
@@ -344,6 +344,26 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 }
 EXPORT_SYMBOL_GPL(dax_copy_to_iter);
 
+int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+			unsigned offset, size_t len)
+{
+	if (!dax_alive(dax_dev))
+		return -ENXIO;
+
+	if (!dax_dev->ops->zero_page_range)
+		return -EOPNOTSUPP;
+
+	/*
+	 * There are no users as of now. Once users are there, fix dm code
+	 * to be able to split a long range across targets.
+	 */
+	if (offset + len > PAGE_SIZE)
+		return -EIO;
+
+	return dax_dev->ops->zero_page_range(dax_dev, pgoff, offset, len);
+}
+EXPORT_SYMBOL_GPL(dax_zero_page_range);
+
 #ifdef CONFIG_ARCH_HAS_PMEM_API
 void arch_wb_cache_pmem(void *addr, size_t size);
 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size)
drivers/nvdimm/pmem.c +50 -0

62 lines not on this page · raw message

fs/dax.c +15 -0
index 1f1f0201cad1..35631a4d0295 100644
@@ -1057,6 +1057,21 @@ static bool dax_range_is_aligned(struct block_device *bdev,
 	return true;
 }
 
+int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				unsigned int offset, size_t len)
+{
+	long rc;
+	void *kaddr;
+
+	rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL);
+	if (rc < 0)
+		return rc;
+	memset(kaddr + offset, 0, len);
+	dax_flush(dax_dev, kaddr + offset, len);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(generic_dax_zero_page_range);
+
 int __dax_zero_page_range(struct block_device *bdev,
 		struct dax_device *dax_dev, sector_t sector,
 		unsigned int offset, unsigned int size)
include/linux/dax.h +6 -0
index 9bd8528bd305..3356b874c55d 100644
@@ -34,6 +34,8 @@ struct dax_operations {
 	/* 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 for fs-dax direct-i/o */
+	int (*zero_page_range)(struct dax_device *, pgoff_t, unsigned, size_t);
 };
 
 extern struct attribute_group dax_attribute_group;
@@ -209,6 +211,10 @@ size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 		size_t bytes, struct iov_iter *i);
 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
 		size_t bytes, struct iov_iter *i);
+int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+			unsigned offset, size_t len);
+int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				 unsigned int offset, size_t len);
 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
 
 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Signature · 1 line
2.18.1
#2 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

drivers/dax/super.c size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 359

Quoted 4 lines
drivers/dax/super.c +4 -0
+	/*
+	 * There are no users as of now. Once users are there, fix dm code
+	 * to be able to split a long range across targets.
+	 */

This comment confused me. I think this wants to say something like:

/*
* There are now callers that want to zero across a page boundary as of
* now. Once there are users this check can be removed after the
* device mapper code has been updated to split ranges across targets. */

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 275

Quoted 5 lines
drivers/nvdimm/pmem.c +5 -0
+static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				    unsigned int offset, size_t len)
+{
+	int rc = 0;
+	phys_addr_t phys_pos = pgoff * PAGE_SIZE + offset;

Any reason not to pass a phys_addr_t in the calling convention for the method and maybe also for dax_zero_page_range itself?

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 294

Quoted 2 lines
drivers/nvdimm/pmem.c +2 -0
+	sector_start = ALIGN(phys_pos, 512)/512;
+	sector_end = ALIGN_DOWN(phys_pos + bytes, 512)/512;

Missing whitespaces. Also this could use DIV_ROUND_UP and DIV_ROUND_DOWN.

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 301

Quoted 7 lines
drivers/nvdimm/pmem.c +7 -0
+	if (sector_end > sector_start)
+		nr_sectors = sector_end - sector_start;
+
+	if (nr_sectors &&
+	    unlikely(is_bad_pmem(&pmem->bb, sector_start,
+				 nr_sectors * 512)))
+		bad_pmem = true;

How could nr_sectors be zero?

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 313

Quoted 11 lines
drivers/nvdimm/pmem.c +11 -0
+	write_pmem(pmem_addr, page, 0, bytes);
+	if (unlikely(bad_pmem)) {
+		/*
+		 * Pass block aligned offset and length. That seems
+		 * to work as of now. Other finer grained alignment
+		 * cases can be addressed later if need be.
+		 */
+		rc = pmem_clear_poison(pmem, ALIGN(pmem_off, 512),
+				       nr_sectors * 512);
+		write_pmem(pmem_addr, page, 0, bytes);
+	}

This code largerly duplicates the write side of pmem_do_bvec. I think it might make sense to split pmem_do_bvec into a read and a write side as a prep patch, and then reuse the write side here.

include/linux/dax.h size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 217

Quoted 2 lines
include/linux/dax.h +2 -0
+int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				 unsigned int offset, size_t len);

This should probably go into a separare are of the header and have comment about being a section for generic helpers for drivers.

#3 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 7 lines · Christoph Hellwig

drivers/dax/super.c size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 359

Quoted 4 lines
drivers/dax/super.c +4 -0
+	/*
+	 * There are no users as of now. Once users are there, fix dm code
+	 * to be able to split a long range across targets.
+	 */

This comment confused me. I think this wants to say something like:

Quoted 5 lines

/*
* There are now callers that want to zero across a page boundary as of
* now. Once there are users this check can be removed after the
* device mapper code has been updated to split ranges across targets. */

Yes, that's what I wanted to say but I missed one line. Thanks. Will fix it.

Quoted 9 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 275

Quoted 6 lines
drivers/nvdimm/pmem.c +5 -0
+static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				    unsigned int offset, size_t len)
+{
+	int rc = 0;
+	phys_addr_t phys_pos = pgoff * PAGE_SIZE + offset;

Any reason not to pass a phys_addr_t in the calling convention for the method and maybe also for dax_zero_page_range itself?

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

Quoted 6 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 294

Quoted 3 lines
drivers/nvdimm/pmem.c +2 -0
+	sector_start = ALIGN(phys_pos, 512)/512;
+	sector_end = ALIGN_DOWN(phys_pos + bytes, 512)/512;

Missing whitespaces. Also this could use DIV_ROUND_UP and DIV_ROUND_DOWN.

Will do.

Quoted 10 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 301

Quoted 8 lines
drivers/nvdimm/pmem.c +7 -0
+	if (sector_end > sector_start)
+		nr_sectors = sector_end - sector_start;
+
+	if (nr_sectors &&
+	    unlikely(is_bad_pmem(&pmem->bb, sector_start,
+				 nr_sectors * 512)))
+		bad_pmem = true;

How could nr_sectors be zero?

If somebody specified a range across two sectors but none of the sector is completely written. Then nr_sectors will be zero. In fact this check shoudl probably be nr_sectors > 0 as writes with-in a sector will lead to nr_sector being -1.

Am I missing something.

Quoted 16 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 313

Quoted 12 lines
drivers/nvdimm/pmem.c +11 -0
+	write_pmem(pmem_addr, page, 0, bytes);
+	if (unlikely(bad_pmem)) {
+		/*
+		 * Pass block aligned offset and length. That seems
+		 * to work as of now. Other finer grained alignment
+		 * cases can be addressed later if need be.
+		 */
+		rc = pmem_clear_poison(pmem, ALIGN(pmem_off, 512),
+				       nr_sectors * 512);
+		write_pmem(pmem_addr, page, 0, bytes);
+	}

This code largerly duplicates the write side of pmem_do_bvec. I think it might make sense to split pmem_do_bvec into a read and a write side as a prep patch, and then reuse the write side here.

Ok, I will look into it. How about just add a helper function for write side and use that function both here and in pmem_do_bvec().

Quoted 6 lines

include/linux/dax.h size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 217

Quoted 3 lines
include/linux/dax.h +2 -0
+int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				 unsigned int offset, size_t len);

This should probably go into a separare are of the header and have comment about being a section for generic helpers for drivers.

ok, will do.

Thanks
Vivek

#4 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

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

drivers/dax/super.c size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 359

Quoted 4 lines
drivers/dax/super.c +4 -0
+   /*
+    * There are no users as of now. Once users are there, fix dm code
+    * to be able to split a long range across targets.
+    */
Quoted 7 lines

This comment confused me. I think this wants to say something like:

/*
* There are now callers that want to zero across a page boundary as of
* now. Once there are users this check can be removed after the
* device mapper code has been updated to split ranges across targets. */

Yes, that's what I wanted to say but I missed one line. Thanks. Will fix it.

Quoted 9 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 275

Quoted 6 lines
drivers/nvdimm/pmem.c +5 -0
+static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+                               unsigned int offset, size_t len)
+{
+   int rc = 0;
+   phys_addr_t phys_pos = pgoff * PAGE_SIZE + offset;

Any reason not to pass a phys_addr_t in the calling convention for the method and maybe also for dax_zero_page_range itself?

Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

dax_direct_access(...)
generic_dax_zero_page_range(...)

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

#5 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 7 lines · Dan Williams
Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

Quoted 6 lines

dax_direct_access(...)
generic_dax_zero_page_range(...)

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Maybe phys_addr_t was the wrong type - but why do we split the offset into the block device argument into a pgoff and offset into page instead of a single 64-bit value?

#6 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Dan Williams
Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

dax_direct_access(...)
generic_dax_zero_page_range(...)

Quoted 7 lines
Quoted 3 lines

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Maybe phys_addr_t was the wrong type - but why do we split the offset into the block device argument into a pgoff and offset into page instead of a single 64-bit value?

Oh, got it yes, that looks odd for sub-page zeroing. Yes, let's just have one device relative byte-offset.

#7 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 17 lines · Dan Williams
Quoted 16 lines · Christoph Hellwig
Quoted 13 lines · Dan Williams
Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

dax_direct_access(...)
generic_dax_zero_page_range(...)

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Quoted 6 lines
Quoted 3 lines

Maybe phys_addr_t was the wrong type - but why do we split the offset into the block device argument into a pgoff and offset into page instead of a single 64-bit value?

Oh, got it yes, that looks odd for sub-page zeroing. Yes, let's just have one device relative byte-offset.

So what's the best type to represent this offset. "u64" or "phys_addr_t" or "loff_t" or something else. I like phys_addr_t followed by u64.

Vivek

#8 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 23 lines · Vivek Goyal
Quoted 21 lines · Dan Williams
Quoted 19 lines · Christoph Hellwig
Quoted 7 lines · Dan Williams
Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

Quoted 6 lines

dax_direct_access(...)
generic_dax_zero_page_range(...)

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Maybe phys_addr_t was the wrong type - but why do we split the offset into the block device argument into a pgoff and offset into page instead of a single 64-bit value?

Quoted 5 lines
Quoted 2 lines

Oh, got it yes, that looks odd for sub-page zeroing. Yes, let's just have one device relative byte-offset.

So what's the best type to represent this offset. "u64" or "phys_addr_t" or "loff_t" or something else. I like phys_addr_t followed by u64.

Let's make it u64.

phys_addr_t has already led to confusion in this thread because the first question I ask when I read it is "why call ->direct_access() to do the translation when you already have the physical address?".

#9 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

In reply to Dan Williams
Quoted 36 lines · Dan Williams
Quoted 28 lines · Vivek Goyal
Quoted 5 lines · Christoph Hellwig

drivers/dax/super.c size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 359

Quoted 4 lines
drivers/dax/super.c +4 -0
+   /*
+    * There are no users as of now. Once users are there, fix dm code
+    * to be able to split a long range across targets.
+    */
Quoted 7 lines

This comment confused me. I think this wants to say something like:

/*
* There are now callers that want to zero across a page boundary as of
* now. Once there are users this check can be removed after the
* device mapper code has been updated to split ranges across targets. */

Yes, that's what I wanted to say but I missed one line. Thanks. Will fix it.

Quoted 9 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 275

Quoted 6 lines
drivers/nvdimm/pmem.c +5 -0
+static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+                               unsigned int offset, size_t len)
+{
+   int rc = 0;
+   phys_addr_t phys_pos = pgoff * PAGE_SIZE + offset;

Any reason not to pass a phys_addr_t in the calling convention for the method and maybe also for dax_zero_page_range itself?

Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

Quoted 6 lines

dax_direct_access(...)
generic_dax_zero_page_range(...)

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Hi Dan,

Drivers can easily convert offset into dax device (say phys_addr_t) to pgoff and offset into page, isn't it?

pgoff_t = phys_addr_t/PAGE_SIZE;
offset = phys_addr_t & (PAGE_SIZE - 1);

And pgoff can easily be converted into sectors which dm/md can use for mapping and come up with pgoff in target device.

Anyway, I am fine with anything.

Thanks
Vivek

#10 lore raw

Re: [PATCH 1/5] dax, pmem: Add a dax operation zero_page_range

Quoted 41 lines · Vivek Goyal
Quoted 39 lines · Dan Williams
Quoted 28 lines · Vivek Goyal
Quoted 5 lines · Christoph Hellwig

drivers/dax/super.c size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, · line 359

Quoted 4 lines
drivers/dax/super.c +4 -0
+   /*
+    * There are no users as of now. Once users are there, fix dm code
+    * to be able to split a long range across targets.
+    */
Quoted 7 lines

This comment confused me. I think this wants to say something like:

/*
* There are now callers that want to zero across a page boundary as of
* now. Once there are users this check can be removed after the
* device mapper code has been updated to split ranges across targets. */

Yes, that's what I wanted to say but I missed one line. Thanks. Will fix it.

Quoted 9 lines

drivers/nvdimm/pmem.c static const struct block_device_operations pmem_fops = { · line 275

Quoted 6 lines
drivers/nvdimm/pmem.c +5 -0
+static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+                               unsigned int offset, size_t len)
+{
+   int rc = 0;
+   phys_addr_t phys_pos = pgoff * PAGE_SIZE + offset;

Any reason not to pass a phys_addr_t in the calling convention for the method and maybe also for dax_zero_page_range itself?

Quoted 2 lines

I don't have any reason not to pass phys_addr_t. If that sounds better, will make changes.

The problem is device-mapper. That wants to use offset to route through the map to the leaf device. If it weren't for the firmware communication requirement you could do:

dax_direct_access(...)
generic_dax_zero_page_range(...)

Quoted 8 lines
Quoted 3 lines

...but as long as the firmware error clearing path is required I think we need to do pass the pgoff through the interface and do the pgoff to virt / phys translation inside the ops handler.

Hi Dan,

Drivers can easily convert offset into dax device (say phys_addr_t) to pgoff and offset into page, isn't it?

It's not a phys_addr_t it's a 64-bit device relative offset.

#11 lore raw

PATCH v2 2/5 s390,dax: Add dax zero_page_range operation to dcssblk driver

In reply to Vivek Goyal

Add dax operation zero_page_range. This just calls generic helper generic_dax_zero_page_range().

---
 drivers/s390/block/dcssblk.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/s390/block/dcssblk.c +7 -0
index 63502ca537eb..f6709200bcd0 100644
@@ -62,6 +62,7 @@ static const struct dax_operations dcssblk_dax_ops = {
 	.dax_supported = generic_fsdax_supported,
 	.copy_from_iter = dcssblk_dax_copy_from_iter,
 	.copy_to_iter = dcssblk_dax_copy_to_iter,
+	.zero_page_range = dcssblk_dax_zero_page_range,
 };
 
 struct dcssblk_dev_info {
@@ -941,6 +942,12 @@ dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	return __dcssblk_direct_access(dev_info, pgoff, nr_pages, kaddr, pfn);
 }
 
+static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,pgoff_t pgoff,
+				       unsigned offset, size_t len)
+{
+	return generic_dax_zero_page_range(dax_dev, pgoff, offset, len);
+}
+
 static void
 dcssblk_check_params(void)
 {
Signature · 1 line
2.18.1
#12 lore raw

Re: [PATCH 2/5] s390,dax: Add dax zero_page_range operation to dcssblk driver

Quoted 13 lines
drivers/s390/block/dcssblk.c +1 -0
index 63502ca537eb..f6709200bcd0 100644
@@ -62,6 +62,7 @@ static const struct dax_operations dcssblk_dax_ops = {
 	.dax_supported = generic_fsdax_supported,
 	.copy_from_iter = dcssblk_dax_copy_from_iter,
 	.copy_to_iter = dcssblk_dax_copy_to_iter,
+	.zero_page_range = dcssblk_dax_zero_page_range,
 };
 
 struct dcssblk_dev_info {

drivers/s390/block/dcssblk.c dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, · line 949

Quoted 8 lines
drivers/s390/block/dcssblk.c +5 -0
@@ -941,6 +942,12 @@ dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	return __dcssblk_direct_access(dev_info, pgoff, nr_pages, kaddr, pfn);
 }
 
+static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,pgoff_t pgoff,
+				       unsigned offset, size_t len)
+{
+	return generic_dax_zero_page_range(dax_dev, pgoff, offset, len);
+}

Wouldn't this need a forward declaration? Then again given that dcssblk is the only caller of generic_dax_zero_page_range we might as well merge the two. If you want to keep the generic one it could be wired up to dcssblk_dax_ops directly, though.

#13 lore raw

Re: [PATCH 2/5] s390,dax: Add dax zero_page_range operation to dcssblk driver

Quoted 16 lines · Christoph Hellwig
Quoted 16 lines
drivers/s390/block/dcssblk.c +1 -0
index 63502ca537eb..f6709200bcd0 100644
@@ -62,6 +62,7 @@ static const struct dax_operations dcssblk_dax_ops = {
 	.dax_supported = generic_fsdax_supported,
 	.copy_from_iter = dcssblk_dax_copy_from_iter,
 	.copy_to_iter = dcssblk_dax_copy_to_iter,
+	.zero_page_range = dcssblk_dax_zero_page_range,
 };
 
 struct dcssblk_dev_info {
@@ -941,6 +942,12 @@ dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
 	return __dcssblk_direct_access(dev_info, pgoff, nr_pages, kaddr, pfn);
 }
 
Quoted 10 lines

drivers/s390/block/dcssblk.c dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, · line 949

Quoted 5 lines
drivers/s390/block/dcssblk.c +5 -0
+static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,pgoff_t pgoff,
+				       unsigned offset, size_t len)
+{
+	return generic_dax_zero_page_range(dax_dev, pgoff, offset, len);
+}

Wouldn't this need a forward declaration? Then again given that dcssblk is the only caller of generic_dax_zero_page_range we might as well merge the two. If you want to keep the generic one it could be wired up to dcssblk_dax_ops directly, though.

Given dcssblk is the only user, I am inclined to get rid of genric version. We can add one later if another user shows up.

Thanks
Vivek

#14 lore raw

PATCH v2 3/5 dm,dax: Add dax zero_page_range operation

In reply to Vivek Goyal

This patch adds support for dax zero_page_range operation to dm targets.

---
 drivers/md/dm-linear.c        | 18 ++++++++++++++++++
 drivers/md/dm-log-writes.c    | 17 +++++++++++++++++
 drivers/md/dm-stripe.c        | 23 +++++++++++++++++++++++
 drivers/md/dm.c               | 30 ++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |  3 +++
 5 files changed, 91 insertions(+)
drivers/md/dm-linear.c +18 -0
index 8d07fdf63a47..a6db998f0264 100644
@@ -201,10 +201,27 @@ static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t 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,
+		unsigned offset, size_t len)
+{
+	int ret;
+	struct linear_c *lc = ti->private;
+	struct block_device *bdev = lc->dev->bdev;
+	struct dax_device *dax_dev = lc->dev->dax_dev;
+	sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
+
+	dev_sector = linear_map_sector(ti, sector);
+	ret = bdev_dax_pgoff(bdev, dev_sector, ALIGN(len, PAGE_SIZE), &pgoff);
+	if (ret)
+		return ret;
+	return dax_zero_page_range(dax_dev, pgoff, offset, len);
+}
+
 #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
 
 static struct target_type linear_target = {
@@ -226,6 +243,7 @@ static struct target_type linear_target = {
 	.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,
 };
 
 int __init dm_linear_init(void)
drivers/md/dm-log-writes.c +17 -0
index 99721c76225d..be20605f7544 100644
@@ -994,10 +994,26 @@ static size_t log_writes_dax_copy_to_iter(struct dm_target *ti,
 	return dax_copy_to_iter(lc->dev->dax_dev, pgoff, addr, bytes, i);
 }
 
+static int log_writes_dax_zero_page_range(struct dm_target *ti,
+					  pgoff_t pgoff, unsigned offset,
+					  size_t len)
+{
+	int ret;
+	struct log_writes_c *lc = ti->private;
+	sector_t sector = pgoff * PAGE_SECTORS;
+
+	ret = bdev_dax_pgoff(lc->dev->bdev, sector, ALIGN(len, PAGE_SIZE),
+			     &pgoff);
+	if (ret)
+		return ret;
+	return dax_zero_page_range(lc->dev->dax_dev, pgoff, offset, len);
+}
+
 #else
 #define log_writes_dax_direct_access NULL
 #define log_writes_dax_copy_from_iter NULL
 #define log_writes_dax_copy_to_iter NULL
+#define log_writes_dax_zero_page_range NULL
 #endif
 
 static struct target_type log_writes_target = {
@@ -1016,6 +1032,7 @@ static struct target_type log_writes_target = {
 	.direct_access = log_writes_dax_direct_access,
 	.dax_copy_from_iter = log_writes_dax_copy_from_iter,
 	.dax_copy_to_iter = log_writes_dax_copy_to_iter,
+	.dax_zero_page_range = log_writes_dax_zero_page_range,
 };
 
 static int __init dm_log_writes_init(void)
drivers/md/dm-stripe.c +23 -0
index 63bbcc20f49a..8ad3c956efbf 100644
@@ -360,10 +360,32 @@ static size_t stripe_dax_copy_to_iter(struct dm_target *ti, pgoff_t 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,
+				      unsigned offset, size_t len)
+{
+	int ret;
+	sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
+	struct stripe_c *sc = ti->private;
+	struct dax_device *dax_dev;
+	struct block_device *bdev;
+	uint32_t stripe;
+
+	stripe_map_sector(sc, sector, &stripe, &dev_sector);
+	dev_sector += sc->stripe[stripe].physical_start;
+	dax_dev = sc->stripe[stripe].dev->dax_dev;
+	bdev = sc->stripe[stripe].dev->bdev;
+
+	ret = bdev_dax_pgoff(bdev, dev_sector, ALIGN(len, PAGE_SIZE), &pgoff);
+	if (ret)
+		return ret;
+	return dax_zero_page_range(dax_dev, pgoff, offset, len);
+}
+
 #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
 
 /*
@@ -486,6 +508,7 @@ static struct target_type stripe_target = {
 	.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,
 };
 
 int __init dm_stripe_init(void)
drivers/md/dm.c +30 -0
index e8f9661a10a1..4605d30dad60 100644
@@ -1198,6 +1198,35 @@ static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
 	return ret;
 }
 
+static int dm_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
+				  unsigned offset, size_t len)
+{
+	struct mapped_device *md = dax_get_private(dax_dev);
+	sector_t sector = pgoff * PAGE_SECTORS;
+	struct dm_target *ti;
+	int ret = -EIO;
+	int srcu_idx;
+
+	ti = dm_dax_get_live_target(md, sector, &srcu_idx);
+
+	if (!ti)
+		goto out;
+	if (WARN_ON(!ti->type->dax_zero_page_range)) {
+		/*
+		 * ->zero_page_range() is mandatory dax operation. If we are
+		 *  here, something is wrong.
+		 */
+		dm_put_live_table(md, srcu_idx);
+		goto out;
+	}
+	ret = ti->type->dax_zero_page_range(ti, pgoff, offset, len);
+
+ out:
+	dm_put_live_table(md, srcu_idx);
+
+	return ret;
+}
+
 /*
  * A target may call dm_accept_partial_bio only from the map routine.  It is
  * allowed for all bio types except REQ_PREFLUSH, REQ_OP_ZONE_RESET,
@@ -3194,6 +3223,7 @@ static const struct dax_operations dm_dax_ops = {
 	.dax_supported = dm_dax_supported,
 	.copy_from_iter = dm_dax_copy_from_iter,
 	.copy_to_iter = dm_dax_copy_to_iter,
+	.zero_page_range = dm_dax_zero_page_range,
 };
 
 /*
include/linux/device-mapper.h +3 -0
index 475668c69dbc..04009accf819 100644
@@ -141,6 +141,8 @@ 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,
+		unsigned, size_t len);
 #define PAGE_SECTORS (PAGE_SIZE / 512)
 
 void dm_error(const char *message);
@@ -195,6 +197,7 @@ struct target_type {
 	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. */
 	struct list_head list;
Signature · 1 line
2.18.1
#15 lore raw

Re: [PATCH 3/5] dm,dax: Add dax zero_page_range operation

Quoted 1 line · Vivek Goyal

This patch adds support for dax zero_page_range operation to dm targets.

Any way to share the code with the dax copy iter here?

#16 lore raw

Re: [PATCH 3/5] dm,dax: Add dax zero_page_range operation

Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Vivek Goyal

This patch adds support for dax zero_page_range operation to dm targets.

Any way to share the code with the dax copy iter here?

Had a look at it and can't think of a good way of sharing the code. If you have something specific in mind, I am happy to make changes.

Vivek

#17 lore raw

PATCH v2 4/5 dax,iomap: Start using dax native zero_page_range()

In reply to Vivek Goyal

Get rid of calling block device interface for zeroing in iomap dax zeroing path and use dax native zeroing interface instead.

---
 fs/dax.c | 45 +++++++++------------------------------------
 1 file changed, 9 insertions(+), 36 deletions(-)
fs/dax.c +9 -36
index 35631a4d0295..1b9ba6b59cdb 100644
@@ -1044,19 +1044,6 @@ static vm_fault_t dax_load_hole(struct xa_state *xas,
 	return ret;
 }
 
-static bool dax_range_is_aligned(struct block_device *bdev,
-				 unsigned int offset, unsigned int length)
-{
-	unsigned short sector_size = bdev_logical_block_size(bdev);
-
-	if (!IS_ALIGNED(offset, sector_size))
-		return false;
-	if (!IS_ALIGNED(length, sector_size))
-		return false;
-
-	return true;
-}
-
 int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 				unsigned int offset, size_t len)
 {
@@ -1076,31 +1063,17 @@ int __dax_zero_page_range(struct block_device *bdev,
 		struct dax_device *dax_dev, sector_t sector,
 		unsigned int offset, unsigned int size)
 {
-	if (dax_range_is_aligned(bdev, offset, size)) {
-		sector_t start_sector = sector + (offset >> 9);
-
-		return blkdev_issue_zeroout(bdev, start_sector,
-				size >> 9, GFP_NOFS, 0);
-	} else {
-		pgoff_t pgoff;
-		long rc, id;
-		void *kaddr;
+	pgoff_t pgoff;
+	long rc, id;
 
-		rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
-		if (rc)
-			return rc;
+	rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
+	if (rc)
+		return rc;
 
-		id = dax_read_lock();
-		rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL);
-		if (rc < 0) {
-			dax_read_unlock(id);
-			return rc;
-		}
-		memset(kaddr + offset, 0, size);
-		dax_flush(dax_dev, kaddr + offset, size);
-		dax_read_unlock(id);
-	}
-	return 0;
+	id = dax_read_lock();
+	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	dax_read_unlock(id);
+	return rc;
 }
 EXPORT_SYMBOL_GPL(__dax_zero_page_range);
 
Signature · 1 line
2.18.1
#18 lore raw

Re: [PATCH 4/5] dax,iomap: Start using dax native zero_page_range()

fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1076

Quoted 4 lines · Vivek Goyal
fs/dax.c +4 -0
+	id = dax_read_lock();
+	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	dax_read_unlock(id);
+	return rc;

Is there a good reason not to move the locking into dax_zero_page_range?

#19 lore raw

Re: [PATCH 4/5] dax,iomap: Start using dax native zero_page_range()

Quoted 7 lines · Christoph Hellwig

fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1076

Quoted 4 lines · Vivek Goyal
fs/dax.c +4 -0
+	id = dax_read_lock();
+	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	dax_read_unlock(id);
+	return rc;

Is there a good reason not to move the locking into dax_zero_page_range?

No reason. I can move locking inside dax_zero_page_range(). Will do.

Vivek

#20 lore raw

Re: [PATCH 4/5] dax,iomap: Start using dax native zero_page_range()

In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1076

Quoted 4 lines · Vivek Goyal
fs/dax.c +4 -0
+	id = dax_read_lock();
+	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	dax_read_unlock(id);
+	return rc;

Is there a good reason not to move the locking into dax_zero_page_range?

Thinking more about it. If we keep locking outside, then we don't have to take lock again when we recurse into dax_zero_page_range() in device mapper path. IIUC, just taking lock once at top level is enough. If that's the case then it probably is better to keep locking outside of dax_zero_page_range().

Thanks
Vivek

#21 lore raw

PATCH v2 5/5 dax,iomap: Add helper dax_iomap_zero() to zero a range

In reply to Vivek Goyal

Add a helper dax_ioamp_zero() to zero a range. This patch basically merges __dax_zero_page_range() and iomap_dax_zero().

---
 fs/dax.c               | 12 ++++++------
 fs/iomap/buffered-io.c |  9 +--------
 include/linux/dax.h    | 11 +++++------
 3 files changed, 12 insertions(+), 20 deletions(-)
fs/dax.c +6 -6
index 1b9ba6b59cdb..63303e274221 100644
@@ -1059,23 +1059,23 @@ int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
 }
 EXPORT_SYMBOL_GPL(generic_dax_zero_page_range);
 
-int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int size)
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+			      struct iomap *iomap)
 {
 	pgoff_t pgoff;
 	long rc, id;
+	sector_t sector = iomap_sector(iomap, pos & PAGE_MASK);
 
-	rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
+	rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff);
 	if (rc)
 		return rc;
 
 	id = dax_read_lock();
-	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	rc = dax_zero_page_range(iomap->dax_dev, pgoff, offset, size);
 	dax_read_unlock(id);
 	return rc;
 }
-EXPORT_SYMBOL_GPL(__dax_zero_page_range);
+EXPORT_SYMBOL_GPL(dax_iomap_zero);
 
 static loff_t
 dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
fs/iomap/buffered-io.c +1 -8
index 828444e14d09..5a5d784a110e 100644
@@ -974,13 +974,6 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,
 	return iomap_write_end(inode, pos, bytes, bytes, page, iomap, srcmap);
 }
 
-static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,
-		struct iomap *iomap)
-{
-	return __dax_zero_page_range(iomap->bdev, iomap->dax_dev,
-			iomap_sector(iomap, pos & PAGE_MASK), offset, bytes);
-}
-
 static loff_t
 iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
 		void *data, struct iomap *iomap, struct iomap *srcmap)
@@ -1000,7 +993,7 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
 		bytes = min_t(loff_t, PAGE_SIZE - offset, count);
 
 		if (IS_DAX(inode))
-			status = iomap_dax_zero(pos, offset, bytes, iomap);
+			status = dax_iomap_zero(pos, offset, bytes, iomap);
 		else
 			status = iomap_zero(inode, pos, offset, bytes, iomap,
 					srcmap);
include/linux/dax.h +5 -6
index 3356b874c55d..ffaaa12f8ca9 100644
@@ -13,6 +13,7 @@
 typedef unsigned long dax_entry_t;
 
 struct iomap_ops;
+struct iomap;
 struct dax_device;
 struct dax_operations {
 	/*
@@ -228,13 +229,11 @@ int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
 				      pgoff_t index);
 
 #ifdef CONFIG_FS_DAX
-int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length);
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+			      struct iomap *iomap);
 #else
-static inline int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length)
+static inline int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+				 struct iomap *iomap)
 {
 	return -ENXIO;
 }
Signature · 1 line
2.18.1
#22 lore raw

Re: [PATCH 5/5] dax,iomap: Add helper dax_iomap_zero() to zero a range

I love your patch! Yet something to improve:

Hi Vivek,

I love your patch! Yet something to improve:

[auto build test ERROR on dm/for-next]
[also build test ERROR on s390/features xfs-linux/for-next linus/master linux-nvdimm/libnvdimm-for-next v5.5 next-20200203] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Vivek-Goyal/dax-pmem-Provide-a-dax-operation-to-zero-range-of-memory/20200204-082750
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
config: s390-alldefconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 7.5.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=s390

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> drivers/s390/block/dcssblk.c:65:21: error: 'dcssblk_dax_zero_page_range' undeclared here (not in a function); did you mean 'generic_dax_zero_page_range'?

.zero_page_range = dcssblk_dax_zero_page_range,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
generic_dax_zero_page_range
drivers/s390/block/dcssblk.c:945:12: warning: 'dcssblk_dax_zero_page_range' defined but not used [-Wunused-function]
static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,pgoff_t pgoff,
^~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +65 drivers/s390/block/dcssblk.c

b3a9a0c36e1f7b Dan Williams   2018-05-02  59  
7a2765f6e82063 Dan Williams   2017-01-26  60  static const struct dax_operations dcssblk_dax_ops = {
7a2765f6e82063 Dan Williams   2017-01-26  61  	.direct_access = dcssblk_dax_direct_access,
7bf7eac8d64805 Dan Williams   2019-05-16  62  	.dax_supported = generic_fsdax_supported,
5d61e43b3975c0 Dan Williams   2017-06-27  63  	.copy_from_iter = dcssblk_dax_copy_from_iter,
b3a9a0c36e1f7b Dan Williams   2018-05-02  64  	.copy_to_iter = dcssblk_dax_copy_to_iter,
c5cb636194a0d8 Vivek Goyal    2020-02-03 @65  	.zero_page_range = dcssblk_dax_zero_page_range,

^1da177e4c3f41 Linus Torvalds 2005-04-16 66 };
^1da177e4c3f41 Linus Torvalds 2005-04-16 67

:::::: The code at line 65 was first introduced by commit
:::::: c5cb636194a0d8d33d549903c92189385db48406 s390,dax: Add dax zero_page_range operation to dcssblk driver

:::::: TO: Vivek Goyal <[email protected]>
:::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation

#23 lore raw

Re: [PATCH 5/5] dax,iomap: Add helper dax_iomap_zero() to zero a range

In reply to Vivek Goyal
Quoted 10 lines
fs/dax.c +4 -1
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+			      struct iomap *iomap)
 {
 	pgoff_t pgoff;
 	long rc, id;
+	sector_t sector = iomap_sector(iomap, pos & PAGE_MASK);
 
-	rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
+	rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff);
 	if (rc)

fs/dax.c int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · line 1078

Quoted 10 lines
fs/dax.c +2 -2
 		return rc;
 
 	id = dax_read_lock();
-	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	rc = dax_zero_page_range(iomap->dax_dev, pgoff, offset, size);
 	dax_read_unlock(id);
 	return rc;
 }
-EXPORT_SYMBOL_GPL(__dax_zero_page_range);
+EXPORT_SYMBOL_GPL(dax_iomap_zero);

This function is only used by fs/iomap/buffered-io.c, so no need to export it.

Quoted 5 lines

#ifdef CONFIG_FS_DAX

include/linux/dax.h +1 -3
-int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length);
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,

include/linux/dax.h int dax_invalidate_mapping_entry_sync(struct address_space *mapping, · line 239

Quoted 10 lines
include/linux/dax.h +3 -3
+			      struct iomap *iomap);
 #else
-static inline int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length)
+static inline int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+				 struct iomap *iomap)
 {
 	return -ENXIO;
 }

Given that the only caller is under an IS_DAX() check you could just declare the function unconditionally and let the compiler optimize away the guaranteed dead call for the !CONFIG_FS_DAX case, like we do with various other functions.

#24 lore raw

Re: [PATCH 5/5] dax,iomap: Add helper dax_iomap_zero() to zero a range

Quoted 12 lines · Christoph Hellwig
Quoted 12 lines
fs/dax.c +4 -1
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+			      struct iomap *iomap)
 {
 	pgoff_t pgoff;
 	long rc, id;
+	sector_t sector = iomap_sector(iomap, pos & PAGE_MASK);
 
-	rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
+	rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff);
 	if (rc)
 		return rc;
Quoted 11 lines

fs/dax.c int generic_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · line 1078

Quoted 8 lines
fs/dax.c +2 -2
 	id = dax_read_lock();
-	rc = dax_zero_page_range(dax_dev, pgoff, offset, size);
+	rc = dax_zero_page_range(iomap->dax_dev, pgoff, offset, size);
 	dax_read_unlock(id);
 	return rc;
 }
-EXPORT_SYMBOL_GPL(__dax_zero_page_range);
+EXPORT_SYMBOL_GPL(dax_iomap_zero);

This function is only used by fs/iomap/buffered-io.c, so no need to export it.

Will do.

Quoted 13 lines
Quoted 13 lines

#ifdef CONFIG_FS_DAX

include/linux/dax.h +4 -6
-int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length);
+int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+			      struct iomap *iomap);
 #else
-static inline int __dax_zero_page_range(struct block_device *bdev,
-		struct dax_device *dax_dev, sector_t sector,
-		unsigned int offset, unsigned int length)
+static inline int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
+				 struct iomap *iomap)
Quoted 8 lines
Quoted 3 lines

{
return -ENXIO;
}

Given that the only caller is under an IS_DAX() check you could just declare the function unconditionally and let the compiler optimize away the guaranteed dead call for the !CONFIG_FS_DAX case, like we do with various other functions.

Sure, will do.

Vivek