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 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
Date: Tue, 24 Nov 2026 06:01:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-230572@kernel.org> (raw)
In-Reply-To: <20261124054811.798763-6-karthik.poosa@intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/xe/hwmon: mode 0 sets manual mode in
  xe_hwmon_set_user_fan_pwm()
- [Medium] drm/xe/hwmon: xe_hwmon_set_user_fan_pwm() clobbers user table
  in mode 0
- [Medium] drm/xe/hwmon: uninitialized pwm_enable_mode on stock table
  read failure
--

commit 2c87d5a2e63abba6144fe6efb9070eacc54a6cbc
Author: Karthik Poosa <karthik.poosa@intel.com>

drm/xe/hwmon: Expose pwm[1-3]_enable

This commit exposes the pwm[1-3]_enable sysfs attributes to select between
full-speed mode (0), manual user-table control (1), and firmware stock-table
control (2).

> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index c053d597f26c5..59a8521316c2c 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c

[ ... ]

> @@ -1190,10 +1208,80 @@ static int xe_hwmon_get_fan_point_count(struct xe_hwmon *hwmon, u8 fan, u32 *poi
>  /* Temperature to set when setting the fan PWM with pwmN. */
>  #define FIXED_PWM_TEMP	1
>  
> -static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm)
> +static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, bool full_speed)
>  {
>  	struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
>  	struct xe_pcode_write writes[MIN_FAN_CONTROL_POINTS + 1];
> @@ -1201,6 +1289,11 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm)
>  	u8 speed;
>  	int ret, i;
>  
> +	if (!full_speed && fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) {
> +		xe_dbg(hwmon->xe, "fan %d manual mode is not active, cannot set pwm\n", fan);
> +		return -EINVAL;
> +	}

[ ... ]

> @@ -1245,6 +1338,8 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm)
>  	}
>  	fi->fan_table[USER_FAN_TABLE].point_count = MIN_FAN_CONTROL_POINTS;
>  
> +	fi->pwm_enable_mode = XE_FAN_PWM_MANUAL_USER_TABLE;
> +	fi->is_full_speed = full_speed;
>  	return 0;
>  }

[Severity: Medium]
When full_speed is true (writing 0 to pwm[1-3]_enable), should
xe_hwmon_set_user_fan_pwm() set fi->pwm_enable_mode to
XE_FAN_PWM_FULL_SPEED instead of XE_FAN_PWM_MANUAL_USER_TABLE?

Because fi->pwm_enable_mode is set to XE_FAN_PWM_MANUAL_USER_TABLE (1),
reading pwm[1-3]_enable in this commit returns 1 right after writing 0
(until later commit "drm/xe/hwmon: Enable fan curve control support" checks
fi->is_full_speed in xe_hwmon_pwm_read()).  In addition, subsequent writes
to pwm[1-3] while in mode 0 pass the fi->pwm_enable_mode !=
XE_FAN_PWM_MANUAL_USER_TABLE check above and drop the fan out of full-speed
mode instead of failing with -EINVAL as documented in the ABI.

> @@ -1320,6 +1415,9 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)
>  		if (!fi->fan_table[STOCK_FAN_TABLE].point_count)
>  			continue;
>  
> +		/* Set PWM enable mode to automatic i.e stock table in use. */
> +		fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE;
> +

[Severity: Medium]
If reading the stock fan table fails or returns 0 points in
xe_hwmon_read_fan_control_info(), does the early continue leave
fi->pwm_enable_mode zero-initialized to XE_FAN_PWM_FULL_SPEED (0)?

Because xe_hwmon_pwm_is_visible() only checks has_fan_control and
IS_FAN_ENABLED(), pwm[1-3]_enable is still exposed and reports mode 0
(full speed) even though the fan is under default firmware control, while
later commit "drm/xe/hwmon: Update fan info after late binding" only
initializes fi->pwm_enable_mode for newly enabled fan bits.

[ ... ]

> @@ -1984,7 +2090,53 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val)
>  			ret = -EINVAL;
>  			break;
>  		}
> -		ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val);
> +		ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val, false);
> +		break;
> +	case hwmon_pwm_enable:
> +		if (val == XE_FAN_PWM_FULL_SPEED) {
> +			ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, U8_MAX, true);
> +			if (ret) {
> +				xe_warn(hwmon->xe,
> +					"full speed enable for fan %d failed, ret=%d\n",
> +					channel, ret);
> +				break;
> +			}
> +		} else if (val == XE_FAN_PWM_MANUAL_USER_TABLE) {
> +			enum fan_table_type source = fi->fan_table[USER_FAN_TABLE].point_count ?
> +				USER_FAN_TABLE : STOCK_FAN_TABLE;
> +
> +			/*
> +			 * Manual fan speed control using user fan table.
> +			 * If user fan table is not programmed, it would be initialized with
> +			 * clamped stock points which allows manual control with some
> +			 * default points.
> +			 */
> +			ret = xe_hwmon_activate_user_fan_table(hwmon, channel, false, source);

[Severity: Medium]
Does enabling XE_FAN_PWM_FULL_SPEED via xe_hwmon_set_user_fan_pwm() clobber
fi->fan_table[USER_FAN_TABLE] with a 2-point 100% table?

When the user later writes 1 (XE_FAN_PWM_MANUAL_USER_TABLE) to
pwm[1-3]_enable, fi->fan_table[USER_FAN_TABLE].point_count is non-zero
(MIN_FAN_CONTROL_POINTS from mode 0), so xe_hwmon_pwm_write() selects
USER_FAN_TABLE and keeps the 2-point 100% full-speed table active instead
of initializing from STOCK_FAN_TABLE or restoring a prior user table.

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

  reply	other threads:[~2026-11-24  6:01 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 [this message]
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
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-230572@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