From: Usama Arif <usama.arif@linux.dev>
To: dsterba@suse.com, linux-kernel@vger.kernel.org, terrelln@fb.com,
linux-crypto@vger.kernel.org, yosry@kernel.org
Cc: hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev,
shakeel.butt@linux.dev, kernel-team@meta.com,
Usama Arif <usama.arif@linux.dev>
Subject: [PATCH 1/3] zstd: use ZSTD_cpuSupportsBmi2() in ZSTD_initStaticCCtx()
Date: Wed, 26 Aug 2026 05:25:36 -0700 [thread overview]
Message-ID: <20260826122558.2662013-2-usama.arif@linux.dev> (raw)
In-Reply-To: <20260826122558.2662013-1-usama.arif@linux.dev>
ZSTD_initStaticCCtx() open-codes its BMI2 probe as
ZSTD_cpuid_bmi2(ZSTD_cpuid()). Every other context setup -
ZSTD_initCCtx() and ZSTD_initDCtx_internal() - goes through
ZSTD_cpuSupportsBmi2(), which requires BMI1 as well as BMI2.
Requiring both is the correct test. The alternate function bodies the
flag selects are tagged BMI2_TARGET_ATTRIBUTE, which is
TARGET_ATTRIBUTE("lzcnt,bmi,bmi2"), so the compiler may emit BMI1 and
LZCNT instructions in them; BMI2 alone does not make that safe. No
shipping x86 CPU implements BMI2 without BMI1, so this is a latent
inconsistency rather than an observed failure.
Route the static path through the same helper. That also leaves a
single place where the probe is issued, which the following patches
build on.
No functional change on any CPU in the field.
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
lib/zstd/compress/zstd_compress.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/zstd/compress/zstd_compress.c b/lib/zstd/compress/zstd_compress.c
index c41a747413e01..4ab67d679bb63 100644
--- a/lib/zstd/compress/zstd_compress.c
+++ b/lib/zstd/compress/zstd_compress.c
@@ -142,7 +142,7 @@ ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize)
cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->workspace, sizeof(ZSTD_compressedBlockState_t));
cctx->tmpWorkspace = ZSTD_cwksp_reserve_object(&cctx->workspace, TMP_WORKSPACE_SIZE);
cctx->tmpWkspSize = TMP_WORKSPACE_SIZE;
- cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
+ cctx->bmi2 = ZSTD_cpuSupportsBmi2();
return cctx;
}
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-26 12:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 12:25 [PATCH 0/3] zstd: probe the CPU for BMI2 support once, not per context Usama Arif
2026-08-26 12:25 ` Usama Arif [this message]
2026-08-26 12:25 ` [PATCH 2/3] zstd: skip the BMI2 probe when dynamic BMI2 dispatch is disabled Usama Arif
2026-08-26 12:25 ` [PATCH 3/3] zstd: probe the CPU for BMI2 support only once Usama Arif
2026-08-26 17:10 ` [PATCH 0/3] zstd: probe the CPU for BMI2 support once, not per context 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=20260826122558.2662013-2-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=dsterba@suse.com \
--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=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®