mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xin Li <xin@zytor.com>
To: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	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>,
	Ricardo Neri <ricardo.neri-calderon@linux.intel.com>,
	Kyung Min Park <kyung.min.park@intel.com>,
	Tony Luck <tony.luck@intel.com>
Cc: xin3.li@intel.com, Farrah Chen <farrah.chen@intel.com>,
	stable@vger.kernel.org, Borislav Petkov <bp@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] x86: Clear feature bits disabled at compile-time
Date: Thu, 24 Jul 2025 10:58:06 -0700	[thread overview]
Message-ID: <e009fd66-420c-4ad6-a68b-9293345d9a8e@zytor.com> (raw)
In-Reply-To: <20250724125346.2792543-1-maciej.wieczor-retman@intel.com>

On 7/24/2025 5:53 AM, Maciej Wieczor-Retman wrote:
> If some config options are disabled during compile time, they still are
> enumerated in macros that use the x86_capability bitmask - cpu_has() or
> this_cpu_has().
> 
> The features are also visible in /proc/cpuinfo even though they are not
> enabled - which is contrary to what the documentation states about the
> file. Examples of such feature flags are lam, fred, sgx, ibrs_enhanced,
> split_lock_detect, user_shstk, avx_vnni and enqcmd.
> 
> Add a DISABLED_MASK_INITIALIZER macro that creates an initializer list
> filled with DISABLED_MASKx bitmasks.
> 
> Initialize the cpu_caps_cleared array with the autogenerated disabled
> bitmask.

It's worth appending:

And apply_forced_caps() will clear the corresponding bits in 
boot_cpu_data.x86_capability[] and APs' cpu_data.x86_capability[].
Thus features disabled at build time won't show up in /proc/cpuinfo.

> 
> Fixes: ea4e3bef4c94 ("Documentation/x86: Add documentation for /proc/cpuinfo feature flags")
> Reported-by: Farrah Chen <farrah.chen@intel.com>
> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
> Cc: <stable@vger.kernel.org>
> ---
> Changelog v4:
> - Fix macro name to match with the patch message.
> - Add Peter's SoB.
> 
> Changelog v3:
> - Remove Fixes: tags, keep only one at the point where the documentation
>    changed and promised feature bits wouldn't show up if they're not
>    enabled.
> - Don't use a helper to initialize cpu_caps_cleared, just statically
>    initialize it.
> - Remove changes to cpu_caps_set.
> - Rewrite patch message to account for changes.
> 
> Changelog v2:
> - Redo the patch to utilize a more generic solution, not just fix the
>    LAM and FRED feature bits.
> - Note more feature flags that shouldn't be present.
> - Add fixes and cc tags.
> 
>   arch/x86/kernel/cpu/common.c       | 3 ++-
>   arch/x86/tools/cpufeaturemasks.awk | 6 ++++++
>   2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index 77afca95cced..a9040038ad9d 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -704,7 +704,8 @@ static const char *table_lookup_model(struct cpuinfo_x86 *c)
>   }
>   
>   /* Aligned to unsigned long to avoid split lock in atomic bitmap ops */
> -__u32 cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
> +__u32 cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long)) =
> +	DISABLED_MASK_INITIALIZER;
>   __u32 cpu_caps_set[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
>   
>   #ifdef CONFIG_X86_32
> diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
> index 173d5bf2d999..1eabbc69f50d 100755
> --- a/arch/x86/tools/cpufeaturemasks.awk
> +++ b/arch/x86/tools/cpufeaturemasks.awk
> @@ -84,5 +84,11 @@ END {
>   		printf "\t) & (1U << ((x) & 31)))\n\n";
>   	}
>   
> +		printf "\n#define DISABLED_MASK_INITIALIZER\t\t\t\\";
> +		printf "\n\t{\t\t\t\t\t\t\\";
> +		for (i = 0; i < ncapints; i++)
> +			printf "\n\t\tDISABLED_MASK%d,\t\t\t\\", i;
> +		printf "\n\t}\n\n";
> +

The indentation is incorrect.

And I think it's no harm to generate both REQUIRED_MASK_INITIALIZER and
DISABLED_MASK_INITIALIZER, so you can put this new code block inside the
above

	for (ns in sets) {
		...
	}

loop.

>   	printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
>   }

      reply	other threads:[~2025-07-24 17:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-24 12:53 Maciej Wieczor-Retman
2025-07-24 17:58 ` Xin Li [this message]

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=e009fd66-420c-4ad6-a68b-9293345d9a8e@zytor.com \
    --to=xin@zytor.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=farrah.chen@intel.com \
    --cc=hpa@zytor.com \
    --cc=kyung.min.park@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=mingo@redhat.com \
    --cc=ricardo.neri-calderon@linux.intel.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.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®