Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karthik Poosa" <karthik.poosa@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v4 08/10] drm/xe/hwmon: Preserve fan user table across suspend resume
Date: Tue, 24 Nov 2026 06:07:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-230575@kernel.org> (raw)
In-Reply-To: <20261124054811.798763-9-karthik.poosa@intel.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] drm/xe/hwmon: xe_hwmon_resume() clears staged fan curve
  points
- [Medium] drm/xe/hwmon: fan mode desync on PCODE error in
  suspend/resume
- [Medium] drm/xe/hwmon: xe_hwmon_suspend() treats unprobed fan mode as
  user table
- [Medium] drm/xe/hwmon: uninitialized point_count in
  xe_hwmon_get_fan_point_count()
--

commit 5afbb369b25a32407c56f7ca0be622b0b78f35d5
Author: Karthik Poosa <karthik.poosa@intel.com>

drm/xe/hwmon: Preserve fan user table across suspend resume

This commit adds xe_hwmon_suspend() and xe_hwmon_resume() hooks to save
active fan user tables before suspend or FLR and restore them on resume.

> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index b9e2e76d73c33..8efb5d2ce9ac2 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
[ ... ]
> @@ -2898,4 +2900,137 @@ void xe_hwmon_unregister(struct xe_device *xe)
>  	hwmon_device_unregister(xe->hwmon->hwmon_dev);
>  	xe->hwmon = NULL;
>  }
> +
> +/**
> + * xe_hwmon_suspend - Save hwmon state before suspend
> + * @xe: xe device instance
> + * @runtime: true for runtime suspend, false for system suspend or FLR prepare
> + *
> + * Save any hwmon runtime state that must survive PM suspend transitions.
> + */
> +void xe_hwmon_suspend(struct xe_device *xe, bool runtime)
> +{
> +	struct xe_hwmon *hwmon = xe->hwmon;
> +	struct xe_tile *root_tile;
> +	int fan;
> +
> +	if (!hwmon || !xe->info.has_fan_control)
> +		return;
> +
> +	/* Runtime suspend keeps the fan tables unless the device enters d3cold. */
> +	if (runtime && !xe->d3cold.allowed) {
> +		xe_dbg(xe, "d3cold not allowed, skipping fan user-table snapshot\n");
> +		return;
> +	}
> +
> +	root_tile = xe_device_get_root_tile(hwmon->xe);
> +
> +	mutex_lock(&hwmon->hwmon_lock);
> +
> +	for (fan = 0; fan < FAN_MAX; fan++) {
> +		struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
> +		struct fan_control_point points[MAX_FAN_CONTROL_POINTS];
> +		u32 point_count = 0;
> +		u32 point;
> +		int ret;
> +
> +		if (!IS_FAN_ENABLED(hwmon, fan))
> +			continue;
> +
> +		fi->restore_user_table = false;
> +		if (fi->pwm_enable_mode == XE_FAN_PWM_AUTO_STOCK_TABLE)
> +			continue;

[Severity: Medium]
Can this treat an uninitialized fi->pwm_enable_mode as an active user fan
table?

Because struct xe_hwmon is zero-allocated, fi->pwm_enable_mode starts at 0
(XE_FAN_PWM_FULL_SPEED) and is only set to XE_FAN_PWM_AUTO_STOCK_TABLE in
xe_hwmon_read_fan_control_info() after reading the stock fan table from
PCODE succeeds.  On platforms like DG2 (which sets fan_enable_mask =
GENMASK(1, 0) for tachometer reads without PCODE fan tables) or when stock
table initialization fails at probe, fi->pwm_enable_mode stays 0 while
IS_FAN_ENABLED(hwmon, fan) is true.  Since every path that activates a user
table sets fi->pwm_enable_mode to XE_FAN_PWM_MANUAL_USER_TABLE, checking
only for equality with XE_FAN_PWM_AUTO_STOCK_TABLE causes
xe_hwmon_suspend() to issue failing PCODE reads and log warnings on every
suspend.

Checking fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE would skip
fans that have no active user table.

> +
> +		ret = xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, USER_FAN_TABLE);
> +		if (ret || point_count < MIN_FAN_CONTROL_POINTS) {
> +			xe_warn(hwmon->xe,
> +				"fan %d user table point count before suspend invalid, ret=%d, count=%u\n",
> +				fan, ret, point_count);
> +			continue;
> +		}
> +
> +		for (point = 0; point < point_count; point++) {
> +			u32 fcp = FCP_INDEX(USER_FAN_TABLE, point);
> +
> +			ret = xe_pcode_read(root_tile, PCODE_MBOX(FAN_SPEED_CONTROL,
> +								  FSC_READ_FAN_TABLE, fan),
> +					    &fcp, NULL);
> +			if (ret) {
> +				xe_warn(hwmon->xe,
> +					"failed to read fan %d user table point %u before suspend, ret=%d\n",
> +					fan, point, ret);
> +				break;
> +			}
> +
> +			points[point].temp =
> +				REG_FIELD_GET(FAN_CONTROL_POINT_TEMP_MASK, fcp);
> +			points[point].speed =
> +				REG_FIELD_GET(FAN_CONTROL_POINT_SPEED_MASK, fcp);
> +		}
> +		if (ret)
> +			continue;
> +
> +		memcpy(fi->fan_table[USER_FAN_TABLE].fcp, points,
> +		       point_count * sizeof(points[0]));
> +		fi->fan_table[USER_FAN_TABLE].point_count = point_count;
> +		fi->restore_user_table = true;

[Severity: Medium]
Does xe_hwmon_suspend() need to re-read the user table from PCODE when
fi->fan_table[USER_FAN_TABLE] is already cached by every path that commits
or activates a user table?

xe_device_suspend() also runs during PCIe FLR prepare via
xe_pci_reset_prepare(), when hardware state may be corrupted and PCODE
mailbox reads can fail.  Because fi->restore_user_table is cleared to false
before the PCODE reads, a mailbox error during suspend or FLR prepare skips
restoring the already-cached user table on resume.  When either this
pre-suspend read or xe_hwmon_activate_user_fan_table() in xe_hwmon_resume()
fails, hardware falls back to the stock fan table after reset while
fi->pwm_enable_mode remains XE_FAN_PWM_MANUAL_USER_TABLE and
fi->is_full_speed remains set, leaving sysfs out of sync with the hardware.

[ ... ]
> +void xe_hwmon_resume(struct xe_device *xe, bool runtime)
> +{
> +	struct xe_hwmon *hwmon = xe->hwmon;
> +	int fan;
> +
> +	if (!hwmon || !xe->info.has_fan_control)
> +		return;
> +
> +	if (runtime && !xe->d3cold.allowed) {
> +		xe_dbg(xe, "d3cold not allowed, skipping fan user-table restore\n");
> +		return;
> +	}
> +
> +	mutex_lock(&hwmon->hwmon_lock);
> +
> +	for (fan = 0; fan < FAN_MAX; fan++) {
> +		struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
> +		int ret;
> +
> +		if (!IS_FAN_ENABLED(hwmon, fan))
> +			continue;
> +
> +		if (!fi->restore_user_table) {
> +			xe_dbg(xe, "fan %d user table restore not required\n", fan);
> +			continue;
> +		}
> +
> +		/* Re-program cached user-table settings for fans active before suspend. */
> +		ret = xe_hwmon_activate_user_fan_table(hwmon, fan,
> +						       fi->is_full_speed,
> +						       USER_FAN_TABLE);

[Severity: Medium]
Does calling xe_hwmon_activate_user_fan_table() on resume discard fan curve
points that userspace is in the middle of staging?

drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_activate_user_fan_table() {
    ...
	fi->fan_table[USER_FAN_TABLE].point_count = point_count;
	fi->fan_table[USER_FAN_TABLE].temp_staged = 0;
	fi->fan_table[USER_FAN_TABLE].speed_staged = 0;
    ...
}

Each sysfs write in xe_hwmon_pwm_auto_point_temp_store() and
xe_hwmon_pwm_auto_point_pwm_store() only holds a runtime PM reference for
that single attribute write while staging a multi-point curve in
Manual/User mode.  If the device enters D3cold runtime suspend or system
suspend between point writes, xe_hwmon_resume() zeroes temp_staged and
speed_staged, so subsequent writes to finish the curve see missing prefix
bits in xe_hwmon_update_user_fan_point() and return 0 without committing
the curve.

> +		if (ret) {
> +			xe_warn(xe, "failed to restore fan %d user table after resume, ret=%d\n",
> +				fan, ret);
> +			continue;
> +		}

[Severity: Medium]
Does xe_hwmon_get_fan_point_count() pass uninitialized or non-zero values
in *point_count into PCODE_DATA0?

__pcode_mailbox_rw() writes *data0 to PCODE_DATA0 before issuing the
mailbox read command, but xe_hwmon_get_fan_point_count() passes point_count
straight to xe_hwmon_pcode_read_fan_control() without initializing
*point_count = 0.  In xe_hwmon_activate_user_fan_table() (called here on
resume), point_count holds source_table->point_count rather than 0, and in
xe_hwmon_pwm_auto_point_temp_show() and xe_hwmon_pwm_auto_point_pwm_show(),
point_count is an uninitialized stack variable whose contents are written to
PCODE_DATA0.

Initializing *point_count = 0 at the start of
xe_hwmon_get_fan_point_count() would avoid passing stale or uninitialized
data to PCODE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124054811.798763-1-karthik.poosa@intel.com?part=8

  reply	other threads:[~2026-11-24  6:07 UTC|newest]

Thread overview: 17+ 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-24  5:48 ` [PATCH v4 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-11-24  5:48 ` [PATCH v4 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
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-24  5:48 ` [PATCH v4 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-24  6:02   ` sashiko-bot
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-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 [this message]
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-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-230575@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox