Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3409415rwa; Tue, 23 Aug 2022 04:25:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR53Ak9qlrkoXYi5KI83eEoEpgW7uVlwEY7EGINBoCGRt64zMfdOvdTvRxiwFAobr6i6YRGC X-Received: by 2002:a17:903:1cd:b0:16e:e519:c6f6 with SMTP id e13-20020a17090301cd00b0016ee519c6f6mr23631954plh.116.1661253917066; Tue, 23 Aug 2022 04:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253917; cv=none; d=google.com; s=arc-20160816; b=nWZjyAoxxLWqBHMbs7oWrTOLg7LWPIpoNZZv5IBuKFLzhhb+S5E6idbKmmlo5YZBk6 Hde+1T+K8DK9+YVaCVe1jZu9Q+aYyrSTEN30osHvy7+yzuYY5aTwwgRDt8kpqsNsz0iH pctdQpqrmF90nE7YufpeDWLIlmHuxJNfVGvQZ29vGqN62MWZJvwK7eQB2bCKIerJ68rp Kn9J5mhQ8FCBPwfAAW+51qPmkQbJkgsbuLjgKXak5YXcKGdaLowemy7Mv0fBSJgdbh0C lVbl+iptyEKHnCJ85tMKPnoog4VfQIE0A3QigcuVrfzQTIZeyazQxzzHmsXmC6/oZ5et R00Q== 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=LwhkHqvk8aonPv88c9qjKFCQYoPHQkXfHMn0xfbF450=; b=OVaBT+QLAbQzaxtpnJ3NCAQbolss7V5/AX3zisZ2CW0CHFSyyQuu3IpTls1Oz5V4kN MbsMppsfDNb7Ltu0mZ1jjFbtq/UncSrqrDFmsTmNpMEv/wuKw4ZnZ9QTatmd4MSl4eJm wcl5O+mM40e9KxQ7Ai1Q9GCkDS5TQOMqI+Z4kNi4xMeG48aDfHyx6uKFFr6rgcdqZD+l 3yoV2oU2UYdD5NwLmkrbACcCGjZRsRDWx32+ZFIgZJy1b75VrWUNMDXM98msviuvLpHa P2CYabQeiturAqymTiJYIGVUOCWKQXDgAv90qQr1sv4WHgDML/NwGOgTKIXqeSz84KBl anIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tc0FCln6; 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 d66-20020a636845000000b0042a02350c42si14459460pgc.245.2022.08.23.04.25.05; Tue, 23 Aug 2022 04:25:17 -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=tc0FCln6; 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 S1356226AbiHWKln (ORCPT + 99 others); Tue, 23 Aug 2022 06:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354472AbiHWK16 (ORCPT ); Tue, 23 Aug 2022 06:27:58 -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 30FBEA405E; Tue, 23 Aug 2022 02:06:02 -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 733B96158C; Tue, 23 Aug 2022 09:06:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72363C433D6; Tue, 23 Aug 2022 09:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245560; bh=8NPO/RNil3EyMz/EeLQp6oCAYjcVHI/yHBSsPEKl6aE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tc0FCln69K+TnD8hJKRTi+iE/eGyrpNi0gIAILbqy1n67IXYe96LleSb3+Zv9hGl0 VCiqqpr9eEaR+8prT6vc+fCTo6XHeJx6M01pkkmCHSFZzY+tmFnB642nvBRD91Gbw+ SqqbHXH4J+grJSZx4Ks9CHJZCygOE11cM8bnKeOE= 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 4.19 117/287] mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release Date: Tue, 23 Aug 2022 10:24:46 +0200 Message-Id: <20220823080104.327374824@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 f3bd86e13603..e57f7ba054bc 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -1091,9 +1091,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