From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/2] xfs: fix splice/direct-IO deadlock
Date: Mon, 8 Aug 2011 16:45:27 +1000 [thread overview]
Message-ID: <1312785927-10662-3-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1312785927-10662-1-git-send-email-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
lockdep reports splice vs direct-io write lock inversions due to
generic_file_splice_write() taking the inode->i_mutex inside
XFS_IOLOCK_EXCL context. These lock contexts are inverted, hence can
deadlock. Use splice_write_to_file() with an actor that does not
take the i_mutex to avoid these problems.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
fs/xfs/linux-2.6/xfs_file.c | 41 +++++++++++++++++++++++++++++------------
1 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index 62a5022..959d8b2 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -38,6 +38,7 @@
#include <linux/dcache.h>
#include <linux/falloc.h>
+#include <linux/splice.h>
static const struct vm_operations_struct xfs_file_vm_ops;
@@ -431,13 +432,29 @@ xfs_aio_write_newsize_update(
}
}
+static ssize_t
+xfs_file_splice_write_actor(
+ struct pipe_inode_info *pipe,
+ struct splice_desc *sd)
+{
+ struct file *out = sd->u.file;
+ ssize_t ret;
+
+ ret = file_remove_suid(out);
+ if (!ret) {
+ file_update_time(out);
+ ret = splice_from_pipe_feed(pipe, sd, pipe_to_file);
+ }
+
+ return ret;
+}
+
/*
- * xfs_file_splice_write() does not use xfs_rw_ilock() because
- * generic_file_splice_write() takes the i_mutex itself. This, in theory,
- * couuld cause lock inversions between the aio_write path and the splice path
- * if someone is doing concurrent splice(2) based writes and write(2) based
- * writes to the same inode. The only real way to fix this is to re-implement
- * the generic code here with correct locking orders.
+ * xfs_file_splice_write() does not use the generic file splice write path
+ * because that takes the i_mutex, causing lock inversions with the IOLOCK.
+ * Instead, we call splice_write_to_file() directly with our own actor that does
+ * not take the i_mutex. This allows us to use the xfs_rw_ilock() functions like
+ * the rest of the code and hence avoid lock inversions and deadlocks.
*/
STATIC ssize_t
xfs_file_splice_write(
@@ -461,22 +478,22 @@ xfs_file_splice_write(
if (XFS_FORCED_SHUTDOWN(ip->i_mount))
return -EIO;
- xfs_ilock(ip, XFS_IOLOCK_EXCL);
+ xfs_rw_ilock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
new_size = *ppos + count;
-
- xfs_ilock(ip, XFS_ILOCK_EXCL);
if (new_size > ip->i_size)
ip->i_new_size = new_size;
- xfs_iunlock(ip, XFS_ILOCK_EXCL);
+
+ xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
trace_xfs_file_splice_write(ip, count, *ppos, ioflags);
- ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
+ ret = splice_write_to_file(pipe, outfilp, ppos, count, flags,
+ xfs_file_splice_write_actor);
xfs_aio_write_isize_update(inode, ppos, ret);
xfs_aio_write_newsize_update(ip, new_size);
- xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+ xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL);
return ret;
}
--
1.7.5.4
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2011-08-08 6:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-08 6:45 [PATCH 0/2] splice: i_mutex vs splice write deadlock V2 Dave Chinner
2011-08-08 6:45 ` [PATCH 1/2] vfs: split generic splice code from i_mutex locking Dave Chinner
2011-08-09 11:36 ` Jan Kara
2011-08-10 10:12 ` Christoph Hellwig
2011-08-08 6:45 ` Dave Chinner [this message]
2011-08-10 10:17 ` [PATCH 2/2] xfs: fix splice/direct-IO deadlock Christoph Hellwig
2011-08-10 10:19 ` [PATCH 0/2] splice: i_mutex vs splice write deadlock V2 Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2012-11-28 2:12 [PATCH 0/2] splice: fix direct IO/splice deadlock Dave Chinner
2012-11-28 2:12 ` [PATCH 2/2] xfs: fix splice/direct-IO deadlock Dave Chinner
2012-11-28 16:07 ` Christoph Hellwig
2012-11-28 21:33 ` Dave Chinner
2011-07-18 4:04 [PATCH 0/2] splice: i_mutex vs splice write deadlock Dave Chinner
2011-07-18 4:04 ` [PATCH 2/2] xfs: fix splice/direct-IO deadlock Dave Chinner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1312785927-10662-3-git-send-email-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox