From nobody Fri Apr 3 13:49:09 2026 Received: from mail-106120.protonmail.ch (mail-106120.protonmail.ch [79.135.106.120]) (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 3EC513446DE for ; Fri, 20 Feb 2026 12:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591504; cv=none; b=HHE6dBSCl/2bG/UlQcT7BRft06dQtTsvcI9pDp29j6rbdV6NKwNFGyllSfock4qUEUcIEX38bR969hSZTQzSq6g66qCe+DeGfwMhL9pnty8ZYbNhe+6LSMax0CNIbT9nAdAX3ilOdOdIjYenIEU+mLIJ5IdFHCszhtDFT3tPY0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591504; c=relaxed/simple; bh=SnYYqYLvanlR+WoEHY4YZxCbr7GGiRUBqbCKaSNdHp8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KkMvjOwV7FzP3P+fofkf8Nt7e2TEQ0JDGfftVnqg/pWTivbMRNm/fHZsVctkZYbL0KuYdQIhmbJFaWEdEWe7Hu0zNMyfI4E6EAZAOMiRIM8rWifLXW22j3ptAB5ehK43hzaXuRH3RaUV2L4yZ+s+48IDOLQPc+bzjl2RTJcVxL4= 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=csTFGOBh; arc=none smtp.client-ip=79.135.106.120 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="csTFGOBh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1771591491; x=1771850691; bh=zSS9i65tCPoxZMt75pB/krRlarbbjIZ+KDWjsDSZDRA=; 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=csTFGOBhxV34p8yn/8d3fo2gN9rOC4xSZjNkSWX5MGqeMi1txrK5MEo0FfOgqtcle YkBDSLO+pNMqWf8LNFosOQVh+q2C56fAycfFqDXxatyLvXjFPJtbmTS0Os+C+10rHI ALyeAk+aY/gfCgoQVs9wNt2RjGabzaJenORxLCfEsb5yzwj8y5rgzMU56qlJ34fXOJ n/RPJCg0MJkoWQebmNx+tkaS9B7KDf4K9dDq7pXWiPIcbpvbODIdmlgB8sD7w5YFwZ DTbmuHYVHEXUkrnRbCwKCPVP+qn9CDZqfnDw4AMD3UPG1Xp9der6LZmpT3D7QV255B avAQdSCkEX+7Q== Date: Fri, 20 Feb 2026 12:44:47 +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, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v6 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: 56a91d580c6d07c71ec193bc98bbc173bed1045b 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. 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 --- 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/kernel/cpu/common.c | 26 +++++++++++++++++++++----- arch/x86/kernel/cpu/cpuid-deps.c | 20 +++----------------- include/linux/cpu.h | 2 ++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8d12c5722245..44ae2f936395 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -675,6 +675,7 @@ cpuid_dependent_features[] =3D { static void filter_cpuid_features(struct cpuinfo_x86 *c, bool warn) { const struct cpuid_dependent_feature *df; + char feature_buf[16]; =20 for (df =3D cpuid_dependent_features; df->feature; df++) { =20 @@ -697,7 +698,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, feature_buf), df->level); } } =20 @@ -1631,6 +1632,7 @@ static inline bool parse_set_clear_cpuid(char *arg, b= ool set) =20 while (arg) { bool found __maybe_unused =3D false; + char name_buf[16]; unsigned int bit; =20 opt =3D strsep(&arg, ","); @@ -1651,10 +1653,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, name_buf)); =20 taint++; } @@ -1972,6 +1971,23 @@ static void generic_identify(struct cpuinfo_x86 *c) #endif } =20 +const char *x86_cap_name(unsigned int bit, char *buf) +{ + unsigned int word =3D bit >> 5; + 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(buf, sizeof(buf), "%u:%u", word, bit & 31); + return 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..7fad18e7d2eb 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,21 +157,6 @@ 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]; @@ -185,8 +171,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, feature_buf), + x86_cap_name(d->depends, depends_buf)); } } } diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 487b3bf2e1ea..30e5a92430da 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, char *buf); + #endif /* _LINUX_CPU_H_ */ --=20 2.53.0