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>
Wed, 3 Jan 2018 03:27:28 +0000 (19:27 -0800)
commit21020812c9e1ab593367fad9ce579f842a0b406d
tree753b5e94c5b00ca74dc64d370b259f88070e2e05
parente17d488bce9ef4fe3b18d1548ea79b65f836b497
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