Linux Power Management development
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: Brian Norris <briannorris@chromium.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Ulf Hansson <ulf.hansson@oss.qualcomm.com>,
	Linux Driver Core Development <driver-core@lists.linux.dev>
Subject: [PATCH v2 3/4] PM: runtime: Update last_busy in all rpm_idle() paths
Date: Tue, 24 Nov 2026 16:37:51 +0100	[thread overview]
Message-ID: <2373315.iZASKD2KPV@rafael.j.wysocki> (raw)
In-Reply-To: <4779892.LvFx2qVVIh@rafael.j.wysocki>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

The changelog of commit 26236a3e8803 ("PM: runtime: Update last_busy
before calling rpm_suspend() in rpm_idle()") stated that rpm_idle() only
needed to update last_busy when it was about to call rpm_suspend(), but
that is incorrect.  There are still cases in which a device may be
autosuspended earlier than expected.

Namely, when rpm_idle() returns without calling rpm_suspend(), for example
because the callback has returned a transient error, while an autosuspend
timer is running, the timer may suspend the device without respecting the
autosuspend delay.  Moreover, an autosuspend timer may fire while the
callback is running in rpm_idle() and it will not see the new last_busy
value in that case.

To address these cases, add one more pm_runtime_mark_last_busy() call to
rpm_idle(), before the first retval check, and add a comment next to it
to explain the rationale for updating last_busy at that point.

Fixes: 26236a3e8803 ("PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2:
   * Address only one case addressed by the v1 (out of two)
   * Add a new last_busy update instead of moving the existing one in case the
     runtime idle callback waits for the device to become idle or similar

---
 drivers/base/power/runtime.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index a71afaea7707..bdcf1f10b39c 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -538,6 +538,13 @@ static int rpm_idle(struct device *dev, int rpmflags)
 	else if (dev->power.idle_notification)
 		retval = -EINPROGRESS;
 
+	/*
+	 * Since an autosuspend timer may be running and the new last_busy value
+	 * needs to be seen by it, update last_busy before returning an error or
+	 * dropping the spinlock and allowing the timer function to grab it.
+	 */
+	pm_runtime_mark_last_busy(dev);
+
 	if (retval)
 		goto out;
 
-- 
2.51.0





  parent reply	other threads:[~2026-11-24 15:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 15:29 [PATCH v2 0/4] PM: runtime: Fix issues related to autosuspend Rafael J. Wysocki
2026-11-24 15:31 ` [PATCH v2 1/4] PM: runtime: Add memory barrier before reading last_busy Rafael J. Wysocki
2026-11-24 15:35 ` [PATCH v2 2/4] PM: runtime: Avoid suspends without respecting autosuspend delay Rafael J. Wysocki
2026-11-24 15:37 ` Rafael J. Wysocki [this message]
2026-11-24 15:39 ` [PATCH v2 4/4] PM: runtime: Update stale pm_runtime_put_sync() kerneldoc comment Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2373315.iZASKD2KPV@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=briannorris@chromium.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-pm@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox