tmp_suning_uos_patched/fs/erofs
Huang Jianan 77d9c2efa8 erofs: fix deadlock when shrink erofs slab
[ Upstream commit 57bbeacdbee72a54eb97d56b876cf9c94059fc34 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-12-01 09:19:05 +01:00
..
compress.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
data.c erofs: avoid using generic_block_bmap 2020-12-30 11:53:46 +01:00
decompressor.c erofs: don't trigger WARN() when decompression fails 2021-11-18 14:04:01 +01:00
dir.c erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
erofs_fs.h erofs: add unsupported inode i_format check 2021-05-11 14:47:13 +02:00
inode.c erofs: add unsupported inode i_format check 2021-05-11 14:47:13 +02:00
internal.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
Kconfig erofs: support superblock checksum 2019-11-24 11:02:41 +08:00
Makefile
namei.c erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
super.c erofs: fix error return code in erofs_read_superblock() 2021-07-14 16:56:53 +02:00
tagptr.h
utils.c erofs: fix deadlock when shrink erofs slab 2021-12-01 09:19:05 +01:00
xattr.c erofs: initialized fields can only be observed after bit is set 2021-03-04 11:38:28 +01:00
xattr.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
zdata.c erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-21 13:46:37 +01:00
zdata.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
zmap.c erofs: initialized fields can only be observed after bit is set 2021-03-04 11:38:28 +01:00
zpvec.h erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-21 13:46:37 +01:00