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 v5 07/10] drm/xe/hwmon: Restore fan user tables after resume
Date: Sat, 28 Nov 2026 06:15:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-238489@kernel.org> (raw)
In-Reply-To: <20261128055923.3316956-8-karthik.poosa@intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/xe: synchronous flush_work() in xe_late_bind_pm_resume()
  deadlocks resume
- [Medium] drm/xe/hwmon: xe_hwmon_resume() clears staged fan curve
  points on resume
- [Low] drm/xe/hwmon: duplicate xe_hwmon_fan_set_auto() fallback in
  xe_hwmon_resume()
--

commit 487a525936d402c4983c294401d28e7b960944fa
Author: Karthik Poosa <karthik.poosa@intel.com>

drm/xe/hwmon: Restore fan user tables after resume

This commit saves active manual and full-speed fan tables before system
suspend, runtime D3cold suspend, and FLR, and restores them on resume
after waiting for late-bound fan-control firmware to reload.

> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 4d6eb6f6fbc2f..76c2b519a21f7 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c

[ ... ]

> +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() here discard any
in-progress staged fan curve points across suspend and resume?

Each write to pwmN_auto_pointM_temp or pwmN_auto_pointM_pwm holds a
runtime PM reference only for that single sysfs write while recording
progress in temp_staged and speed_staged.  If the device enters runtime
D3cold (or system suspend) between sysfs writes while a user fan table is
already active, xe_hwmon_resume() calls xe_hwmon_activate_user_fan_table(),
which unconditionally clears both staged bitmasks:

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

Later sysfs writes to finish the curve then see missing prefix bits in
xe_hwmon_update_user_fan_point() and silently fail to commit the new
curve.

> +		if (ret) {
> +			xe_warn(xe, "failed to restore fan %d user table after resume, ret=%d\n",
> +				fan, ret);
> +			fi->fan_table[USER_FAN_TABLE].point_count = 0;
> +			fi->restore_user_table = false;
> +			ret = xe_hwmon_fan_set_auto(hwmon, fan);
> +			if (ret) {
> +				xe_warn(xe, "fan %d stock fallback failed, state unconfirmed, ret=%d\n",
> +					fan, ret);
> +				continue;
> +			}
> +			continue;
> +		}

[Severity: Low]
Does this error path duplicate the stock fallback that
xe_hwmon_activate_user_fan_table() already performs?

xe_hwmon_suspend() only sets restore_user_table when point_count is
within bounds, so xe_hwmon_activate_user_fan_table() only fails here if
writing or verifying the table fails, in which case it has already cleared
point_count and called xe_hwmon_fan_set_auto(hwmon, fan) before returning.

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c
> index ad39383a7e41f..c577e2d516200 100644
> --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
> +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
> @@ -517,10 +517,17 @@ void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind)
>   */
>  void xe_late_bind_pm_resume(struct xe_late_bind *late_bind)
>  {
> +	struct xe_late_bind_fw *fan_control_fw;
> +	bool fan_control_fw_pending;
> +
>  	if (!late_bind->component_added || late_bind->disable)
>  		return;
>  
> +	fan_control_fw = &late_bind->late_bind_fw[XE_LB_FW_FAN_CONTROL];
> +	fan_control_fw_pending = !!fan_control_fw->payload;
>  	xe_late_bind_fw_load(late_bind);
> +	if (fan_control_fw_pending)
> +		flush_work(&fan_control_fw->work);
>  }

[Severity: High]
Does flushing fan_control_fw->work inside xe_late_bind_pm_resume()
deadlock against the child MEI auxiliary device during both system resume
and runtime D3cold resume, ultimately timing out and freeing
fan_control_fw->payload?

On platforms such as Battlemage, heci_gsc_add_device() registers the
xe.mei-gscfi auxiliary device with aux_dev->dev.parent = &pdev->dev.
During system suspend, mei_gsc_pm_suspend() stops the MEI bus and unbinds
the late-bind component, clearing late_bind->component.ops = NULL.  During
system resume, the PM core runs the parent xe_device_resume() callback
before the child aux_dev->dev is allowed to resume:

PM resume context                 kworker (late_bind->wq)
xe_device_resume()
  xe_late_bind_pm_resume()
    xe_late_bind_fw_load()
      queue_work(..., &lbfw->work)
    flush_work(&fan_control_fw->work)
                                  xe_late_bind_work()
                                    /* waits up to 20s for component.ops */
                                    while (!late_bind->component.ops)
                                      msleep(100);
                                    /* mei_gsc_pm_resume() blocked on parent */
                                    drmm_kfree(..., lbfw->payload);
                                    lbfw->payload = NULL;  <-- firmware lost

Runtime resume from D3cold hits a similar dependency cycle:
xe_pm_runtime_resume() runs while pdev->dev.power.runtime_status is
RPM_RESUMING and blocks in flush_work(&fan_control_fw->work).
xe_late_bind_work() calls push_payload() -> mei_lb_push_payload() ->
mei_cldev_enable() -> mei_cl_connect(), which calls
pm_runtime_get(&aux_dev->dev) and waits 15 seconds for
mei_gsc_pm_runtime_resume(), while pm_wq cannot runtime-resume
aux_dev->dev until its parent pdev->dev finishes RPM_RESUMING.

In both paths, resume stalls for 15 to 20 seconds, xe_late_bind_work()
permanently frees fan_control_fw->payload until reboot, and
xe_hwmon_resume() runs without the fan-control firmware loaded.

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

  reply	other threads:[~2026-11-28  6:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  5:59 [PATCH v5 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-11-28  5:59 ` [PATCH v5 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-11-28  5:59 ` [PATCH v5 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-11-28  5:59 ` [PATCH v5 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-11-28  6:04   ` sashiko-bot
2026-11-28  5:59 ` [PATCH v5 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-11-28  5:59 ` [PATCH v5 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-11-28  6:13   ` sashiko-bot
2026-11-28  5:59 ` [PATCH v5 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-28  6:10   ` sashiko-bot
2026-11-28  5:59 ` [PATCH v5 07/10] drm/xe/hwmon: Restore fan user tables after resume Karthik Poosa
2026-11-28  6:15   ` sashiko-bot [this message]
2026-11-28  5:59 ` [PATCH v5 08/10] drm/xe/hwmon: Refresh fan data after late binding Karthik Poosa
2026-11-28  6:27   ` sashiko-bot
2026-11-28  5:59 ` [PATCH v5 09/10] drm/xe: Expose tjmax_fan_control_enable device sysfs Karthik Poosa
2026-11-28  6:12   ` sashiko-bot
2026-11-28  5:59 ` [PATCH v5 10/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-11-28  6:14 ` ✗ CI.KUnit: failure for drm/xe/hwmon: Add fan control support (rev2) 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-238489@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