From nobody Thu Apr 2 20:26:58 2026 Received: from mail-244116.protonmail.ch (mail-244116.protonmail.ch [109.224.244.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3C36208D0 for ; Thu, 12 Feb 2026 15:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770910514; cv=none; b=uMVh360oUyPLGAF1GEEFn/LmZLeq8SB/xq3JagiNG60eNF+xI/wrut75EvOzaFq7XECfBMja4kC90NHR2wJ2Jl6N70MVnLlTEzoqLdjrmYCnf7LihIBXXUHHLkm8IIDNYfds22BoHCL/pV24VpO9lbAO5G4pOkEQFOTpPasz2AU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770910514; c=relaxed/simple; bh=rFFRTyiZShwLcbB/FgEzqO0dLPAGInQeVzGKDS+HTMc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=drCCMFr+7yATRG301PwGEwcHcAUl8JZvQE+0HYTmE1Nxpt0GBIr2xLe4jXfaKtd9rWCte2FvK9Q5gCepaHOGnU6dGG71gj4G9iLecs79XrLKV8p61IYei5i1c/66yP4U++Ii4J9Um2cC7Nf8dKzwuELbBOOK7p8VW1dcy4FNWtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=ijnwd1FD; arc=none smtp.client-ip=109.224.244.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="ijnwd1FD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1770910504; x=1771169704; bh=W0A9N2Fw8pqBE/WkeOiFSoSBigIQ6Y0Owh+Jgu01drc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ijnwd1FDpWd9fVDusMmFW36B92aS4bfNaelVcCnyc3WKBbj2uS4W9sCsYgk/Zhpcs zQr6jIdwEv9Cv3tKm1lwpBuPAPTzzzlHoQlhBq9wagMbvQNmW5SFIwHDpyIOBKBtfv r2R/a35fnXK5UR8gVHlNaTukLO4actgTDzi5e20vzDRYA7V9x3W64edO4DK6WXP0Sb b4iHJIkczDLpS92HDK9edLJ16mViwKvjScZqA8tg0VOFYHd5gWDsuMFPtwbsnrtDFJ RdLq82lRfFyPUf5eivZzc9FMHJZA86qiVhQvkM9oow7i7DVRyvgLX0yw7po+0/zlhQ lxmAAPdsra2Lg== Date: Thu, 12 Feb 2026 15:35:01 +0000 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, pawel.chmielewski@linux.intel.com, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v5 2/3] x86/cpu: Check if feature string is non-zero Message-ID: In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: fff179b6ef81bac0a26a845542ae3806d2dfe9a6 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman 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 helper that verifies the feature string in filter_cpuid_features() is non-zero, and also cleans up the open coded paths mentioned above. Signed-off-by: Maciej Wieczor-Retman --- arch/x86/kernel/cpu/common.c | 25 ++++++++++++++++++++----- arch/x86/kernel/cpu/cpuid-deps.c | 21 +++------------------ include/linux/cpu.h | 2 ++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8d12c5722245..7aede0760ebc 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -697,7 +697,7 @@ static void filter_cpuid_features(struct cpuinfo_x86 *c= , bool warn) continue; =20 pr_warn("CPU: CPU feature %s disabled, no CPUID level 0x%x\n", - x86_cap_flags[df->feature], df->level); + x86_cap_name(df->feature), df->level); } } =20 @@ -1651,10 +1651,7 @@ static inline bool parse_set_clear_cpuid(char *arg, = bool set) setup_clear_cpu_cap(bit); } /* empty-string, i.e., ""-defined feature flags */ - if (!x86_cap_flags[bit]) - pr_cont(" %d:%d\n", bit >> 5, bit & 31); - else - pr_cont(" %s\n", x86_cap_flags[bit]); + pr_cont(" %s\n", x86_cap_name(bit)); =20 taint++; } @@ -1972,6 +1969,24 @@ static void generic_identify(struct cpuinfo_x86 *c) #endif } =20 +const char *x86_cap_name(unsigned int bit) +{ + unsigned int word =3D bit >> 5; + static char undef_buf[16]; + const char *name =3D NULL; + + if (likely(word < NCAPINTS)) + name =3D x86_cap_flags[bit]; + else if (likely(word < NCAPINTS + NBUGINTS)) + name =3D x86_bug_flags[bit - 32 * NCAPINTS]; + + if (name) + return name; + + snprintf(undef_buf, sizeof(undef_buf), "%u:%u", word, bit & 31); + return undef_buf; +} + /* * This does the hard work of actually picking apart the CPU stuff... */ diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-d= eps.c index 146f6f8b0650..1106a5476dca 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -2,6 +2,7 @@ #include #include #include +#include #include =20 struct cpuid_dep { @@ -156,24 +157,8 @@ void setup_clear_cpu_cap(unsigned int feature) do_clear_cpu_cap(NULL, feature); } =20 -/* - * Return the feature "name" if available, otherwise return - * the X86_FEATURE_* numerals to make it easier to identify - * the feature. - */ -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; -} - void check_cpufeature_deps(struct cpuinfo_x86 *c) { - char feature_buf[16], depends_buf[16]; const struct cpuid_dep *d; =20 for (d =3D cpuid_deps; d->feature; d++) { @@ -185,8 +170,8 @@ void check_cpufeature_deps(struct cpuinfo_x86 *c) */ pr_warn_once("x86 CPU feature dependency check failure: CPU%d has '%s' = enabled but '%s' disabled. Kernel might be fine, but no guarantees.\n", smp_processor_id(), - x86_feature_name(d->feature, feature_buf), - x86_feature_name(d->depends, depends_buf)); + x86_cap_name(d->feature), + x86_cap_name(d->depends)); } } } diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 487b3bf2e1ea..8b2176561f29 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -229,4 +229,6 @@ static inline bool cpu_attack_vector_mitigated(enum cpu= _attack_vectors v) #define smt_mitigations SMT_MITIGATIONS_OFF #endif =20 +const char *x86_cap_name(unsigned int bit); + #endif /* _LINUX_CPU_H_ */ --=20 2.53.0