f2fs: fix avoid race between truncate and background GC
authorChao Yu <yuchao0@huawei.com>
Sun, 5 Aug 2018 15:04:25 +0000 (23:04 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 13 Aug 2018 17:48:17 +0000 (10:48 -0700)
commita33c150237a20d97a174243bc658c86502f9d370
tree1bdaea29bcb138882d6318eb3e151b2febceba2a
parentc7079853c859c910b9d047a37891b4aafb8f8dd7
f2fs: fix avoid race between truncate and background GC

Thread A Background GC
- f2fs_setattr isize to 0
 - truncate_setsize
- gc_data_segment
 - f2fs_get_read_data_page page #0
  - set_page_dirty
  - set_cold_data
 - f2fs_truncate

- f2fs_setattr isize to 4k
- read 4k <--- hit data in cached page #0

Above race condition can cause read out invalid data in a truncated
page, fix it by i_gc_rwsem[WRITE] lock.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/file.c