From: Usama Arif <usama.arif@linux.dev>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Eric Biggers <ebiggers@kernel.org>,
David Sterba <dsterba@suse.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Nick Terrell <terrelln@fb.com>,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
yosry@kernel.org, Johannes Weiner <hannes@cmpxchg.org>,
Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Kernel Team <kernel-team@meta.com>
Subject: Re: [PATCH 0/3] zstd: probe the CPU for BMI2 support once, not per context
Date: Fri, 28 Aug 2026 22:54:07 +0100 [thread overview]
Message-ID: <c0bca273-1395-419a-a2eb-5627f2243452@linux.dev> (raw)
In-Reply-To: <CAHk-=whZf9=X+qKkO9_pQzbLdOnbMw5yO8gu0TkahegVW3cC-g@mail.gmail.com>
On 28/08/2026 21:19, Linus Torvalds wrote:
> [ Sorry for breaking threading - I have turned off IMAP access to my
> mailbox, and so I have issues replying to lore messages sanely ]
>
> On Thu, 27 Aug 2026, Usama Arif wrote:
>>
>> On 27/08/2026 03:39, Eric Biggers wrote:
>>>
>>> Why not just use cpu_feature_enabled(X86_FEATURE_BMI2), which compiles
>>> down to a static branch? All these issues are caused by lib/zstd/ using
>>> its own custom CPU feature detection code, instead of the normal CPU
>>> feature detection code that the rest of the kernel uses.
>
> Yes, please. The zlib code is just broken in how it makes up its own
> random inine asm that is actively worse than what the kernel already
> exposes.
>
>> The only issue I saw with that was that zstd is a standalone library that
>> is imported
>
> Let's ignore that part, and just make it work right. The Zstd people
> should think about this problem on their side.
>
>> Keep the existing raw CPUID fallback for preboot and other builds which
>> cannot use the normal x86 feature infrastructure. Also retain the early
>> return when dynamic dispatch is disabled.
>
> No, this is not great, that whole
>
> cctx->bmi2 = ZSTD_cpuSupportsBmi2();
> ...
> if (bmi2) ...
>
> model in zstd needs to just die.
>
> For the kernel, the whole dynamic "test a variable" model is simply wrong.
> It should expand to
>
> if (cpu_feature_enabled(X86_FEATURE_BMI2))
>
> because for the kernel, that becomes a simple static branch.
>
> When zstd goes through that variable, it loses that entirely and
> instead turns it in a static assignment and then a dynamic test (well,
> not "entirely" - with inlining it could still recover the right code).
>
> So zstd really should be fixed to get rid of that bad
>
> #if DYNAMIC_BMI2
> if (bmi2) {
> ....
>
> pattern entirely, and be taught to have a *helper* macro that just turns
> into 0 for when DYNAMIC_BMI2 is not set, and turns into using that stupid
> flag in user mode, and for the kernel it should just turn into that
> "cpu_feature_enabled(X86_FEATURE_BMI2)"
>
> Why does it check for both BMI1 and BMI2 anyway? And Arif added an
> extra check for ABM. That all looks bogus. You can't have BMI2 without
> having BMI1, so all this code looks completely bogus to begin with.
>
The three checks came from interpreting BMI2_TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
as requiring all three feature bits. Agreed that this is unnecessary here.
The kernel path should check only X86_FEATURE_BMI2.
I was also trying to preserve zstd’s standalone-library behavior.
I will instead make normal x86 kernel builds use a helper that expands directly to
cpu_feature_enabled(X86_FEATURE_BMI2) at each dispatch site. The stored BMI2
context flag and private CPUID probe will be removed from that path.
Preboot and standalone builds will retain their existing caller-provided
lag and CPUID-based detection.
I will send a revised patch in a little bit.
Thanks!
Usama
next prev parent reply other threads:[~2026-08-28 21:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 20:19 Linus Torvalds
2026-08-28 21:54 ` Usama Arif [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-08-26 12:25 Usama Arif
2026-08-26 17:10 ` Nhat Pham
2026-08-27 2:39 ` Eric Biggers
2026-08-27 14:21 ` Usama Arif
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=c0bca273-1395-419a-a2eb-5627f2243452@linux.dev \
--to=usama.arif@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=dsterba@suse.com \
--cc=ebiggers@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nphamcs@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=torvalds@linux-foundation.org \
--cc=yosry@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®