From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
To: Jonathan Cameron <jic23@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: rafael@kernel.org, dakr@kernel.org, ulf.hansson@linaro.org,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, geert@linux-m68k.org,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] driver core: platform: Use devres group to free driver probe resources
Date: Wed, 19 Feb 2025 14:45:07 +0200 [thread overview]
Message-ID: <8d83ea72-bb81-4c63-bf69-28cf5848ae20@tuxon.dev> (raw)
In-Reply-To: <4bf01946-90e3-4169-91fa-10d9f90310e9@tuxon.dev>
Hi, Daniel, Jonathan,
On 15.02.2025 15:51, Claudiu Beznea wrote:
> Hi, Greg,
>
> On 15.02.2025 15:25, Greg KH wrote:
>> On Sat, Feb 15, 2025 at 03:08:49PM +0200, Claudiu wrote:
>>> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>>>
>>> On the Renesas RZ/G3S (and other Renesas SoCs, e.g., RZ/G2{L, LC, UL}),
>>> clocks are managed through PM domains. These PM domains, registered on
>>> behalf of the clock controller driver, are configured with
>>> GENPD_FLAG_PM_CLK. In most of the Renesas drivers used by RZ SoCs, the
>>> clocks are enabled/disabled using runtime PM APIs. The power domains may
>>> also have power_on/power_off support implemented. After the device PM
>>> domain is powered off any CPU accesses to these domains leads to system
>>> aborts.
>>>
>>> During probe, devices are attached to the PM domain controlling their
>>> clocks and power. Similarly, during removal, devices are detached from the
>>> PM domain.
>>>
>>> The detachment call stack is as follows:
>>>
>>> device_driver_detach() ->
>>> device_release_driver_internal() ->
>>> __device_release_driver() ->
>>> device_remove() ->
>>> platform_remove() ->
>>> dev_pm_domain_detach()
>>>
>>> During driver unbind, after the device is detached from its PM domain,
>>> the device_unbind_cleanup() function is called, which subsequently invokes
>>> devres_release_all(). This function handles devres resource cleanup.
>>>
>>> If runtime PM is enabled in driver probe via devm_pm_runtime_enable(), the
>>> cleanup process triggers the action or reset function for disabling runtime
>>> PM. This function is pm_runtime_disable_action(), which leads to the
>>> following call stack of interest when called:
>>>
>>> pm_runtime_disable_action() ->
>>> pm_runtime_dont_use_autosuspend() ->
>>> __pm_runtime_use_autosuspend() ->
>>> update_autosuspend() ->
>>> rpm_idle()
>>>
>>> The rpm_idle() function attempts to resume the device at runtime. However,
>>> at the point it is called, the device is no longer part of a PM domain
>>> (which manages clocks and power states). If the driver implements its own
>>> runtime PM APIs for specific functionalities - such as the rzg2l_adc
>>> driver - while also relying on the power domain subsystem for power
>>> management, rpm_idle() will invoke the driver's runtime PM API. However,
>>> since the device is no longer part of a PM domain at this point, the PM
>>> domain's runtime PM APIs will not be called. This leads to system aborts on
>>> Renesas SoCs.
>>>
>>> Another identified case is when a subsystem performs various cleanups
>>> using device_unbind_cleanup(), calling driver-specific APIs in the process.
>>> A known example is the thermal subsystem, which may call driver-specific
>>> APIs to disable the thermal device. The relevant call stack in this case
>>> is:
>>>
>>> device_driver_detach() ->
>>> device_release_driver_internal() ->
>>> device_unbind_cleanup() ->
>>> devres_release_all() ->
>>> devm_thermal_of_zone_release() ->
>>> thermal_zone_device_disable() ->
>>> thermal_zone_device_set_mode() ->
>>> struct thermal_zone_device_ops::change_mode()
>>>
>>> At the moment the driver-specific change_mode() API is called, the device
>>> is no longer part of its PM domain. Accessing its registers without proper
>>> power management leads to system aborts.
>>>
>>> Open a devres group before calling the driver probe, and close it
>>> immediately after the driver remove function is called and before
>>> dev_pm_domain_detach(). This ensures that driver-specific devm actions or
>>> reset functions are executed immediately after the driver remove function
>>> completes. Additionally, it prevents driver-specific runtime PM APIs from
>>> being called when the device is no longer part of its power domain.
>>>
>>> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>>> ---
>>>
>>> Hi,
>>>
>>> Although Ulf gave its green light for the approaches on both IIO [1],
>>> [2] and thermal subsystems [3], Jonathan considered unacceptable the
>>> approaches in [1], [2] as he considered it may lead to dificult to
>>> maintain code and code opened to subtle bugs (due to the potential of
>>> mixing devres and non-devres calls). He pointed out a similar approach
>>> that was done for the I2C bus [4], [5].
>>>
>>> As the discussions in [1], [2] stopped w/o a clear conclusion, this
>>> patch tries to revive it by proposing a similar approach that was done
>>> for the I2C bus.
>>>
>>> Please let me know you input.
>>
>> I'm with Jonathan here, the devres stuff is getting crazy here and you
>> have drivers mixing them and side affects happening and lots of
>> confusion. Your change here is only going to make it even more
>> confusing, and shouldn't actually solve it for other busses (i.e. what
>> about iio devices NOT on the platform bus?)
>
> You're right, other busses will still have this problem.
>
>>
>> Why can't your individual driver handle this instead?
>
> Initially I tried it at the driver level by using non-devres PM runtime
> enable API but wasn't considered OK by all parties.
>
> I haven't thought about having devres_open_group()/devres_close_group() in
> the driver itself but it should work.
Are you OK with having the devres_open_group()/devres_close_group() in the
currently known affected drivers (drivers/iio/adc/rzg2l_adc.c and the
proposed drivers/thermal/renesas/rzg3s_thermal.c [1]) ?
Thank you,
Claudiu
[1]
https://lore.kernel.org/all/20250103163805.1775705-5-claudiu.beznea.uj@bp.renesas.com
>
> Thank you,
> Claudiu
>
>>
>> thanks,
>>
>> greg k-h
>
next prev parent reply other threads:[~2025-02-19 12:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-15 13:08 [PATCH] driver core: platform: Use devres group to free driver probe resources Claudiu
2025-02-15 13:25 ` Greg KH
2025-02-15 13:51 ` Claudiu Beznea
2025-02-19 12:45 ` Claudiu Beznea [this message]
2025-03-05 14:03 ` Jonathan Cameron
2025-03-06 6:11 ` Dmitry Torokhov
2025-03-27 16:47 ` Claudiu Beznea
2025-03-30 15:31 ` Jonathan Cameron
2025-04-09 16:12 ` Claudiu Beznea
2025-05-09 11:51 ` Claudiu Beznea
2025-05-09 13:07 ` Ulf Hansson
2025-05-09 14:12 ` Claudiu Beznea
2025-05-11 11:01 ` Jonathan Cameron
2025-05-19 16:20 ` Dmitry Torokhov
2025-05-19 15:02 ` Ulf Hansson
2025-05-19 16:13 ` Dmitry Torokhov
2025-05-20 12:09 ` Ulf Hansson
2025-05-20 19:08 ` Dmitry Torokhov
2025-05-21 5:41 ` Claudiu Beznea
2025-05-21 12:37 ` Ulf Hansson
2025-05-21 14:57 ` Dmitry Torokhov
2025-05-22 9:48 ` Claudiu Beznea
2025-05-22 11:53 ` Ulf Hansson
2025-05-22 14:08 ` Claudiu Beznea
2025-05-22 16:28 ` Ulf Hansson
2025-05-22 18:47 ` Dmitry Torokhov
2025-05-22 22:09 ` Ulf Hansson
2025-05-22 23:06 ` Dmitry Torokhov
2025-05-23 9:47 ` Ulf Hansson
2025-05-23 10:52 ` Claudiu Beznea
2025-05-23 13:48 ` Ulf Hansson
2025-05-22 14:55 ` Geert Uytterhoeven
2025-05-22 22:24 ` Ulf Hansson
2025-05-22 10:32 ` 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=8d83ea72-bb81-4c63-bf69-28cf5848ae20@tuxon.dev \
--to=claudiu.beznea@tuxon.dev \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=dakr@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=ulf.hansson@linaro.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