lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0hPDBWZA4zwrnkam=6a5APjviccoEh6gEHEQegpjpnAtA@mail.gmail.com>
Date: Thu, 1 Aug 2024 12:23:51 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Sasha Levin <sashal@...nel.org>
Cc: linux-kernel@...r.kernel.org, stable@...r.kernel.org, 
	"Rafael J. Wysocki" <rafael.j.wysocki@...el.com>, rafael@...nel.org, daniel.lezcano@...aro.org, 
	linux-pm@...r.kernel.org
Subject: Re: [PATCH AUTOSEL 6.10 069/121] thermal: trip: Use READ_ONCE() for
 lockless access to trip properties

On Thu, Aug 1, 2024 at 2:15 AM Sasha Levin <sashal@...nel.org> wrote:
>
> From: "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>
>
> [ Upstream commit a52641bc6293a24f25956a597e7f32148b0e2bb8 ]
>
> When accessing trip temperature and hysteresis without locking, it is
> better to use READ_ONCE() to prevent compiler optimizations possibly
> affecting the read from being applied.
>
> Of course, for the READ_ONCE() to be effective, WRITE_ONCE() needs to
> be used when updating their values.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
> Signed-off-by: Sasha Levin <sashal@...nel.org>

This is more of a matter of annotation than practical issue.  That's
why I haven't even added a Fixes: tag to it.

Whether or not to take it into "stable" is up to you.  It certainly is
low-risk in any case.

> ---
>  drivers/thermal/thermal_sysfs.c | 6 +++---
>  drivers/thermal/thermal_trip.c  | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index 88211ccdfbd62..5be6113e7c80f 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -150,7 +150,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
>         if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
>                 return -EINVAL;
>
> -       return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature);
> +       return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.temperature));
>  }
>
>  static ssize_t
> @@ -174,7 +174,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
>         trip = &tz->trips[trip_id].trip;
>
>         if (hyst != trip->hysteresis) {
> -               trip->hysteresis = hyst;
> +               WRITE_ONCE(trip->hysteresis, hyst);
>
>                 thermal_zone_trip_updated(tz, trip);
>         }
> @@ -194,7 +194,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
>         if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
>                 return -EINVAL;
>
> -       return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis);
> +       return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.hysteresis));
>  }
>
>  static ssize_t
> diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c
> index 49e63db685172..b4e7411b2fe74 100644
> --- a/drivers/thermal/thermal_trip.c
> +++ b/drivers/thermal/thermal_trip.c
> @@ -152,7 +152,7 @@ void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
>         if (trip->temperature == temp)
>                 return;
>
> -       trip->temperature = temp;
> +       WRITE_ONCE(trip->temperature, temp);
>         thermal_notify_tz_trip_change(tz, trip);
>
>         if (temp == THERMAL_TEMP_INVALID) {
> --
> 2.43.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ