Skip to contentSkip to conversation

fix regression in direct I/O to pmem devices

PATCH In review Jeff Moyer 5 participants 11 messages Aug 14, 2015 – Sep 8, 2015

Subsystems (2)
lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

cover fix regression in direct I/O to pmem devices

Linda Knippers noticed that commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. Further investigation also uncovered issues related to misaligned partitions. This patch set addresses the two issues.

[PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

 fs/block_dev.c | 7 +++++++
 fs/dax.c       | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
author
#1 lore raw

PATCH 1/2 dax: fix O_DIRECT I/O to the last block of a blockdev

commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. That utility sets the block size of the device to the logical block size using the BLKBSZSET ioctl, and then issues a single sector read from the last sector of the device. This results in the dax_io code trying to do a page-sized read from 512 bytes from the end of the device. The result is -ERANGE being returned to userspace.

The fix is to align the block to the page size before calling get_block.

Thanks to willy for simplifying my original patch.

---
 fs/dax.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dax.c +2 -1
index a7f77e1..ef35a20 100644
@@ -116,7 +116,8 @@ static ssize_t dax_io(struct inode *inode, struct iov_iter *iter,
 		unsigned len;
 		if (pos == max) {
 			unsigned blkbits = inode->i_blkbits;
-			sector_t block = pos >> blkbits;
+			long page = pos >> PAGE_SHIFT;
+			sector_t block = page << (PAGE_SHIFT - blkbits);
 			unsigned first = pos - (block << blkbits);
 			long size;
 
Signature · 1 line
1.8.3.1
Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev

Quoted 8 lines · Jeff Moyer

commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. That utility sets the block size of the device to the logical block size using the BLKBSZSET ioctl, and then issues a single sector read from the last sector of the device. This results in the dax_io code trying to do a page-sized read from 512 bytes from the end of the device. The result is -ERANGE being returned to userspace.

Quoted 6 lines

The fix is to align the block to the page size before calling get_block.

Thanks to willy for simplifying my original patch.

Quoted 19 lines
---
 fs/dax.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dax.c +2 -1
index a7f77e1..ef35a20 100644
@@ -116,7 +116,8 @@ static ssize_t dax_io(struct inode *inode, struct iov_iter *iter,
 		unsigned len;
 		if (pos == max) {
 			unsigned blkbits = inode->i_blkbits;
-			sector_t block = pos >> blkbits;
+			long page = pos >> PAGE_SHIFT;
+			sector_t block = page << (PAGE_SHIFT - blkbits);
 			unsigned first = pos - (block << blkbits);
 			long size;
 
#3 lore raw

Re: [PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev

This patch and the 2/2 patch don't seem to have gone anywhere. Willy? or Ross?

-- ljk

Quoted 38 lines · Linda Knippers
Quoted 8 lines · Jeff Moyer

commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. That utility sets the block size of the device to the logical block size using the BLKBSZSET ioctl, and then issues a single sector read from the last sector of the device. This results in the dax_io code trying to do a page-sized read from 512 bytes from the end of the device. The result is -ERANGE being returned to userspace.

Quoted 6 lines

The fix is to align the block to the page size before calling get_block.

Thanks to willy for simplifying my original patch.

Quoted 19 lines
---
 fs/dax.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dax.c +2 -1
index a7f77e1..ef35a20 100644
@@ -116,7 +116,8 @@ static ssize_t dax_io(struct inode *inode, struct iov_iter *iter,
 		unsigned len;
 		if (pos == max) {
 			unsigned blkbits = inode->i_blkbits;
-			sector_t block = pos >> blkbits;
+			long page = pos >> PAGE_SHIFT;
+			sector_t block = page << (PAGE_SHIFT - blkbits);
 			unsigned first = pos - (block << blkbits);
 			long size;
 
#4 lore raw

Re: [PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev

Quoted 3 lines · Linda Knippers

This patch and the 2/2 patch don't seem to have gone anywhere. Willy? or Ross?

Yes, these should have gone into 4.2, The nvdimm.git tree will pick them up after 4.3-rc1 and tag them for -stable.

author
#5 lore raw

PATCH 2/2 blockdev: don't set S_DAX for misaligned partitions

In reply to Jeff Moyer

The dax code doesn't currently support misaligned partitions, so disable O_DIRECT via dax until such time as that support materializes.

---
 fs/block_dev.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/block_dev.c +7 -0
index 1982437..1170f8c 100644
@@ -1241,6 +1241,13 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 				goto out_clear;
 			}
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
+			/*
+			 * If the partition is not aligned on a page
+			 * boundary, we can't do dax I/O to it.
+			 */
+			if ((bdev->bd_part->start_sect % (PAGE_SIZE / 512)) ||
+			    (bdev->bd_part->nr_sects % (PAGE_SIZE / 512)))
+				bdev->bd_inode->i_flags &= ~S_DAX;
 		}
 	} else {
 		if (bdev->bd_contains == bdev) {
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

Quoted 16 lines · Jeff Moyer

The dax code doesn't currently support misaligned partitions, so disable O_DIRECT via dax until such time as that support materializes.

---
fs/block_dev.c | 7 +++++++

1 file changed, 7 insertions(+)
fs/block_dev.c +0 -0
index 1982437..1170f8c 100644

fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1249

Quoted 9 lines
fs/block_dev.c +6 -0
@@ -1241,6 +1241,13 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 				goto out_clear;
 			}
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
+			/*
+			 * If the partition is not aligned on a page
+			 * boundary, we can't do dax I/O to it.
+			 */
+			if ((bdev->bd_part->start_sect % (PAGE_SIZE / 512)) ||
+			    (bdev->bd_part->nr_sects % (PAGE_SIZE / 512)))

Maybe I'm missing something, but doesn't the second condition above disable DAX for the case that the 1/2 patch is fixing (i.e. the last sectors at the end of a non-PAGE_SIZE-multiple device)? It seems a shame to disable DAX for the whole device because of the last sector.

Quoted 6 lines
fs/block_dev.c +1 -0
+				bdev->bd_inode->i_flags &= ~S_DAX;
 		}
 	} else {
 		if (bdev->bd_contains == bdev) {
Signature · 1 line
1.8.3.1

Cheers, Andreas

author
#7 lore raw

Re: [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

Quoted 23 lines · Andreas Dilger
Quoted 22 lines · Jeff Moyer

The dax code doesn't currently support misaligned partitions, so disable O_DIRECT via dax until such time as that support materializes.

---
fs/block_dev.c | 7 +++++++

1 file changed, 7 insertions(+)
fs/block_dev.c +3 -0
index 1982437..1170f8c 100644
@@ -1241,6 +1241,13 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 				goto out_clear;
 			}
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
+			/*
+			 * If the partition is not aligned on a page
+			 * boundary, we can't do dax I/O to it.
Quoted 8 lines

fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1249

Quoted 3 lines
fs/block_dev.c +3 -0
+			 */
+			if ((bdev->bd_part->start_sect % (PAGE_SIZE / 512)) ||
+			    (bdev->bd_part->nr_sects % (PAGE_SIZE / 512)))

Maybe I'm missing something, but doesn't the second condition above disable DAX for the case that the 1/2 patch is fixing (i.e. the last sectors at the end of a non-PAGE_SIZE-multiple device)? It seems a shame to disable DAX for the whole device because of the last sector.

No. Patch 1/2 fixes a 512 byte read of the last sector of a properly aligned partiton. The goal is to eventually fix things so we can enable the dax path for misaligned partitions, but it's not going to happen in time for 4.2. Also, keep in mind that this is just for opening the block device itself with O_DIRECT.

Thanks for taking a look.

Cheers,
Jeff

#8 lore raw
In reply to Jeff Moyer
Quoted 7 lines · Jeff Moyer

Linda Knippers noticed that commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. Further investigation also uncovered issues related to misaligned partitions. This patch set addresses the two issues.

[PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

Should these be "Cc: <[email protected]>" given the regression fix is applicable back to 4.0?

#9 lore raw
Quoted 11 lines · Dan Williams
Quoted 7 lines · Jeff Moyer

Linda Knippers noticed that commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. Further investigation also uncovered issues related to misaligned partitions. This patch set addresses the two issues.

[PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

Should these be "Cc: <[email protected]>" given the regression fix is applicable back to 4.0?

Sorry, regression *since* 4.0.

author
#10 lore raw
Quoted 7 lines · Dan Williams
Quoted 6 lines · Dan Williams
Quoted 5 lines · Jeff Moyer

Linda Knippers noticed that commit bbab37ddc20b (block: Add support for DAX reads/writes to block devices) caused a regression in mkfs.xfs. Further investigation also uncovered issues related to misaligned partitions. This patch set addresses the two issues.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

[PATCH 1/2] dax: fix O_DIRECT I/O to the last block of a blockdev [PATCH 2/2] blockdev: don't set S_DAX for misaligned partitions

Should these be "Cc: <[email protected]>" given the regression fix is applicable back to 4.0?

Sorry, regression *since* 4.0.

$ git describe --contains bbab37ddc20b
v4.2-rc1~2^2~4

Looks like this was not sprung on the public yet.

-Jeff