Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp176843pxj; Tue, 18 May 2021 00:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWQ5+xYpueic3On6Xkvpb8HDffGCfV3GhyM5GmUVWBd7lRk2lGzfrAnyh0g3qcPeXUF+cK X-Received: by 2002:a17:906:f885:: with SMTP id lg5mr4529636ejb.313.1621322552794; Tue, 18 May 2021 00:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621322552; cv=none; d=google.com; s=arc-20160816; b=jf+wew4AdbGXtAixMA5RIW5C7owYKPfzgwuU/0YEkHhiMsnZ+Szo6kI8FQFFDtou2H l+KOB4/2fZ6ic6g4U7cyrjYF4gxQMjxJk3XqwVoVi85kv+fm5/xmZ8BQAGXd1PjL+1Ns 2efbd+zubw99CpEy9clS2F9V8PWhJCZeFDUshp99m2q5zydmpS9m0UC9cq9lWSrK4TPB YNFPa05+mWVERsw3RFxPGybYKUwl6H+oQofsr5+ED+gMXa0sizGyROxq+CrB47NFafJL lO5Q/p/6UF58eq2Y/ZinzkVo7WlYO8d//JyzUEkoL+fprjGXs4+MHg4YuOFQI4ZSdz/8 PP3Q== 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=ETQ4AvygXF/Um+iz626OakmUC3K8WoFLpvZ6jDIs9+0=; b=tGiXpuHWhOXDLH2NpKxr7/s8AVPai7QYMoZPJvgRk6WhPi6m14P2YIlxknzHXMGsHI yzHwl+ixnUPFACUhirMtcF91q4fems6yTj/Kpvs+vQure7VPPzKfgGL+2KHNgG2OXNCG uy6ZnBootORewBtj83l2mFtz5q8MyisvYVSoYeQ1vtE7MyKkfjZfODTBal+gQEr+qIv6 dzUC9uUb6flYBZI+bnzyI7HANRtPyxxGY1rbAEHGb/fG9UcCai64o/uFsV69yQre0gjs ybMPW6rK5vaKjz2V+8v7cYV+c7bwhRG6WHLjKmCGI4VZ42nRtFB9tnptP/PU4uT/JsdF 3KQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjWJ9SZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si12947610ejl.393.2021.05.18.00.22.10; Tue, 18 May 2021 00:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjWJ9SZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S242392AbhEQOzP (ORCPT + 99 others); Mon, 17 May 2021 10:55:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240824AbhEQOrQ (ORCPT ); Mon, 17 May 2021 10:47:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 962586196A; Mon, 17 May 2021 14:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261323; bh=PeEuDQ1RPr0AL0urufJWxpvRE4VsKXS8HuL0uvj1oms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjWJ9SZlzvLGrlS4ogSl/kn4NDbnL0Ri/jY6GSWJkrSUcCqKIkFWl+faBLPiwFoG9 +DngtWDFgqn3DMSmril1qJ9Cu9tjudGJLLT5hT/OMph0DNuklCrYVBEbXp0REDD93w 5pMrSgjSzFg+EeNRgYACZpVmyJb6gB5jVPqzvOnc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Lindgren , Ulf Hansson , Tomi Valkeinen , "Rafael J. Wysocki" Subject: [PATCH 5.10 008/289] PM: runtime: Fix unpaired parent child_count for force_resume Date: Mon, 17 May 2021 15:58:53 +0200 Message-Id: <20210517140305.458489074@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tony Lindgren commit c745253e2a691a40c66790defe85c104a887e14a upstream. As pm_runtime_need_not_resume() relies also on usage_count, it can return a different value in pm_runtime_force_suspend() compared to when called in pm_runtime_force_resume(). Different return values can happen if anything calls PM runtime functions in between, and causes the parent child_count to increase on every resume. So far I've seen the issue only for omapdrm that does complicated things with PM runtime calls during system suspend for legacy reasons: omap_atomic_commit_tail() for omapdrm.0 dispc_runtime_get() wakes up 58000000.dss as it's the dispc parent dispc_runtime_resume() rpm_resume() increases parent child_count dispc_runtime_put() won't idle, PM runtime suspend blocked pm_runtime_force_suspend() for 58000000.dss, !pm_runtime_need_not_resume() __update_runtime_status() system suspended pm_runtime_force_resume() for 58000000.dss, pm_runtime_need_not_resume() pm_runtime_enable() only called because of pm_runtime_need_not_resume() omap_atomic_commit_tail() for omapdrm.0 dispc_runtime_get() wakes up 58000000.dss as it's the dispc parent dispc_runtime_resume() rpm_resume() increases parent child_count dispc_runtime_put() won't idle, PM runtime suspend blocked ... rpm_suspend for 58000000.dss but parent child_count is now unbalanced Let's fix the issue by adding a flag for needs_force_resume and use it in pm_runtime_force_resume() instead of pm_runtime_need_not_resume(). Additionally omapdrm system suspend could be simplified later on to avoid lots of unnecessary PM runtime calls and the complexity it adds. The driver can just use internal functions that are shared between the PM runtime and system suspend related functions. Fixes: 4918e1f87c5f ("PM / runtime: Rework pm_runtime_force_suspend/resume()") Signed-off-by: Tony Lindgren Reviewed-by: Ulf Hansson Tested-by: Tomi Valkeinen Cc: 4.16+ # 4.16+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/base/power/runtime.c | 10 +++++++--- include/linux/pm.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1637,6 +1637,7 @@ void pm_runtime_init(struct device *dev) dev->power.request_pending = false; dev->power.request = RPM_REQ_NONE; dev->power.deferred_resume = false; + dev->power.needs_force_resume = 0; INIT_WORK(&dev->power.work, pm_runtime_work); dev->power.timer_expires = 0; @@ -1804,10 +1805,12 @@ int pm_runtime_force_suspend(struct devi * its parent, but set its status to RPM_SUSPENDED anyway in case this * function will be called again for it in the meantime. */ - if (pm_runtime_need_not_resume(dev)) + if (pm_runtime_need_not_resume(dev)) { pm_runtime_set_suspended(dev); - else + } else { __update_runtime_status(dev, RPM_SUSPENDED); + dev->power.needs_force_resume = 1; + } return 0; @@ -1834,7 +1837,7 @@ int pm_runtime_force_resume(struct devic int (*callback)(struct device *); int ret = 0; - if (!pm_runtime_status_suspended(dev) || pm_runtime_need_not_resume(dev)) + if (!pm_runtime_status_suspended(dev) || !dev->power.needs_force_resume) goto out; /* @@ -1853,6 +1856,7 @@ int pm_runtime_force_resume(struct devic pm_runtime_mark_last_busy(dev); out: + dev->power.needs_force_resume = 0; pm_runtime_enable(dev); return ret; } --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -600,6 +600,7 @@ struct dev_pm_info { unsigned int idle_notification:1; unsigned int request_pending:1; unsigned int deferred_resume:1; + unsigned int needs_force_resume:1; unsigned int runtime_auto:1; bool ignore_children:1; unsigned int no_callbacks:1;