* Re: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
2024-12-07 0:41 ` [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies Sohil Mehta
@ 2024-12-07 8:35 ` Ingo Molnar
2024-12-07 13:14 ` Sohil Mehta
2024-12-07 21:11 ` H. Peter Anvin
2024-12-09 4:18 ` kernel test robot
2 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2024-12-07 8:35 UTC (permalink / raw)
To: Sohil Mehta
Cc: x86, Borislav Petkov, Dave Hansen, Thomas Gleixner, Ingo Molnar,
H . Peter Anvin, Uros Bizjak, Sandipan Das, Sean Christopherson,
Peter Zijlstra, Vegard Nossum, Tony Luck, Pawan Gupta,
Nikolay Borisov, Eric Biggers, Xin Li, Alexander Shishkin,
Kirill Shutemov, linux-kernel
* Sohil Mehta <sohil.mehta@intel.com> wrote:
> Instead of silently disabling features, add a print which might be
> useful to users if their favorite feature gets unexpectedly disabled.
>
> Features are typically represented through unsigned integers though some
> of them have user friendly names if they are exposed via cpuinfo. Show
> the friendlier name if available otherwise display the X86_FEATURE_*
> numerals to make it easier to identify the feature.
>
> Use pr_debug() to avoid spamming the kernel log and generating false
> alarms. Note that the print will occur once per disabled feature on
> every CPU. Show this information only when someone is really looking for
> it.
>
> Suggested-by: Tony Luck <tony.luck@intel.com>
> Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
> ---
> Sent as a separate patch to make it easier to review and drop if it
> feels unnecessary.
>
> I can see both sides of the argument. The pr_debug() serves a
> compromise between the two.
>
> v3: New patch.
>
> ---
> arch/x86/kernel/cpu/cpuid-deps.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
> index 8bea5c5e4fd2..c72f2dd77d72 100644
> --- a/arch/x86/kernel/cpu/cpuid-deps.c
> +++ b/arch/x86/kernel/cpu/cpuid-deps.c
> @@ -147,12 +147,32 @@ void setup_clear_cpu_cap(unsigned int feature)
> do_clear_cpu_cap(NULL, feature);
> }
>
> +/*
> + * Return the feature "name" if available otherwise return
> + * the X86_FEATURE_* numerals to make it easier to identify
> + * the feature.
> + */
> +static const char *x86_feature_name(unsigned int feature, char *buf)
> +{
> + if (x86_cap_flags[feature])
> + return x86_cap_flags[feature];
> +
> + snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
> +
> + return buf;
> +}
> +
> void filter_feature_dependencies(struct cpuinfo_x86 *c)
> {
> + char feature_buf[12], depends_buf[12];
> const struct cpuid_dep *d;
>
> for (d = cpuid_deps; d->feature; d++) {
> - if (cpu_has(c, d->feature) && !cpu_has(c, d->depends))
> + if (cpu_has(c, d->feature) && !cpu_has(c, d->depends)) {
> + pr_debug("x86/cpu: Disabling feature %s since feature %s is missing\n",
> + x86_feature_name(d->feature, feature_buf),
> + x86_feature_name(d->depends, depends_buf));
> do_clear_cpu_cap(c, d->feature);
So why not make this a pr_info() at minimum?
Since this new logic will disable certain feature bits on random
machines, I'm sure there will be some surprises. I'd sure like to see
this printed in the system log of my machine if it happens.
It might also inform firmware & distro testers that something wasn't
set up properly on the firmware (or virtualization) side.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
2024-12-07 8:35 ` Ingo Molnar
@ 2024-12-07 13:14 ` Sohil Mehta
0 siblings, 0 replies; 7+ messages in thread
From: Sohil Mehta @ 2024-12-07 13:14 UTC (permalink / raw)
To: Ingo Molnar
Cc: x86, Borislav Petkov, Dave Hansen, Thomas Gleixner, Ingo Molnar,
H . Peter Anvin, Uros Bizjak, Sandipan Das, Sean Christopherson,
Peter Zijlstra, Vegard Nossum, Tony Luck, Pawan Gupta,
Nikolay Borisov, Eric Biggers, Xin Li, Alexander Shishkin,
Kirill Shutemov, linux-kernel
On 12/7/2024 12:35 AM, Ingo Molnar wrote:
>> void filter_feature_dependencies(struct cpuinfo_x86 *c)
>> {
>> + char feature_buf[12], depends_buf[12];
>> const struct cpuid_dep *d;
>>
>> for (d = cpuid_deps; d->feature; d++) {
>> - if (cpu_has(c, d->feature) && !cpu_has(c, d->depends))
>> + if (cpu_has(c, d->feature) && !cpu_has(c, d->depends)) {
>> + pr_debug("x86/cpu: Disabling feature %s since feature %s is missing\n",
>> + x86_feature_name(d->feature, feature_buf),
>> + x86_feature_name(d->depends, depends_buf));
>> do_clear_cpu_cap(c, d->feature);
>
> So why not make this a pr_info() at minimum?
>
I was hesitant because the feature disabling may be inconsequential to
the end user. Also, the printed numbers would not make sense unless they
have the kernel source handy. But maybe it's better to inform and let
the user decide.
> Since this new logic will disable certain feature bits on random
> machines, I'm sure there will be some surprises. I'd sure like to see
> this printed in the system log of my machine if it happens.
>
Sure, will update the print as follows in the next (hopefully final)
version.
pr_info("CPU%d: Disabling feature %s due to missing feature %s\n",
smp_processor_id(),
x86_feature_name(d->feature, feature_buf),
x86_feature_name(d->depends, depends_buf));
Since it seems almost certain that we are going in this direction will
merge this patch into the previous one and send a combined one next time.
> It might also inform firmware & distro testers that something wasn't
> set up properly on the firmware (or virtualization) side.
>
Sohil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
2024-12-07 0:41 ` [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies Sohil Mehta
2024-12-07 8:35 ` Ingo Molnar
@ 2024-12-07 21:11 ` H. Peter Anvin
2024-12-09 19:28 ` Sohil Mehta
2024-12-09 4:18 ` kernel test robot
2 siblings, 1 reply; 7+ messages in thread
From: H. Peter Anvin @ 2024-12-07 21:11 UTC (permalink / raw)
To: Sohil Mehta, x86, Borislav Petkov, Dave Hansen
Cc: Thomas Gleixner, Ingo Molnar, Uros Bizjak, Sandipan Das,
Sean Christopherson, Peter Zijlstra, Vegard Nossum, Tony Luck,
Pawan Gupta, Nikolay Borisov, Eric Biggers, Xin Li,
Alexander Shishkin, Kirill Shutemov, linux-kernel
On December 6, 2024 4:41:26 PM PST, Sohil Mehta <sohil.mehta@intel.com> wrote:
>Instead of silently disabling features, add a print which might be
>useful to users if their favorite feature gets unexpectedly disabled.
>
>Features are typically represented through unsigned integers though some
>of them have user friendly names if they are exposed via cpuinfo. Show
>the friendlier name if available otherwise display the X86_FEATURE_*
>numerals to make it easier to identify the feature.
>
>Use pr_debug() to avoid spamming the kernel log and generating false
>alarms. Note that the print will occur once per disabled feature on
>every CPU. Show this information only when someone is really looking for
>it.
>
>Suggested-by: Tony Luck <tony.luck@intel.com>
>Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
>---
>Sent as a separate patch to make it easier to review and drop if it
>feels unnecessary.
>
>I can see both sides of the argument. The pr_debug() serves a
>compromise between the two.
>
>v3: New patch.
>
>---
> arch/x86/kernel/cpu/cpuid-deps.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
>diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
>index 8bea5c5e4fd2..c72f2dd77d72 100644
>--- a/arch/x86/kernel/cpu/cpuid-deps.c
>+++ b/arch/x86/kernel/cpu/cpuid-deps.c
>@@ -147,12 +147,32 @@ void setup_clear_cpu_cap(unsigned int feature)
> do_clear_cpu_cap(NULL, feature);
> }
>
>+/*
>+ * Return the feature "name" if available otherwise return
>+ * the X86_FEATURE_* numerals to make it easier to identify
>+ * the feature.
>+ */
>+static const char *x86_feature_name(unsigned int feature, char *buf)
>+{
>+ if (x86_cap_flags[feature])
>+ return x86_cap_flags[feature];
>+
>+ snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
>+
>+ return buf;
>+}
>+
> void filter_feature_dependencies(struct cpuinfo_x86 *c)
> {
>+ char feature_buf[12], depends_buf[12];
> const struct cpuid_dep *d;
>
> for (d = cpuid_deps; d->feature; d++) {
>- if (cpu_has(c, d->feature) && !cpu_has(c, d->depends))
>+ if (cpu_has(c, d->feature) && !cpu_has(c, d->depends)) {
>+ pr_debug("x86/cpu: Disabling feature %s since feature %s is missing\n",
>+ x86_feature_name(d->feature, feature_buf),
>+ x86_feature_name(d->depends, depends_buf));
> do_clear_cpu_cap(c, d->feature);
>+ }
> }
> }
Ok, I realize that the x86 maintainers **very legitimately** don't want more crap in /proc/cpuinfo, but perhaps we could include the strings for printing debug messages in cleartext? Add a bitmap for which entries should go into /proc/cpuinfo.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
2024-12-07 21:11 ` H. Peter Anvin
@ 2024-12-09 19:28 ` Sohil Mehta
0 siblings, 0 replies; 7+ messages in thread
From: Sohil Mehta @ 2024-12-09 19:28 UTC (permalink / raw)
To: H. Peter Anvin, x86, Ahmed S . Darwish
Cc: Thomas Gleixner, Ingo Molnar, Uros Bizjak, Sandipan Das,
Sean Christopherson, Peter Zijlstra, Vegard Nossum, Tony Luck,
Pawan Gupta, Nikolay Borisov, Eric Biggers, Xin Li,
Alexander Shishkin, Kirill Shutemov, linux-kernel,
Borislav Petkov, Dave Hansen
On 12/7/2024 1:11 PM, H. Peter Anvin wrote:
>
> Ok, I realize that the x86 maintainers **very legitimately** don't
> want more crap in /proc/cpuinfo, but perhaps we could include the
> strings for printing debug messages in cleartext? Add a bitmap for
> which entries should go into /proc/cpuinfo.
Could the cpuid-db project be helpful at some point in this regard? It
seems to have a name ("id") for each feature and a tracking of whether
each feature is exposed via cpuinfo and with what name.
> <bit20 len="1" id="cet_ibt" desc="CET indirect branch tracking">
> <linux feature="true" proc="true" altid="ibt" />
> </bit20>
Though I am not sure if it only tracks the hardware originating features
represented in cpuid or the linux defined features as well?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
2024-12-07 0:41 ` [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies Sohil Mehta
2024-12-07 8:35 ` Ingo Molnar
2024-12-07 21:11 ` H. Peter Anvin
@ 2024-12-09 4:18 ` kernel test robot
2 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2024-12-09 4:18 UTC (permalink / raw)
To: Sohil Mehta, x86, Borislav Petkov, Dave Hansen
Cc: oe-kbuild-all, Thomas Gleixner, Ingo Molnar, H . Peter Anvin,
Uros Bizjak, Sohil Mehta, Sandipan Das, Sean Christopherson,
Peter Zijlstra, Vegard Nossum, Tony Luck, Pawan Gupta,
Nikolay Borisov, Eric Biggers, Xin Li, Alexander Shishkin,
Kirill Shutemov, linux-kernel
Hi Sohil,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tip/master]
[also build test WARNING on tip/x86/core tip/auto-latest bp/for-next linus/master v6.13-rc1 next-20241206]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sohil-Mehta/x86-cpufeature-Add-a-debug-print-for-unmet-dependencies/20241207-084543
base: tip/master
patch link: https://lore.kernel.org/r/20241207004126.2054658-2-sohil.mehta%40intel.com
patch subject: [PATCH v3 2/2] x86/cpufeature: Add a debug print for unmet dependencies
config: x86_64-randconfig-103-20241207 (https://download.01.org/0day-ci/archive/20241207/202412071926.MHYBbSb1-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241207/202412071926.MHYBbSb1-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412071926.MHYBbSb1-lkp@intel.com/
All warnings (new ones prefixed by >>):
arch/x86/kernel/cpu/cpuid-deps.c: In function 'filter_feature_dependencies':
>> arch/x86/kernel/cpu/cpuid-deps.c:160:30: warning: '*32+' directive output may be truncated writing 4 bytes into a region of size between 3 and 11 [-Wformat-truncation=]
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~
In function 'x86_feature_name',
inlined from 'x86_feature_name' at arch/x86/kernel/cpu/cpuid-deps.c:155:20,
inlined from 'filter_feature_dependencies' at arch/x86/kernel/cpu/cpuid-deps.c:172:4:
arch/x86/kernel/cpu/cpuid-deps.c:160:27: note: directive argument in the range [0, 31]
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~~~~~~~~
arch/x86/kernel/cpu/cpuid-deps.c:160:9: note: 'snprintf' output between 8 and 16 bytes into a destination of size 12
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/cpuid-deps.c: In function 'filter_feature_dependencies':
>> arch/x86/kernel/cpu/cpuid-deps.c:160:30: warning: '*32+' directive output may be truncated writing 4 bytes into a region of size between 3 and 11 [-Wformat-truncation=]
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~
In function 'x86_feature_name',
inlined from 'x86_feature_name' at arch/x86/kernel/cpu/cpuid-deps.c:155:20,
inlined from 'filter_feature_dependencies' at arch/x86/kernel/cpu/cpuid-deps.c:172:4:
arch/x86/kernel/cpu/cpuid-deps.c:160:27: note: directive argument in the range [0, 31]
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~~~~~~~~
arch/x86/kernel/cpu/cpuid-deps.c:160:9: note: 'snprintf' output between 8 and 16 bytes into a destination of size 12
160 | snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +160 arch/x86/kernel/cpu/cpuid-deps.c
149
150 /*
151 * Return the feature "name" if available otherwise return
152 * the X86_FEATURE_* numerals to make it easier to identify
153 * the feature.
154 */
155 static const char *x86_feature_name(unsigned int feature, char *buf)
156 {
157 if (x86_cap_flags[feature])
158 return x86_cap_flags[feature];
159
> 160 snprintf(buf, 12, "%d*32+%2d", feature / 32, feature % 32);
161
162 return buf;
163 }
164
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread