aboutsummaryrefslogtreecommitdiffstats
path: root/fs/splice.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/splice.c')
-rw-r--r--fs/splice.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/fs/splice.c b/fs/splice.c
index a567010b62ac..c1072b6940c3 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -713,6 +713,7 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
713{ 713{
714 int ret, do_wakeup, err; 714 int ret, do_wakeup, err;
715 struct splice_desc sd; 715 struct splice_desc sd;
716 struct inode *inode = out->f_mapping->host;
716 717
717 ret = 0; 718 ret = 0;
718 do_wakeup = 0; 719 do_wakeup = 0;
@@ -722,8 +723,13 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
722 sd.file = out; 723 sd.file = out;
723 sd.pos = *ppos; 724 sd.pos = *ppos;
724 725
725 if (pipe->inode) 726 /*
726 mutex_lock(&pipe->inode->i_mutex); 727 * The actor worker might be calling ->prepare_write and
728 * ->commit_write. Most of the time, these expect i_mutex to
729 * be held. Since this may result in an ABBA deadlock with
730 * pipe->inode, we have to order lock acquiry here.
731 */
732 inode_double_lock(inode, pipe->inode);
727 733
728 for (;;) { 734 for (;;) {
729 if (pipe->nrbufs) { 735 if (pipe->nrbufs) {
@@ -797,8 +803,7 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
797 pipe_wait(pipe); 803 pipe_wait(pipe);
798 } 804 }
799 805
800 if (pipe->inode) 806 inode_double_unlock(inode, pipe->inode);
801 mutex_unlock(&pipe->inode->i_mutex);
802 807
803 if (do_wakeup) { 808 if (do_wakeup) {
804 smp_mb(); 809 smp_mb();
@@ -1400,13 +1405,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
1400 * grabbing by inode address. Otherwise two different processes 1405 * grabbing by inode address. Otherwise two different processes
1401 * could deadlock (one doing tee from A -> B, the other from B -> A). 1406 * could deadlock (one doing tee from A -> B, the other from B -> A).
1402 */ 1407 */
1403 if (ipipe->inode < opipe->inode) { 1408 inode_double_lock(ipipe->inode, opipe->inode);
1404 mutex_lock_nested(&ipipe->inode->i_mutex, I_MUTEX_PARENT);
1405 mutex_lock_nested(&opipe->inode->i_mutex, I_MUTEX_CHILD);
1406 } else {
1407 mutex_lock_nested(&opipe->inode->i_mutex, I_MUTEX_PARENT);
1408 mutex_lock_nested(&ipipe->inode->i_mutex, I_MUTEX_CHILD);
1409 }
1410 1409
1411 do { 1410 do {
1412 if (!opipe->readers) { 1411 if (!opipe->readers) {
@@ -1450,8 +1449,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
1450 i++; 1449 i++;
1451 } while (len); 1450 } while (len);
1452 1451
1453 mutex_unlock(&ipipe->inode->i_mutex); 1452 inode_double_unlock(ipipe->inode, opipe->inode);
1454 mutex_unlock(&opipe->inode->i_mutex);
1455 1453
1456 /* 1454 /*
1457 * If we put data in the output pipe, wakeup any potential readers. 1455 * If we put data in the output pipe, wakeup any potential readers.