* Re: [PATCH v1] PM: runtime: Fix conditional guard definitions
2025-10-20 15:03 [PATCH v1] PM: runtime: Fix conditional guard definitions Rafael J. Wysocki
@ 2025-10-20 15:48 ` Jonathan Cameron
2025-10-20 18:43 ` dan.j.williams
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-10-20 15:48 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Takashi Iwai, LKML, Linux PCI, Alex Williamson,
Bjorn Helgaas, Zhang Qilong, Ulf Hansson, Frank Li, Dhruva Gole,
Dan Williams
On Mon, 20 Oct 2025 17:03:28 +0200
"Rafael J. Wysocki" <rafael@kernel.org> wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Since pm_runtime_get_active() returns 0 on success, all of the
> DEFINE_GUARD_COND() macros in pm_runtime.h need the "_RET == 0"
> condition at the end of the argument list or they would not work
> correctly.
>
> Fixes: 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/linux-pm/202510191529.BCyjKlLQ-lkp@intel.com/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Makes sense.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
These macros are a bit awkward to get right - I'd forgotten the oddity that
conditional locks use != 0 to mean the lock was taken.
> ---
> include/linux/pm_runtime.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str
> * device.
> */
> DEFINE_GUARD_COND(pm_runtime_active, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
>
> /**
> * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1] PM: runtime: Fix conditional guard definitions
2025-10-20 15:03 [PATCH v1] PM: runtime: Fix conditional guard definitions Rafael J. Wysocki
2025-10-20 15:48 ` Jonathan Cameron
@ 2025-10-20 18:43 ` dan.j.williams
2025-10-21 20:03 ` Farhan Ali
2025-10-27 5:14 ` Dhruva Gole
3 siblings, 0 replies; 5+ messages in thread
From: dan.j.williams @ 2025-10-20 18:43 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Jonathan Cameron, Takashi Iwai, LKML, Linux PCI, Alex Williamson,
Bjorn Helgaas, Zhang Qilong, Ulf Hansson, Frank Li, Dhruva Gole,
Dan Williams
Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Since pm_runtime_get_active() returns 0 on success, all of the
> DEFINE_GUARD_COND() macros in pm_runtime.h need the "_RET == 0"
> condition at the end of the argument list or they would not work
> correctly.
>
> Fixes: 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/linux-pm/202510191529.BCyjKlLQ-lkp@intel.com/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> include/linux/pm_runtime.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str
> * device.
> */
> DEFINE_GUARD_COND(pm_runtime_active, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
I missed the detail that these are named "try" guards, but return
"-error" on failure. In all the existing cases of "try" vs "conditional"
acquire the polarity is different, e.g.:
DEFINE_GUARD_COND(rwsem_read, _try, down_read_trylock(_T))
DEFINE_GUARD_COND(rwsem_read, _intr, down_read_interruptible(_T), _RET == 0)
So, while this fix is correct, I wonder if a follow-on patch should
change the naming..., but I cannot think of sufficient replacement.
Reminder for me to be vigilant about this detail moving forward:
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1] PM: runtime: Fix conditional guard definitions
2025-10-20 15:03 [PATCH v1] PM: runtime: Fix conditional guard definitions Rafael J. Wysocki
2025-10-20 15:48 ` Jonathan Cameron
2025-10-20 18:43 ` dan.j.williams
@ 2025-10-21 20:03 ` Farhan Ali
2025-10-27 5:14 ` Dhruva Gole
3 siblings, 0 replies; 5+ messages in thread
From: Farhan Ali @ 2025-10-21 20:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Jonathan Cameron, Takashi Iwai, LKML, Linux PCI, Alex Williamson,
Bjorn Helgaas, Zhang Qilong, Ulf Hansson, Frank Li, Dhruva Gole,
Dan Williams
On 10/20/2025 8:03 AM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Since pm_runtime_get_active() returns 0 on success, all of the
> DEFINE_GUARD_COND() macros in pm_runtime.h need the "_RET == 0"
> condition at the end of the argument list or they would not work
> correctly.
>
> Fixes: 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/linux-pm/202510191529.BCyjKlLQ-lkp@intel.com/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> include/linux/pm_runtime.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str
> * device.
> */
> DEFINE_GUARD_COND(pm_runtime_active, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
>
> /**
> * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
>
>
This does fix the issue for me mentioned here
https://lore.kernel.org/all/25435d82-575d-495f-ae61-bd38570ff9ad@linux.ibm.com/
Feel free to add
Tested-by: Farhan Ali <alifm@linux.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1] PM: runtime: Fix conditional guard definitions
2025-10-20 15:03 [PATCH v1] PM: runtime: Fix conditional guard definitions Rafael J. Wysocki
` (2 preceding siblings ...)
2025-10-21 20:03 ` Farhan Ali
@ 2025-10-27 5:14 ` Dhruva Gole
3 siblings, 0 replies; 5+ messages in thread
From: Dhruva Gole @ 2025-10-27 5:14 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Jonathan Cameron, Takashi Iwai, LKML, Linux PCI,
Alex Williamson, Bjorn Helgaas, Zhang Qilong, Ulf Hansson,
Frank Li, Dan Williams
On Oct 20, 2025 at 17:03:28 +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Since pm_runtime_get_active() returns 0 on success, all of the
> DEFINE_GUARD_COND() macros in pm_runtime.h need the "_RET == 0"
> condition at the end of the argument list or they would not work
> correctly.
>
> Fixes: 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/linux-pm/202510191529.BCyjKlLQ-lkp@intel.com/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> include/linux/pm_runtime.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str
> * device.
> */
> DEFINE_GUARD_COND(pm_runtime_active, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
> - pm_runtime_get_active(_T, RPM_TRANSPARENT))
> + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
> DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
> - pm_runtime_resume_and_get(_T))
> + pm_runtime_resume_and_get(_T), _RET == 0)
The 3-argument form automatically assumes success, so we were
essentially ignoring RET val. This seems correct now.
Reviewed-by: Dhruva Gole <d-gole@ti.com>
Best regards,
Dhruva Gole
Texas Instruments Incorporated
^ permalink raw reply [flat|nested] 5+ messages in thread