Skip to contentSkip to conversation

fix write synchronization for DAX

PATCH Applied Christoph Hellwig 4 participants 9 messages Jan 10, 2017 – Feb 8, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

While I've fixed both ext4 and XFS to not incorrectly allow parallel writers when mounting with -o dax ext4 still has this issue after the iomap conversion.

Patch 1 fixes it, and patch 2 adds a lockdep assert to catch any new file systems copy and pasting from the direct I/O path.

#6 lore raw

PATCH 2/2 dax: assert that i_rwsem is held exclusive for writes

Make sure all callers follow the same locking protocol, given that DAX transparantly replaced the normal buffered I/O path.

---
 fs/dax.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/dax.c +5 -1
index 5c74f60..04734da 100644
@@ -1061,8 +1061,12 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
 	loff_t pos = iocb->ki_pos, ret = 0, done = 0;
 	unsigned flags = 0;
 
-	if (iov_iter_rw(iter) == WRITE)
+	if (iov_iter_rw(iter) == WRITE) {
+		lockdep_assert_held_exclusive(&inode->i_rwsem);
 		flags |= IOMAP_WRITE;
+	} else {
+		lockdep_assert_held(&inode->i_rwsem);
+	}
 
 	while (iov_iter_count(iter)) {
 		ret = iomap_apply(inode, pos, iov_iter_count(iter), flags, ops,
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 ext4: fix DAX write locking

In reply to Christoph Hellwig

Unlike O_DIRECT DAX is not an optional opt-in feature selected by the application, so we'll have to provide the traditional synchronіzation of overlapping writes as we do for buffered writes.

This was broken historically for DAX, but got fixed for ext2 and XFS as part of the iomap conversion. Fix up ext4 as well.

---
 fs/ext4/file.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
fs/ext4/file.c +1 -9
index d663d3d..a1e88aa 100644
@@ -175,7 +175,6 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct inode *inode = file_inode(iocb->ki_filp);
 	ssize_t ret;
-	bool overwrite = false;
 
 	inode_lock(inode);
 	ret = ext4_write_checks(iocb, from);
@@ -188,16 +187,9 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (ret)
 		goto out;
 
-	if (ext4_overwrite_io(inode, iocb->ki_pos, iov_iter_count(from))) {
-		overwrite = true;
-		downgrade_write(&inode->i_rwsem);
-	}
 	ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops);
 out:
-	if (!overwrite)
-		inode_unlock(inode);
-	else
-		inode_unlock_shared(inode);
+	inode_unlock(inode);
 	if (ret > 0)
 		ret = generic_write_sync(iocb, ret);
 	return ret;
Signature · 1 line
2.1.4
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ext4: fix DAX write locking

Quoted 8 lines · Christoph Hellwig

Unlike O_DIRECT DAX is not an optional opt-in feature selected by the application, so we'll have to provide the traditional synchronіzation of overlapping writes as we do for buffered writes.

This was broken historically for DAX, but got fixed for ext2 and XFS as part of the iomap conversion. Fix up ext4 as well.

Makes sense. You can add:

Ted, can you please pick it up? Thanks!

Honza

Quoted 37 lines
---
 fs/ext4/file.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
fs/ext4/file.c +1 -9
index d663d3d..a1e88aa 100644
@@ -175,7 +175,6 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct inode *inode = file_inode(iocb->ki_filp);
 	ssize_t ret;
-	bool overwrite = false;
 
 	inode_lock(inode);
 	ret = ext4_write_checks(iocb, from);
@@ -188,16 +187,9 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (ret)
 		goto out;
 
-	if (ext4_overwrite_io(inode, iocb->ki_pos, iov_iter_count(from))) {
-		overwrite = true;
-		downgrade_write(&inode->i_rwsem);
-	}
 	ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops);
 out:
-	if (!overwrite)
-		inode_unlock(inode);
-	else
-		inode_unlock_shared(inode);
+	inode_unlock(inode);
 	if (ret > 0)
 		ret = generic_write_sync(iocb, ret);
 	return ret;
Signature · 1 line
2.1.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] dax: assert that i_rwsem is held exclusive for writes

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Make sure all callers follow the same locking protocol, given that DAX transparantly replaced the normal buffered I/O path.

Looks good. You can add:

Probably also for Ted since it depends on the ext4 fix...

Honza

Quoted 25 lines
---
 fs/dax.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/dax.c +5 -1
index 5c74f60..04734da 100644
@@ -1061,8 +1061,12 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
 	loff_t pos = iocb->ki_pos, ret = 0, done = 0;
 	unsigned flags = 0;
 
-	if (iov_iter_rw(iter) == WRITE)
+	if (iov_iter_rw(iter) == WRITE) {
+		lockdep_assert_held_exclusive(&inode->i_rwsem);
 		flags |= IOMAP_WRITE;
+	} else {
+		lockdep_assert_held(&inode->i_rwsem);
+	}
 
 	while (iov_iter_count(iter)) {
 		ret = iomap_apply(inode, pos, iov_iter_count(iter), flags, ops,
Signature · 1 line
2.1.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw

Re: [PATCH 1/2] ext4: fix DAX write locking

In reply to Jan Kara
Quoted 8 lines · Jan Kara
Quoted 7 lines · Christoph Hellwig

Unlike O_DIRECT DAX is not an optional opt-in feature selected by the application, so we'll have to provide the traditional synchronіzation of overlapping writes as we do for buffered writes.

This was broken historically for DAX, but got fixed for ext2 and XFS as part of the iomap conversion. Fix up ext4 as well.

Quoted 7 lines
Quoted 1 line

Makes sense. You can add:

Ted, can you please pick it up? Thanks!

Did this get picked up?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#4 lore raw

Re: [PATCH 1/2] ext4: fix DAX write locking

Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · Jan Kara
Quoted 8 lines · Christoph Hellwig

Unlike O_DIRECT DAX is not an optional opt-in feature selected by the application, so we'll have to provide the traditional synchronіzation of overlapping writes as we do for buffered writes.

This was broken historically for DAX, but got fixed for ext2 and XFS as part of the iomap conversion. Fix up ext4 as well.

Quoted 7 lines
Quoted 5 lines

Makes sense. You can add:

Ted, can you please pick it up? Thanks!

Did this get picked up?

Sorry, I missed Jan's request to pick it up. I had assumed it would be going in via the dax tree. I'll take a look at it now for the ext4 tree.

- Ted

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Applied
#5 lore raw

Re: [PATCH 1/2] ext4: fix DAX write locking

In reply to Jan Kara
Quoted 8 lines · Jan Kara
Quoted 7 lines · Christoph Hellwig

Unlike O_DIRECT DAX is not an optional opt-in feature selected by the application, so we'll have to provide the traditional synchronіzation of overlapping writes as we do for buffered writes.

This was broken historically for DAX, but got fixed for ext2 and XFS as part of the iomap conversion. Fix up ext4 as well.

Quoted 7 lines
Quoted 1 line

Makes sense. You can add:

Ted, can you please pick it up? Thanks!

Thanks, applied to the ext4 tree.

- Ted
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Applied
#8 lore raw

Re: [PATCH 2/2] dax: assert that i_rwsem is held exclusive for writes

In reply to Jan Kara
Quoted 11 lines · Jan Kara
Quoted 4 lines · Christoph Hellwig

Make sure all callers follow the same locking protocol, given that DAX transparantly replaced the normal buffered I/O path.

Looks good. You can add:

Probably also for Ted since it depends on the ext4 fix...

Thanks, applied to the ext4 tree.

- Ted