f2fs: Prevent s_writer rw_sem count mismatch in f2fs_evict_inode
authorYeongjin Gil <youngjin.gil@samsung.com>
Fri, 22 Mar 2024 04:16:39 +0000 (13:16 +0900)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 26 Mar 2024 16:52:26 +0000 (16:52 +0000)
commit3127f1010c9b27d925e83081d413ea7fc361abb0
tree98fff95dfbadc3412f971cab9ad0efa6af63a6fa
parentee745e4736fbf33079d0d0808e1343c2280fd59a
f2fs: Prevent s_writer rw_sem count mismatch in f2fs_evict_inode

If f2fs_evict_inode is called between freeze_super and thaw_super, the
s_writer rwsem count may become negative, resulting in hang.

CPU1                       CPU2

f2fs_resize_fs()           f2fs_evict_inode()
  f2fs_freeze
    set SBI_IS_FREEZING
                             skip sb_start_intwrite
  f2fs_unfreeze
    clear SBI_IS_FREEZING
                             sb_end_intwrite

To solve this problem, the call to sb_end_write is determined by whether
sb_start_intwrite is called, rather than the current freezing status.

Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
Signed-off-by: Yeongjin Gil <youngjin.gil@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/inode.c