From: Sohil Mehta <sohil.mehta@intel.com>
To: Maciej Wieczor-Retman <m.wieczorretman@pm.me>
Cc: 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>,
Peter Zijlstra <peterz@infradead.org>,
<pawel.chmielewski@linux.intel.com>,
"Maciej Wieczor-Retman" <maciej.wieczor-retman@intel.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 2/3] x86/cpu: Check if feature string is non-zero
Date: Fri, 13 Feb 2026 10:22:31 -0800 [thread overview]
Message-ID: <781ec3ba-d14c-4170-9726-b268658064db@intel.com> (raw)
In-Reply-To: <aY7sXdnGZ3R5InEY@wieczorr-mobl1.localdomain>
On 2/13/2026 2:02 AM, Maciej Wieczor-Retman wrote:
> On 2026-02-12 at 16:28:10 -0800, Sohil Mehta wrote:
>> On 2/12/2026 7:35 AM, Maciej Wieczor-Retman wrote:
>>
>>>
>>> +const char *x86_cap_name(unsigned int bit)
>>> +{
>>> + unsigned int word = bit >> 5;
>>> + static char undef_buf[16];
>>> + const char *name = NULL;
>>> +
>>> + if (likely(word < NCAPINTS))
>>> + name = x86_cap_flags[bit];
>>> + else if (likely(word < NCAPINTS + NBUGINTS))
>>> + name = x86_bug_flags[bit - 32 * NCAPINTS];
>>> +
>>> + if (name)
>>> + return name;
>>> +
>>> + snprintf(undef_buf, sizeof(undef_buf), "%u:%u", word, bit & 31);
>>> + return undef_buf;
>>> +}
>>> +
>>
>> Isn't it unsafe to return undef_buf because the pointer is local to this
>> function even though it is marked static?
>>
>> For example, the consecutive calls below would overwrite the value
>> stored at that address.
>
> I just rechecked and after I caused that pr_warn_once() to be executed the
> strings are printed correctly.
>
The issue would only happen if both d->feature and d->depends don't have
anything in x86_cap_flags[]. Was that true for your test?
> Looking a bit further down, the pointers of the returned const char* are two
> distinct values. So I assume because there are two calls to x86_cap_name() in
> the pr_warn_once() the two static undef_buf char arrays are statically allocated
> and there is no overwriting, but please correct me if that assumption is wrong.
>
I don't think it works that way. As the variable is defined as "static",
only a single undef_buf is allocated. So the same pointer should be
returned after every call. I added the below dependency and it prints
the same feature twice.
"x86 CPU feature dependency check failure: CPU0 has '12:19' enabled but
'12:19' disabled. Kernel..."
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c
b/arch/x86/kernel/cpu/cpuid-deps.c
index 1106a5476dca..51c482c18a2c 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -93,6 +93,7 @@ static const struct cpuid_dep cpuid_deps[] = {
{ X86_FEATURE_FRED, X86_FEATURE_LKGS },
{ X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL },
{ X86_FEATURE_LASS, X86_FEATURE_SMAP },
+ { X86_FEATURE_WRMSRNS, X86_FEATURE_FZRM},
{}
};
>>> 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));
>>> }
>>> }
>>> }
>
next prev parent reply other threads:[~2026-02-13 18:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 15:33 [PATCH v5 0/3] x86: Capability bits fix and required bits sanity check Maciej Wieczor-Retman
2026-02-12 15:34 ` [PATCH v5 1/3] x86/cpu: Clear feature bits disabled at compile-time Maciej Wieczor-Retman
2026-02-12 15:58 ` Borislav Petkov
2026-02-12 16:23 ` Maciej Wieczor-Retman
2026-02-12 21:34 ` H. Peter Anvin
2026-02-12 21:51 ` Borislav Petkov
2026-02-12 23:04 ` Sohil Mehta
2026-02-12 23:47 ` Borislav Petkov
2026-02-13 0:14 ` Sohil Mehta
2026-02-13 0:36 ` Sohil Mehta
2026-02-13 0:58 ` Borislav Petkov
2026-02-13 20:11 ` H. Peter Anvin
2026-02-12 15:35 ` [PATCH v5 2/3] x86/cpu: Check if feature string is non-zero Maciej Wieczor-Retman
2026-02-13 0:28 ` Sohil Mehta
2026-02-13 10:02 ` Maciej Wieczor-Retman
2026-02-13 18:22 ` Sohil Mehta [this message]
2026-02-13 19:10 ` Maciej Wieczor-Retman
2026-02-13 20:00 ` Sohil Mehta
2026-02-13 20:26 ` Maciej Wieczor-Retman
2026-02-13 20:15 ` H. Peter Anvin
2026-02-13 20:24 ` Maciej Wieczor-Retman
2026-02-12 15:35 ` [PATCH v5 3/3] x86/cpu: Required feature bits sanity check Maciej Wieczor-Retman
2026-02-13 20:17 ` H. Peter Anvin
2026-02-13 20:23 ` [PATCH v5 0/3] x86: Capability bits fix and required " H. Peter Anvin
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=781ec3ba-d14c-4170-9726-b268658064db@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=pawel.chmielewski@linux.intel.com \
--cc=peterz@infradead.org \
--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®