linux-stable/fs/f2fs
Chao Yu 466357dc9b f2fs: fix potential deadlock on compressed quota file
generic/232 reports below deadlock:

fsstress        D    0 96980  96969 0x00084000
Call Trace:
 schedule+0x4a/0xb0
 io_schedule+0x12/0x40
 __lock_page+0x127/0x1d0
 pagecache_get_page+0x1d8/0x250
 prepare_compress_overwrite+0xe0/0x490 [f2fs]
 f2fs_prepare_compress_overwrite+0x5d/0x80 [f2fs]
 f2fs_write_begin+0x833/0xb90 [f2fs]
 f2fs_quota_write+0x145/0x1e0 [f2fs]
 write_blk+0x36/0x80 [quota_tree]
 do_insert_tree+0x2ac/0x4a0 [quota_tree]
 do_insert_tree+0x26e/0x4a0 [quota_tree]
 qtree_write_dquot+0x70/0x190 [quota_tree]
 v2_write_dquot+0x43/0x90 [quota_v2]
 dquot_acquire+0x77/0x100
 f2fs_dquot_acquire+0x2f/0x60 [f2fs]
 dqget+0x310/0x450
 dquot_transfer+0xb2/0x120
 f2fs_setattr+0x11a/0x4a0 [f2fs]
 notify_change+0x349/0x480
 chown_common+0x168/0x1c0
 do_fchownat+0xbc/0xf0
 __x64_sys_lchown+0x21/0x30
 do_syscall_64+0x5f/0x220
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

  task                        PC stack   pid father
kworker/u256:0  D    0 103444      2 0x80084000
Workqueue: writeback wb_workfn (flush-251:1)
Call Trace:
 schedule+0x4a/0xb0
 schedule_timeout+0x15e/0x2f0
 io_schedule_timeout+0x19/0x40
 congestion_wait+0x7e/0x120
 f2fs_write_multi_pages+0x12a/0x840 [f2fs]
 f2fs_write_cache_pages+0x48f/0x790 [f2fs]
 f2fs_write_data_pages+0x2db/0x330 [f2fs]
 do_writepages+0x1a/0x60
 __writeback_single_inode+0x3d/0x340
 writeback_sb_inodes+0x225/0x4a0
 wb_writeback+0xf7/0x320
 wb_workfn+0xba/0x470
 process_one_work+0x16c/0x3f0
 worker_thread+0x4c/0x440
 kthread+0xf8/0x130
 ret_from_fork+0x35/0x40

fsstress        D    0  5277   5266 0x00084000
Call Trace:
 schedule+0x4a/0xb0
 rwsem_down_write_slowpath+0x29d/0x540
 block_operations+0x105/0x360 [f2fs]
 f2fs_write_checkpoint+0x101/0x1010 [f2fs]
 f2fs_sync_fs+0xa8/0x130 [f2fs]
 f2fs_do_sync_file+0x1ad/0x890 [f2fs]
 do_fsync+0x38/0x60
 __x64_sys_fdatasync+0x13/0x20
 do_syscall_64+0x5f/0x220
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The root cause is there is potential deadlock between quota data
update and writeback.

Kworker					Thread B			Thread C
- f2fs_write_cache_pages
 - lock whole cluster	--- A
 - f2fs_write_multi_pages
  - f2fs_write_raw_pages
   - f2fs_write_single_data_page
    - f2fs_do_write_data_page
					- f2fs_setattr
					 - f2fs_lock_op	--- B
									- f2fs_write_checkpoint
									 - block_operations
									  - f2fs_lock_all --- B
					 - dquot_transfer
					  - f2fs_quota_write
					   - f2fs_prepare_compress_overwrite
					    - pagecache_get_page --- A
     - f2fs_trylock_op failed	--- B
  - congestion_wait
  - goto rewrite

To fix this issue, during quota file writeback, just redirty all pages
left in cluster rather holding pages' lock in cluster and looping retrying
lock cp_rwsem.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-03-30 20:46:23 -07:00
..
acl.c f2fs: Replace spaces with tab 2019-05-08 21:23:11 -07:00
acl.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
checkpoint.c f2fs: Add a new CP flag to help fsck fix resize SPO issues 2020-03-22 21:16:28 -07:00
compress.c f2fs: fix potential deadlock on compressed quota file 2020-03-30 20:46:23 -07:00
data.c f2fs: delete DIO read lock 2020-03-30 20:46:23 -07:00
debug.c f2fs: show mounted time 2020-03-19 11:41:25 -07:00
dir.c f2fs-for-5.6 2020-01-30 15:39:24 -08:00
extent_cache.c f2fs: introduce f2fs_<level> macros to wrap f2fs_printk() 2019-07-02 15:40:40 -07:00
f2fs.h f2fs: don't mark compressed inode dirty during f2fs_iget() 2020-03-30 20:46:23 -07:00
file.c f2fs: fix to show tracepoint correctly 2020-03-19 11:41:26 -07:00
gc.c f2fs: fix to update f2fs_super_block fields under sb_lock 2020-03-22 21:16:29 -07:00
gc.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
hash.c f2fs: Support case-insensitive file name lookups 2019-08-23 07:57:13 -07:00
inline.c f2fs: convert inline_dir early before starting rename 2020-01-17 16:48:42 -08:00
inode.c f2fs: introduce DEFAULT_IO_TIMEOUT 2020-03-19 11:41:26 -07:00
Kconfig f2fs-for-5.6 2020-01-30 15:39:24 -08:00
Makefile f2fs: support data compression 2020-01-17 16:48:07 -08:00
namei.c f2fs: fix inconsistent comments 2020-03-10 09:18:33 -07:00
node.c f2fs: add prefix for f2fs slab cache name 2020-03-19 11:41:26 -07:00
node.h f2fs: check PageWriteback flag for ordered case 2018-12-26 15:16:56 -08:00
recovery.c f2fs: introduce DEFAULT_IO_TIMEOUT 2020-03-19 11:41:26 -07:00
segment.c f2fs: add prefix for f2fs slab cache name 2020-03-19 11:41:26 -07:00
segment.h f2fs: show mounted time 2020-03-19 11:41:25 -07:00
shrinker.c f2fs: fix inconsistent comments 2020-03-10 09:18:33 -07:00
super.c f2fs: use kmem_cache pool during inline xattr lookups 2020-03-22 21:16:27 -07:00
sysfs.c f2fs: show mounted time 2020-03-19 11:41:25 -07:00
trace.c f2fs: do not use mutex lock in atomic context 2019-03-05 19:58:06 -08:00
trace.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
verity.c fs-verity: implement readahead of Merkle tree pages 2020-01-14 13:27:32 -08:00
xattr.c f2fs: use kmem_cache pool during inline xattr lookups 2020-03-22 21:16:27 -07:00
xattr.h f2fs: xattr.h: Replace zero-length array with flexible-array member 2020-03-22 21:16:29 -07:00