mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: <x86@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Uros Bizjak <ubizjak@gmail.com>,
	Sandipan Das <sandipan.das@amd.com>,
	Sean Christopherson <seanjc@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Tony Luck <tony.luck@intel.com>,
	Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	Eric Biggers <ebiggers@google.com>, Xin Li <xin3.li@intel.com>,
	"Alexander Shishkin" <alexander.shishkin@intel.com>,
	Kirill Shutemov <kirill.shutemov@linux.intel.com>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] x86/cpufeature: Warn about unmet feature dependencies
Date: Wed, 12 Mar 2025 16:16:28 -0700	[thread overview]
Message-ID: <ed81aa4e-6ebc-40ad-af45-289cc7138c0f@intel.com> (raw)
In-Reply-To: <Z8resWzgtZaTuzEN@gmail.com>

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.




  reply	other threads:[~2025-03-12 23:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07  0:02 Sohil Mehta
2025-03-07 11:55 ` Ingo Molnar
2025-03-12 23:16   ` Sohil Mehta [this message]
2025-03-13 10:14     ` Ingo Molnar
2025-03-13 16:35       ` Sohil Mehta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed81aa4e-6ebc-40ad-af45-289cc7138c0f@intel.com \
    --to=sohil.mehta@intel.com \
    --cc=alexander.shishkin@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiggers@google.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=sandipan.das@amd.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=ubizjak@gmail.com \
    --cc=vegard.nossum@oracle.com \
    --cc=x86@kernel.org \
    --cc=xin3.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®