Skip to content

Commit f773f0a

Browse files
ZhaoLong Wangrichardweinberger
authored andcommitted
ubi: Fix deadlock caused by recursively holding work_sem
During the processing of the bgt, if the sync_erase() return -EBUSY or some other error code in __erase_worker(),schedule_erase() called again lead to the down_read(ubi->work_sem) hold twice and may get block by down_write(ubi->work_sem) in ubi_update_fastmap(), which cause deadlock. ubi bgt other task do_work down_read(&ubi->work_sem) ubi_update_fastmap erase_worker # Blocked by down_read __erase_worker down_write(&ubi->work_sem) schedule_erase schedule_ubi_work down_read(&ubi->work_sem) Fix this by changing input parameter @nested of the schedule_erase() to 'true' to avoid recursively acquiring the down_read(&ubi->work_sem). Also, fix the incorrect comment about @nested parameter of the schedule_erase() because when down_write(ubi->work_sem) is held, the @nested is also need be true. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217093 Fixes: 2e8f08d ("ubi: Fix races around ubi_refill_pools()") Signed-off-by: ZhaoLong Wang <[email protected]> Reviewed-by: Zhihao Cheng <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 0988a0e commit f773f0a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/mtd/ubi/wl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
575575
* @vol_id: the volume ID that last used this PEB
576576
* @lnum: the last used logical eraseblock number for the PEB
577577
* @torture: if the physical eraseblock has to be tortured
578-
* @nested: denotes whether the work_sem is already held in read mode
578+
* @nested: denotes whether the work_sem is already held
579579
*
580580
* This function returns zero in case of success and a %-ENOMEM in case of
581581
* failure.
@@ -1131,7 +1131,7 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
11311131
int err1;
11321132

11331133
/* Re-schedule the LEB for erasure */
1134-
err1 = schedule_erase(ubi, e, vol_id, lnum, 0, false);
1134+
err1 = schedule_erase(ubi, e, vol_id, lnum, 0, true);
11351135
if (err1) {
11361136
spin_lock(&ubi->wl_lock);
11371137
wl_entry_destroy(ubi, e);

0 commit comments

Comments
 (0)