xfs: fix recursive splice read locking with DAX
authorDave Chinner <dchinner@redhat.com>
Mon, 4 Jan 2016 05:28:25 +0000 (16:28 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 4 Jan 2016 05:28:25 +0000 (16:28 +1100)
Doing a splice read (generic/249) generates a lockdep splat because
we recursively lock the inode iolock in this path:

SyS_sendfile64
do_sendfile
do_splice_direct
splice_direct_to_actor
do_splice_to
xfs_file_splice_read <<<<<< lock here
default_file_splice_read
vfs_readv
do_readv_writev
do_iter_readv_writev
xfs_file_read_iter <<<<<< then here

The issue here is that for DAX inodes we need to avoid the page
cache path and hence simply push it into the normal read path.
Unfortunately, we can't tell down at xfs_file_read_iter() whether we
are being called from the splice path and hence we cannot avoid the
locking at this layer. Hence we simply have to drop the inode
locking at the higher splice layer for DAX.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Tested-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_file.c

index f5392ab..ebe9b82 100644 (file)
@@ -402,19 +402,26 @@ xfs_file_splice_read(
        if (XFS_FORCED_SHUTDOWN(ip->i_mount))
                return -EIO;
 
-       xfs_rw_ilock(ip, XFS_IOLOCK_SHARED);
-
        trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
 
-       /* for dax, we need to avoid the page cache */
-       if (IS_DAX(VFS_I(ip)))
-               ret = default_file_splice_read(infilp, ppos, pipe, count, flags);
-       else
-               ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
-       if (ret > 0)
-               XFS_STATS_ADD(ip->i_mount, xs_read_bytes, ret);
+       /*
+        * DAX inodes cannot ues the page cache for splice, so we have to push
+        * them through the VFS IO path. This means it goes through
+        * ->read_iter, which for us takes the XFS_IOLOCK_SHARED. Hence we
+        * cannot lock the splice operation at this level for DAX inodes.
+        */
+       if (IS_DAX(VFS_I(ip))) {
+               ret = default_file_splice_read(infilp, ppos, pipe, count,
+                                              flags);
+               goto out;
+       }
 
+       xfs_rw_ilock(ip, XFS_IOLOCK_SHARED);
+       ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
        xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
+out:
+       if (ret > 0)
+               XFS_STATS_ADD(ip->i_mount, xs_read_bytes, ret);
        return ret;
 }