From nobody Fri Sep 5 20:09:26 2025 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 5FF0DC49EC6 for ; Tue, 23 Aug 2022 11:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357964AbiHWL1A (ORCPT ); Tue, 23 Aug 2022 07:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357958AbiHWLV0 (ORCPT ); Tue, 23 Aug 2022 07:21:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A202615; Tue, 23 Aug 2022 02:23:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D93D8612DC; Tue, 23 Aug 2022 09:23:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D49DCC433C1; Tue, 23 Aug 2022 09:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246596; bh=j2GtI424F0IpXJ7BTSozzvlq9NUAJXxztm02mXYMtiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s71+wNIATXS+Ze3/+XODF8AO26c4k62eXTkAnb+57ZJzOHAWVReOoT8poeDMhD5pM 3mobC++MA6KsH6trah8TVidVURFb630vgvkLMPA4hjUE2dBncb+/XBQiO5tBdK1BuG 8QJzZvN33vAXdumAWsIF3S7D6ua9CHsqZbF2zMO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Miquel Raynal , Sasha Levin Subject: [PATCH 5.4 158/389] mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release Date: Tue, 23 Aug 2022 10:23:56 +0200 Message-Id: <20220823080122.200503930@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Duoming Zhou [ Upstream commit a61528d997619a518ee8c51cf0ef0513021afaff ] There is a deadlock between sm_release and sm_cache_flush_work which is a work item. The cancel_work_sync in sm_release will not return until sm_cache_flush_work is finished. If we hold mutex_lock and use cancel_work_sync to wait the work item to finish, the work item also requires mutex_lock. As a result, the sm_release will be blocked forever. The race condition is shown below: (Thread 1) | (Thread 2) sm_release | mutex_lock(&ftl->mutex) | sm_cache_flush_work | mutex_lock(&ftl->mutex) cancel_work_sync | ... This patch moves del_timer_sync and cancel_work_sync out of mutex_lock in order to mitigate deadlock. Fixes: 7d17c02a01a1 ("mtd: Add new SmartMedia/xD FTL") Signed-off-by: Duoming Zhou Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20220524044841.10517-1-duoming@zju.= edu.cn Signed-off-by: Sasha Levin --- drivers/mtd/sm_ftl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index 4744bf94ad9a..d4e72fd5e5b3 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -1097,9 +1097,9 @@ static void sm_release(struct mtd_blktrans_dev *dev) { struct sm_ftl *ftl =3D dev->priv; =20 - mutex_lock(&ftl->mutex); del_timer_sync(&ftl->timer); cancel_work_sync(&ftl->flush_work); + mutex_lock(&ftl->mutex); sm_cache_flush(ftl); mutex_unlock(&ftl->mutex); } --=20 2.35.1