Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1392685ybz; Thu, 16 Apr 2020 08:22:58 -0700 (PDT) X-Google-Smtp-Source: APiQypI1Y6syjJlniID/gBwSYryZ6w8mfSAFI2C0DDkBs33D3/HEZLrqcL7JrWfZICqiqSFK9jS4 X-Received: by 2002:a50:c112:: with SMTP id l18mr31714289edf.37.1587050578216; Thu, 16 Apr 2020 08:22:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587050578; cv=none; d=google.com; s=arc-20160816; b=bBnXR9eQp3cVsuryVu5lLLcAdWv68Y+4hvCVGn4FCDltUZ+bewDNyR94/gGuPVW5aY GddCmyNyPVVeRsy4ileHxK+2ZHo9K8CW9TBSwm/wXhTyRmyYQ3gCrFo6//s9wG18M8kt KqnfMy0f5E1S79fQkLvBOZdQTcByiwMqRLPHjLASfIv+9LwsDSNrI7h42PcP4VPyFTp9 mb+PyvtjKXojzTxTEgboqXPH7MmTMBhIVk1Xk3CtUkhR6mhOCh7vMl1HrT9F/2V/ojKt z06NluUhkBUY9CEyfHe+aTzcHoQB4vXlU8PrJ9NllJvqmNAM+kvkGy/ForSYTPLXUVXy a1Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=ohyAo2/aAx4OQ5LLendrU1yJoOnyn1I+A8LCf6bpalY=; b=JOaTpLLnfhSgI32XtmHCbI5L9UDZ8n2OvkH6R/afkTVstc8aB3tqzE6pNXNxKLpien oDtN2ohZ6M7OS2IEsBZbQXXamvaiU84o+GwOANRb1TvrEitnpVdOPlON/T9gRgDyinh7 AiXGaDD4RwgaafxUTcYYwBVTdl0jNC8kggjksmpxSy4UND5JWE911i32kgbKGC0huA4d 2TWvMB3ejTW6+3FZr3BtJofoHxM2pjF/ar6FWAQgbOuOJ+x0AFu9/mc3FaN/K0q1nR98 Nl2Lmro7WcI3pPCS18y64AMuE8R7Ha70KW/WvToLbTRz1xGWergQPegiuIR/DlP/qTRo GqTQ== 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 c5si13162954ejr.178.2020.04.16.08.22.35; Thu, 16 Apr 2020 08:22:58 -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 S2502440AbgDPPS0 (ORCPT + 99 others); Thu, 16 Apr 2020 11:18:26 -0400 Received: from netrider.rowland.org ([192.131.102.5]:48115 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S2504094AbgDPPSQ (ORCPT ); Thu, 16 Apr 2020 11:18:16 -0400 Received: (qmail 4506 invoked by uid 500); 16 Apr 2020 11:18:15 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 16 Apr 2020 11:18:15 -0400 Date: Thu, 16 Apr 2020 11:18:15 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: "Rafael J. Wysocki" cc: "Rafael J. Wysocki" , Qais Yousef , USB list , Linux-pm mailing list , Kernel development list Subject: Re: lockdep warning in urb.c:363 usb_submit_urb In-Reply-To: <1998412.Cp2JyuGtSI@kreacher> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for all your help straightening this out. I think the end result will be a distinct improvement over the old code. On Thu, 16 Apr 2020, Rafael J. Wysocki wrote: > This means that the dev_pm_skip_resume() logic really is relatively > straightforward: > - If the current transition is RESTORE, return "false". > - Otherwise, if the current transition is THAW, return the return value > of dev_pm_skip_suspend(). > - Otherwise (so the current transition is RESUME which is the only remaining > case), return the logical negation of power.must_resume. > > > Also, it would mean > > that a device whose subsystem doesn't know about power.may_skip_resume > > would never be allowed to stay in runtime suspend. > > Not really, because I want the core to set power.may_skip_resume for the > devices for which dev_pm_skip_suspend() returns "true" if the "suspend_late" > subsystem-level callback is not present. [It might be more consistent > to simply set it for all devices for which dev_pm_skip_suspend() returns > "true" and let the subsystems update it should they want to? IOW, the > default value of power.may_skip_resume could be the return value of > dev_pm_skip_suspend()?] How about this? Let's set power.may_skip_resume to "true" for each device before issuing ->prepare. The subsystem can set it to "false" if it wants to during any of the suspend-side callbacks. Following the ->suspend_noirq callback, the core will do the equivalent of: dev->power.may_skip_resume &= dev_pm_skip_suspend(dev); before propagating the flag. Any subsystem changes to support this should be minimal, since only ACPI and PCI currently use may_skip_resume. > > What about the runtime PM usage counter? > > Yes, it applies to that too. > > Of course, if dev_pm_skip_suspend() returns "true", the usage counter cannot > be greater than 1 (for the given device as well as for any dependent devices). Well, in theory the subsystem could call pm_runtime_get_noresume(). I can't imagine why it would want to, though. So here's what we've got: > > Transition Conditions for dev_pm_skip_resume() to return "true" > > ---------- ---------------------------------------------------- > > > > RESTORE Never > > Right. > THAW dev_pm_skip_suspend() returns "true". > RESUME power.must_resume is clear (which requires > MAY_SKIP_RESUME and power.may_skip_resume to be set and > the runtime usage counter to be = 1, and which > propagates up from dependent devices) > > Nothing else is really strictly required IMO. This seems very clear and simple. And I will repeat here some of the things posted earlier, to make the description more complete: During the suspend side, for each of the {suspend,freeze,poweroff}_{late,noirq} phases: If dev_pm_skip_suspend() returns true then the subsystem should not invoke the driver's callback, and if there is no subsystem callback then the core will not invoke the driver's callback. During the resume side, for each of the {resume,thaw,restore}_{early,noirq} phases: If dev_pm_skip_resume() returns true then the subsystem should not invoke the driver's callback, and if there is no subsystem callback then the core will not invoke the driver's callback. dev_pm_skip_suspend() will return "true" if SMART_SUSPEND is set and the device's runtime status is "suspended". For dev_pm_skip_resume() and power.must_resume, see above. At the start of the {resume,thaw,restore}_noirq phase, if dev_pm_skip_resume() returns true then the core will set the runtime status to "suspended". Otherwise it will set the runtime status to "active". If this is not what the subsystem or driver wants, it must update the runtime status itself. For this to work properly, we will have to rely on subsystems/drivers to call pm_runtime_resume() during the suspend/freeze transition if SMART_SUSPEND is clear. Otherwise we could have the following scenario: Device A has a child B, and both are runtime suspended when hibernation starts. Suppose that the SMART_SUSPEND flag is set for A but not for B, and suppose that B's subsystem/driver neglects to call pm_runtime_resume() during the FREEZE transition. Then during the THAW transition, dev_pm_skip_resume() will return "true" for A and "false" for B. This will lead to an error when the core tries to set B's runtime status to "active" while A's status is "suspended". One way to avoid this is to have the core make the pm_runtime_resume() call, but you have said that you don't like that approach. Any suggestions? Should the core take some special action following ->freeze_noirq if the runtime status is "suspended" and SMART_SUSPEND is clear? Alan Stern