lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0ia=tXJ7Fo7Jkh_keyzDYe+w20Qcqg7z3WKm8jJzymEUw@mail.gmail.com>
Date: Fri, 5 Sep 2025 19:42:02 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Sakari Ailus <sakari.ailus@...ux.intel.com>
Cc: Brian Norris <briannorris@...omium.org>, "Rafael J. Wysocki" <rafael@...nel.org>, 
	Pavel Machek <pavel@...nel.org>, "Rafael J . Wysocki" <rafael.j.wysocki@...el.com>, 
	kunit-dev@...glegroups.com, Len Brown <lenb@...nel.org>, linux-pm@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] PM: runtime: Make put{,_sync}() return 1 when already suspended

On Tue, Sep 2, 2025 at 9:25 AM Sakari Ailus
<sakari.ailus@...ux.intel.com> wrote:
>
> Hi Brian,
>
> On Thu, Aug 28, 2025 at 05:28:27PM -0700, Brian Norris wrote:
> > The pm_runtime.h docs say pm_runtime_put() and pm_runtime_put_sync()
> > return 1 when already suspended, but this is not true -- they return
> > -EAGAIN. On the other hand, pm_runtime_put_sync_suspend() and
> > pm_runtime_put_sync_autosuspend() *do* return 1.
> >
> > This is an artifact of the fact that the former are built on rpm_idle(),
> > whereas the latter are built on rpm_suspend().
> >
> > There are precious few pm_runtime_put()/pm_runtime_put_sync() callers
> > that check the return code at all, but most of them only log errors, and
> > usually only for negative error codes. None of them should be treating
> > this as an error, so:
> >
> >  * at best, this may fix some case where a driver treats this condition
> >    as an error, when it shouldn't;
> >
> >  * at worst, this should make no effect; and
> >
> >  * somewhere in between, we could potentially clear up non-fatal log
> >    messages.
> >
> > Fix the pm_runtime_already_suspended_test() while tweaking the behavior.
> > The test makes a lot more sense when these all return 1 when the device
> > is already suspended:
> >
> >     pm_runtime_put(dev);
> >     pm_runtime_put_sync(dev);
> >     pm_runtime_suspend(dev);
> >     pm_runtime_autosuspend(dev);
> >     pm_request_autosuspend(dev);
> >     pm_runtime_put_sync_autosuspend(dev);
> >     pm_runtime_put_autosuspend(dev);
> >
> > Signed-off-by: Brian Norris <briannorris@...omium.org>
> > ---
> >
> >  drivers/base/power/runtime-test.c | 8 ++------
> >  drivers/base/power/runtime.c      | 3 +++
> >  2 files changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
> > index 263c28d5fc50..1be18e871f1d 100644
> > --- a/drivers/base/power/runtime-test.c
> > +++ b/drivers/base/power/runtime-test.c
> > @@ -43,15 +43,11 @@ static void pm_runtime_already_suspended_test(struct kunit *test)
> >       KUNIT_EXPECT_EQ(test, 0, pm_runtime_barrier(dev)); /* no wakeup needed */
> >
> >       KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
> > -     /*
> > -      * We never actually left RPM_SUSPENDED, but rpm_idle() still treats
> > -      * this as -EAGAIN / "runtime PM status change ongoing".
> > -      */
> > -     KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_put(dev));
> > +     KUNIT_EXPECT_EQ(test, 1, pm_runtime_put(dev));
> >
> >       pm_runtime_get_noresume(dev);
> >       KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
> > -     KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_put_sync(dev));
> > +     KUNIT_EXPECT_EQ(test, 1, pm_runtime_put_sync(dev));
> >
> >       KUNIT_EXPECT_EQ(test, 1, pm_runtime_suspend(dev));
> >       KUNIT_EXPECT_EQ(test, 1, pm_runtime_autosuspend(dev));
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index 3e84dc4122de..17cf111d16aa 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -498,6 +498,9 @@ static int rpm_idle(struct device *dev, int rpmflags)
> >       if (retval < 0)
> >               ;       /* Conditions are wrong. */
> >
> > +     else if ((rpmflags & RPM_GET_PUT) && (retval == 1))
> > +             ;       /* put() is allowed in RPM_SUSPENDED */
>
> Ah, I missed this while reviewing the 3rd patch. Makes sense. Please ignore
> my comments regarding the 3rd patch on whether the return value 1 is
> applicable.
>
> The latter parentheses are redundant (the former, too, actually, but the
> compiler warns so let them be).

Right.

But overall this should work.

> > +
> >       /* Idle notifications are allowed only in the RPM_ACTIVE state. */
> >       else if (dev->power.runtime_status != RPM_ACTIVE)
> >               retval = -EAGAIN;
>
> --

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ