WSL2-Linux-Kernel/fs/erofs
Huang Jianan 57bbeacdbe erofs: fix deadlock when shrink erofs slab
We observed the following deadlock in the stress test under low
memory scenario:

Thread A                               Thread B
- erofs_shrink_scan
 - erofs_try_to_release_workgroup
  - erofs_workgroup_try_to_freeze -- A
                                       - z_erofs_do_read_page
                                        - z_erofs_collection_begin
                                         - z_erofs_register_collection
                                          - erofs_insert_workgroup
                                           - xa_lock(&sbi->managed_pslots) -- B
                                           - erofs_workgroup_get
                                            - erofs_wait_on_workgroup_freezed -- A
  - xa_erase
   - xa_lock(&sbi->managed_pslots) -- B

To fix this, it needs to hold xa_lock before freezing the workgroup
since xarray will be touched then. So let's hold the lock before
accessing each workgroup, just like what we did with the radix tree
before.

[ Gao Xiang: Jianhua Hao also reports this issue at
  https://lore.kernel.org/r/b10b85df30694bac8aadfe43537c897a@xiaomi.com ]

Link: https://lore.kernel.org/r/20211118135844.3559-1-huangjianan@oppo.com
Fixes: 64094a0441 ("erofs: convert workstn to XArray")
Reviewed-by: Chao Yu <chao@kernel.org>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Huang Jianan <huangjianan@oppo.com>
Reported-by: Jianhua Hao <haojianhua1@xiaomi.com>
Signed-off-by: Gao Xiang <xiang@kernel.org>
2021-11-23 14:58:16 +08:00
..
Kconfig erofs: lzma compression support 2021-10-19 23:44:30 +08:00
Makefile erofs: lzma compression support 2021-10-19 23:44:30 +08:00
compress.h erofs: get rid of ->lru usage 2021-10-25 08:22:59 +08:00
data.c gfs2: Fix mmap + page fault deadlocks 2021-11-02 12:25:03 -07:00
decompressor.c erofs: don't trigger WARN() when decompression fails 2021-10-31 21:00:28 +08:00
decompressor_lzma.c erofs: get rid of ->lru usage 2021-10-25 08:22:59 +08:00
dir.c erofs: clean up file headers & footers 2021-06-08 00:41:24 +08:00
erofs_fs.h erofs: lzma compression support 2021-10-19 23:44:30 +08:00
inode.c erofs: decouple basic mount options from fs_context 2021-10-17 23:57:15 +08:00
internal.h erofs: get rid of ->lru usage 2021-10-25 08:22:59 +08:00
namei.c erofs: add fiemap support with iomap 2021-08-19 00:13:43 +08:00
pcpubuf.c erofs: get rid of ->lru usage 2021-10-25 08:22:59 +08:00
super.c erofs: lzma compression support 2021-10-19 23:44:30 +08:00
tagptr.h erofs: clean up file headers & footers 2021-06-08 00:41:24 +08:00
utils.c erofs: fix deadlock when shrink erofs slab 2021-11-23 14:58:16 +08:00
xattr.c erofs: decouple basic mount options from fs_context 2021-10-17 23:57:15 +08:00
xattr.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
zdata.c Changes since last update: 2021-11-13 11:27:02 -08:00
zdata.h Changes since last update: 2021-11-13 11:27:02 -08:00
zmap.c erofs: lzma compression support 2021-10-19 23:44:30 +08:00
zpvec.h erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-08 10:02:10 +08:00