Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2405759pxa; Mon, 24 Aug 2020 13:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOLL5UZxM5jpOWp9A2vtm6f1mUKBEo8ERBthlTaL2OlPlXPGgbiWMVI008pzPP+Nz42s9R X-Received: by 2002:a17:906:1757:: with SMTP id d23mr6903781eje.126.1598300220165; Mon, 24 Aug 2020 13:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598300220; cv=none; d=google.com; s=arc-20160816; b=iKzYTRcG74Lzn7KMHWBB8BkRTQuiwFwdaLz4ncxFRdXWb++793Tr/0itxM8uWFLuaW jBQQY2YGBoqFyjDmfp5/AUK+AeYOn5LqskrZh0UArAupV/MZw9Q6gcNGJ8J9EKODGLLj ITPK+q8ixmTDY0XTvrhprOtzNbUdpPkCxGp893OGYkqmBf/cLqm3cTuyrkSa+YlThwD3 6loxUu1WolYL1lk+IHLsGMvLknNpEBqG/aqKt+KiWAmLjPITMgp/z+8aSZYtDT/dcc1x HHN8qS9EnpnsI9cfnLS0CdzfNRYkRLBjcq28ivzlXUfdXsfJPq3FXoi+NQIahkN+ZWHQ Ar/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Res2H5+rCnsIaTb6hvO538pO9xa8V7p+7ZdsWPbjdGs=; b=w1CRssm4Fex6YdJRfcmVyCoFMtJ8UemJYusXzNLsf/j8MZpLlw1mPaIHKuNnMsYFN6 zTspSJ6Ab8UHyGzGlcdRs0PbtRs+SiJXM0fWUU9kn/9hDRhqToNHZ3o1cECVE8PXkaOk om+qgCLX/xDIaLDyKkLeHER8ss2PsyftBsqOCdNH5FQVSa6dBoQYZSN5jdpe1cy50nkO pUKfU2KnfD15hTfopCAHpp+m71AnT/AtbnonYMp1suhv0jphKGZ8mDyV0Iw7DVkzivpm osANh7O46Y+pEVlvAO5R9leP85nDOeDenIkg+8zcGLaJhk1QabWSTb62wLvefjRvRKyu E55Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si8099744eju.364.2020.08.24.13.16.35; Mon, 24 Aug 2020 13:17:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbgHXUP1 (ORCPT + 99 others); Mon, 24 Aug 2020 16:15:27 -0400 Received: from netrider.rowland.org ([192.131.102.5]:47345 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725904AbgHXUPZ (ORCPT ); Mon, 24 Aug 2020 16:15:25 -0400 Received: (qmail 345315 invoked by uid 1000); 24 Aug 2020 16:15:24 -0400 Date: Mon, 24 Aug 2020 16:15:24 -0400 From: Alan Stern To: "Rafael J. Wysocki" Cc: Linux PM , LKML , Linux ACPI , Greg Kroah-Hartman , "Rafael J. Wysocki" , Mika Westerberg Subject: Re: [PATCH v2] PM: sleep: core: Fix the handling of pending runtime resume requests Message-ID: <20200824201524.GB344424@rowland.harvard.edu> References: <1954100.8R8RjBe1nF@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1954100.8R8RjBe1nF@kreacher> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 24, 2020 at 07:35:31PM +0200, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > It has been reported that system-wide suspend may be aborted in the > absence of any wakeup events due to unforseen interactions of it with > the runtume PM framework. > > One failing scenario is when there are multiple devices sharing an > ACPI power resource and runtime-resume needs to be carried out for > one of them during system-wide suspend (for example, because it needs > to be reconfigured before the whole system goes to sleep). In that > case, the runtime-resume of that device involves turning the ACPI > power resource "on" which in turn causes runtime-resume requests > to be queued up for all of the other devices sharing it. Those > requests go to the runtime PM workqueue which is frozen during > system-wide suspend, so they are not actually taken care of until > the resume of the whole system, but the pm_runtime_barrier() > call in __device_suspend() sees them and triggers system wakeup > events for them which then cause the system-wide suspend to be > aborted if wakeup source objects are in active use. > > Of course, the logic that leads to triggering those wakeup events is > questionable in the first place, because clearly there are cases in > which a pending runtime resume request for a device is not connected > to any real wakeup events in any way (like the one above). Moreover, > it is racy, because the device may be resuming already by the time > the pm_runtime_barrier() runs and so if the driver doesn't take care > of signaling the wakeup event as appropriate, it will be lost. > However, if the driver does take care of that, the extra > pm_wakeup_event() call in the core is redundant. > > Accordingly, drop the conditional pm_wakeup_event() call fron > __device_suspend() and make the latter call pm_runtime_barrier() > alone. Also modify the comment next to that call to reflect the new > code and extend it to mention the need to avoid unwanted interactions > between runtime PM and system-wide device suspend callbacks. > > Fixes: 1e2ef05bb8cf8 ("PM: Limit race conditions between runtime PM and system sleep (v2)") > Reported-by: Mika Westerberg > Signed-off-by: Rafael J. Wysocki > --- > > -> v2: > * Do not call pm_runtime_resume() if pm_runtime_barrier() returns 1, > because the device have been resumed by it already. > * Extend the comment next to the pm_runtime_barrier() call. > * Update the changelog in accordance with the above. > > --- > drivers/base/power/main.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > Index: linux-pm/drivers/base/power/main.c > =================================================================== > --- linux-pm.orig/drivers/base/power/main.c > +++ linux-pm/drivers/base/power/main.c > @@ -1606,13 +1606,17 @@ static int __device_suspend(struct devic > } > > /* > - * If a device configured to wake up the system from sleep states > - * has been suspended at run time and there's a resume request pending > - * for it, this is equivalent to the device signaling wakeup, so the > - * system suspend operation should be aborted. > + * Wait for possible runtime PM transitions of the device in progress > + * to complete and if there's a runtime resume request pending for it, > + * resume it before proceeding with invoking the system-wide suspend > + * callbacks for it. > + * > + * If the system-wide suspend callbacks below change the configuration > + * of the device, they must disable runtime PM for it or otherwise > + * ensure that its runtime-resume callbacks will not be confused by that > + * change in case they are invoked going forward. > */ > - if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) > - pm_wakeup_event(dev, 0); > + pm_runtime_barrier(dev); > > if (pm_wakeup_pending()) { > dev->power.direct_complete = false; Acked-by: Alan Stern