From bf186ea702f11705d61ea90b957e02276a16aaf7 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 10 Feb 2017 00:51:53 -0500 Subject: [PATCH] add ext4 dax write locking patches --- ...sert-that-i_rw_sem-is-held-exclusive-for-writes | 32 +++++++++++++ fix-dax-write-locking | 56 ++++++++++++++++++++++ series | 3 ++ timestamps | 8 ++-- 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 dax-assert-that-i_rw_sem-is-held-exclusive-for-writes create mode 100644 fix-dax-write-locking diff --git a/dax-assert-that-i_rw_sem-is-held-exclusive-for-writes b/dax-assert-that-i_rw_sem-is-held-exclusive-for-writes new file mode 100644 index 00000000..c02fe485 --- /dev/null +++ b/dax-assert-that-i_rw_sem-is-held-exclusive-for-writes @@ -0,0 +1,32 @@ +dax: assert that i_rwsem is held exclusive for writes + +From: 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 +Signed-off-by: Theodore Ts'o +Reviewed-by: Jan Kara +--- + fs/dax.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/fs/dax.c b/fs/dax.c +index 5c74f60d0a50..04734daed1bd 100644 +--- a/fs/dax.c ++++ b/fs/dax.c +@@ -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, diff --git a/fix-dax-write-locking b/fix-dax-write-locking new file mode 100644 index 00000000..d4f9d67d --- /dev/null +++ b/fix-dax-write-locking @@ -0,0 +1,56 @@ +ext4: fix DAX write locking + +From: 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. + +Signed-off-by: Christoph Hellwig +Signed-off-by: Theodore Ts'o +Reviewed-by: Jan Kara +--- + fs/ext4/file.c | 10 +--------- + 1 file changed, 1 insertion(+), 9 deletions(-) + +diff --git a/fs/ext4/file.c b/fs/ext4/file.c +index d663d3d..a1e88aa 100644 +--- a/fs/ext4/file.c ++++ b/fs/ext4/file.c +@@ -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; +-- +2.1.4 + +-- +To unsubscribe from this list: send the line "unsubscribe linux-ext4" in +the body of a message to majordomo@vger.kernel.org +More majordomo info at http://vger.kernel.org/majordomo-info.html + diff --git a/series b/series index beeeb3a6..0c6ca3fb 100644 --- a/series +++ b/series @@ -22,6 +22,9 @@ rename-s_resize_flags-to-s_ext4_flags add_shutdown_flag add-shutdown-ioctl +fix-dax-write-locking +dax-assert-that-i_rw_sem-is-held-exclusive-for-writes + #################################################### # unstable patches #################################################### diff --git a/timestamps b/timestamps index 7ba5ee14..860c8e09 100755 --- a/timestamps +++ b/timestamps @@ -63,7 +63,9 @@ touch -d @1486276008 return-erofs-for-recovery-when-device-readonly touch -d @1486276068 rename-s_resize_flags-to-s_ext4_flags touch -d @1486276071 stable-boundary touch -d @1486276128 add_shutdown_flag -touch -d @1486278280 series touch -d @1486342034 add-shutdown-ioctl -touch -d @1486412501 status -touch -d @1486412503 timestamps +touch -d @1486582767 fix-dax-write-locking +touch -d @1486582930 series +touch -d @1486582993 dax-assert-that-i_rw_sem-is-held-exclusive-for-writes +touch -d @1486582994 status +touch -d @1486705898 timestamps -- 2.11.4.GIT