From: sashiko-bot@kernel.org
To: "Karthik Poosa" <karthik.poosa@intel.com>,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v4 06/10] drm/xe/hwmon: Enable fan curve control support
Date: Tue, 24 Nov 2026 06:02:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-230573@kernel.org> (raw)
In-Reply-To: <20261124054811.798763-7-karthik.poosa@intel.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] drm/xe/hwmon: stale staged state on error in
xe_hwmon_update_user_fan_point()
- [Medium] drm/xe/hwmon: missing is_full_speed check in curve store
callbacks
- [Medium] drm/xe/hwmon: min_pwm clamping bypassed in
xe_hwmon_pwm_auto_point_pwm_store()
- [Medium] drm/xe/hwmon: overflow and post-rounding check in
xe_hwmon_sysfs_to_hw_val()
- [Medium] drm/xe/hwmon: live pcode count vs cache mismatch in curve
show callbacks
- [Low] drm/xe/hwmon: missing ABI documentation update claimed in commit
message
- [Low] drm/xe/hwmon: xe_err() and 0-based indices used in curve store
mode logs
- [Low] drm/xe/hwmon: guard() mixed with goto unlock in curve sysfs
callbacks
--
commit 148c3dbca37416a6517d9d7801eb5f432ec2b872
Author: Karthik Poosa <karthik.poosa@intel.com>
drm/xe/hwmon: Enable fan curve control support
This commit adds hwmon sysfs attributes pwm[1-3]_auto_point[1-10]_temp and
pwm[1-3]_auto_point[1-10]_pwm to stage and commit custom fan control curves
via pcode.
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 59a8521316c2c..77c4d1b0ecaef 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
[ ... ]
> @@ -1337,12 +1423,354 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo
[ ... ]
> +static ssize_t
> +xe_hwmon_pwm_auto_point_temp_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
[ ... ]
> + fi = &hwmon->fi[fan];
> + active_table = xe_hwmon_get_active_fan_table(hwmon, fan);
> +
> + ret = xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, active_table);
> + if (ret)
> + goto unlock;
> +
> + /* Slots beyond the active curve can still be staged for the next curve. */
> + if (point >= point_count &&
> + (active_table != USER_FAN_TABLE ||
> + !(fi->fan_table[USER_FAN_TABLE].temp_staged & BIT(point))))
> + temp = 0;
> + else if (point >= point_count)
> + temp = fi->fan_table[USER_FAN_TABLE].staged_fcp[point].temp;
> + else
> + temp = fi->fan_table[active_table].fcp[point].temp;
> + ret = sysfs_emit(buf, "%u\n", temp * MILLIDEGREE_PER_DEGREE);
[Severity: Medium]
Should xe_hwmon_pwm_auto_point_temp_show() and
xe_hwmon_pwm_auto_point_pwm_show() use the cached
fi->fan_table[active_table].point_count and check temp_staged / speed_staged
before falling back to active fcp[point]?
Querying point_count live from pcode via xe_hwmon_get_fan_point_count() while
reading point values from the software cache can desynchronize the bound from
the cache: if a previous table update or stock table probe failed and reset
cached point_count to 0, pcode can still report a non-zero count and cause
show to read unpopulated or stale fcp[] entries, and if stock point_count
exceeded MAX_FAN_CONTROL_POINTS (which xe_hwmon_read_fan_control_info()
clamps), xe_hwmon_get_fan_point_count() fails with -EINVAL. Also, checking
temp_staged / speed_staged only when point >= point_count means staging a new
value for an existing point (< point_count) still reads back the old active
value until the whole curve is committed.
> +
> +unlock:
> + mutex_unlock(&hwmon->hwmon_lock);
> +
> + return ret;
> +}
> +
> +static int xe_hwmon_update_user_fan_point(struct xe_hwmon *hwmon, u8 fan, u32 point,
> + bool is_temp, u8 value)
> +{
> + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
> + struct fan_table *table;
> + u32 point_count;
> + int ret;
> +
> + table = &fi->fan_table[USER_FAN_TABLE];
> +
> + if (is_temp) {
> + table->staged_fcp[point].temp = value;
> + table->temp_staged |= BIT(point);
> + } else {
> + table->staged_fcp[point].speed = value;
> + table->speed_staged |= BIT(point);
> + }
> +
> + /* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */
> + for (point_count = 0; point_count < MAX_FAN_CONTROL_POINTS; point_count++) {
> + if (!(table->temp_staged & BIT(point_count)) ||
> + !(table->speed_staged & BIT(point_count)))
> + return 0;
> + if (!table->staged_fcp[point_count].temp &&
> + !table->staged_fcp[point_count].speed)
> + break;
> + }
> +
> + if (point_count < MIN_FAN_CONTROL_POINTS) {
> + xe_dbg(hwmon->xe, "fan %d curve needs at least %d points, got %u\n",
> + fan, MIN_FAN_CONTROL_POINTS, point_count);
> + return -EINVAL;
> + }
> +
> + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, table->staged_fcp, point_count);
> + if (ret)
> + return ret;
[Severity: Medium]
When curve validation or xe_hwmon_commit_user_fan_table() fails here, does
leaving table->temp_staged and table->speed_staged set wedge subsequent curve
writes?
Because every bit in the completed prefix remains set in temp_staged and
speed_staged after an error return, the next single-attribute sysfs write
immediately sees a complete prefix and re-runs the commit check with the left
over staged points instead of waiting for both temp and pwm of the new curve
to be staged. In addition, if xe_hwmon_commit_user_fan_table() fails in or
after xe_pcode_write_batch(), pcode's user table may already be partially
overwritten while table->point_count is not invalidated to 0 as in
xe_hwmon_set_user_fan_pwm().
[ ... ]
> +static int xe_hwmon_sysfs_to_hw_val(struct xe_hwmon *hwmon, long val, bool is_temp, u8 *out)
> +{
> + long max = is_temp ? U8_MAX : 100;
> + long hw_val;
> +
> + /* Temperature is in degrees Celsius, speed in percent. */
> + if (is_temp)
> + hw_val = DIV_ROUND_CLOSEST(val, MILLIDEGREE_PER_DEGREE);
> + else
> + hw_val = DIV_ROUND_CLOSEST(val * 100, U8_MAX);
> +
> + if (hw_val < 0 || hw_val > max) {
> + xe_dbg(hwmon->xe, "%s value %ld out of range\n", is_temp ? "temp" : "pwm", val);
> + return -EINVAL;
> + }
[Severity: Medium]
Can validating hw_val after DIV_ROUND_CLOSEST() overflow val * 100 and accept
out-of-range sysfs inputs?
Because val is an arbitrary signed long from kstrtol(), large values overflow
val * 100 or DIV_ROUND_CLOSEST() before the range check and can wrap into
0..max. Checking after rounding also accepts out-of-range inputs near the
boundaries, such as negative temperatures in -499..-1 (which round to 0 and
can trigger the (0, 0) end marker) or pwm values of -1 and 256. Validating
val against 0..U8_MAX * MILLIDEGREE_PER_DEGREE for temperature and 0..U8_MAX
for pwm before converting avoids both issues.
> +
> + *out = hw_val;
> +
> + return 0;
> +}
> +
> +static ssize_t
> +xe_hwmon_pwm_auto_point_temp_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
[ ... ]
> + guard(xe_pm_runtime)(hwmon->xe);
> +
> + mutex_lock(&hwmon->hwmon_lock);
> + fi = &hwmon->fi[fan];
> +
> + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) {
> + xe_err(hwmon->xe, "pwm%d_enable not in manual mode; cannot update temp point %d\n",
> + fan, point);
> + ret = -EINVAL;
> + goto unlock;
> + }
[Severity: Medium]
Does this check allow staging and committing a user fan curve while
pwmN_enable is set to 0 (XE_FAN_PWM_FULL_SPEED)?
When full-speed mode is enabled via xe_hwmon_set_user_fan_pwm(),
fi->pwm_enable_mode is set to XE_FAN_PWM_MANUAL_USER_TABLE with
fi->is_full_speed = true. Because xe_hwmon_pwm_auto_point_temp_store() and
xe_hwmon_pwm_auto_point_pwm_store() do not check !fi->is_full_speed, curve
writes succeed in full-speed mode and silently clear fi->is_full_speed = false
on commit, switching pwmN_enable from 0 to 1.
> +
> + xe_dbg(hwmon->xe, "staging fan %d point %d temp to %u\n", fan, point, temp);
> + ret = xe_hwmon_update_user_fan_point(hwmon, fan, point, true, temp);
> +
> +unlock:
> + mutex_unlock(&hwmon->hwmon_lock);
> +
> + return ret ? ret : count;
> +}
> +
> +static ssize_t
> +xe_hwmon_pwm_auto_point_pwm_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
[ ... ]
> + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point);
> + if (ret)
> + return ret;
> +
> + guard(xe_pm_runtime)(hwmon->xe);
> +
> + mutex_lock(&hwmon->hwmon_lock);
> +
> + fi = &hwmon->fi[fan];
> + active_table = xe_hwmon_get_active_fan_table(hwmon, fan);
> +
> + ret = xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, active_table);
> + if (ret)
> + goto unlock;
[ ... ]
> +unlock:
> + mutex_unlock(&hwmon->hwmon_lock);
> +
> + return ret;
> +}
[Severity: Low]
This isn't a bug, but the four new curve show/store callbacks mix
guard(xe_pm_runtime) with manual mutex_lock(&hwmon->hwmon_lock) and goto
unlock; using guard(mutex)(&hwmon->hwmon_lock) would avoid mixing cleanup
helpers with goto-based unwinding.
> +
> +static ssize_t
> +xe_hwmon_pwm_auto_point_pwm_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
[ ... ]
> + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) {
> + xe_err(hwmon->xe,
> + "pwm%d_enable is not in manual user mode, cannot update pwm point %d\n",
> + fan, point);
> + ret = -EINVAL;
> + goto unlock;
> + }
[Severity: Low]
Should this and the matching check in xe_hwmon_pwm_auto_point_temp_store() use
xe_dbg() and print fan + 1 and point + 1?
Logging at error level lets unprivileged-style invalid mode writes spam dmesg,
and printing the 0-based fan and point indices reports "pwm0_enable" and
"point 0" when writing to pwm1_auto_point1_pwm.
> +
> + /* Speed and min_pwm are in percent; keep zero for the (0, 0) end marker. */
> + if (speed)
> + speed = max_t(u32, speed, min_t(u32, fi->min_pwm, 100));
[Severity: Medium]
Can an active curve point bypass fi->min_pwm when userspace writes a pwm value
of 0 or 1?
Both 0 and 1 convert to speed == 0 in xe_hwmon_sysfs_to_hw_val(), so skipping
the clamp here leaves speed at 0% and xe_hwmon_commit_user_fan_table() writes
0% directly to pcode for active points whose temperature is non-zero. Also,
if a point has temp == 0 and userspace writes pwm == 1, rounding speed to 0
without clamping turns the point into a (0, 0) end-of-curve marker. Clamping
active points (0 .. point_count - 1) to fi->min_pwm at commit time after
identifying the (0, 0) terminator would enforce min_pwm on all active points.
[ ... ]
> +static void xe_hwmon_init_curve_attrs(struct xe_hwmon *hwmon)
> +{
> + int fan, kind, point, i = 0;
> +
> + /* Per fan: all temp points then all pwm points; is_visible relies on this layout. */
> + for (fan = 0; fan < FAN_MAX; fan++) {
> + for (kind = 0; kind < 2; kind++) {
> + bool is_temp = !kind;
> +
> + for (point = 0; point < MAX_FAN_CONTROL_POINTS; point++, i++) {
> + struct sensor_device_attribute *sda = &hwmon->curve_sda[i];
> +
> + snprintf(hwmon->curve_names[i], XE_CURVE_ATTR_NAME_LEN,
> + "pwm%d_auto_point%d_%s", fan + 1, point + 1,
> + is_temp ? "temp" : "pwm");
[Severity: Low]
The commit message states that this patch updates the Xe hwmon ABI
documentation for these attributes, but
Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon is not modified in this
patch. Was the documentation hunk dropped by mistake?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124054811.798763-1-karthik.poosa@intel.com?part=6
next prev parent reply other threads:[~2026-11-24 6:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 5:48 [PATCH v4 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-11-24 5:48 ` [PATCH v4 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-11-27 21:31 ` Purkait, Soham
2026-11-24 5:48 ` [PATCH v4 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-11-25 18:26 ` Rodrigo Vivi
2026-11-24 5:48 ` [PATCH v4 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-11-25 18:29 ` Rodrigo Vivi
2026-11-26 13:48 ` Poosa, Karthik
2026-11-24 5:48 ` [PATCH v4 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-11-24 5:48 ` [PATCH v4 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-11-24 6:01 ` sashiko-bot
2026-11-25 13:26 ` Poosa, Karthik
2026-11-24 5:48 ` [PATCH v4 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-24 6:02 ` sashiko-bot [this message]
2026-11-26 17:05 ` Poosa, Karthik
2026-11-24 5:48 ` [PATCH v4 07/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-11-24 5:53 ` sashiko-bot
2026-11-26 12:33 ` Poosa, Karthik
2026-11-24 5:48 ` [PATCH v4 08/10] drm/xe/hwmon: Preserve fan user table across suspend resume Karthik Poosa
2026-11-24 6:07 ` sashiko-bot
2026-11-26 13:35 ` Poosa, Karthik
2026-11-24 5:48 ` [PATCH v4 09/10] drm/xe/hwmon: Update fan info after late binding Karthik Poosa
2026-11-24 6:11 ` sashiko-bot
2026-11-24 5:48 ` [PATCH v4 10/10] drm/xe/hwmon: Enable fan support for CRI Karthik Poosa
2026-11-25 18:30 ` Rodrigo Vivi
2026-11-24 5:56 ` ✗ CI.KUnit: failure for drm/xe/hwmon: Add fan control support Patchwork
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=sashiko-outbox-230573@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=karthik.poosa@intel.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.