]> git.hungrycats.org Git - linux/commit
f2fs: fix race condition on setting FI_NO_EXTENT flag
authorZhang Qilong <zhangqilong3@huawei.com>
Mon, 5 Sep 2022 04:59:17 +0000 (12:59 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Oct 2022 07:58:07 +0000 (09:58 +0200)
commit1f4d5d31ddfffbbdb24d8b34b012b528e241a1ea
treeb2ed23b0a451317ad33e89602bd297eeffff6286
parenta3e69948da570167a147ac53404d0801ddcc6564
f2fs: fix race condition on setting FI_NO_EXTENT flag

[ Upstream commit 07725adc55c0a414c10acb5c8c86cea34b95ddef ]

The following scenarios exist.
process A:               process B:
->f2fs_drop_extent_tree  ->f2fs_update_extent_cache_range
                          ->f2fs_update_extent_tree_range
                           ->write_lock
 ->set_inode_flag
                           ->is_inode_flag_set
                           ->__free_extent_tree // Shouldn't
                                                // have been
                                                // cleaned up
                                                // here
  ->write_lock

In this case, the "FI_NO_EXTENT" flag is set between
f2fs_update_extent_tree_range and is_inode_flag_set
by other process. it leads to clearing the whole exten
tree which should not have happened. And we fix it by
move the setting it to the range of write_lock.

Fixes:5f281fab9b9a3 ("f2fs: disable extent_cache for fcollapse/finsert inodes")
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/extent_cache.c