Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091275rwb; Mon, 15 Aug 2022 17:54:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JhKktaVubLkXwy/mQUzWJbxQD4CLjHrWCDDCVprXavAH1qDdxpPqsbOdODXELYc8H5+lA X-Received: by 2002:a17:907:2722:b0:731:201a:df9c with SMTP id d2-20020a170907272200b00731201adf9cmr12226557ejl.149.1660611203428; Mon, 15 Aug 2022 17:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611203; cv=none; d=google.com; s=arc-20160816; b=zU4FSSQu1uZdTV/MvUjnYeji9cKIIxssybmoaTxMPtG5UteI9he1JOqStAWIP6Iwwn cIcmxJUS0Hb5NcYe8IR+t7xVfcPQ2Z/y/hPJbDjlajKtjSq1A099LgaK4Tm+lxpykSO7 K1bod4fx5UxrY4E1s0sxR6WsF4mS0TU5HllOtJF9VQhIRYYZc7DBlmJ2+IWYixiz2p7A SPpFyGAiQXtHI4EEYblkd2CxeUc3stEwFpeNyMvRkhmCxA5I3mAVaPOtKClK3jfX+iyV TtYJZwk67BaTfNYF+ToB8f5YncW+iFKESZ59XfVxXMkoID9Y0KJRTXmaX/FpMGN7s2+q ZlXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DDClf7STfnWM8EVjKNKpiIeSUQLtwLTt8ZkwJzFBxpM=; b=F68RRO+m8rkH4orQG0pTZPuQlHP6RyY9Jk9+5u00X8VOR/ETJKNf6uBbRznX8LxNgw KebPoHCdunyUWJZQE7DXVgUt4cI3qpcWLwaoZmGvtiW7VDi7M0Z8SD94tH0qZHJd3MAI lK49euXO8zfKDi0oHhcMBUQ8uGn3d1Xe1sKgIOvQOiSblN0UcFmLu6sM9rYlAS7Zidod xZqxS3IGoYAyq+IHAGhSo2fiIrDMZxewT7a+Dm2Q+/NAD30OJtRv/2kj6cVb+J7TpAyq TsMPwRczQ2vlkXVYGzX6Vf3fCaONvp6NR5RBB1NkNvcb4zg/CJNvvOXFLDA9HMI5ZtQS 0wBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qaBNShYP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020aa7d607000000b0043d48a3adddsi8123583edr.355.2022.08.15.17.52.58; Mon, 15 Aug 2022 17:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qaBNShYP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351385AbiHPAIq (ORCPT + 99 others); Mon, 15 Aug 2022 20:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354407AbiHPAAj (ORCPT ); Mon, 15 Aug 2022 20:00:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05CC39751F; Mon, 15 Aug 2022 13:21:50 -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 94E3361073; Mon, 15 Aug 2022 20:21:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AE0CC433C1; Mon, 15 Aug 2022 20:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594909; bh=zUlcBjt3sYFgyUmwRf5ZWSN61dwFobVQH7Z7LAAaPPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qaBNShYPoyseY9PXX62AIIS7l+XZe4opmzy42pNRSs1nkg6p6F92NSrNb+1eX630j 2Ycr207rQtxOsPQuikL/LbITrbaPt7PszFosGGLbLzHts4Ep5zBmj7qtPMJoyCQvf/ /KeM+f/acr0j6EHsWQLwfmMTmd5WEoRjN7w0nzvw= 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.19 0597/1157] mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release Date: Mon, 15 Aug 2022 19:59:13 +0200 Message-Id: <20220815180503.537118036@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 0cff2cda1b5a..7f955fade838 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -1111,9 +1111,9 @@ static void sm_release(struct mtd_blktrans_dev *dev) { struct sm_ftl *ftl = dev->priv; - 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); } -- 2.35.1