Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1948852ima; Thu, 25 Oct 2018 07:26:34 -0700 (PDT) X-Google-Smtp-Source: AJdET5f409pPCy8ukmCB2yWc7WoDdgswCAMVNDoz9bH6ZSzERlm7j4nEWIkRNoIZXJxm7/qdEFni X-Received: by 2002:a63:2218:: with SMTP id i24-v6mr1693958pgi.238.1540477594885; Thu, 25 Oct 2018 07:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477594; cv=none; d=google.com; s=arc-20160816; b=UFT6Iy3CoPxliIqWFcSfJxdf+6YuVoS55pEitQG3BWZZt8FytINSQmH2LR2U+5Ti29 zLPk4kaucjZIQ5IOFbdoBqKYs+i/I3OCGUCJ+MvDJDbFbdbACfmScnfK2SwlfbufTK6S vRLTC6nJlgNi7bp7XK7qrK+cDxGMC5qCoYMtfqg6Uv1yMglEoUkAqYmMnG7iRr+hEg1H JimqGY4Zm2lCxn3i0xam4gGDmZ6QtgX28KCihF/2rriZicZR9vnIZDTDOfXpoyG1smzX 1kqGwcmQF3UbTgFrVyOb4EH9TT20QcVq4SKJz5dIOrANJWm7meA4YPUAIgIM1DxZC5V7 aaNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wBkycG46hlMvJgXDvNdejLbSa/xd/WXo0HiL7qJx4aU=; b=wEvzqAfEv/FzdZqPfLduKrTSsnhN0ebkm7/86E6CVNF6sTnKngG4UQUnleSBYIXDsb S1MoreRpHjweYBttk6I0YdIBuGMbYvnoQVemXbQU2aLNonLI/+ZTppsDXksPTePaoCkh zzEZq81lfZoXZTbRjXri/NwB9/WRmDORX7aFpUJ589uU8xNZexvTsyzr3AAWGQBB0GBK lwrVAgNRUp7DShbkIzrsiyNBVCX5xrPP8mIXmp5VQl6Ji2gPIa6bAU3KcdrLGH/RchbT x/TeSFqnKAocgi9F5dnemhtIFurlYnMKtbOoaPJtMiXVenAHug49R2JVBDspC6xxLGmE wjxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ckeHRf5C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d70-v6si4665824pfd.109.2018.10.25.07.25.54; Thu, 25 Oct 2018 07:26:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ckeHRf5C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731039AbeJYWxZ (ORCPT + 99 others); Thu, 25 Oct 2018 18:53:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:35902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730997AbeJYWxX (ORCPT ); Thu, 25 Oct 2018 18:53:23 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAA1F20848; Thu, 25 Oct 2018 14:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540477225; bh=0sQ+f8bVoklB/YfLYu6NQqSR0Jjp1YogOt9E1kNBgAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckeHRf5CyWs8Ed86CeF1S+fKQvu5pYGiO7sFx4xO+fBECSqGs4m+cVzhMfp7/qHHw adDtYRjK+EFmZcinUO60k8rrQ2q5dVEB6gI2BYr3ONnC8T0IBHfXFkkMdNn1krc2WK /WEQmC8pQFNHWgUhwUnqPVsIhij2rWKu9aEy84sk= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Junichi Nomura , Mike Snitzer , Sasha Levin Subject: [PATCH AUTOSEL 3.18 60/98] dm: fix AB-BA deadlock in __dm_destroy() Date: Thu, 25 Oct 2018 10:18:15 -0400 Message-Id: <20181025141853.214051-60-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141853.214051-1-sashal@kernel.org> References: <20181025141853.214051-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Junichi Nomura [ Upstream commit 2a708cff93f1845b9239bc7d6310aef54e716c6a ] __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 Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- 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 1d08dc6fa0b5..00c86ff3c721 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2599,14 +2599,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.17.1