From: Usama Arif <usama.arif@linux.dev>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: dsterba@suse.com, linux-kernel@vger.kernel.org, terrelln@fb.com,
terrelln@meta.com, linux-crypto@vger.kernel.org,
yosry@kernel.org, ebiggers@kernel.org, hannes@cmpxchg.org,
nphamcs@gmail.com, chengming.zhou@linux.dev,
shakeel.butt@linux.dev, kernel-team@meta.com
Subject: Re: [PATCH v2 2/2] zstd: use cpu_feature_enabled() for in-kernel BMI2 dispatch
Date: Mon, 31 Aug 2026 13:09:09 +0100 [thread overview]
Message-ID: <bed66f22-8bf1-4328-a400-d214e15693e2@linux.dev> (raw)
In-Reply-To: <CAHk-=wg3d5HUkgdWq4Ac74xoUDU_BiHTC_ONacwYFoXnMQZ7Pw@mail.gmail.com>
On 31/08/2026 00:06, Linus Torvalds wrote:
> On Sun, 30 Aug 2026 at 15:21, Usama Arif <usama.arif@linux.dev> wrote:
>>
>> Add ZSTD_USE_BMI2() and use it at every runtime BMI2/default selector.
>
> Thanks, this looks sane to me.
>
> I do still react to a couple of places. Notably, this part (repeated a
> couple of times):
>
>> +#if !defined(ZSTD_USE_KERNEL_CPU_FEATURES)
>> cctx->bmi2 = ZSTD_cpuSupportsBmi2();
>> +#endif
>
> should probably be an "set state" macro the same way ZSTD_USE_BMI2()
> is now a "get state" macro.
>
Ack, have added ZSTD_SET_BMI2():
#if !DYNAMIC_BMI2
# define ZSTD_USE_BMI2(bmi2) 0
# define ZSTD_SET_BMI2(state, value) do { } while (0)
#elif defined(ZSTD_USE_KERNEL_CPU_FEATURES)
# define ZSTD_USE_BMI2(bmi2) cpu_feature_enabled(X86_FEATURE_BMI2)
# define ZSTD_SET_BMI2(state, value) do { } while (0)
#else
# define ZSTD_USE_BMI2(bmi2) (bmi2)
# define ZSTD_SET_BMI2(state, value) do { (state) = (value); } while (0)
#endif
will use above in next revision.
> And:
>
>> +ccflags-$(CONFIG_X86) += -DZSTD_USE_KERNEL_CPU_FEATURES
>
> We don't have anything like this for any other ZSTD defines, so my gut
> feel is that either this is in the wrong place, and it should be in
> something like
>
> lib/zstd/common/zstd_deps.h
>
> which already has kernel-specific stuff in it, or it should just use
> #ifdef __KERNEL__ like we use elsewhere for things that are also used
> by user space.
>
Ack, removed it from the Makefile for next revision.
__KERNEL__ alone was insufficient because it is also defined for the x86
compressed boot code. That environment defines __DISABLE_EXPORTS and cannot
use the normal alternatives infrastructure, so it retains zstd’s raw-CPUID
path.
I have added
#if defined(__KERNEL__) && defined(CONFIG_X86) && \
!defined(__DISABLE_EXPORTS)
#define ZSTD_USE_KERNEL_CPU_FEATURES
#endif
in lib/zstd/common/zstd_deps.h for the next revision.
> The whole situation with ZSTD configuration is a bit strange. I note
> that there are things like ZSTD_ARCH_ARM_NEON that the kernel never
> uses.
>
> Why is "DYNAMIC_BMI2" a settimg but things like that
> ZSTD_ARCH_X86_SSE2 and ZSTD_ARCH_ARM_NEON are never set? This all
> looks messy.
>
DYNAMIC_BMI2 is defined in lib/zstd/common/portability_macros.h.
ZSTD_ARCH_X86_SSE2 and ZSTD_ARCH_ARM_NEON are upstream zstd configuration
knobs. The kernel import is generated with ZSTD_NO_INTRINSICS [1], so their
automatic definitions are disabled even though some guarded references
remain in the imported source. The kernel cannot use SSE/NEON transparently
because that requires architecture-specific SIMD/FPU state management, whereas
BMI2 operates only on general-purpose registers.
[1] https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/Makefile#L30
> Or is there some hidden config I didn't find?
>
> Strange.
>
> Linus
prev parent reply other threads:[~2026-08-31 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 22:20 [PATCH v2 0/2] zstd: use x86 feature infrastructure for " Usama Arif
2026-08-30 22:20 ` [PATCH v2 1/2] lib/zstd: add fallback aliases for disabled BMI2 variants Usama Arif
2026-08-30 22:20 ` [PATCH v2 2/2] zstd: use cpu_feature_enabled() for in-kernel BMI2 dispatch Usama Arif
2026-08-30 23:06 ` Linus Torvalds
2026-08-31 12:09 ` Usama Arif [this message]
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=bed66f22-8bf1-4328-a400-d214e15693e2@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=terrelln@meta.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®