All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2 1/4] PM: runtime: Add memory barrier before reading last_busy
Date: Wed, 25 Nov 2026 17:43:55 -0800	[thread overview]
Message-ID: <aweO20KV0XzcPBeF@google.com> (raw)
In-Reply-To: <14142601.uLZWGnKmhe@rafael.j.wysocki>

On Tue, Nov 24, 2026 at 04:31:51PM +0100, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> The users of pm_runtime_put_sync_autosuspend() and
> pm_runtime_put_autosuspend() can expect that the autosuspend delay of
> the device will be respected after calling one of them because they
> both invoke pm_runtime_mark_last_busy() upfront.  However, that may not
> happen due to a leftover autosuspend timer running when the last_busy
> update takes place, in which case rpm_suspend() triggered by the timer
> may run in parallel with the lockless last_busy update.
> 
> Namely, the last_busy access in pm_runtime_autosuspend_expiration()
> called by rpm_suspend() may be reordered before the initial read of the
> device's runtime PM usage counter in rpm_suspend(), and if last_busy
> gets updated between those two reads, the update will be missed and the
> device may be suspended right away.
> 
> To prevent that from occurring, add a read memory barrier before the
> last_busy read in pm_runtime_autosuspend_expiration() along with a
> comment explaining the reason for adding it.
> 
> Fixes: b3db492e8335 ("PM: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()")
> Fixes: e24e0630b5ba ("PM: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()")
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If you're into this sort of thing:

Reported-by: Brian Norris <briannorris@chromium.org>
Closes: https://lore.kernel.org/all/awC0tcqgq2KvCyxO@google.com/

and

Reviewed-by: Brian Norris <briannorris@chromium.org>

> ---
> 
> New patch in v2, based on
> 
> https://web.git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=26236a3e8803f7e1ace104020d7f006edb220116
> 
> ---
>  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 0b15c718c1bb..c295acf6a718 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -186,6 +186,13 @@ u64 pm_runtime_autosuspend_expiration(struct device *dev)
>  	if (autosuspend_delay < 0)
>  		return 0;
>  
> +	/*
> +	 * Prevent last_busy updates occurring before the rpm_drop_usage_count()
> +	 * invocations in __pm_runtime_idle() and __pm_runtime_suspend() from
> +	 * being missed if the last_busy access below gets reordered before the
> +	 * initial usage counter check in rpm_suspend().

super-nit / feel free to ignore: it's a bit odd to write this comment
covering super-precise details of function calls, and then immediately
rewrite it in patch 2.

I think it might make for a better long-lasting comment if we just write
in terms of "last_busy update" and "lockless usage-count decrement".
Then we don't have to update it every time these things move around and
get patched.

Sample:

	/*
	 * Ensure ordering between the initial usage counter check in
	 * rpm_suspend() and this last_busy access, to avoid missing
	 * any last_busy update performed before the last lockless usage
	 * count decrement.
	 */


But again, that's a bit nitpicky.

I'll try to look at the rest next week.

Thanks,
Brian

> +	 */
> +	smp_rmb();
>  	expires  = READ_ONCE(dev->power.last_busy);
>  	expires += (u64)autosuspend_delay * NSEC_PER_MSEC;
>  	if (expires > ktime_get_mono_fast_ns())
> -- 
> 2.51.0
> 
> 
> 
> 

  reply	other threads:[~2026-11-26  1:43 UTC|newest]

Thread overview: 17+ 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-26  1:43   ` Brian Norris [this message]
2026-11-26 14:04     ` Rafael J. Wysocki (Intel)
2026-11-30 22:36       ` Brian Norris
2026-11-24 15:35 ` [PATCH v2 2/4] PM: runtime: Avoid suspends without respecting autosuspend delay Rafael J. Wysocki
2026-11-30 22:38   ` Brian Norris
2026-11-30 22:59     ` Brian Norris
2026-12-01 12:01       ` Rafael J. Wysocki (Intel)
2026-11-24 15:37 ` [PATCH v2 3/4] PM: runtime: Update last_busy in all rpm_idle() paths Rafael J. Wysocki
2026-11-30 22:31   ` Brian Norris
2026-11-24 15:39 ` [PATCH v2 4/4] PM: runtime: Update stale pm_runtime_put_sync() kerneldoc comment Rafael J. Wysocki
2026-11-30 22:39   ` Brian Norris
2026-12-01 14:48     ` Rafael J. Wysocki (Intel)
2026-11-26 11:51 ` [PATCH v2 0/4] PM: runtime: Fix issues related to autosuspend Ulf Hansson
2026-11-26 12:50   ` Rafael J. Wysocki (Intel)
2026-11-26 13:28     ` Ulf Hansson

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=aweO20KV0XzcPBeF@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.