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

From: Sohil Mehta
Date: Wed Mar 12 2025 - 19:17:21 EST


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().

>
>> + */
>> +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; \
}) \
)


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.

>> +void scan_feature_dependencies(struct cpuinfo_x86 *c)
>> +{
>> + char feature_buf[16], depends_buf[16];
>> + const struct cpuid_dep *d;
>> +
>> + for (d = cpuid_deps; d->feature; d++) {
>> + if (cpu_has(c, d->feature) && !cpu_has(c, d->depends)) {
>> + /*
>> + * Only warn about the first unmet dependency on the
>> + * first CPU where it is encountered to avoid spamming
>> + * the kernel log.
>> + */
>> + pr_warn_once("CPU%d: feature:%s may not work properly without feature:%s\n",
>> + smp_processor_id(),
>> + x86_feature_name(d->feature, feature_buf),
>> + x86_feature_name(d->depends, depends_buf));
>
> 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."

> Because initially most of these warnings will be about quirks and
> oddities that happen to work fine in the current code.
>

Yeah, we can probably modify the check later based on how it goes.