[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aE-hNs1bWTbqE6ih@mozart.vkv.me>
Date: Sun, 15 Jun 2025 21:44:38 -0700
From: Calvin Owens <calvin@...nvd.org>
To: "Zhang, Rui" <rui.zhang@...el.com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
"lenb@...nel.org" <lenb@...nel.org>
Subject: Re: [PATCH] tools/power turbostat: Fix MSRs with CONFIG_MULTIUSER=n
On Sunday 06/15 at 21:38 -0700, Calvin Owens wrote:
> On Monday 06/16 at 01:30 +0000, Zhang, Rui wrote:
> > On Fri, 2025-06-13 at 19:20 -0700, Calvin Owens wrote:
> > > Handle ENOSYS from cap_get_proc() in check_for_cap_sys_rawio(), so
> > > turbostat can display temperatures when running on kernels compiled
> > > without multiuser support.
> > >
> > > Signed-off-by: Calvin Owens <calvin@...nvd.org>
> > > ---
> > > tools/power/x86/turbostat/turbostat.c | 7 ++++++-
> > > 1 file changed, 6 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/power/x86/turbostat/turbostat.c
> > > b/tools/power/x86/turbostat/turbostat.c
> > > index 925556b90770..f7d665913a52 100644
> > > --- a/tools/power/x86/turbostat/turbostat.c
> > > +++ b/tools/power/x86/turbostat/turbostat.c
> > > @@ -6496,8 +6496,13 @@ int check_for_cap_sys_rawio(void)
> > > int ret = 0;
> > >
> > > caps = cap_get_proc();
> > > - if (caps == NULL)
> > > + if (caps == NULL) {
> > > + /* Support CONFIG_MULTIUSER=n */
> > > + if (errno == ENOSYS)
> >
> > Can you point me where this knowledge comes from?
> >
> > I downloaded the libcap source and didn't see how ENOSYS is set.
>
> Hi Rui,
>
> When the kernel is built without multiuser support, the capget() et al.
> syscalls are #ifdef'd out:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/capability.c#n32
>
> ...so userspace will get -ENOSYS when it tries to call them, and that
> ends up being propagated to errno in userspace.
Sorry, what I meant was: the kernel syscall returns -ENOSYS to
userspace, and the syscall() wrapper (in userspace) assigns the positive
error value to errno, where it remains after cap_get_proc() returns.
> Admittedly it is sort of implicit. Maybe a better way to "fix" this
> would be to warn the user if the capability check fails, but still
> attempt to access the MSR devices? I can do that if you prefer.
>
> That is my only problem here: when check_for_cap_sys_rawio() fails, the
> current code doesn't attempt to access the MSR devices at all, even
> though in my case it would actually work.
>
> I realize this is very weird: it came up when I was recently including
> turbostat as part of an extremely tiny bootable utility image.
>
> Thanks,
> Calvin
>
> > thanks,
> > rui
> > > + return 0;
> > > +
> > > return 1;
> > > + }
> > >
> > > if (cap_get_flag(caps, CAP_SYS_RAWIO, CAP_EFFECTIVE,
> > > &cap_flag_value)) {
> > > ret = 1;
> >
Powered by blists - more mailing lists