ufs: fix deadlocks introduced by sb mutex merge

Commit 0244756edc4b ("ufs: sb mutex merge + mutex_destroy") introduces
deadlocks in ufs_new_inode() and ufs_free_inode().
Most callers of that functions acqure the mutex by themselves and
ufs_{new,free}_inode() do that via lock_ufs(),
i.e we have an unavoidable double lock.

The patch proposes to resolve the issue by making sure that
ufs_{new,free}_inode() are not called with the mutex held.

Found by Linux Driver Verification project (linuxtesting.org).

Cc: stable@vger.kernel.org # 3.16
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by Alexey Khoroshilov and committed by Al Viro 9ef7db7f 81b6b061

Changed files
+8 -13
fs
+2 -5
fs/ufs/inode.c
··· 902 902 invalidate_inode_buffers(inode); 903 903 clear_inode(inode); 904 904 905 - if (want_delete) { 906 - lock_ufs(inode->i_sb); 907 - ufs_free_inode (inode); 908 - unlock_ufs(inode->i_sb); 909 - } 905 + if (want_delete) 906 + ufs_free_inode(inode); 910 907 }
+6 -8
fs/ufs/namei.c
··· 126 126 if (l > sb->s_blocksize) 127 127 goto out_notlocked; 128 128 129 - lock_ufs(dir->i_sb); 130 129 inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO); 131 130 err = PTR_ERR(inode); 132 131 if (IS_ERR(inode)) 133 - goto out; 132 + goto out_notlocked; 134 133 134 + lock_ufs(dir->i_sb); 135 135 if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) { 136 136 /* slow symlink */ 137 137 inode->i_op = &ufs_symlink_inode_operations; ··· 181 181 struct inode * inode; 182 182 int err; 183 183 184 - lock_ufs(dir->i_sb); 185 - inode_inc_link_count(dir); 186 - 187 184 inode = ufs_new_inode(dir, S_IFDIR|mode); 188 - err = PTR_ERR(inode); 189 185 if (IS_ERR(inode)) 190 - goto out_dir; 186 + return PTR_ERR(inode); 191 187 192 188 inode->i_op = &ufs_dir_inode_operations; 193 189 inode->i_fop = &ufs_dir_operations; 194 190 inode->i_mapping->a_ops = &ufs_aops; 195 191 196 192 inode_inc_link_count(inode); 193 + 194 + lock_ufs(dir->i_sb); 195 + inode_inc_link_count(dir); 197 196 198 197 err = ufs_make_empty(inode, dir); 199 198 if (err) ··· 211 212 inode_dec_link_count(inode); 212 213 inode_dec_link_count(inode); 213 214 iput (inode); 214 - out_dir: 215 215 inode_dec_link_count(dir); 216 216 unlock_ufs(dir->i_sb); 217 217 goto out;