f2fs: fix lock dependency in between dio_rwsem & i_mmap_sem
authorChao Yu <yuchao0@huawei.com>
Thu, 23 Nov 2017 15:26:52 +0000 (23:26 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 27 Jan 2018 21:29:07 +0000 (13:29 -0800)
commit3f12c94d1b3cc3c9a403017b337a9d6f91a25465
tree9b9c233ea4e822920eebe584e2e72fcb5d92ae3c
parent39685b35e80abb69cb2a5a4f965ddf9d0776b18b
f2fs: fix lock dependency in between dio_rwsem & i_mmap_sem

test/generic/208 reports a potential deadlock as below:

Chain exists of:
  &mm->mmap_sem --> &fi->i_mmap_sem --> &fi->dio_rwsem[WRITE]

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&fi->dio_rwsem[WRITE]);
                               lock(&fi->i_mmap_sem);
                               lock(&fi->dio_rwsem[WRITE]);
  lock(&mm->mmap_sem);

This patch changes the lock dependency as below in fallocate() to
fix this issue:
- dio_rwsem
 - i_mmap_sem

Fixes: bb06664a534b ("f2fs: avoid race in between GC and block exchange")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c