Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Golla, Nagendra" <Nagendra.Golla@amd.com>
To: "Rafael J. Wysocki (Intel)" <rafael@kernel.org>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Michal Simek <michal.simek@amd.com>,
	Kedareswara rao Appana <appana.durga.rao@xilinx.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Michael Tretter <m.tretter@pengutronix.de>,
	Harini Katakam <harini.katakam@amd.com>,
	Shyam Pandey <radhey.shyam.pandey@amd.com>,
	dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	devicetree@vger.kernel.org, git@amd.com
Subject: Re: [PATCH v4 2/6] PM: runtime: Add pm_runtime_if_active guard and conditional variant
Date: Thu, 15 Oct 2026 16:01:29 +0530	[thread overview]
Message-ID: <f9bfd24b-60fc-447d-83ed-5204efc60626@amd.com> (raw)
In-Reply-To: <CAJZ5v0iLOJ49Zn_vPbpbqhPQ_F3W5PCpFN1VnxOzoxL7Y4PN+A@mail.gmail.com>

Hi Rafael,

On 10/13/2026 12:14 AM, Rafael J. Wysocki (Intel) wrote:
> On Fri, Oct 9, 2026 at 6:00 AM Golla Nagendra <nagendra.golla@amd.com> wrote:
>>
>> Add a pm_runtime_if_active base guard and its _try conditional variant
>> to pm_runtime.h for drivers that need to conditionally acquire a runtime
>> PM reference only when the device is already active.
>>
>> The base guard must not be used directly via guard()/scoped_guard()
>> because pm_runtime_get_if_active() only acquires a reference when it
>> returns 1; the destructor unconditionally calls pm_runtime_put(), which
>> would underflow usage_count on a suspended device. The base guard
>> exists solely to back the DEFINE_GUARD_COND _try variant.
>>
>> The _try variant (used via PM_RUNTIME_ACQUIRE_IF_ACTIVE) satisfies the
>> _try API contract that guards must not produce an error when runtime PM
>> is disabled for the device. When pm_runtime_get_if_active() returns
>> -EINVAL (runtime PM disabled), the expression calls
>> pm_runtime_get_noresume() to pre-balance the destructor's unconditional
>> pm_runtime_put(), then returns 1 so the guard condition succeeds
>> (bypass). This mirrors the behaviour of pm_runtime_active_try which
>> uses RPM_TRANSPARENT for the same purpose. When the device is genuinely
>> runtime-suspended (return value 0), the guard condition fails and
>> ACQUIRE_ERR returns true, allowing callers such as interrupt handlers to
>> skip MMIO accesses.
>>
>> Signed-off-by: Golla Nagendra <nagendra.golla@amd.com>
>> ---
>>   include/linux/pm_runtime.h | 27 +++++++++++++++++++++++++++
>>   1 file changed, 27 insertions(+)
>>
>> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
>> index 64921b10ac74..ae2a8740ffb3 100644
>> --- a/include/linux/pm_runtime.h
>> +++ b/include/linux/pm_runtime.h
>> @@ -609,6 +609,13 @@ DEFINE_GUARD(pm_runtime_active, struct device *,
>>               pm_runtime_get_sync(_T), pm_runtime_put(_T));
>>   DEFINE_GUARD(pm_runtime_active_auto, struct device *,
>>               pm_runtime_get_sync(_T), pm_runtime_put_autosuspend(_T));
>> +/*
>> + * Do not use directly -- the destructor calls pm_runtime_put()
>> + * unconditionally, which underflows if no reference was acquired.
>> + * Use only via the _try variant below.
>> + */
>> +DEFINE_GUARD(pm_runtime_if_active, struct device *,
>> +            pm_runtime_get_if_active(_T), pm_runtime_put(_T));
>>   /*
>>    * Use the following guards with ACQUIRE()/ACQUIRE_ERR().
>>    *
>> @@ -624,6 +631,23 @@ DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
>>                    pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)
>>   DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
>>                    pm_runtime_resume_and_get(_T), _RET == 0)
>> +/*
>> + * The _try contract is that no error is produced when runtime PM is disabled,
>> + * so bypass the guard when pm_runtime_get_if_active() returns -EINVAL: take a
>> + * reference with pm_runtime_get_noresume() to pre-balance the destructor's
>> + * pm_runtime_put() and return 1 so the guard condition succeeds. Interrupt
>> + * handlers then keep servicing interrupts when runtime PM is disabled for the
>> + * device or CONFIG_PM is not enabled.
>> + */
>> +DEFINE_GUARD_COND(pm_runtime_if_active, _try,
>> +                 ({
>> +                       int _r = pm_runtime_get_if_active(_T);
>> +
>> +                       if (_r == -EINVAL)
>> +                               pm_runtime_get_noresume(_T);
>> +                       _r == -EINVAL ? 1 : (_r ?: -EAGAIN);
>> +                 }),
>> +                 _RET == 1)
>>
>>   /* ACQUIRE() wrapper macros for the guards defined above. */
>>
>> @@ -639,6 +663,9 @@ DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
>>   #define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(_dev, _var)  \
>>          ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev)
>>
>> +#define PM_RUNTIME_ACQUIRE_IF_ACTIVE(_dev, _var)       \
>> +       ACQUIRE(pm_runtime_if_active_try, _var)(_dev)
>> +
>>   /*
>>    * ACQUIRE_ERR() wrapper macro for guard pm_runtime_active.
>>    *
>>
>> --
> 
> For the record, I'm still unconvinced about the guard definitions above.
> 
> Please try to reimplement the series without them for the time being.
> 
> Thanks!

Thanks, for the review

Sure — I’ll drop these two patches from the next version (v5) and
re-implement the series without the PM guard helpers for now. I’ll keep
the reset-related patches in v5,and discuss the PM guard work in a 
separate series later.

Thanks,
Nagendra





  reply	other threads:[~2026-10-15 10:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  4:00 [PATCH v4 0/6] dmaengine: zynqmp_dma: Per-channel reset, IRQ guard improvements, and PM fixes Golla Nagendra
2026-10-09  4:00 ` [PATCH v4 1/6] dmaengine: zynqmp_dma: Use PM guard for probe-time runtime PM reference Golla Nagendra
2026-10-10  3:09   ` Frank Li
2026-10-09  4:00 ` [PATCH v4 2/6] PM: runtime: Add pm_runtime_if_active guard and conditional variant Golla Nagendra
2026-10-10  2:57   ` Frank Li
2026-10-12 18:44   ` Rafael J. Wysocki (Intel)
2026-10-15 10:31     ` Golla, Nagendra [this message]
2026-10-09  4:00 ` [PATCH v4 3/6] dmaengine: zynqmp_dma: Guard IRQ handler against spurious interrupts Golla Nagendra
2026-10-10  2:59   ` Frank Li
2026-10-09  4:00 ` [PATCH v4 4/6] dt-bindings: dma: xlnx,zynqmp-dma: Add Versal Net compatible support Golla Nagendra
2026-10-09 15:33   ` Conor Dooley
2026-10-09  4:00 ` [PATCH v4 5/6] dmaengine: zynqmp_dma: Add new compatible string for Versal Net Golla Nagendra
2026-10-09  4:00 ` [PATCH v4 6/6] dmaengine: zynqmp_dma: Add per-channel reset support Golla Nagendra

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=f9bfd24b-60fc-447d-83ed-5204efc60626@amd.com \
    --to=nagendra.golla@amd.com \
    --cc=Frank.Li@kernel.org \
    --cc=appana.durga.rao@xilinx.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=git@amd.com \
    --cc=harini.katakam@amd.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=m.tretter@pengutronix.de \
    --cc=michal.simek@amd.com \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=vkoul@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox