The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: Maciej Wieczor-Retman <m.wieczorretman@pm.me>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v9 2/3] x86/cpu: Check if feature string is non-zero
Date: Tue, 10 Mar 2026 15:35:51 -0700	[thread overview]
Message-ID: <e061d22b-90ad-4775-a22e-3caa2e40f2bf@intel.com> (raw)
In-Reply-To: <6443812f9a8a43986f37341d0db5074a2019e80a.1773165421.git.m.wieczorretman@pm.me>

On 3/10/2026 11:03 AM, Maciej Wieczor-Retman wrote:
> From: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
> 
> In filter_cpuid_features, x86_cap_flags[] is read, but it's not verified

filter_cpuid_features()

> whether the string is non-zero which could lead to unwanted output.
> 
> In two more places there are open coded paths that try to retrieve a
> feature string, and if there isn't one, the feature word and bit are
> returned instead. 

How about wording the next sentence as:

Add a common helper to fix filter_cpuid_features() as well as clean up
the open coded cases.

> While correcting filter_cpuid_features() with a helper
> it's trivial to also clean up these open coded cases.
> 
> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
> ---

> diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
> index ad235dda1ded..93e8ad2786bf 100644
> --- a/arch/x86/include/asm/cpu.h
> +++ b/arch/x86/include/asm/cpu.h
> @@ -9,6 +9,8 @@
>  #include <linux/percpu.h>
>  #include <asm/ibt.h>
>  
> +#define X86_CAP_BUF_SIZE			16
> +
>  #ifndef CONFIG_SMP
>  #define cpu_physical_id(cpu)			boot_cpu_physical_apicid
>  #define cpu_acpi_id(cpu)			0
> @@ -67,4 +69,6 @@ int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type);
>  
>  extern struct cpumask cpus_stop_mask;
>  
> +const char *x86_cap_name(unsigned int bit, char *buf);
> +

These declarations - X86_CAP_BUF_SIZE and x86_cap_name() are better
suited to asm/cpufeature.h instead of asm/cpu.h.


Also, it would make more sense to have the #define closer to the
function declaration. Maybe, right above it?


>  #endif /* _ASM_X86_CPU_H */

...

>  
> +/*
> + * Return the feature "name" if available, otherwise return the
> + * X86_FEATURE_* numerals to make it easier to identify the feature.
> + */

Should we add a sentence here to say that all callers must pass a buffer
of size X86_CAP_BUF_SIZE.

> +const char *x86_cap_name(unsigned int bit, char *buf)
> +{
> +	unsigned int word = bit >> 5;
> +	const char *name = NULL;
> +
> +	if (likely(word < NCAPINTS))
> +		name = x86_cap_flags[bit];
> +	else if (likely(word < NCAPINTS + NBUGINTS))
> +		name = x86_bug_flags[bit - 32 * NCAPINTS];
> +

Can we get rid of the two likely() annotations here? Is x86_cap_name()
called from any performance critical path?

> +	if (name)
> +		return name;
> +
> +	snprintf(buf, X86_CAP_BUF_SIZE, "%u:%u", word, bit & 31);
> +	return buf;
> +}
> +
>  /*
>   * This does the hard work of actually picking apart the CPU stuff...
>   */

  reply	other threads:[~2026-03-10 22:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 18:01 [PATCH v9 0/3] x86: Capability bits fix and required bits sanity check Maciej Wieczor-Retman
2026-03-10 18:03 ` [PATCH v9 1/3] x86/cpu: Clear feature bits disabled at compile-time Maciej Wieczor-Retman
2026-03-10 22:00   ` Sohil Mehta
2026-03-11 13:16     ` Maciej Wieczor-Retman
2026-03-10 18:03 ` [PATCH v9 2/3] x86/cpu: Check if feature string is non-zero Maciej Wieczor-Retman
2026-03-10 22:35   ` Sohil Mehta [this message]
2026-03-11 13:48     ` Maciej Wieczor-Retman
2026-03-10 18:03 ` [PATCH v9 3/3] x86/cpu: Do a sanity check on required feature bits Maciej Wieczor-Retman
2026-03-10 23:13   ` Sohil Mehta
2026-03-11 14:33     ` Maciej Wieczor-Retman
2026-03-11 15:46       ` Maciej Wieczor-Retman

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=e061d22b-90ad-4775-a22e-3caa2e40f2bf@intel.com \
    --to=sohil.mehta@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.wieczorretman@pm.me \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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