From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796078190; b=FsqI+/Vk5pxmwqYFomCeja/dDkzrDC6JIoeOh4qyJflqT17qRZzixze/4/vJhML/wRso uoTYLHvVL56k6GBX1r7yc1uVNyqwV38EBF+r4+Zr76xzWaotiswAK+i4K6Ck9r/mnerPA 03b+m1dPIweaNH6JhRorh6AnrDYI4s7amkixmOot71anDJliifzyEW5S6xKxqaifI3hp2 /rlHWNeeS0Mb+1tbqMtamYyYnnV0fzIFMw5bAWyncfuxc3xKEkNUwntaFIoZR+cbkHkYw zac6OhbsndutmP8rJAR7h9rNRnycuTx9BCFl1RSycSLQqBwH1tks99bUA/MdL3o1hPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796078190; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To; bh=HGpELodfYIpuOlzwmHgblrVzfAT+seAXgX6/wCLVIFg=; b=PS9TRpaxJpQPCGXmnvIu4OUKKO/XwB4VnW70ageFazHO6wAZL13qpfIgeYtE54qSMR+c UOVwOBtDnt8Hz6N83aWbjLrE5thhNdOVK9CykV3VhaCa1l89Eg3vrc3QviHXsAohnc1lI x75+KyAzevpz3872lPWnaPvXs74TbXxgPr9OEZhFmqjjM6jSS12krTC9n70w7cD2IlfEH H6Jcw/nuVSco0yhhIah4OnGztBw8QFgSJLPyLxrnprl2TNZboNsLtMd/987PsyRRpCO7L L5DskMHLnOCh0necb11Yk9lX0OoBGTUAtCQEzaw6IiMdh0gONZimu5BMPX1L0+XHz+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=LK1nwwMt; arc=none smtp.remote-ip=74.125.82.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86DB7606A327 for ; Mon, 30 Nov 2026 22:36:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86DB7606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=LK1nwwMt Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-3866a784546so15589868eec.0 for ; Mon, 30 Nov 2026 14:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796078189; x=1796682989; darn=lists.linux.dev; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=HGpELodfYIpuOlzwmHgblrVzfAT+seAXgX6/wCLVIFg=; b=LK1nwwMtH0KCZoUBsptzjIBh667giGVmEZ94/Xwm2ZbM/iq99mShNiNqX4isDcxYqe feW5HfGDK/q8UWZ+qfLhk0lma0OeXXGgGPpljzwOS7Mbe3DdgWLvQKZWtvZn08vqVIsS 9DAnTgZcQGeFXhVKEcS7Jryw1f2jxEuJLxGGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796078189; x=1796682989; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=HGpELodfYIpuOlzwmHgblrVzfAT+seAXgX6/wCLVIFg=; b=f8Vdl1farckQ/ps52+/RisfHoZ/Q9/hTMEPjMMSzwLScyy5g/Y0wcmojEgXj5M3c6S ZRqkE8kBb5tGk8wIkaxhh4Q2MkVKxBAZxWIw34RcCkcXcHF5hs3KQB4ReA75zi6UAlgT 7zBj8vGDfeUwJJThxxbiXqgV7yxZeVHuiM4JzHqSzqqxqzDkVixic94QmAJpY7Vvck9K 7WvBxEpodcHpW7tHwer9FPVnwyazXA4qv3jP6YYmmomkmo0cDotAQNIxeYLptG8tONE/ NbSw7dnZjJ4h5r6Xxk2pVrAMW9VZYh83CvdXWGRX6jZQtwBWTynLEClgShZRt2gJGtZg lELA== X-Forwarded-Encrypted: i=1; AL+hErEg/7Ea7dLI9gh+kCuuTxZ7PuLdCP7B8/0yUV1x435VG1fPS981DFUjRuLiMhrKFvK0nuxYho598HGeqQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+RDFPV7h/6na2flaK7QkhRyCUU415W3pqHlcUICDC/wMTq2MB7 rUpUn+5fVlqpaZljm573tboDRgUUqSAhNS6ZWp8LOBC2FqvXzR9sJ8PACC/DNFYtlA== X-Gm-Gg: AZFdTZfS658z8UBPSA/91aYYXDRcQmf6rc9JTLyoOc6MleDkXsFdB7on4SqqpnSmzSH PxyPkP/BB0foezZE7Xaw14+AbPPRsTJeHrxiLKtFSdN+cSSMjGBQ4s+H1meBMFF1IUejZPjEFhS e93ZQ9RW1J9+bku0lrQykxui1OTPAi/wRJw6wV2kfpWuQgEqEbHRyzSqasmuEIqQ7m2xoDiKUD/ RPYzXmopS/6nLtY0OUlpta2B28scnhUknK3G32XFDDqlaREX/ndueStzZRvSSFRNAKIja8MLo4o W6+LvJPv43weyVdaEGUcdfzv0qiyIHfvdn1P7GU1vz+7vuehFDzersnsz8LyUHXHUDgX4Py0YKW OLvDGmB6yEwCAzvzzKY+m4lkIaoPurH7W04mwezln+VdJ7spPzfA49+nkzf5HbmcokUH1d7rSQO 8qssqFVoXeFGuDFwajuSW4PpPVslk7qtFySt8zjxgJPA2NRwzmJrjJI4HznbhbB6ZDocJiI44gJ BF2GnrTSMA/ks0siTaXS1SLRtgjOzLlF98whf1QKdA6nkzb5xrtAWS85BlfpnqlkUF/z4rq/MtX 4rzqFeszudkbCQGs6C0UMUmHXrJL274HG9dGo6n5qH/NO1UZcS0OL7PH1K1shTipfJws/getiyO 1eW18L9/McTsgDOs= X-Received: by 2002:a05:7301:4d11:b0:386:c666:ec45 with SMTP id 5a478bee46e88-386c666eeb2mr18069572eec.12.1796078188391; Mon, 30 Nov 2026 14:36:28 -0800 (PST) Received: from localhost ([2a00:79e0:2e7c:8:d64c:d468:46b8:64da]) by smtp.gmail.com with UTF8SMTPSA id 5a478bee46e88-386b9bdafb5sm69933773eec.9.2026.11.30.14.36.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 14:36:27 -0800 (PST) Date: Mon, 30 Nov 2026 14:36:26 -0800 From: Brian Norris To: "Rafael J. Wysocki (Intel)" Cc: Linux PM , Alan Stern , Sakari Ailus , Ulf Hansson , Linux Driver Core Development Subject: Re: [PATCH v2 1/4] PM: runtime: Add memory barrier before reading last_busy Message-ID: References: <4779892.LvFx2qVVIh@rafael.j.wysocki> <14142601.uLZWGnKmhe@rafael.j.wysocki> X-Mailing-List: driver-core@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Nov 26, 2026 at 03:04:04PM +0100, Rafael J. Wysocki (Intel) wrote: > On Thu, Nov 26, 2026 at 2:44 AM Brian Norris wrote: > > > > On Tue, Nov 24, 2026 at 04:31:51PM +0100, Rafael J. Wysocki wrote: > > > From: "Rafael J. Wysocki" > > > > > > 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 > > > > If you're into this sort of thing: > > > > Reported-by: Brian Norris > > Closes: https://lore.kernel.org/all/awC0tcqgq2KvCyxO@google.com/ > > OK > > > and > > > > Reviewed-by: Brian Norris > > Thanks! > > > > --- > > > > > > 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. > > Well, say "stable" picks up this one without the next one (which is > entirely possible). > > And the time spent on writing it has already been sacrificed so to speak. Part of my thought (that I failed to mention) was that depending on what you really meant, the __pm_runtime_idle() part is a bit misleading, for exactly the "stable" case you mention. __pm_runtime_idle() doesn't actually update last_busy the way you mention until patch 2. If you meant literal code like the following, then sure, you have a point: pm_runtime_mark_last_busy(); pm_runtime_put(); // __pm_runtime_idle() is hidden under the hood here But I don't expect anybody should have been expecting such code to do sensible things, at least not until we recently decided to tweak autosuspend and rpm_idle() behaviors. In any case, I doubt anybody else is reading these code/comments that closely for advice. > > 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. > > Thank you! > > I'll queue this series up in the meantime because it has been reviewed > by Ulf and Sashiko has no concerns, but if you find anything needing a > fix in it, please let me know. Tags would be appreciated too. ;-) Sounds good. Brian > > > + */ > > > + smp_rmb(); > > > expires = READ_ONCE(dev->power.last_busy); > > > expires += (u64)autosuspend_delay * NSEC_PER_MSEC; > > > if (expires > ktime_get_mono_fast_ns()) > > > --