Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp115316pxj; Mon, 17 May 2021 22:36:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS189tqa81/BmSG6I29LIJ1Va+mFIhbVH2t2oGB5WT99Qa46DkhxaA/BErhhyCbd9ikH5f X-Received: by 2002:a05:6e02:1ca3:: with SMTP id x3mr2830409ill.150.1621316176910; Mon, 17 May 2021 22:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621316176; cv=none; d=google.com; s=arc-20160816; b=XdO3s5Nl7LxlAK4jpox67vCuLcwOJVG1gYSa+Xw48phF58BqTKkEPxt6yfI3f1WSh7 5X/AljADnyg/pWkat3P3NvC2MDBlCeF1y1qe7Ebc9SqBqAkBMvKUgoLZP+bcF0h97KVo nGQhdogHE7zfLkaEJVg+J3xinjtxnjAYcXAANPTo3pDkYUFlpeHg6Vy9af6YOI8LdIGV C46QZb0Qa1ssYtt5+nlujcScvpXTnmQVvHQpAULmQgFqmVD6NcOQ7LzfMUtNLpxYVw+v r/rda20kh9q4kUXVEhUvWKqlQ58BcDS6Jp//UmI8ErviI4vhGGyysRc3E/pSPfMl1zwF v/vQ== 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=ortxd5nzx+VOJdoTBh2w+rd/MsXxjo2N5Bztw/kaueY=; b=QEPRaIDAXTOONDaCeCamsB6c1tpGBSO8uj8McSoA0o7UbPLreHKxHFPPk23yZTnru7 jy3OuyHK/ulYVbwO3VHeZAd4F8YB4XDN4mciiGiMFq/rFXxSD+DIKoaKM6D5u8leVuL8 2qPg7F0YsAMxjEqdc0ckt4H+wTqdny8+nkqKvI9owpKvYLJIa49ahtya3dcIYdOjyiBM 0Po7ZLFHJEAdm6VHsliYp/A4LXlZG3mFes++zUGNubvr8w/W5BR0mxi5UA66ABRWw5FV DX8Ai3YAKM81oHqVEQhwpBp5opAmeknHKee6dKcdVS23SW4TolEQR+v5/d/jd9fphmJ0 htbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1u5h3PLF; 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 v17si4918322jan.123.2021.05.17.22.36.03; Mon, 17 May 2021 22:36:16 -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=1u5h3PLF; 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 S241027AbhEQOrV (ORCPT + 99 others); Mon, 17 May 2021 10:47:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:33966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240886AbhEQOjU (ORCPT ); Mon, 17 May 2021 10:39:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0F2961935; Mon, 17 May 2021 14:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261100; bh=bL8ChzVeQkW6b0eLm0zdaTKfl/1CCGxbzYAwhkpID0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1u5h3PLFGzf5y5FtZ/Chfhb5qQj+44Ir4O3kIWog8a7o6QIw0Bs1e3zLHnkb+uPBD SLmeBm669dFQwZukoxXA4gnznZI+s3fbAF7hRkiqR79JTQuZpzFnrqLYHORKO6q0l9 T/dAb3S1RlL9S7mxhoD2Nlk/QZlwnwUtaYcJz+0E= 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.4 005/141] PM: runtime: Fix unpaired parent child_count for force_resume Date: Mon, 17 May 2021 16:00:57 +0200 Message-Id: <20210517140242.943260142@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@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 @@ -1610,6 +1610,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; @@ -1777,10 +1778,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; @@ -1807,7 +1810,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; /* @@ -1826,6 +1829,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 @@ -608,6 +608,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;