Miklos Szeredi 7bfac9ecf0 splice: fix deadlock in splicing to file
There's a possible deadlock in generic_file_splice_write(),
splice_from_pipe() and ocfs2_file_splice_write():

 - task A calls generic_file_splice_write()
 - this calls inode_double_lock(), which locks i_mutex on both
   pipe->inode and target inode
 - ordering depends on inode pointers, can happen that pipe->inode is
   locked first
 - __splice_from_pipe() needs more data, calls pipe_wait()
 - this releases lock on pipe->inode, goes to interruptible sleep
 - task B calls generic_file_splice_write(), similarly to the first
 - this locks pipe->inode, then tries to lock inode, but that is
   already held by task A
 - task A is interrupted, it tries to lock pipe->inode, but fails, as
   it is already held by task B
 - ABBA deadlock

Fix this by explicitly ordering locks: the outer lock must be on
target inode and the inner lock (which is later unlocked and relocked)
must be on pipe->inode.  This is OK, pipe inodes and target inodes
form two nonoverlapping sets, generic_file_splice_write() and friends
are not called with a target which is a pipe.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Acked-by: Mark Fasheh <mfasheh@suse.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-04-07 08:34:46 -07:00
..
2009-04-02 19:05:08 -07:00
2009-04-02 19:05:08 -07:00
2009-04-03 16:42:41 +01:00
2009-04-01 08:59:23 -07:00
2009-01-22 13:15:57 +03:00
2009-03-31 23:00:26 -04:00
2009-04-01 08:59:23 -07:00
2009-04-02 19:05:09 -07:00
2009-03-31 19:44:38 +03:00
2009-03-31 23:00:26 -04:00
2009-01-22 13:15:58 +03:00
2009-04-02 19:05:09 -07:00
2009-03-31 23:00:26 -04:00
2008-10-17 02:38:36 +11:00
2009-03-27 14:44:05 -04:00
2009-04-02 19:05:10 -07:00
2009-04-02 19:04:48 -07:00
2009-04-02 19:05:10 -07:00
2009-04-02 19:05:10 -07:00
2009-03-27 14:44:03 -04:00
2008-12-31 18:07:43 -05:00
2009-01-03 11:45:54 -08:00
2009-03-31 23:00:27 -04:00
2009-03-31 23:00:28 -04:00
2009-04-02 19:04:48 -07:00
2009-03-31 23:00:26 -04:00
2009-03-16 08:34:35 -06:00
2009-04-07 08:31:16 -07:00
2009-04-07 08:31:16 -07:00
2009-02-18 15:37:53 -08:00