Commit ca9ee53c authored by Huang Jianan's avatar Huang Jianan Committed by Todd Kjos
Browse files

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: 64094a04 ("erofs: convert workstn to XArray")
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Reviewed-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: default avatarHuang Jianan <huangjianan@oppo.com>
Reported-by: default avatarJianhua Hao <haojianhua1@xiaomi.com>
Signed-off-by: default avatarGao Xiang <xiang@kernel.org>
Signed-off-by: default avatarhaojianhua1 <haojianhua1@xiaomi.com>
Change-Id: Icdfb520c073de8773d44cff64fd5f7a8499cdc85
Signed-off-by: default avatarhaojianhua1 <haojianhua1@xiaomi.com>

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

Change-Id: Ie282b4362898fa8e0c829b8c2454887e953a2610
Signed-off-by: default avatarhaojianhua1 <haojianhua1@xiaomi.com>
parent 898e7ec9
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment