fix write synchronization for DAX
Subsystems (4)
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.
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
@@ -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
PATCH 1/2 ext4: fix DAX write locking
In reply to Christoph HellwigUnlike 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
@@ -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
Re: [PATCH 1/2] ext4: fix DAX write locking
Quoted 8 lines · Christoph Hellwig
Unlike
O_DIRECTDAX 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.
Signed-off-by Christoph Hellwig <[email protected]>
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@@ -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
Re: [PATCH 2/2] dax: assert that i_rwsem is held exclusive for writes
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Make sure all callers follow the same locking protocol, given that DAX transparantly replaced the normal buffered I/O path.
Signed-off-by Christoph Hellwig <[email protected]>
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@@ -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
Re: [PATCH 1/2] ext4: fix DAX write locking
In reply to Jan KaraQuoted 8 lines · Jan Kara
Quoted 7 lines · Christoph Hellwig
Unlike
O_DIRECTDAX 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
Signed-off-by Christoph Hellwig <[email protected]>Makes sense. You can add:
Reviewed-by Jan Kara <[email protected]>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
Theodore Ts'o
maintainerRe: [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_DIRECTDAX 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.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 7 lines
Quoted 5 lines
Makes sense. You can add:
Reviewed-by Jan Kara <[email protected]>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
Re: [PATCH 1/2] ext4: fix DAX write locking
In reply to Jan KaraQuoted 8 lines · Jan Kara
Quoted 7 lines · Christoph Hellwig
Unlike
O_DIRECTDAX 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
Signed-off-by Christoph Hellwig <[email protected]>Makes sense. You can add:
Reviewed-by Jan Kara <[email protected]>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
Re: [PATCH 2/2] dax: assert that i_rwsem is held exclusive for writes
In reply to Jan KaraQuoted 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.
Signed-off-by Christoph Hellwig <[email protected]>Looks good. You can add:
Reviewed-by Jan Kara <[email protected]>Probably also for Ted since it depends on the ext4 fix...
Thanks, applied to the ext4 tree.
- Ted