f2fs: Fix the race condition of resize flag between resizefs
authorZhang Qilong <zhangqilong3@huawei.com>
Tue, 18 Oct 2022 02:45:32 +0000 (10:45 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:30 +0000 (13:32 +0100)
commit1550e871120e779b6147490367c72d66aaf72ac2
treee74182711bcda83c2609975992252567c1b41632
parent0ea2ba0d5b4ff04905c8afabc147d0ad5b2e019f
f2fs: Fix the race condition of resize flag between resizefs

[ Upstream commit 28fc4e9077ce59ab28c89c20dc6be5154473218f ]

Because the set/clear SBI_IS_RESIZEFS flag not between any locks,
In the following case:
  thread1 thread2
   ->ioctl(resizefs)
    ->set RESIZEFS flag  ->ioctl(resizefs)
    ...                      ->set RESIZEFS flag
    ->clear RESIZEFS flag
       ->resizefs stream
    # No RESIZEFS flag in the stream

Also before freeze_super, the resizefs not started, we should not set
the SBI_IS_RESIZEFS flag.

So move the set/clear SBI_IS_RESIZEFS flag between the cp_mutex and
gc_lock.

Fixes: b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in progress")
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/gc.c