Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1504659

[PATCH 3.12 1/5] dm: fix AB-BA deadlock in __dm_destroy()

From Jiri Slaby <jslaby@suse.cz>
Newsgroups linux.kernel
Subject [PATCH 3.12 1/5] dm: fix AB-BA deadlock in __dm_destroy()
Date 2016-10-20 11:00 +0200
Message-ID <suhmF-5dC-17@gated-at.bofh.it> (permalink)
References <suhmF-5dC-19@gated-at.bofh.it> <suhcZ-5ak-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Junichi Nomura <j-nomura@ce.jp.nec.com>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit 2a708cff93f1845b9239bc7d6310aef54e716c6a 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 <j-nomura@ce.jp.nec.com>
Fixes: ab7c7bb6f4ab ("dm: hold suspend_lock while suspending device during device deletion")
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/md/dm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 5a0b1742f794..78ab0a131cf1 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2434,7 +2434,6 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
 	might_sleep();
 
 	spin_lock(&_minor_lock);
-	map = dm_get_live_table(md, &srcu_idx);
 	idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md))));
 	set_bit(DMF_FREEING, &md->flags);
 	spin_unlock(&_minor_lock);
@@ -2444,14 +2443,14 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
 	 * do not race with internal suspend.
 	 */
 	mutex_lock(&md->suspend_lock);
+	map = dm_get_live_table(md, &srcu_idx);
 	if (!dm_suspended_md(md)) {
 		dm_table_presuspend_targets(map);
 		dm_table_postsuspend_targets(map);
 	}
-	mutex_unlock(&md->suspend_lock);
-
 	/* dm_put_live_table must be before msleep, otherwise deadlock is possible */
 	dm_put_live_table(md, srcu_idx);
+	mutex_unlock(&md->suspend_lock);
 
 	/*
 	 * Rare, but there may be I/O requests still going to complete,
-- 
2.10.1

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH 3.12 1/5] dm: fix AB-BA deadlock in __dm_destroy() Jiri Slaby <jslaby@suse.cz> - 2016-10-20 10:50 +0200
  [PATCH 3.12 5/5] mm: remove gup_flags FOLL_WRITE games from __get_user_pages() Jiri Slaby <jslaby@suse.cz> - 2016-10-20 10:50 +0200
  [PATCH 3.12 4/5] x86/build: Build compressed x86 kernels as PIE Jiri Slaby <jslaby@suse.cz> - 2016-10-20 10:50 +0200
  [PATCH 3.12 2/5] ratelimit: fix bug in time interval by resetting right begin time Jiri Slaby <jslaby@suse.cz> - 2016-10-20 10:50 +0200
  [PATCH 3.12 3/5] brcmfmac: avoid potential stack overflow in brcmf_cfg80211_start_ap() Jiri Slaby <jslaby@suse.cz> - 2016-10-20 10:50 +0200
  [PATCH 3.12 1/5] dm: fix AB-BA deadlock in __dm_destroy() Jiri Slaby <jslaby@suse.cz> - 2016-10-20 11:00 +0200

csiph-web