Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Poosa, Karthik" <karthik.poosa@intel.com>
To: <sashiko-reviews@lists.linux.dev>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe/xe_late_bind_fw: Correct fan count parsing
Date: Fri, 4 Dec 2026 12:22:39 +0530	[thread overview]
Message-ID: <04497039-68ee-4ea5-8e36-e2488de37080@intel.com> (raw)
In-Reply-To: <sashiko-outbox-248231@kernel.org>


On 03-12-2026 22:28, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] drm/xe: inconsistent FSC_READ_NUM_FANS bitmask vs count
>    parsing on Battlemage
> --
>
> commit 133e36e73163f5120eca6f3253d97ab200fe4b2e
> Author: Karthik Poosa <karthik.poosa@intel.com>
>
> drm/xe/xe_late_bind_fw: Correct fan count parsing
>
> This commit updates xe_late_bind_fw_num_fans() to count the set bits returned
> by the FSC_READ_NUM_FANS pcode mailbox command with hweight32(), and zeroes
> *num_fans on read failure.
>
>> diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c
>> index ad39383a7e41f..13516b3a1be34 100644
>> --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
>> +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
>> @@ -226,9 +226,17 @@ static int xe_late_bind_fw_num_fans(struct xe_late_bind *late_bind, u32 *num_fan
>>   {
>>   	struct xe_device *xe = late_bind_to_xe(late_bind);
>>   	struct xe_tile *root_tile = xe_device_get_root_tile(xe);
>> +	int ret = 0;
>>   
>> -	return xe_pcode_read(root_tile,
>> -			     PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0), num_fans, NULL);
>> +	ret = xe_pcode_read(root_tile,
>> +			    PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0), num_fans, NULL);
>> +	if (ret) {
>> +		*num_fans = 0;
>> +		return ret;
>> +	}
>> +	*num_fans = hweight32(*num_fans);
>> +
>> +	return 0;
>>   }
> [Severity: Medium]
> Does xe_hwmon_fan_is_visible() also need to parse FSC_READ_NUM_FANS as a
> bitmask, or does Battlemage pcode still return a count?

It is already parsing as a mask, see next comment below,

BMG also returns a bitmask.

>
> bmg_desc in drivers/gpu/drm/xe/xe_pci.c enables both has_fan_control and
> late_bind_mask = BIT(XE_LB_FW_FAN_CONTROL), so both functions issue
> PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0) on the same hardware,
> while xe_hwmon_fan_is_visible() still treats the reply as an integer count:
>
> drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_fan_is_visible() {
>      ...
> 		if (xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_NUM_FANS, &uval))
> 			return 0;
>
> 		return channel < uval ? 0444 : 0;
>      ...
> }
>
> If FSC_READ_NUM_FANS returns a bitmask on Battlemage, a 2-fan card returning
> 0x3 satisfies channel < 3 and exposes a bogus fan3_input sysfs attribute that
> reads BMG_FAN_3_SPEED for a nonexistent fan.  If Battlemage returns a count
> instead, unconditionally calling hweight32() here miscounts 2 fans as 1.
>
> Either xe_hwmon_fan_is_visible() (and the XE_DG2 override in
> xe_hwmon_pcode_read_fan_control()) should parse FSC_READ_NUM_FANS as a
> bitmask, or the hweight32() conversion should be restricted to platforms where
> pcode returns a bitmask.


Please check with the latest code, recently merged fan control patch 
series treat its as bitmask

272 /* Check if a fan is enabled based on the fan_enable_mask got from 
FSC_READ_NUM_FANS. */
273 #define IS_FAN_ENABLED(hwmon, fan) ((hwmon)->fan_enable_mask & BIT(fan))

1296 static int xe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon)
1297 {
1298         int ret;
1299
1300         /* Platforms that don't return correct value */
1301         if (hwmon->xe->info.platform == XE_DG2) {
1302                 hwmon->fan_enable_mask = GENMASK(1, 0);
1303                 return 0;
1304         }
1305
1306         ret = xe_hwmon_pcode_read_fan_control(hwmon, 
FSC_READ_NUM_FANS, 0,
1307  &hwmon->fan_enable_mask);
1308         if (ret) {
1309                 hwmon->fan_enable_mask = 0;
1310                 xe_warn(hwmon->xe, "failed to read number of fans, 
ret=%d\n", ret);
1311                 return ret;
1312         }
1313
1314         /* Check if fan mask exceeds FAN_MAX and log a warning if 
it does */
1315         if (hwmon->fan_enable_mask & ~GENMASK(FAN_MAX - 1, 0)) {
1316                 xe_warn(hwmon->xe, "Fan enable mask exceeds %d 
supported fans, clamping\n",
1317                         FAN_MAX);
1318                 hwmon->fan_enable_mask &= GENMASK(FAN_MAX - 1, 0);
1319         }
1320
1321         xe_info(hwmon->xe, "Number of fans detected: %u\n", 
hweight32(hwmon->fan_enable_mask));        //treated as bitmask
1322
1323         return 0;
1324 }

2470 static umode_t
2471 xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
2472 {
2473         if (!hwmon->xe->info.has_fan)
2474                 return 0;
2475
2476         switch (attr) {
2477         case hwmon_fan_input:
2478                 return IS_FAN_ENABLED(hwmon, channel) ? 0444 : 0;  
               //visible checks the mask
2479         case hwmon_fan_max:
2480         {
2481                 guard(mutex)(&hwmon->hwmon_lock);
2482                 return IS_FAN_ENABLED(hwmon, channel) && 
hwmon->fi[channel].max_rps ? 0444 : 0;
2483         }
2484         default:
2485                 return 0;
2486         }
2487 }



>

  reply	other threads:[~2026-12-04  6:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:36 [PATCH] drm/xe/xe_late_bind_fw: Correct fan count parsing Karthik Poosa
2026-12-03 16:43 ` ✓ CI.KUnit: success for " Patchwork
2026-12-03 16:58 ` [PATCH] " sashiko-bot
2026-12-04  6:52   ` Poosa, Karthik [this message]
2026-12-03 17:28 ` ✗ Xe.CI.BAT: failure for " 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=04497039-68ee-4ea5-8e36-e2488de37080@intel.com \
    --to=karthik.poosa@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --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