Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1520403pxb; Tue, 8 Feb 2022 20:56:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNIORLl8EkkSaUWbD8xI7ANQNdXO8Htqqda59wYn0mYGoKWkk2mChth89UlORBv6/DiJLw X-Received: by 2002:a17:902:eccd:: with SMTP id a13mr523015plh.28.1644382599164; Tue, 08 Feb 2022 20:56:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644382599; cv=none; d=google.com; s=arc-20160816; b=HJvaIZ1x/sP/HvXBCy7nFk+zvsLUTBpis1qBKDaD9IjfYeK4srwVH50PgsD8JaEEA6 PjrDRX0giYM1c0Gt+VkAeRa/3OIAqd/eEYh2q8DhuE5RxaEumpB1xFEsYifSvAG0uCe4 o85aJMH5Bw9ASJl5S7Hi0xRr8VTQH76IO4wacJW0sa97IP7g07FKpjDaw906tmE6Ape+ 4ZN2kAHks3hmNVsxU/D2GG/TAR5CjaGJyLpzTUCHgWAi2nziDQyQG+w7J9i0QuJ0M3ZE RrrZYiAP1U/N8gqAb46Wxth6a8VfoWZ1f/Mky68VPkFmLGH0lOlt18uejD5W/Ye6U5RR jhRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2ohsQEjDse7zsmEGtz2Jbz8nU63RBALMF0dW8H0wGD0=; b=LZ2KgfLkPnyWen1RfFQDmCLEDdW8f9/dgq6ca/+B1MxtJ7baIDyX20fQBsbXtQsS9O NjRPplUdlFlCLwjz9n7UTn2tW9LrYjvWmgEKr0jcgjQdSjF1GfxWKMPqCfzlzZWUa1P1 ybiV4U1R2gBin6A0zNBtK82SsGxj/s7Ra4OekhUrCzFKwctdTMX7ZnX4X+JFUYMlsY45 HTRawPD/cT9a6RsJIjUzwfi7BseynTxePLkur+RRJl6xmXaLMGkH0t0cIx0r/hsQhkIZ 363effkUO++PidGIGD3Q7E9TKriRM2yqw2j2sMjZMcmfpFiQvn8NBWsD4NTwUhGo0kPK NgGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQ0Q1uPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w9si14619094plz.485.2022.02.08.20.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 20:56:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQ0Q1uPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A7C28C03E961; Tue, 8 Feb 2022 20:56:30 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239956AbiBGG57 (ORCPT + 99 others); Mon, 7 Feb 2022 01:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244239AbiBGGjS (ORCPT ); Mon, 7 Feb 2022 01:39:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 859F4C043184; Sun, 6 Feb 2022 22:39:17 -0800 (PST) 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 6330A608CC; Mon, 7 Feb 2022 06:39:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02037C004E1; Mon, 7 Feb 2022 06:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644215955; bh=x0+qU7jW+I6pS9yDRMI6eYb/c2RxQC1bhyeo7aFHyY0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hQ0Q1uPSjrKlkH+8zu3b1QjeLuuhFlRFXuI+pbSDJ3NfbIaJR9kKLKcWsg/kjF+lX M5dNenFMXdjFaGtmzYbHHOL0BMwfAl8xdRZoGXDa4AMPzasTH6er+lFw1vwP24VbRM 8ingmHtZySUbzYn9UNfqamBqSO70IEZg7tVW2r4iEq6GCt0LrZRpe+2DU332ZsZE4c DEt7pG6yPpEVk1o9P5MDYPOLmjxuYpgRw4m/vxAzKQ0nA/IvxPN+2f33beEeZD/rcP O96G7vOJuzFQwxcayzcP/1YEFLmHx84iRX52XLJKH5vIhRWsYR1gWXoO4S11kKig5x Vx+28MxMz4zzA== Date: Mon, 7 Feb 2022 12:09:08 +0530 From: Manivannan Sadhasivam To: Jia-Ju Bai Cc: hemantk@codeaurora.org, bbhatt@codeaurora.org, loic.poulain@linaro.org, jhugo@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel Subject: Re: [BUG] bus: mhi: possible deadlock in mhi_pm_disable_transition() and mhi_async_power_up() Message-ID: <20220207063908.GB1905@thinkpad> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Hi, Thanks for the report! On Sat, Jan 29, 2022 at 10:56:30AM +0800, Jia-Ju Bai wrote: > Hello, > > My static analysis tool reports a possible deadlock in the mhi driver in > Linux 5.10: > > mhi_async_power_up() > ? mutex_lock(&mhi_cntrl->pm_mutex); --> Line 933 (Lock A) > ? wait_event_timeout(mhi_cntrl->state_event, ...) --> Line 985 (Wait X) > ? mutex_unlock(&mhi_cntrl->pm_mutex); --> Line 1040 (Unlock A) > > mhi_pm_disable_transition() > ? mutex_lock(&mhi_cntrl->pm_mutex); --> Line 463 (Lock A) > ? wake_up_all(&mhi_cntrl->state_event); --> Line 474 (Wake X) > ? mutex_unlock(&mhi_cntrl->pm_mutex); --> Line 524 (Unlock A) > ? wake_up_all(&mhi_cntrl->state_event); --> Line 526 (Wake X) > > When mhi_async_power_up() is executed, "Wait X" is performed by holding > "Lock A". If mhi_pm_disable_transition() is concurrently executed at this > time, "Wake X" cannot be performed to wake up "Wait X" in > mhi_async_power_up(), because "Lock A" is already hold by > mhi_async_power_up(), causing a possible deadlock. > I find that "Wait X" is performed with a timeout, to relieve the possible > deadlock; but I think this timeout can cause inefficient execution. > As per the MHI design, we can be sure that mhi_pm_disable_transition() won't be called until wait_event_timeout() completes in mhi_async_power_up(). So this deadlock is not possible in practical. Thanks, Mani > I am not quite sure whether this possible problem is real and how to fix it > if it is real. > Any feedback would be appreciated, thanks :) > > > Best wishes, > Jia-Ju Bai > > >