linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Mark Brown <broonie@kernel.org>
Cc: "Matti Vaittinen" <mazziesaccount@gmail.com>,
	"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
	dri-devel@lists.freedesktop.org,
	"Johan Hovold" <johan+linaro@kernel.org>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Kevin Hilman" <khilman@baylibre.com>,
	linux-kernel@vger.kernel.org, "Daniel Vetter" <daniel@ffwll.ch>,
	linux-amlogic@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-doc@vger.kernel.org, "Jonathan Cameron" <jic23@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Miaoqian Lin" <linmq006@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	"Alexandru Tachici" <alexandru.tachici@analog.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Andrzej Hajda" <andrzej.hajda@intel.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jonas Karlman" <jonas@kwiboo.se>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Alexandru Ardelean" <aardelean@deviqon.com>,
	linux-hwmon@vger.kernel.org, linux-clk@vger.kernel.org,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Robert Foss" <robert.foss@linaro.org>,
	"Aswath Govindraju" <a-govindraju@ti.com>,
	"David Airlie" <airlied@linux.ie>,
	linux-iio@vger.kernel.org
Subject: Re: (subset) [PATCH v2 0/7] Devm helpers for regulator get and enable
Date: Mon, 15 Aug 2022 21:52:36 +0300	[thread overview]
Message-ID: <YvqV9Mq6I3gXQaf2@pendragon.ideasonboard.com> (raw)
In-Reply-To: <Yvp1Qkuh7xfeb/B2@sirena.org.uk>

Hi Mark,

On Mon, Aug 15, 2022 at 05:33:06PM +0100, Mark Brown wrote:
> On Mon, Aug 15, 2022 at 06:54:45PM +0300, Laurent Pinchart wrote:
> 
> > - With devres, you don't have full control over the order in which
> >   resources will be released, which means that you can't control the
> >   power off sequence, in particular if it needs to be sequenced with
> >   GPIOs and clocks. That's not a concern for all drivers, but this API
> >   will creep in in places where it shouldn't be used, driver authours
> >   should really pay attention to power management and not live with the
> >   false impression that everything will be handled automatically for
> >   them. In the worst cases, an incorrect power off sequence could lead
> >   to hardware damage.
> 
> I basically agree with these concerns which is why I was only happy with
> this API when Matti suggested doing it in a way that meant that the
> callers are unable to access the regulator at runtime, this means that
> if anyone wants to do any kind of management of the power state outside
> of probe and remove they are forced to convert to the full fat APIs.
> The general ordering concern with devm is that the free happens too late
> but for the most part this isn't such a concern with regulators, they
> might have delayed power off anyway due to sharing - it's no worse than
> memory allocation AFAICT.  Given all the other APIs using devm it's
> probably going to end up fixing some bugs.
> 
> For sequencing I'm not convinced it's much worse than the bulk API is
> anyway, and practically speaking I expect most devices that have
> problems here will also need more control over power anyway - it's
> certainly the common case that hardware has pretty basic requirements
> and is fairly tolerant.

I'm not extremely concerned here at the moment, as power should be the
last thing to be turned off, after clocks and reset signals. As clocks
and GPIOs will still be controlled manually in the driver .remove()
function, it means that power will go last, which should be fine.
However, should a devm_clk_get_enable() or similar function be
implemented, we'll run into trouble. Supplying active high input signals
to a device that is not powered can lead to latch-up, which tends to
only manifest after a statistically significant number of occurrences of
the condition, and can slowly damage the hardware over time. This is a
real concern as it will typically not be caught during early
development. I think we would still be better off with requiring drivers
to manually handle powering off the device until we provide a mechanism
that can do so safely in an automated way.

> > - Powering regulators on at probe time and leaving them on is a very bad
> >   practice from a power management point of view, and should really be
> >   discouraged. Adding convenience helpers to make this easy is the wrong
> >   message, we should instead push driver authors to implement proper
> >   runtime PM.
> 
> The stick simply isn't working here as far as I can see.

Do you think there's no way we can get it to work, instead of giving up
and adding an API that goes in the wrong direction ? :-( I'll give a
talk about the dangers of devm_* at the kernel summit, this is something
I can mention to raise awareness of the issue among maintainers,
hopefully leading to improvements through better reviews.

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2022-08-15 19:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12 10:08 [PATCH v2 0/7] Devm helpers for regulator get and enable Matti Vaittinen
2022-08-12 10:09 ` [PATCH v2 1/7] docs: devres: regulator: Add missing devm_* functions to devres.rst Matti Vaittinen
2022-08-12 10:10 ` [PATCH v2 2/7] regulator: Add devm helpers for get and enable Matti Vaittinen
2022-08-12 10:10 ` [PATCH v2 3/7] docs: devres: regulator: Add new get_enable functions to devres.rst Matti Vaittinen
2022-08-12 10:11 ` [PATCH v2 4/7] clk: cdce925: simplify using devm_regulator_get_enable() Matti Vaittinen
2022-08-12 10:11 ` [PATCH v2 5/7] gpu: drm: simplify drivers using devm_regulator_*get_enable*() Matti Vaittinen
2022-08-12 10:11 ` [PATCH v2 6/7] hwmon: lm90: simplify using devm_regulator_get_enable() Matti Vaittinen
2022-08-12 10:12 ` [PATCH v2 7/7] iio: Simplify drivers using devm_regulator_*get_enable() Matti Vaittinen
     [not found]   ` <CAHp75Vcz_ufnLCE8TYBjM0b8BiS4W1AgXq8euNrUFo3WZy3=fA@mail.gmail.com>
2022-08-15  4:34     ` Matti Vaittinen
     [not found] ` <166057828406.697572.228317501909350108.b4-ty@kernel.org>
2022-08-15 15:54   ` (subset) [PATCH v2 0/7] Devm helpers for regulator get and enable Laurent Pinchart
2022-08-15 16:33     ` Mark Brown
2022-08-15 18:52       ` Laurent Pinchart [this message]
2022-08-15 20:58         ` Stephen Boyd
2022-08-15 21:17           ` Laurent Pinchart
2022-08-15 22:55             ` Mark Brown
2022-08-16  4:56               ` Matti Vaittinen
2022-08-16 10:36                 ` Mark Brown
2022-08-16 11:06                   ` Vaittinen, Matti
2022-08-16 11:31                     ` Mark Brown
2022-08-16  8:42             ` Andy Shevchenko
2022-08-15 22:07           ` Mark Brown
2022-08-30 19:42             ` Stephen Boyd
2022-08-16  8:23         ` Andy Shevchenko
2022-08-18 11:33   ` Matti Vaittinen
2022-08-18 11:54     ` Mark Brown
2022-08-18 12:04       ` Vaittinen, Matti

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=YvqV9Mq6I3gXQaf2@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=a-govindraju@ti.com \
    --cc=aardelean@deviqon.com \
    --cc=airlied@linux.ie \
    --cc=alexandru.tachici@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrunet@baylibre.com \
    --cc=jdelvare@suse.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jic23@kernel.org \
    --cc=johan+linaro@kernel.org \
    --cc=jonas@kwiboo.se \
    --cc=khilman@baylibre.com \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linmq006@gmail.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lorenzo@kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=narmstrong@baylibre.com \
    --cc=nuno.sa@analog.com \
    --cc=robert.foss@linaro.org \
    --cc=sboyd@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;
as well as URLs for NNTP newsgroup(s).