]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
f2fs: compress: fix potential deadlock
authorChao Yu <yuchao0@huawei.com>
Mon, 11 Jan 2021 09:42:53 +0000 (17:42 +0800)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 15 Mar 2021 14:09:09 +0000 (15:09 +0100)
commit8bda39a82abbe1731a61ff8318da000555be99ca
treeeb29f64974ac6e7d032880076542b4fda80bee43
parentd7b6a2f1245b5aa3ce39c6821fa09feaa0dcda1c
f2fs: compress: fix potential deadlock

[ Upstream commit 3afae09ffea5e08f523823be99a784675995d6bb ]

generic/269 reports a hangtask issue, the root cause is ABBA deadlock
described as below:

Thread A Thread B
- down_write(&sbi->gc_lock) -- A
- f2fs_write_data_pages
 - lock all pages in cluster -- B
 - f2fs_write_multi_pages
  - f2fs_write_raw_pages
   - f2fs_write_single_data_page
    - f2fs_balance_fs
     - down_write(&sbi->gc_lock) -- A
- f2fs_gc
 - do_garbage_collect
  - ra_data_block
   - pagecache_get_page -- B

To fix this, it needs to avoid calling f2fs_balance_fs() if there is
still cluster pages been locked in context of cluster writeback, so
instead, let's call f2fs_balance_fs() in the end of
f2fs_write_raw_pages() when all cluster pages were unlocked.

Fixes: 4c8ff7095bef ("f2fs: support data compression")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
fs/f2fs/compress.c
fs/f2fs/data.c
fs/f2fs/f2fs.h