From: Srinivas Pandruvada srinivas.pandruvada@linux.intel.com
[ Upstream commit 0115d063559fa6d25e41751cf455dda40aa2c856 ]
The workload hint may contain some other hints which are not defined. So mask out unsupported types. Currently only lower 4 bits of workload type hints are defined.
Signed-off-by: Srinivas Pandruvada srinivas.pandruvada@linux.intel.com Link: https://patch.msgid.link/20250828201541.931425-1-srinivas.pandruvada@linux.i... [ rjw: Subject cleanup ] Signed-off-by: Rafael J. Wysocki rafael.j.wysocki@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
## BACKPORT RECOMMENDATION: **YES**
### Executive Summary This commit should be backported to stable kernel trees. It fixes a real correctness issue in the Intel thermal workload_hint selftest that can cause false "Invalid workload type index" errors when firmware sets undefined upper bits in the workload hint value.
### Detailed Analysis
#### Code Change Analysis The commit adds a single line (`index &= 0x0f;`) at line 147 of `workload_hint_test.c` that masks the workload type index to only the lower 4 bits before validation. This occurs in the main polling loop after reading the workload_type_index from sysfs.
**Location in code flow:** ```c ret = sscanf(index_str, "%d", &index); if (ret < 0) break;
index &= 0x0f; // NEW LINE - masks to lower 4 bits
if (index > WORKLOAD_TYPE_MAX_INDEX) printf("Invalid workload type index\n"); else printf("workload type:%s\n", workload_types[index]); ```
#### Technical Context
1. **Feature Background**: The workload_hint feature was introduced in v6.7 (August 2023) for Intel Meteor Lake and newer processors. The firmware predicts workload type (idle, battery_life, sustained, bursty) and exposes it via MMIO register bits 47:40.
2. **Driver Implementation**: In `processor_thermal_wt_hint.c:73`, the kernel driver extracts the workload hint using: ```c wt = FIELD_GET(SOC_WT, status); // SOC_WT = GENMASK_ULL(47, 40) ``` This extracts all 8 bits (0-255 possible values) and exposes them to userspace via sysfs without any masking.
3. **Specification**: According to the commit message, "Currently only lower 4 bits of workload type hints are defined." This means: - Bits 0-3: Defined workload types (0=idle, 1=battery_life, 2=sustained, 3=bursty) - Bits 4-7: Undefined/reserved (may be used by firmware for future extensions or debugging)
4. **The Bug**: Without the mask, if firmware sets any upper bits (e.g., returns 0x12 = 18): - Test reads index=18 - Check `18 > WORKLOAD_TYPE_MAX_INDEX (3)` triggers - Prints "Invalid workload type index" - **Incorrect behavior**: The actual workload type is 0x12 & 0x0f = 2 (sustained)
5. **With the Fix**: Same scenario with mask: - Test reads index=18 - Masks to `18 & 0x0f = 2` - Check `2 > 3` passes - Prints "workload type:sustained" - **Correct behavior**: Properly identifies the workload type
#### Evidence of Real-World Impact
1. **Platform Expansion**: The feature has been extended to Lunar Lake and Panther Lake processors (commit b59bd75a4b098, December 2024), increasing the likelihood of encountering firmware variations.
2. **Already Selected for Backporting**: The AUTOSEL process has already selected this for stable backporting (commit 61100458645b2, signed by Sasha Levin on Oct 3, 2025), indicating it meets automated stable selection criteria.
3. **Firmware Behavior**: The commit message states "The workload hint may contain some other hints which are not defined," indicating this is based on actual firmware specification knowledge, not theoretical concerns.
#### Stable Kernel Rules Compliance
✅ **Rule 1 - Already in mainline**: Commit 0115d063559fa is in mainline ✅ **Rule 2 - Obviously correct**: Simple bit mask operation, well- understood ✅ **Rule 3 - Size limit**: 2 lines added, well under 100-line limit ✅ **Rule 4 - Fixes real bug**: Prevents incorrect "Invalid" errors for valid firmware values ✅ **Rule 5 - User impact**: Affects selftest correctness, important for validation on stable kernels
#### Risk Assessment
**Risk Level: MINIMAL**
- Single line addition with clear purpose - No changes to kernel driver code (only selftest) - No dependencies on other commits - Cannot cause regressions in kernel functionality - Makes test more robust against firmware variations - Simple bitwise AND operation with well-defined behavior
#### Backporting Priority
**Priority: MEDIUM**
- **Not critical**: Doesn't fix a crash, security issue, or data corruption - **Important for correctness**: Ensures selftest provides accurate validation - **Growing relevance**: As feature extends to more Intel platforms, correct test behavior becomes more important - **Low risk, high value**: Simple fix that improves test reliability
### Recommendation Justification
This commit should be backported because:
1. **Fixes incorrect behavior**: The test currently can produce false "Invalid" errors for legitimate firmware values 2. **Based on specification**: The fix aligns with the documented bit layout (only lower 4 bits defined) 3. **Defensive programming**: Properly handles firmware that sets reserved bits 4. **Active feature**: Being extended to new platforms, making correct testing increasingly important 5. **Already selected**: AUTOSEL has identified this as worthy of backporting 6. **Precedent**: Other selftest fixes are regularly backported to stable kernels 7. **Zero risk**: Cannot introduce regressions in kernel functionality
The fix ensures that users running stable kernels can accurately validate their Intel thermal workload_hint functionality without encountering spurious "Invalid" messages when firmware follows the specification by using all 8 bits while only the lower 4 are currently defined.
.../selftests/thermal/intel/workload_hint/workload_hint_test.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c b/tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c index ba58589a11454..ca2bd03154e4d 100644 --- a/tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c +++ b/tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c @@ -144,6 +144,8 @@ int main(int argc, char **argv) ret = sscanf(index_str, "%d", &index); if (ret < 0) break; + + index &= 0x0f; if (index > WORKLOAD_TYPE_MAX_INDEX) printf("Invalid workload type index\n"); else