From: Guenter Roeck <linux@roeck-us.net>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
rafael@kernel.org
Subject: Re: [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals
Date: Mon, 20 Feb 2023 09:12:10 -0800 [thread overview]
Message-ID: <20230220171210.GA1606748@roeck-us.net> (raw)
In-Reply-To: <1c8efdae-1ef4-ab45-d891-72010d8a4343@linaro.org>
On Mon, Feb 20, 2023 at 04:39:48PM +0100, Daniel Lezcano wrote:
> On 20/02/2023 15:11, Guenter Roeck wrote:
> > On Mon, Feb 20, 2023 at 02:34:08PM +0100, Daniel Lezcano wrote:
> > > Hi Guenter,
> > >
> > > my script should have Cc'ed you but it didn't, so just a heads up this patch
> > > ;)
> > >
> > > On 19/02/2023 15:36, Daniel Lezcano wrote:
> > > > In this function, there is a guarantee the thermal zone is registered.
> > > >
> > > > The sysfs hwmon unregistering will be blocked until we exit the
> > > > function. The thermal zone is unregistered after the sysfs hwmon is
> > > > unregistered.
> > > >
> > > > When we are in this function, the thermal zone is registered.
> > > >
> > > > We can call the thermal_zone_get_crit_temp() function safely and let
> > > > the function use the lock which is private the thermal core code.
> > > >
> >
> > Hmm, if you say so. That very same call used to cause a crash in
> > Chromebooks, which is why I had added the locking.
>
> Mmh, I see. I guess we can assume thermal_hwmon is part of the core code and
> remove this change.
>
Yes. Anyway, the sequence of events was roughly as follows.
- thermal zone is device is registered
- hwmon device is registered
- userspace is triggered and starts reading device attributes
- while userspace has a hwmon attribute open, thermal device is unregistered
- hwmon device is unregistered (sysfs attribute is still open)
- hwmon device attribute function is called
- Since thermal device ops have been released after the thermal device
was unregistered, trying to call an ops callback fails.
That doesn't normally happen, but the Intel wireless driver has the habit
of registering a thermal zone early in its probe function, only to unregister
it immediately afterwards if the probe function fails. If some userspace
activity is triggered by the hwmon device registration, the thermal and
hwmon device removal may be timed such that the hwmon devive is removed
while one (or more) of its attribute files are still open. Normally that
doesn't matter, but it is fatal here since the ops callbacks are not owned
by the hwmon device but by the thermal device.
Essentially every ops callback has this problem.
thermal_zone_get_temp() had it as well, also associated with
a hwmon sysfs attribute read operation. See commit 1c6b30060777
("thermal/core: Ensure that thermal device is registered in
thermal_zone_get_temp").
If you don't want non-thermal code to access ->ops directly, the thermal
code would have to provide protected accessor functions, similar to
thermal_zone_get_temp().
Thanks,
Guenter
>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>
next prev parent reply other threads:[~2023-02-20 17:12 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-19 14:36 [PATCH v1 00/17] Self-encapsulate the thermal zone device structure Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 01/17] thermal/core: Add a thermal zone 'devdata' accessor Daniel Lezcano
2023-02-19 14:56 ` Guenter Roeck
2023-02-19 15:07 ` Niklas Söderlund
2023-02-19 17:07 ` Daniel Lezcano
2023-02-19 18:23 ` Niklas Söderlund
2023-02-19 16:23 ` kernel test robot
2023-02-19 22:34 ` Mark Brown
2023-02-20 8:20 ` Ido Schimmel
2023-02-20 9:09 ` AngeloGioacchino Del Regno
2023-02-20 10:34 ` Balsam CHIHI
2023-02-20 10:37 ` Greenman, Gregory
2023-02-20 11:03 ` DLG Adam Ward
2023-02-20 12:18 ` Geert Uytterhoeven
2023-02-20 14:48 ` DLG Adam Ward
2023-02-20 11:13 ` Baolin Wang
2023-02-20 13:23 ` Sebastian Reichel
2023-02-19 14:36 ` [PATCH v1 02/17] thermal/core: Show a debug message when get_temp() fails Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 03/17] thermal: Remove debug or error messages in get_temp() ops Daniel Lezcano
2023-02-20 8:58 ` Miquel Raynal
2023-02-19 14:36 ` [PATCH v1 04/17] thermal/hwmon: Do not set no_hwmon before calling thermal_add_hwmon_sysfs() Daniel Lezcano
2023-02-19 15:08 ` Niklas Söderlund
2023-02-19 14:36 ` [PATCH v1 05/17] thermal/hwmon: Use the right device for devm_thermal_add_hwmon_sysfs() Daniel Lezcano
2023-02-19 17:26 ` Martin Blumenstingl
2023-02-19 14:36 ` [PATCH v1 06/17] thermal: Don't use 'device' internal thermal zone structure field Daniel Lezcano
2023-02-20 10:50 ` Balsam CHIHI
2023-02-19 14:36 ` [PATCH v1 07/17] thermal/hwmon: Use the thermal API instead tampering the internals Daniel Lezcano
2023-02-20 13:34 ` Daniel Lezcano
2023-02-20 14:11 ` Guenter Roeck
2023-02-20 15:39 ` Daniel Lezcano
2023-02-20 17:12 ` Guenter Roeck [this message]
2023-02-21 16:08 ` Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 08/17] thermal/drivers/spear: Don't use tz->device but pdev->dev Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 09/17] thermal: Add a thermal zone id accessor Daniel Lezcano
2023-02-19 14:55 ` Guenter Roeck
2023-02-19 17:15 ` kernel test robot
2023-02-19 14:36 ` [PATCH v1 10/17] thermal: Do not access 'type' field, use the tz id instead Daniel Lezcano
2023-02-20 8:22 ` Ido Schimmel
2023-02-19 14:36 ` [PATCH v1 11/17] thermal/drivers/da9062: Don't access the thermal zone device fields Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 12/17] thermal/hwmon: Use the thermal_core.h header Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 13/17] thermal/drivers/tegra: Remove unneeded lock when setting a trip point Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 14/17] thermal/tegra: Do not enable the thermal zone, it is already enabled Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 15/17] thermal/drivers/acerhdf: Make interval setting only at module load time Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 16/17] thermal/drivers/acerhdf: Remove pointless governor test Daniel Lezcano
2023-02-19 14:36 ` [PATCH v1 17/17] thermal/traces: Replace the thermal zone structure parameter with the field value Daniel Lezcano
2023-02-19 21:35 ` [PATCH v1 16/17] thermal/drivers/acerhdf: Remove pointless governor test Peter Kästle
2023-02-19 21:38 ` [PATCH v1 15/17] thermal/drivers/acerhdf: Make interval setting only at module load time Peter Kästle
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=20230220171210.GA1606748@roeck-us.net \
--to=linux@roeck-us.net \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
/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).