Re: [PATCH v5] x86/cpufeature: Warn about unmet feature dependencies

From: Ingo Molnar
Date: Thu Mar 13 2025 - 06:15:04 EST



* Sohil Mehta <sohil.mehta@xxxxxxxxx> wrote:

> On 3/7/2025 3:55 AM, Ingo Molnar wrote:
>
> >>
> >> + /* Scan for unmet dependencies based on the CPUID dependency table */
> >> + scan_feature_dependencies(c);
> >
> > s/scane_feature_dependencies
> > /x86_check_cpufeature_deps
> >
>
> How about check_cpufeature_deps() without the "x86" prefix? It would
> blend in with the other function calls in early_identify_cpu() and
> identify_cpu().

Yeah, I suppose that would work too. There's no discernible rhyme and
reason to the naming choices within the interfaces used by
arch/x86/kernel/cpu/common.c that I can see, so I suppose the shorter
one that is still unambiguous wins.

> >> + */
> >> +static const char *x86_feature_name(unsigned int feature, char *buf)
> >> +{
> >> + if (x86_cap_flags[feature])
> >> + return x86_cap_flags[feature];
> >> +
> >> + snprintf(buf, 16, "%d*32+%2d", feature / 32, feature % 32);
> >> +
> >> + return buf;
> >> +}
> >> +
>
> I was wondering if it would be better to build the feature name using
> a macro and reusing it elsewhere? This is all I could come up with:
>
> /*
> * Use with a %s format specifier to print the feature name.
> *
> * Return the feature "name" if set, otherwise return the X86_FEATURE_*
> * numerals to make it easier to identify the feature.
> */
> #define x86_feature_name(feature) \
> (x86_cap_flags[feature] ? x86_cap_flags[feature] : \
> ({ \
> char buf[16]; \
> snprintf(buf, 16, "%d*32+%2d", feature >> 5, feature & 31); \
> buf; \
> }) \
> )

I'm not sure this is an improvement.

> This would remove the need for callers to explicitly define a buffer.
> Also, it would help reduce a few lines in the newly merged
> parse_set_clear_cpuid(). But overall, it doesn't seem worth it. Let
> me know if you think otherwise or have a better idea.

No good ideas right now.

> > I'd make this a bit less passive-aggressive, something like:
> >
> > x86 CPU feature dependency check failure: CPU%d has '%s' enabled but '%s' disabled. Kernel might be fine, but no guarantees.
> >
>
> Sure! How about making it slightly shorter?
>
> "x86 CPU feature check: CPU%d has '%s' enabled but '%s' disabled. Kernel
> might be fine, but no guarantees."

Yeah, so I really wanted to sneak in the 'dependency' part - because
it's not necessarily obvious from the text, and most syslog readers
will have no idea what it's all about.

I don't think line length should be an issue for a message we don't
expect to trigger normally. Clarity is more important.

Thanks,

Ingo