mirror of https://lore.kernel.org/lkml/
 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 3/3] x86/cpu: Do a sanity check on required feature bits
Date: Tue, 10 Mar 2026 16:13:25 -0700	[thread overview]
Message-ID: <5fb77ae8-0536-4222-a19a-6f6c18a95690@intel.com> (raw)
In-Reply-To: <6e64ffe2aef6d87b0f43835b958566035f99865d.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>
> 
> After CPU identification concludes, do a sanity check by comparing the
> final x86_capability bitmask with the pre-defined required feature bits.
> 
> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
> Acked-by: H. Peter Anvin (Intel) <hpa@zytor.com>
> ---

> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index cfffbbda3d95..43ee2d55a708 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -2003,6 +2003,34 @@ const char *x86_cap_name(unsigned int bit, char *buf)
>  	return buf;
>  }
>  
> +/*
> + * As a sanity check compare the final x86_capability bitmask with the initial
> + * predefined required feature bits. In case of a mismatch emit a warning with
> + * all the missing feature names or X86_FEATURE_* numerals.
> + */

I feel the second sentence is more appropriate as part of the commit
message instead of a code comment.

> +static void verify_required_features(const struct cpuinfo_x86 *c)
> +{
> +	u32 missing[NCAPINTS] = REQUIRED_MASK_INIT;
> +	char cap_buf[X86_CAP_BUF_SIZE];
> +	unsigned int i;
> +	u32 error = 0;
> +
> +	for (i = 0; i < NCAPINTS; i++) {
> +		missing[i] &= ~c->x86_capability[i];
> +		error |= missing[i];
> +	}
> +
> +	if (!error)
> +		return;
> +
> +	/* At least one required feature is missing */
> +	pr_warn("cpu %d: missing required feature(s):", c->cpu_index);

s/cpu/CPU

I haven't seen cpu_index being used commonly. I don't know the nuance
between that and smp_processor_id(). It's probably the same in this case.

Also, it seems too noisy to print this for every CPU in a large core
count system. But, pr_warn_once() won't work well with the pr_cont()
implementation that you have.

I don't have a better suggestion except for a static variable. Maybe
someone else has a better idea..

My assumption is that typically we won't run into this on a production
system. But, VMs could encounter this. So, I am not sure.

> +	for_each_set_bit(i, (unsigned long *)missing, NCAPINTS << 5)

NCAPINTS * 32 is the common usage across arch/x86.

> +		pr_cont(" %s", x86_cap_name(i, cap_buf));
> +	pr_cont("\n");
> +	add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
> +}
> +
>  /*
>   * This does the hard work of actually picking apart the CPU stuff...
>   */
> @@ -2132,6 +2160,8 @@ static void identify_cpu(struct cpuinfo_x86 *c)
>  	mcheck_cpu_init(c);
>  
>  	numa_add_cpu(smp_processor_id());
> +
> +	verify_required_features(c);
>  }
>  
>  /*


  reply	other threads:[~2026-03-10 23:13 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
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 [this message]
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=5fb77ae8-0536-4222-a19a-6f6c18a95690@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

all inboxes | Powered by JetHome®