linux/fs/erofs
Huang Jianan ca9ee53cea UPSTREAM: 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>
Signed-off-by: haojianhua1 <haojianhua1@xiaomi.com>
Change-Id: Icdfb520c073de8773d44cff64fd5f7a8499cdc85
Signed-off-by: haojianhua1 <haojianhua1@xiaomi.com>

Bug:208318427
(cherry picked from commit 57bbeacdbe)
Signed-off-by: Gao Xiang <xiang@kernel.org>

Change-Id: Ie282b4362898fa8e0c829b8c2454887e953a2610
Signed-off-by: haojianhua1 <haojianhua1@xiaomi.com>
2021-12-01 17:46:54 +00:00
..
compress.h UPSTREAM: erofs: force inplace I/O under low memory scenario 2021-06-09 12:01:08 +00:00
data.c UPSTREAM: erofs: don't use erofs_map_blocks() any more 2021-09-28 08:23:24 +00:00
decompressor.c UPSTREAM: erofs: support decompress big pcluster for lz4 backend 2021-09-28 08:32:20 +00:00
dir.c
erofs_fs.h UPSTREAM: erofs: enable big pcluster feature 2021-09-28 08:33:20 +00:00
inode.c
internal.h UPSTREAM: erofs: support decompress big pcluster for lz4 backend 2021-09-28 08:32:20 +00:00
Kconfig UPSTREAM: erofs: introduce physical cluster slab pools 2021-09-28 08:29:22 +00:00
Makefile UPSTREAM: erofs: introduce multipage per-CPU buffers 2021-09-28 08:28:24 +00:00
namei.c
pcpubuf.c UPSTREAM: erofs: introduce multipage per-CPU buffers 2021-09-28 08:28:24 +00:00
super.c Merge tag 'android12-5.10.66_r00' into android12-5.10 2021-10-21 09:45:02 +02:00
tagptr.h
utils.c UPSTREAM: erofs: fix deadlock when shrink erofs slab 2021-12-01 17:46:54 +00:00
xattr.c
xattr.h
zdata.c UPSTREAM: erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-30 23:37:10 +00:00
zdata.h UPSTREAM: erofs: introduce physical cluster slab pools 2021-09-28 08:29:22 +00:00
zmap.c UPSTREAM: erofs: fix 1 lcluster-sized pcluster for big pcluster 2021-09-28 08:33:46 +00:00
zpvec.h UPSTREAM: erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-30 23:37:10 +00:00