Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1640987pxb; Wed, 9 Feb 2022 00:54:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLUY+2jMpCK5pVZWz/l3+3ot+87P193cPurI3IGPnYgESHTaTXsKP8/m+G655d28POVdP5 X-Received: by 2002:a17:90b:124e:: with SMTP id gx14mr2261626pjb.63.1644396887192; Wed, 09 Feb 2022 00:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644396887; cv=none; d=google.com; s=arc-20160816; b=kNKW5wPDumXS9Dx+dxrZBzTNcqXycOfLSJgpOAvr0Wb+v6FIGFJi77Dnefjk7HsYTd d8h1HZ6a+2gMFmi73WTDKSMhO8jALcOIe8XfptyAoZ8ZCjs2JIVU4ZQ4XCcqyv7U+yYx 1Wq/38qBV4ReoxOnf8ov0PRNyGDLSSF73RlYL45yW0V9bh/0Mg7xFt+qh7zBHDAjNz1E YwyWBZyUmGqHpGY3F2R5KnPpfa5ngdgtB0eshzJLm9XkrGnUa9Czej8Ij0JXN14+bg4k YjzB9fWU3ALuIgZTnvGbLY4k7Tl+kTkRRpWuW51O58H32L3yb1xMcvdU8zK//rAmWoSI HXDg== 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=q5d736UP89o2VgKDVhyMYYgA7emZyW2VT6dMfo2guGg=; b=mPUTVymPaDfQXGbnfvmM6jEgeDEWlNGjGG0Wb+bjbDv6LT7eMudGbiU62qgMflJemw JOTaT/2/i67JTwQwYB/AeeEo+E89qCx6N9WHuyzAwEREVs4gBD5abJdXPslIyAS08m57 OvoOyEwmaPsJgjy66pJiANPlQ916JwXT//xDiLfDgSbYuRy2bIwtHyNI2XkLh1dBgR/J 1r0h66vwD/Gb0ZOXcIzqsl/Lse18zLb/G/HxtJ5ne52b3DTNtietdAqOFcNATUbQOZ0M hBBfLQsuLVQD1d8QfLovXS2wRCRi/Fp1TYmDczT5JorUsis9fH20Xji+ScPvJHtSvGMM ty5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UDEBiKMG; 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 j65si15043158pge.612.2022.02.09.00.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 00:54:47 -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=UDEBiKMG; 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 0F6ACE00D10B; Wed, 9 Feb 2022 00:46:10 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240857AbiBGG6Q (ORCPT + 99 others); Mon, 7 Feb 2022 01:58:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240072AbiBGGpU (ORCPT ); Mon, 7 Feb 2022 01:45:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80572C043185; Sun, 6 Feb 2022 22:45:19 -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 ams.source.kernel.org (Postfix) with ESMTPS id EB62EB80D83; Mon, 7 Feb 2022 06:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9391FC004E1; Mon, 7 Feb 2022 06:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644216315; bh=iZXpNhr0N3akH/Sjy44hlofDVMLAqUl7QsOwcgUX2zs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UDEBiKMGPEXlEdwQnsw7Z7trJhc6ITA+Rz8zvxvviECIo+3EeSJWZDi8pNHQ1x7Jp baaeb95V7jMHPKiUTL8Jcq7oFCYSYZ4OWLCEG8bJfUWXgptuT+aT5vtst/HsfkoKLh PdQkuvX1EADhbd38ndP/Z6REcliGKLrsLOAtrsG70q4ACjSUi82INxQ/JY6SpxrDiq YoWOlxL5+EjzzUQa0IfZpLaS1EeIREt8qyrxmhVllf35mmgGPxttra1Tje3CpSn25O h8mQc+31Z+nNKq8wKmJskBmHdOa9k/iGUf1rv0VnNzYeiw6ozqL+EseJw8wBRo7xAe 5oNBaUINBpUNw== Date: Mon, 7 Feb 2022 12:15:04 +0530 From: Manivannan Sadhasivam To: Daniel Thompson Cc: Jia-Ju Bai , 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: <20220207064504.GC1905@thinkpad> References: <20220201171540.2udq3x6r2swctzau@maple.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220201171540.2udq3x6r2swctzau@maple.lan> X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 On Tue, Feb 01, 2022 at 05:15:40PM +0000, Daniel Thompson wrote: > 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. > > > > 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 :) > > Interesting find but I think it would be better to run your tool > against more recent kernels to confirm any problem reports. In this > case the code you mention looks like it was removed in v5.17-rc1 > (and should eventually make its way to the stable kernels too). > Hmm, looks like the commit didn't apply cleanly to 5.10: https://www.spinics.net/lists/stable/msg526754.html Let send the fix up version. Thanks, Mani > > Daniel.