From patchwork Wed Apr 20 10:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sugar Zhang X-Patchwork-Id: 12820033 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 707CFC433F5 for ; Wed, 20 Apr 2022 10:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237495AbiDTKac (ORCPT ); Wed, 20 Apr 2022 06:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343847AbiDTKaa (ORCPT ); Wed, 20 Apr 2022 06:30:30 -0400 Received: from mail-m17635.qiye.163.com (mail-m17635.qiye.163.com [59.111.176.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208443D1EF; Wed, 20 Apr 2022 03:27:44 -0700 (PDT) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m17635.qiye.163.com (Hmail) with ESMTPA id D78494005C0; Wed, 20 Apr 2022 18:27:41 +0800 (CST) From: Sugar Zhang To: vkoul@kernel.org Cc: Sugar Zhang , Huibin Hong , Krzysztof Kozlowski , Marek Szyprowski , Russell King , Ulf Hansson , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] dmaengine: pl330: Fix unbalanced runtime PM Date: Wed, 20 Apr 2022 18:27:36 +0800 Message-Id: <1650450456-34351-1-git-send-email-sugar.zhang@rock-chips.com> X-Mailer: git-send-email 2.7.4 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUlKS0tKN1dZLVlBSVdZDwkaFQgSH1lBWUJDTB1WGU4aT0JPSk lMSB9MVRMBExYaEhckFA4PWVdZFhoPEhUdFFlBWU9LSFVKSktITUpVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Mzo6HQw5KD01PilNClYtHxUK LjxPFEtVSlVKTU5LT05LT01JSExPVTMWGhIXVQgOHBoJVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlX WRILWUFZTkNVSUlVTFVKSk9ZV1kIAVlBSEJLQzcG X-HM-Tid: 0a8046837595d991kuwsd78494005c0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org This driver use runtime PM autosuspend mechanism to manager clk. pm_runtime_use_autosuspend(&adev->dev); pm_runtime_set_autosuspend_delay(&adev->dev, PL330_AUTOSUSPEND_DELAY); So, after ref count reached to zero, it will enter suspend after the delay time elapsed. The unbalanced PM: * May cause dmac the next start failed. * May cause dmac read unexpected state. * May cause dmac stall if power down happen at the middle of the transfer. e.g. may lose ack from AXI bus and stall. Considering the following situation: DMA TERMINATE TASKLET ROUTINE | | | issue_pending | | | pch->active = true | pm_runtime_get pm_runtime_put(if active) | pch->active = false | | work_list empty | | | pm_runtime_put(unconditional) | | At this point, it's unbalanced(1 get / 2 put). After this patch: DMA TERMINATE TASKLET ROUTINE | | | issue_pending | | | pch->active = true | pm_runtime_get pm_runtime_put(if active) | pch->active = false | | work_list empty | | | pm_runtime_put(if active) | | Now, it's balanced(1 get / 1 put). Fixes: 5c9e6c2b2ba3 ("dmaengine: pl330: Fix runtime PM support for terminated transfers") Fixes: ae43b3289186 ("ARM: 8202/1: dmaengine: pl330: Add runtime Power Management support v12") Signed-off-by: Huibin Hong Signed-off-by: Sugar Zhang --- Changes in v2: - fixup commit message per Vinod suggestion. drivers/dma/pl330.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c index 858400e..ccd430e 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -2084,7 +2084,7 @@ static void pl330_tasklet(struct tasklet_struct *t) spin_lock(&pch->thread->dmac->lock); _stop(pch->thread); spin_unlock(&pch->thread->dmac->lock); - power_down = true; + power_down = pch->active; pch->active = false; } else { /* Make sure the PL330 Channel thread is active */