Re: [PATCH v10 2/3] x86/cpu: Check if feature string is non-zero

From: Pawan Gupta

Date: Wed Mar 18 2026 - 19:42:32 EST


On Tue, Mar 17, 2026 at 08:00:16PM +0000, Maciej Wieczor-Retman wrote:
> From: Maciej Wieczor-Retman <maciej.wieczor-retman@xxxxxxxxx>
>
> In filter_cpuid_features(), x86_cap_flags[] is read, but it's not verified
> 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.
>
> Add a common helper to fix filter_cpuid_features() as well as clean up
> the open coded cases.
>
> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@xxxxxxxxx>
> ---
> Changelog v10:
> - Reword the patch message a bit.
> - Move x86_cap_name() declaration and X86_CAP_BUF_SIZE define to
> asm/cpufeature.h.
> - Don't include asm/cpu.h in cpuid-deps.c
> - Extend the comment above x86_cap_name to include information on buffer
> size that needs to be prepared before calling the function.
> - Remove the likely(), unlikely() calls since this is not a hot path.
>
> Changelog v9:
> - 16 -> X86_CAP_BUF_SIZE.
> - Add comment to the x86_cap_name().
>
> Changelog v8:
> - Move x86_cap_name() declaration from linux/cpu.h to the arch/cpu.h.
> Include arch/cpu.h in the cpuid-deps.c file instead of linux/cpu.h.
>
> Changelog v7:
> - sizeof(buf) -> 16
> - Rebase onto 7.01-rc1.
>
> Changelog v6:
> - Remove parts of the patch message that are redundant and just copy
> what's visible in the diff.
> - Redo the helper to use an external char buffer instead of a local
> static string.
>
> arch/x86/include/asm/cpufeature.h | 4 ++++
> arch/x86/kernel/cpu/common.c | 32 ++++++++++++++++++++++++++-----
> arch/x86/kernel/cpu/cpuid-deps.c | 21 +++-----------------
> 3 files changed, 34 insertions(+), 23 deletions(-)
>
> diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
> index 3ddc1d33399b..dc1cd44ddd63 100644
> --- a/arch/x86/include/asm/cpufeature.h
> +++ b/arch/x86/include/asm/cpufeature.h
> @@ -138,5 +138,9 @@ static __always_inline bool _static_cpu_has(u16 bit)
> #define CPU_FEATURE_TYPEVAL boot_cpu_data.x86_vendor, boot_cpu_data.x86, \
> boot_cpu_data.x86_model
>
> +#define X86_CAP_BUF_SIZE 16

This can get rid of the extra tab.

Reviewed-by: Pawan Gupta <pawan.kumar.gupta@xxxxxxxxxxxxxxx>