Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3115462pxj; Mon, 17 May 2021 18:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB+hVSTtWbzug9J4dZh2Ky00hWtS5fko1HQk4SocJEOlHRXcpMfWCshVbh+nDoL7/aR5gj X-Received: by 2002:a17:906:38c5:: with SMTP id r5mr2990577ejd.230.1621300209105; Mon, 17 May 2021 18:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300209; cv=none; d=google.com; s=arc-20160816; b=Y3K8ZrxSFZaZOfMV0/Q/H4xSgKpgwhVpluGFxGNwruvb4kowb5LhDfJvC4DWTMBBQa SfY1EMocsP5PCKg+DnU4volGO4HeRwnnHcLGVgJQc6kPAAW//V8SnbPFvy7DWRuMAk8y +qHKTkJVmfRSRXe+RHBePe/+tS7eXZsZvHwIQjaVOxGcF3YkjNPkDVP4b+wRvnJ+JlaH AFYQHKYHRDSEU7Frh5fNxrPhUrZF72iHU6BtdWQfwYfZupV/efaSgPwDN8JeEVgVaySW 6y6vSMdNlXU7AD+pBEoxwke6LrW1ksfQVGwJaFRle/vuLVbnm/mQNlGlORA/rUlE+R4g jxpw== 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=N5a1Dlm6YMkCOCHGIQVjj00p5FPRdVBrcoKrWR6S5i/TSOgpS13jDoziKMjQy+3fHg 4h9c4QPNPi4+Hq15Y48n4sqCKpAPrZ+HhOm5ltHI98l3aP4+n/YgZJXpFoTVJJvUul/0 aWOpUcAqKMZsn3QiOHOP39BlY4rZ3L9GiomxKQY3juugUEcN4b+93lqj9V1khZkrzWcc x3d+z0rE7xHqH/WCdLnn+G1uhwsDK6rQ5YvsDC6tORGWd9Qlw0vUfHjYBZTC2RGEkElZ fZAM9IyXhUowsd4vB6WD2lepvluaXbN8hcpHcW1E3IaY3JrSAgNCBNBCztws6XP/2OTc JjSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SLFMh7w1; 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 v9si6588222ejg.627.2021.05.17.18.09.45; Mon, 17 May 2021 18:10:09 -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=SLFMh7w1; 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 S239286AbhEQObK (ORCPT + 99 others); Mon, 17 May 2021 10:31:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:53296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238624AbhEQO0M (ORCPT ); Mon, 17 May 2021 10:26:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C3A561350; Mon, 17 May 2021 14:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260808; bh=PeEuDQ1RPr0AL0urufJWxpvRE4VsKXS8HuL0uvj1oms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLFMh7w14Cf6pD7pbv5YLzm02o8UXZ+KBaoLWK/EScycjDE/TthBwnOtHFo0n6IBB 9aZv2bhA2f4R9sGfuxpT6pUwoUg1JTxwMVRJTudK964f15UoDllAy1QPZbcduxR5Gg 9O3QBirSYEsSjbXRfyH2749J9qcH+uTrcr1LXgLM= 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.11 009/329] PM: runtime: Fix unpaired parent child_count for force_resume Date: Mon, 17 May 2021 15:58:40 +0200 Message-Id: <20210517140302.358557966@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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;