Return-Path: Received: from TYO200.gate.nec.co.jp ([210.143.35.50]:43517 "EHLO tyo200.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751471AbcJTIqa (ORCPT ); Thu, 20 Oct 2016 04:46:30 -0400 Received: from tyo202.gate.nec.co.jp ([10.7.69.202]) by tyo200.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id u9K8kSuT024228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 20 Oct 2016 17:46:28 +0900 (JST) From: Junichi Nomura To: Jiri Slaby CC: "stable@vger.kernel.org" , Mike Snitzer Subject: Re: [patch added to 3.12-stable] dm: fix AB-BA deadlock in __dm_destroy() Date: Thu, 20 Oct 2016 08:44:34 +0000 Message-ID: <017fee37-2ea9-ed93-924c-68f785d7a414@ce.jp.nec.com> References: <20161020082018.15585-1-jslaby@suse.cz> In-Reply-To: <20161020082018.15585-1-jslaby@suse.cz> Content-Language: ja-JP Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <37314479E3FFC040BF91306A8FB79BA2@gisp.nec.co.jp> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: On 10/20/16 17:20, Jiri Slaby wrote: > 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 > Fixes: ab7c7bb6f4ab ("dm: hold suspend_lock while suspending device during device deletion") > Acked-by: Mikulas Patocka > Signed-off-by: Mike Snitzer > Signed-off-by: Jiri Slaby > --- > drivers/md/dm.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > index 5a0b1742f794..de444d3ae293 100644 > --- a/drivers/md/dm.c > +++ b/drivers/md/dm.c > @@ -2444,14 +2444,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, I don't have 3.12-stable tree at hand but this patch looks incorrect. The patch misses the part of upstream patch that removes existing dm_get_live_table(). By just adding dm_get_live_table(), you will have unbalanced numbers of get and put and break refcounting of md. -- Jun'ichi Nomura, NEC Corporation / NEC Solution Innovators, Ltd.