From nobody Sun Feb 8 18:48:26 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52DF9C77B7E for ; Thu, 1 Jun 2023 06:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbjFAGQO (ORCPT ); Thu, 1 Jun 2023 02:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbjFAGQL (ORCPT ); Thu, 1 Jun 2023 02:16:11 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F9DBE2 for ; Wed, 31 May 2023 23:16:09 -0700 (PDT) Received: from dggpemm500011.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QWwkR1gVyz18LnG; Thu, 1 Jun 2023 14:11:27 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpemm500011.china.huawei.com (7.185.36.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 1 Jun 2023 14:16:06 +0800 From: Li Lingfeng To: CC: , , , , , , Subject: [PATCH] dm: don't lock fs when the map is NULL in process of suspend Date: Thu, 1 Jun 2023 14:14:23 +0800 Message-ID: <20230601061423.3594104-1-lilingfeng3@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500011.china.huawei.com (7.185.36.110) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As described in commit 38d11da522aa ("dm: don't lock fs when the map is NULL in process of resume"), deadlock may be triggered between do_resume and do_mount. What's more, do_suspend and do_mount can also trigger it. So clear DM_SUSPEND_LOCKFS_FLAG in dm_suspend instead of do_resume. Signed-off-by: Li Lingfeng --- drivers/md/dm-ioctl.c | 5 +---- drivers/md/dm.c | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index cc77cf3d4109..7d5c9c582ed2 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1168,13 +1168,10 @@ static int do_resume(struct dm_ioctl *param) /* Do we need to load a new map ? */ if (new_map) { sector_t old_size, new_size; - int srcu_idx; =20 /* Suspend if it isn't already suspended */ - old_map =3D dm_get_live_table(md, &srcu_idx); - if ((param->flags & DM_SKIP_LOCKFS_FLAG) || !old_map) + if (param->flags & DM_SKIP_LOCKFS_FLAG) suspend_flags &=3D ~DM_SUSPEND_LOCKFS_FLAG; - dm_put_live_table(md, srcu_idx); if (param->flags & DM_NOFLUSH_FLAG) suspend_flags |=3D DM_SUSPEND_NOFLUSH_FLAG; if (!dm_suspended_md(md)) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 3b694ba3a106..39424a0b3cd6 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2809,6 +2809,9 @@ int dm_suspend(struct mapped_device *md, unsigned int= suspend_flags) =20 map =3D rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_l= ock)); =20 + if (!map) + suspend_flags &=3D ~DM_SUSPEND_LOCKFS_FLAG; + r =3D __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE, DMF_SUSPEN= DED); if (r) goto out_unlock; --=20 2.31.1