Skip to content

Commit 16d4c27

Browse files
nomuranecgregkh
authored andcommitted
dm: fix AB-BA deadlock in __dm_destroy()
commit 2a708cf upstream. __dm_destroy() takes io_barrier SRCU lock (dm_get_live_table) and suspend_lock in reverse order. Doing so can cause AB-BA deadlock: __dm_destroy dm_swap_table --------------------------------------------------- mutex_lock(suspend_lock) dm_get_live_table() srcu_read_lock(io_barrier) dm_sync_table() synchronize_srcu(io_barrier) .. waiting for dm_put_live_table() mutex_lock(suspend_lock) .. waiting for suspend_lock Fix this by taking the locks in proper order. Signed-off-by: Jun'ichi Nomura <[email protected]> Fixes: ab7c7bb ("dm: hold suspend_lock while suspending device during device deletion") Acked-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2058efb commit 16d4c27

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/md/dm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,8 +2925,6 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
29252925

29262926
might_sleep();
29272927

2928-
map = dm_get_live_table(md, &srcu_idx);
2929-
29302928
spin_lock(&_minor_lock);
29312929
idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md))));
29322930
set_bit(DMF_FREEING, &md->flags);
@@ -2940,14 +2938,14 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
29402938
* do not race with internal suspend.
29412939
*/
29422940
mutex_lock(&md->suspend_lock);
2941+
map = dm_get_live_table(md, &srcu_idx);
29432942
if (!dm_suspended_md(md)) {
29442943
dm_table_presuspend_targets(map);
29452944
dm_table_postsuspend_targets(map);
29462945
}
2947-
mutex_unlock(&md->suspend_lock);
2948-
29492946
/* dm_put_live_table must be before msleep, otherwise deadlock is possible */
29502947
dm_put_live_table(md, srcu_idx);
2948+
mutex_unlock(&md->suspend_lock);
29512949

29522950
/*
29532951
* Rare, but there may be I/O requests still going to complete,

0 commit comments

Comments
 (0)