From: Calvin Owens calvin@wbinvd.org
[ Upstream commit d34fe509f5f76d9dc36291242d67c6528027ebbd ]
Kernels configured with CONFIG_MULTIUSER=n have no cap_get_proc(). Check for ENOSYS to recognize this case, and continue on to attempt to access the requested MSRs (such as temperature).
Signed-off-by: Calvin Owens calvin@wbinvd.org Signed-off-by: Len Brown len.brown@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the following reasons:
## Bug Fix Nature The commit fixes a clear bug where turbostat fails to work on kernels configured with `CONFIG_MULTIUSER=n`. Without this fix, turbostat would incorrectly fail when `cap_get_proc()` returns NULL with `ENOSYS`, preventing users from accessing MSRs (like temperature readings) even when they should be able to.
## Small and Contained Change The fix is minimal - only 9 lines added, 1 line removed. The change is entirely contained within the `check_for_cap_sys_rawio()` function in turbostat.c: - It adds a check for `errno == ENOSYS` when `cap_get_proc()` returns NULL - Returns 0 (success) in this specific case to allow MSR access attempts to proceed - Preserves the original error handling (return 1) for all other failure cases
## No Side Effects or Architectural Changes The change doesn't introduce any new features or architectural modifications. It simply adds proper error handling for a specific configuration scenario that was previously not handled correctly. The logic flow remains the same for all other cases - only the ENOSYS case gets special treatment.
## User Impact This affects real users running embedded or specialized Linux systems with `CONFIG_MULTIUSER=n` (single-user mode kernels). Without this fix, turbostat is completely broken on such systems, unable to read MSRs for temperature monitoring and other power management features.
## Stable Tree Criteria Compliance The fix meets stable kernel criteria: - **Fixes a real bug**: turbostat failure on CONFIG_MULTIUSER=n kernels - **Already upstream**: The commit is in the mainline kernel - **Minimal risk**: The change only affects the specific error case and doesn't alter behavior for normal configurations - **Clear and obvious**: The fix is straightforward - checking for ENOSYS and handling it appropriately
## Tool-Specific Nature Since this is a userspace tool fix (tools/power/x86/turbostat/), it has even lower risk of causing kernel regressions while providing immediate benefit to affected users.
The commit is an ideal candidate for stable backporting as it fixes a specific, reproducible issue with minimal code changes and no risk to systems where `CONFIG_MULTIUSER=y` (the common case).
tools/power/x86/turbostat/turbostat.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 46ee85216373..00fdb6589bea 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -6573,8 +6573,16 @@ int check_for_cap_sys_rawio(void) int ret = 0;
caps = cap_get_proc(); - if (caps == NULL) + if (caps == NULL) { + /* + * CONFIG_MULTIUSER=n kernels have no cap_get_proc() + * Allow them to continue and attempt to access MSRs + */ + if (errno == ENOSYS) + return 0; + return 1; + }
if (cap_get_flag(caps, CAP_SYS_RAWIO, CAP_EFFECTIVE, &cap_flag_value)) { ret = 1;