TencentOS-kernel/fs/f2fs
Chao Yu d9f249b2b2 f2fs: fix to set/clear I_LINKABLE under i_lock
[ Upstream commit 46085f37fc9e12d5c3539fb768b5ad7951e72acf ]

fsstress + fault injection test case reports a warning message as
below:

WARNING: CPU: 13 PID: 6226 at fs/inode.c:361 inc_nlink+0x32/0x40
Call Trace:
 f2fs_init_inode_metadata+0x25c/0x4a0 [f2fs]
 f2fs_add_inline_entry+0x153/0x3b0 [f2fs]
 f2fs_add_dentry+0x75/0x80 [f2fs]
 f2fs_do_add_link+0x108/0x160 [f2fs]
 f2fs_rename2+0x6ab/0x14f0 [f2fs]
 vfs_rename+0x70c/0x940
 do_renameat2+0x4d8/0x4f0
 __x64_sys_renameat2+0x4b/0x60
 do_syscall_64+0x33/0x80
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Following race case can cause this:
Thread A				Kworker
- f2fs_rename
 - f2fs_create_whiteout
  - __f2fs_tmpfile
   - f2fs_i_links_write
    - f2fs_mark_inode_dirty_sync
     - mark_inode_dirty_sync
					- writeback_single_inode
					 - __writeback_single_inode
					  - spin_lock(&inode->i_lock)
   - inode->i_state |= I_LINKABLE
					  - inode->i_state &= ~dirty
					  - spin_unlock(&inode->i_lock)
 - f2fs_add_link
  - f2fs_do_add_link
   - f2fs_add_dentry
    - f2fs_add_inline_entry
     - f2fs_init_inode_metadata
      - f2fs_i_links_write
       - inc_nlink
        - WARN_ON(!(inode->i_state & I_LINKABLE))

Fix to add i_lock to avoid i_state update race condition.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-04-12 12:52:48 +08:00
..
Kconfig Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Makefile Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
acl.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
acl.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
checkpoint.c f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
data.c f2fs: fix a wrong condition in __submit_bio 2021-04-12 12:52:21 +08:00
debug.c f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
dir.c f2fs: fix uninit-value in f2fs_lookup 2021-03-16 16:39:41 +08:00
extent_cache.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
f2fs.h f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
file.c f2fs: fix out-of-repair __setattr_copy() 2021-04-12 12:52:40 +08:00
gc.c f2fs: stop GC when the victim becomes fully valid 2021-03-16 16:36:41 +08:00
gc.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
hash.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
inline.c f2fs: fix to avoid inconsistent quota data 2021-04-12 12:52:20 +08:00
inode.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
namei.c f2fs: fix to set/clear I_LINKABLE under i_lock 2021-04-12 12:52:48 +08:00
node.c f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
node.h f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
recovery.c f2fs: fix error path in do_recover_data() 2021-03-16 16:34:49 +08:00
segment.c f2fs: handle errors of f2fs_get_meta_page_nofail 2021-03-16 16:39:42 +08:00
segment.h f2fs: handle unallocated section and zone on pinned/atgc 2021-04-12 12:52:48 +08:00
shrinker.c f2fs: avoid race condition for shrinker count 2021-03-16 16:43:55 +08:00
super.c f2fs: fix shift-out-of-bounds in sanity_check_raw_super() 2021-03-16 16:43:53 +08:00
sysfs.c f2fs: wait for sysfs kobject removal before freeing f2fs_sb_info 2021-03-16 16:38:58 +08:00
trace.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
trace.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
verity.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
xattr.c f2fs: fix to avoid memory leakage in f2fs_listxattr 2021-03-16 16:26:43 +08:00
xattr.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00