Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp763238pxb; Fri, 22 Apr 2022 10:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2aztQVkS8BEoZHC6jjqhAgGmn2rltdvD5OenTFsk1ClTHu5132jgbUGRSbha7ZrsaVbTR X-Received: by 2002:a17:90a:4e08:b0:1cb:a3ac:938b with SMTP id n8-20020a17090a4e0800b001cba3ac938bmr17265250pjh.112.1650649043612; Fri, 22 Apr 2022 10:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650649043; cv=none; d=google.com; s=arc-20160816; b=0TKOG7ZPbOnczEDYDRCDJ8DYYe73gwG1FYBX/WTbQgLUwUKjjRuxpNaIizU4YjWoCc g0UG1O4bX1zlni6Z15oCTl0OP5Es9/zj8p5z7qE/n5efmg9g0ewue6TvjrQXYdVJspCM x8TfqwQwap+CAxvnYQSQ1s1a0G7XqWAViBRurUbmCdIM/EP7cgdTb4GXbHaLMuBtWjMH Ogq0956wMz/4xgx9cQRBS/fvnSk1wvg/7pG+d7+FJ9zaS35ee5xSpeAtJAQVhPFhScNn tQHI6YvAYZv0MpWIbG9W6c0PkP7hJtNEMzJqMI9JKCl6lvSZlNArDyk2ZUJfUg8uctz1 THAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=GbIzAhbuaysz1h4tY+a9mVGYFPdursEAYmUgZ9GipWU=; b=JXyVqjrUzm5i94R9EYClvbimoN46xL/4mmjBZnxmy2RrZcg7RZVE3d7/H3laCsHHPP i1qTrqRiI+GQRBq8bV+5H6iNJCafqD7hJtIblqlbqGAAcZA6QnALyuQZ5zTjhpCYYP6n bNxPknognEjIICcm3Ysz6xfZZ+Qtb4NlZ9qlDKf5jJzB28TObgRlKqHWTT7P/1ntbqX6 yV8Ss2kgQ5OrWUppS5Sn4kieOZc3iKbU5jgGRHBEilh1PTyJZM+UybVAssmG8+pkP/xS o5D+VnIyu+8jxYPu40FxhTq7WwbdDWzZwDnft7DPrsWDqsfDHocz3jGmcbLCQbrCCfJt Xl4w== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f17-20020a056a00239100b004fa662b24c0si9252390pfc.330.2022.04.22.10.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 10:37:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6C13DCE34; Fri, 22 Apr 2022 10:27:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351671AbiDTKam (ORCPT + 99 others); Wed, 20 Apr 2022 06:30:42 -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 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SORBS_WEB, RDNS_NONE,SPF_HELO_NONE autolearn=no 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 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 */ -- 2.7.4