From: Brian Norris <briannorris@chromium.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.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: Re: [PATCH v1 1/4] PM: runtime: Update last_busy in all rpm_idle() paths
Date: Fri, 20 Nov 2026 12:59:33 -0800 [thread overview]
Message-ID: <awC0tcqgq2KvCyxO@google.com> (raw)
In-Reply-To: <3076901.e9J7NaK4W3@rafael.j.wysocki>
On Thu, Nov 19, 2026 at 09:16:30PM +0100, Rafael J. Wysocki wrote:
> 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.
>
> The first one is when pm_runtime_put() is called while a leftover
> autosuspend timer is running. Then, dropping the device's runtime PM
> usage counter to 0 allows rpm_suspend() triggered by the timer to
> suspend the device immediately before __pm_runtime_idle() is able to
> grab the spinlock. Prevent it from occurring by adding a last_busy
> update before the rpm_drop_usage_count() call in __pm_runtime_idle().
Do consumer->supplier and child->parent refcount drops have the same
problem? e.g., in pm_runtime_release_supplier() and rpm_suspend() /
parent->power.child_count decrement?
> Another one is 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 then suspend the device
> without respecting the autosuspend delay. Moreover, the timer may fire
> while the callback is running and it will not see the new last_busy
> value in that case. To address these cases, move the existing
> pm_runtime_mark_last_busy() call in rpm_idle() before the first return
> value check.
I suppose we don't care about: "what if .runtime_idle() is slow?" --
that makes a small delta in the expiration time.
> In both places mentioned above add comments explaining the rationale for
> updating last_busy.
>
> 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>
> ---
>
> Commit 26236a3e8803 is present in linux-next.
Semi-unrelated cleanup: pm_runtime_put_sync() some stale kerneldoc now,
saying "this does not update the last access time".
> ---
> drivers/base/power/runtime.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 0b15c718c1bb..02e7b4953c38 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -518,6 +518,14 @@ static int rpm_idle(struct device *dev, int rpmflags)
> else if (dev->power.idle_notification)
> retval = -EINPROGRESS;
>
> + /*
> + * Update last_busy to defer autosuspend by the full autosuspend delay.
> + * 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;
>
> @@ -563,7 +571,6 @@ static int rpm_idle(struct device *dev, int rpmflags)
> if (retval)
> return retval;
>
> - pm_runtime_mark_last_busy(dev);
> return rpm_suspend(dev, rpmflags | RPM_AUTO);
> }
>
> @@ -1132,6 +1139,13 @@ int __pm_runtime_idle(struct device *dev, int rpmflags)
> int retval;
>
> if (rpmflags & RPM_GET_PUT) {
> + /*
> + * Once the usage counter drops to 0, a leftover autosuspend
> + * timer may fire before the spinlock below is acquired. Update
> + * last_busy first so it does not find the expiration time in
> + * the past and suspend the device immediately.
> + */
> + pm_runtime_mark_last_busy(dev);
> retval = rpm_drop_usage_count(dev);
This is somewhat of a pre-existing issue (e.g., in
pm_runtime_put_autosuspend()), but weakly ordered architectures don't
really enforce the dependencies you want.
rpm_drop_usage_count() uses an atomic decrement, which has a full
barrier. But this is supposed to influence the rpm_suspend() behavior of
rpm_check_suspend_allowed() (atomic_read) + READ_ONCE(last_busy), which
includes only a conditional dependency and no barrier.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0124r6.html
"Control dependencies can order prior loads against later dependent
stores, however, they do not order prior loads against later dependent
loads. (Use memory_order_consume or memory_order_acquire if you
require this behavior.)"
So, rpm_check_suspend_allowed() should probably use
atomic_read_acquire(&dev->power.usage_count).
(This is probably an extremely narrow, practically impossible issue.)
Brian
> if (retval < 0) {
> return retval;
> --
> 2.51.0
>
>
>
>
next prev parent reply other threads:[~2026-11-20 20:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 20:13 [PATCH v1 0/4] PM: runtime: Close some gaps related to autosuspend Rafael J. Wysocki
2026-11-19 20:16 ` [PATCH v1 1/4] PM: runtime: Update last_busy in all rpm_idle() paths Rafael J. Wysocki
2026-11-20 20:59 ` Brian Norris [this message]
2026-11-20 21:29 ` Rafael J. Wysocki (Intel)
2026-11-19 20:17 ` [PATCH v1 2/4] PM: runtime: Drop space characters preceding labels Rafael J. Wysocki
2026-11-20 2:47 ` Alan Stern
2026-11-20 12:11 ` Rafael J. Wysocki (Intel)
2026-11-20 12:30 ` Rafael J. Wysocki (Intel)
2026-11-20 16:11 ` Alan Stern
2026-11-19 20:17 ` [PATCH v1 3/4] PM: runtime: Let devices suspend after an attempted resume Rafael J. Wysocki
2026-11-20 21:04 ` Brian Norris
2026-11-19 20:18 ` [PATCH v1 4/4] PM: runtime: Drop direct last_busy updates from rpm_resume() 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=awC0tcqgq2KvCyxO@google.com \
--to=briannorris@chromium.org \
--cc=driver-core@lists.linux.dev \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.