Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp882034pxb; Wed, 27 Oct 2021 14:23:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmiDnN5Osgy6kku4AelfKT8guWqeu8+XSrYw45+AThoZhsN+EecT5XGtDG8DwxFG0pim3G X-Received: by 2002:a50:c05b:: with SMTP id u27mr504721edd.56.1635369834842; Wed, 27 Oct 2021 14:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369834; cv=none; d=google.com; s=arc-20160816; b=xw1qeYo4GBWwBupB8e6xpDT9a7c/uuJXFOOdzCpoXyXXlUmqCawa8+mzrSJ1xqUN30 7jkSREqu9826XTa7ldxatCNcEg3zqcAvQXJ4LN5pZXGnXl94xpkAf5VrRI/SRMvbOHKP NTZXP+f98YuPJNwuNBCD2SSF8Tg84BKEtNRobhuZOWb0Kt8IOEFNc2hC9T1JlFLYaJFr fLzOOHSLDYRVX9IpR+u1YgzCsTOHvs8OvhMbmC0gZTFYvnFVOvvVXZ+Ohys3sLk7qgMz U+jzEH1gink4K4q3zhYGRtMzgBGNhds3vJX0k7mLoizSbxzZ2jy0PlVEVLAQ/CsVZCa6 UzMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VcwIbDXyqxOVXmwhFTh3M4U8pwTWBcfpjA1gKThuQwM=; b=MA9UPAqwjd3ZqdWt962wKFttCOAQw6cF7v92DR2EdAJrE80y4Jj/bFRy8A485ggyxX 51pLH2d6L36uvG929ehWblMjDQE8lh9CROCD7GoQWleq1Vnc0LhiReJOhYMbHxthJc3X U89P+h/cZQS+L3DXUYNA/lQHFae3nsFxnlaOxnxE00IWfLLQH1bDuWkwyWmHA1fba6yC /jfzmhgq+EQr7vqBGuIkp3ZELli/OunODiXGu+HuK9SZVtXeL0w9jP+A2nA6hRMo0HwU DRO1WfjvhceTaFazWpBIgFkEBtqsbl1avw0nTxDjybxWSa868yEF1spTQNduX7XZMNf0 hQAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DOleeR66; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f16si1694632edf.92.2021.10.27.14.23.31; Wed, 27 Oct 2021 14:23:54 -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=@linaro.org header.s=google header.b=DOleeR66; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239748AbhJ0K6s (ORCPT + 97 others); Wed, 27 Oct 2021 06:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231473AbhJ0K6r (ORCPT ); Wed, 27 Oct 2021 06:58:47 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B043C061570 for ; Wed, 27 Oct 2021 03:56:22 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 205so3948394ljf.9 for ; Wed, 27 Oct 2021 03:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VcwIbDXyqxOVXmwhFTh3M4U8pwTWBcfpjA1gKThuQwM=; b=DOleeR66hVCWRUSE1vVRgpe8SJwg3hXoPhnYGSWr2h/1QsY59933hT503CxAL7bTNk iAmCUx0TWh3pVoqWNx9NfD3cn8DWC6uQYvCRUH8Mze9MIUaGAlJOWh9Rs6Jb+LYtgoST cjvI7vr2NNcKcaTXT3/tV9MElrGguJ5w9z+JbcXFX/2ofZN8/UsF+gKVIIl+ByuNaQ8Y yPsk8wPrbdfXVROwTXzZuSRkjgb9arBztxSpf3SmGhRUuRLcpdrnjYCpgT+j4EHzVgHA DYQvE5KXJ/1CnQ6ufOLPUW7E3xStkYgXY4qDSJNfLOpWZV1eVezITj1sM6bh3c8kXPLb DFOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VcwIbDXyqxOVXmwhFTh3M4U8pwTWBcfpjA1gKThuQwM=; b=cUX06ntAL8p70FV44GpwnLVd0jOYQ8Otq2vDPoxOZ/u8O1I1OKyATXh2m5sJjW970g 11O38gBEavkDxKhh61NBng9MbUB1F71Exieb3+z9rh7Sop0OH+3wKiiD7WYugb3MA87t ZtSRLGPHnFUNkNd8RueM+FJ8oNGajTGpZhi6404giDJLRCJPIqpRZ7LbDN2xMCyC0AtC ksrTaydv7ymPwnCpz/mTcCbyLuNd3OTrG6AIWfhNI5VzP8c30gUjl8uuZ2shqSrd8kBX iZTHv2FHlhxnZwuFC2DDg9ImAc9a/0wg0TMrAebP5MoCayw83IFdoCCQCoBoEtESF36J LzHA== X-Gm-Message-State: AOAM531KkFosGYrUCnZS9Cg3U2LOoTFMVHqY0V5f5bl0s1XgvyrcK2F9 8K1yn9NV13lil6nzBPk5e+twZnZbav1EsYxxQFcI2g== X-Received: by 2002:a2e:b550:: with SMTP id a16mr32975194ljn.229.1635332180469; Wed, 27 Oct 2021 03:56:20 -0700 (PDT) MIME-Version: 1.0 References: <20211026222626.39222-1-ulf.hansson@linaro.org> <20211027020235.GA1306582@rowland.harvard.edu> In-Reply-To: <20211027020235.GA1306582@rowland.harvard.edu> From: Ulf Hansson Date: Wed, 27 Oct 2021 12:55:43 +0200 Message-ID: Subject: Re: [PATCH] PM: runtime: Allow rpm_resume() to succeed when runtime PM is disabled To: Alan Stern Cc: "Rafael J . Wysocki" , "Rafael J . Wysocki" , linux-pm@vger.kernel.org, Kevin Hilman , Maulik Shah , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Oct 2021 at 04:02, Alan Stern wrote: > > On Wed, Oct 27, 2021 at 12:26:26AM +0200, Ulf Hansson wrote: > > During system suspend, the PM core sets dev->power.is_suspended for the > > device that is being suspended. This flag is also being used in > > rpm_resume(), to allow it to succeed by returning 1, assuming that runtime > > PM has been disabled and the runtime PM status is RPM_ACTIVE, for the > > device. > > > > To make this behaviour a bit more useful, let's drop the check for the > > dev->power.is_suspended flag in rpm_resume(), as it doesn't really need to > > be limited to this anyway. > > > > Signed-off-by: Ulf Hansson > > --- > > drivers/base/power/runtime.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > > index ec94049442b9..fadc278e3a66 100644 > > --- a/drivers/base/power/runtime.c > > +++ b/drivers/base/power/runtime.c > > @@ -742,8 +742,8 @@ static int rpm_resume(struct device *dev, int rpmflags) > > repeat: > > if (dev->power.runtime_error) > > retval = -EINVAL; > > - else if (dev->power.disable_depth == 1 && dev->power.is_suspended > > - && dev->power.runtime_status == RPM_ACTIVE) > > + else if (dev->power.disable_depth > 0 && > > + dev->power.runtime_status == RPM_ACTIVE) > > IIRC there was a good reason why the original code checked for > disable_depth == 1 rather than > 0. But I don't remember exactly what > the reason was. Maybe it had something to do with the fact that during > a system sleep __device_suspend_late calls __pm_runtime_disable, and the > code was checking that there were no other disables in effect. The check was introduced in the below commit: Commit 6f3c77b040fc Author: Kevin Hilman Date: Fri Sep 21 22:47:34 2012 +0000 PM / Runtime: let rpm_resume() succeed if RPM_ACTIVE, even when disabled, v2 By reading the commit message it's pretty clear to me that the check was added to cover only one specific use case, during system suspend. That is, that a driver may want to call pm_runtime_get_sync() from a late/noirq callback (when the PM core has disabled runtime PM), to understand whether the device is still powered on and accessible. > This is > related to the documented behavior of rpm_resume (it's supposed to fail > with -EACCES if the device is disabled for runtime PM, no matter what > power state the device is in). > > That probably is also the explanation for why dev->power.is_suspended > gets checked: It's how the code tells whether a system sleep is in > progress. Yes, you are certainly correct about the current behaviour. It's there for a reason. On the other hand I would be greatly surprised if this change would cause any issues. Of course, I can't make guarantees, but I am, of course, willing to help to fix problems if those happen. As a matter of fact, I think the current behaviour looks quite inconsistent, as it depends on whether the device is being system suspended. Moreover, for syscore devices (dev->power.syscore is set for them), the PM core doesn't set the "is_suspended" flag. Those can benefit from a common behaviour. Finally, I think the "is_suspended" flag actually needs to be protected by a lock when set by the PM core, as it's being used in two separate execution paths. Although, rather than adding a lock for protection, we can just rely on the "disable_depth" in rpm_resume(). It would be easier and makes the behaviour consistent too. > > So overall, I suspect this change should not be made. But some other > improvement (like a nice comment) might be in order. > > Alan Stern Thanks for reviewing! Kind regards Uffe