From nobody Fri Oct 10 13:31:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F0FD722F76C; Fri, 13 Jun 2025 18:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749839953; cv=none; b=tLvRtpDu2j2XNdYmz3LghZLlFLNWNKXoVGeyshzb15TccRbDumbmP8F6SI3tIoWbfrmn9uHFiQmdNVmR3b5cmWQ4Yi/Kn7ucj5J3HAUU1POanbFdjoe0HiZ8NeqyZy/gHsaBHNaPSAkzQl9K7sxtAvObbS6ZUE3OXKn/FDEVqt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749839953; c=relaxed/simple; bh=xl1b59oPWmJ1rntLzD003FXPGqJCUJXZnbl4FDjH9ss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=og9FtKF4C12grSsEhP21+XFz+dGU36jNyZKUdCkLCxAY63JpJTBAohUihY9s8cC1iXEEmAXb3gE5zCNVdB7Pvc9ZfteuwDX5VmMaqHDKcbQIq3a75P5IY4Mm4hi7OccGoG1j3fcmoJjDfAkd0KFcTOi2KmZcLALs9dfWSRzfuwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MZmqv2BC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MZmqv2BC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F16CC4CEEB; Fri, 13 Jun 2025 18:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749839952; bh=xl1b59oPWmJ1rntLzD003FXPGqJCUJXZnbl4FDjH9ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZmqv2BCb3NXXmBTAuOFQzmOdMdh9O6VYvqLiKmtNRElGbgJoeDMPrd/RP0iXyuWU iVaUzVaspNA57y7DeiAodSP/l+Qz/BBe6l5nlKhUtfTtBAxxA8WwAhjndmVunZfgQt xnM08m3NdlNb4vhBBv6Aa2Myw9v2ZNIA6GWnggHmH4RItwktzNsXtqcXdJaxyGg1t8 xCOkUwj8AThrJ+hLRpOxpoFEY2LjYRiEOKVVsv2LSDs7D+PjydigC5vdD152aVIjJl TQo8OaKElXe18E8f0sN8Du+qZzYnhfCbiGvYPd4IGltpN1TtAwitleEfCoo9QZiA6G aio13oCn7zb2Q== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , linux-btrfs@vger.kernel.org, Alexander Gordeev , Chris Mason , Josef Bacik , David Sterba Subject: [PATCH 1/2] btrfs: stop parsing crc32c driver name Date: Fri, 13 Jun 2025 11:37:52 -0700 Message-ID: <20250613183753.31864-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613183753.31864-1-ebiggers@kernel.org> References: <20250613183753.31864-1-ebiggers@kernel.org> 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: Eric Biggers To determine whether the crc32c implementation is "fast", use crc32_optimizations() instead of parsing the crypto_shash driver name. This keeps the code working as intended after the driver name is changed by the next patch. Signed-off-by: Eric Biggers Acked-by: David Sterba --- fs/btrfs/disk-io.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 1beb9458f622a..7bb453b69639c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2024,18 +2024,14 @@ static int btrfs_init_csum_hash(struct btrfs_fs_inf= o *fs_info, u16 csum_type) return PTR_ERR(csum_shash); } =20 fs_info->csum_shash =3D csum_shash; =20 - /* - * Check if the checksum implementation is a fast accelerated one. - * As-is this is a bit of a hack and should be replaced once the csum - * implementations provide that information themselves. - */ + /* Check if the checksum implementation is a fast accelerated one. */ switch (csum_type) { case BTRFS_CSUM_TYPE_CRC32: - if (!strstr(crypto_shash_driver_name(csum_shash), "generic")) + if (crc32_optimizations() & CRC32C_OPTIMIZATION) set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags); break; case BTRFS_CSUM_TYPE_XXHASH: set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags); break; --=20 2.49.0 From nobody Fri Oct 10 13:31:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 64AFF231A57; Fri, 13 Jun 2025 18:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749839953; cv=none; b=petm5FcZPwXRYX8gI3ZLI4OH6f2hO7eCw1yfSXB1MnCl/GXl+1Z3jZ4FAmb/OaazmSYpteXDwVhDJbdDSJHI0w21EaNaub1D295LtGl+Qzce9tiQultQfZ8gP9F80sICOWcPAKC5MsZpxX+3o3ay83/RA9akQ8rcUw6WO5JMd0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749839953; c=relaxed/simple; bh=+scNn74TP1gB3uaExUowjPcO7j2GnDZeXdT2PCkyqF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IwJROt2H/C/ZfbG/FTl4hqeS9t0QtwBJ5eNFDqzfLRPxBXscttMeQzpwMevciYo4OClt1L9WFxAnhE8GidStxrdHbPUczH3Cc3E9JosaLLiNc2l2AQwtSn5QWKo8psuTnqS1FAVdAox49o046iQ6U6QrI4ioTE0eYhgo1dBnQf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FdS4gT1r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FdS4gT1r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B35D5C4CEF2; Fri, 13 Jun 2025 18:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749839953; bh=+scNn74TP1gB3uaExUowjPcO7j2GnDZeXdT2PCkyqF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FdS4gT1rF5AwmxBEXf/SxWH2rzz47c/1nrtqZY7HldtMNWt+Io3tNCrEaR9L+bGT8 gYN5o97tfojw8ta1kxEcFqzp76XN4jUKGabZFJ8nyPc68QaqW7tc4sPne9wx34LRmf g9FNmejWTEx9+bNgrLRYz1YiRVQvdlsRqRiXkASm7TaDRMzv/nheYX8uk2KnZf7Q4H YPBGV2WtEmOqW3OE12DvlKX9KqZ6AP0nICTeqPsWgdZj8fpSD1BVrteL5Cl+qyOPin iOJB1N6ljBFTN0JxkNEdkiS0WWdWSk6uJ0pwehPTy/Z7MmsOraAtXFH+k0M06NGPev m+vEZmxyBWTrw== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , linux-btrfs@vger.kernel.org, Alexander Gordeev , Chris Mason , Josef Bacik , David Sterba Subject: [PATCH 2/2] crypto/crc32[c]: register only "-lib" drivers Date: Fri, 13 Jun 2025 11:37:53 -0700 Message-ID: <20250613183753.31864-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613183753.31864-1-ebiggers@kernel.org> References: <20250613183753.31864-1-ebiggers@kernel.org> 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: Eric Biggers For the "crc32" and "crc32c" shash algorithms, instead of registering "*-generic" drivers as well as conditionally registering "*-$(ARCH)" drivers, instead just register "*-lib" drivers. These just use the regular library functions crc32_le() and crc32c(), so they just do the right thing and are fully accelerated when supported by the CPU. This eliminates the need for the CRC library to export crc32_le_base() and crc32c_base(). Separate patches make those static functions. Since this patch removes the "crc32-generic" and "crc32c-generic" driver names which crypto/testmgr.c expects to exist, update crypto/testmgr.c accordingly. This does mean that crypto/testmgr.c will no longer fuzz-test the "generic" implementation against the "arch" implementation for crc32 and crc32c, but this was redundant with crc_kunit anyway. Besides the above, and btrfs_init_csum_hash() which the previous patch fixed, no code appears to have been relying on the "crc32-generic" or "crc32c-generic" driver names specifically. btrfs does export the checksum driver name in /sys/fs/btrfs/$uuid/checksum. This patch makes that file contain "crc32c-lib" instead of "crc32c-generic" or "crc32c-$(ARCH)". This should be fine, since in practice the purpose of this file seems to have been just to allow users to manually check whether they needed to enable the optimized CRC32C code. This was needed only because of the bug in old kernels where the optimized CRC32C code defaulted to off and even needed to be explicitly added to the ramdisk to be used. Now that it just works in Linux 6.14 and later, there's no need for users to take any action and this file is basically obsolete. (Also, note that the contents of this file already changed in 6.14.) Signed-off-by: Eric Biggers Acked-by: David Sterba --- crypto/Makefile | 2 -- crypto/crc32.c | 65 +++++------------------------------------------ crypto/crc32c.c | 66 ++++-------------------------------------------- crypto/testmgr.c | 2 ++ 4 files changed, 13 insertions(+), 122 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 017df3a2e4bb3..55dd56332dc80 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -152,14 +152,12 @@ obj-$(CONFIG_CRYPTO_CHACHA20) +=3D chacha.o CFLAGS_chacha.o +=3D -DARCH=3D$(ARCH) obj-$(CONFIG_CRYPTO_DEFLATE) +=3D deflate.o obj-$(CONFIG_CRYPTO_MICHAEL_MIC) +=3D michael_mic.o obj-$(CONFIG_CRYPTO_CRC32C) +=3D crc32c-cryptoapi.o crc32c-cryptoapi-y :=3D crc32c.o -CFLAGS_crc32c.o +=3D -DARCH=3D$(ARCH) obj-$(CONFIG_CRYPTO_CRC32) +=3D crc32-cryptoapi.o crc32-cryptoapi-y :=3D crc32.o -CFLAGS_crc32.o +=3D -DARCH=3D$(ARCH) obj-$(CONFIG_CRYPTO_AUTHENC) +=3D authenc.o authencesn.o obj-$(CONFIG_CRYPTO_KRB5ENC) +=3D krb5enc.o obj-$(CONFIG_CRYPTO_LZO) +=3D lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) +=3D lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) +=3D lz4hc.o diff --git a/crypto/crc32.c b/crypto/crc32.c index cc371d42601fd..489cbed9422e2 100644 --- a/crypto/crc32.c +++ b/crypto/crc32.c @@ -57,33 +57,16 @@ static int crc32_init(struct shash_desc *desc) static int crc32_update(struct shash_desc *desc, const u8 *data, unsigned int len) { u32 *crcp =3D shash_desc_ctx(desc); =20 - *crcp =3D crc32_le_base(*crcp, data, len); - return 0; -} - -static int crc32_update_arch(struct shash_desc *desc, const u8 *data, - unsigned int len) -{ - u32 *crcp =3D shash_desc_ctx(desc); - *crcp =3D crc32_le(*crcp, data, len); return 0; } =20 /* No final XOR 0xFFFFFFFF, like crc32_le */ -static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, - u8 *out) -{ - put_unaligned_le32(crc32_le_base(*crcp, data, len), out); - return 0; -} - -static int __crc32_finup_arch(u32 *crcp, const u8 *data, unsigned int len, - u8 *out) +static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *= out) { put_unaligned_le32(crc32_le(*crcp, data, len), out); return 0; } =20 @@ -91,16 +74,10 @@ static int crc32_finup(struct shash_desc *desc, const u= 8 *data, unsigned int len, u8 *out) { return __crc32_finup(shash_desc_ctx(desc), data, len, out); } =20 -static int crc32_finup_arch(struct shash_desc *desc, const u8 *data, - unsigned int len, u8 *out) -{ - return __crc32_finup_arch(shash_desc_ctx(desc), data, len, out); -} - static int crc32_final(struct shash_desc *desc, u8 *out) { u32 *crcp =3D shash_desc_ctx(desc); =20 put_unaligned_le32(*crcp, out); @@ -111,72 +88,42 @@ static int crc32_digest(struct shash_desc *desc, const= u8 *data, unsigned int len, u8 *out) { return __crc32_finup(crypto_shash_ctx(desc->tfm), data, len, out); } =20 -static int crc32_digest_arch(struct shash_desc *desc, const u8 *data, - unsigned int len, u8 *out) -{ - return __crc32_finup_arch(crypto_shash_ctx(desc->tfm), data, len, out); -} - -static struct shash_alg algs[] =3D {{ +static struct shash_alg alg =3D { .setkey =3D crc32_setkey, .init =3D crc32_init, .update =3D crc32_update, .final =3D crc32_final, .finup =3D crc32_finup, .digest =3D crc32_digest, .descsize =3D sizeof(u32), .digestsize =3D CHKSUM_DIGEST_SIZE, =20 .base.cra_name =3D "crc32", - .base.cra_driver_name =3D "crc32-generic", + .base.cra_driver_name =3D "crc32-lib", .base.cra_priority =3D 100, .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, .base.cra_ctxsize =3D sizeof(u32), .base.cra_module =3D THIS_MODULE, .base.cra_init =3D crc32_cra_init, -}, { - .setkey =3D crc32_setkey, - .init =3D crc32_init, - .update =3D crc32_update_arch, - .final =3D crc32_final, - .finup =3D crc32_finup_arch, - .digest =3D crc32_digest_arch, - .descsize =3D sizeof(u32), - .digestsize =3D CHKSUM_DIGEST_SIZE, - - .base.cra_name =3D "crc32", - .base.cra_driver_name =3D "crc32-" __stringify(ARCH), - .base.cra_priority =3D 150, - .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, - .base.cra_ctxsize =3D sizeof(u32), - .base.cra_module =3D THIS_MODULE, - .base.cra_init =3D crc32_cra_init, -}}; - -static int num_algs; +}; =20 static int __init crc32_mod_init(void) { - /* register the arch flavor only if it differs from the generic one */ - num_algs =3D 1 + ((crc32_optimizations() & CRC32_LE_OPTIMIZATION) !=3D 0); - - return crypto_register_shashes(algs, num_algs); + return crypto_register_shash(&alg); } =20 static void __exit crc32_mod_fini(void) { - crypto_unregister_shashes(algs, num_algs); + crypto_unregister_shash(&alg); } =20 module_init(crc32_mod_init); module_exit(crc32_mod_fini); =20 MODULE_AUTHOR("Alexander Boyko "); MODULE_DESCRIPTION("CRC32 calculations wrapper for lib/crc32"); MODULE_LICENSE("GPL"); MODULE_ALIAS_CRYPTO("crc32"); -MODULE_ALIAS_CRYPTO("crc32-generic"); diff --git a/crypto/crc32c.c b/crypto/crc32c.c index e5377898414a2..1eff54dde2f74 100644 --- a/crypto/crc32c.c +++ b/crypto/crc32c.c @@ -83,19 +83,10 @@ static int chksum_setkey(struct crypto_shash *tfm, cons= t u8 *key, static int chksum_update(struct shash_desc *desc, const u8 *data, unsigned int length) { struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); =20 - ctx->crc =3D crc32c_base(ctx->crc, data, length); - return 0; -} - -static int chksum_update_arch(struct shash_desc *desc, const u8 *data, - unsigned int length) -{ - struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); - ctx->crc =3D crc32c(ctx->crc, data, length); return 0; } =20 static int chksum_final(struct shash_desc *desc, u8 *out) @@ -105,17 +96,10 @@ static int chksum_final(struct shash_desc *desc, u8 *o= ut) put_unaligned_le32(~ctx->crc, out); return 0; } =20 static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 = *out) -{ - put_unaligned_le32(~crc32c_base(*crcp, data, len), out); - return 0; -} - -static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len, - u8 *out) { put_unaligned_le32(~crc32c(*crcp, data, len), out); return 0; } =20 @@ -125,98 +109,58 @@ static int chksum_finup(struct shash_desc *desc, cons= t u8 *data, struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); =20 return __chksum_finup(&ctx->crc, data, len, out); } =20 -static int chksum_finup_arch(struct shash_desc *desc, const u8 *data, - unsigned int len, u8 *out) -{ - struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); - - return __chksum_finup_arch(&ctx->crc, data, len, out); -} - static int chksum_digest(struct shash_desc *desc, const u8 *data, unsigned int length, u8 *out) { struct chksum_ctx *mctx =3D crypto_shash_ctx(desc->tfm); =20 return __chksum_finup(&mctx->key, data, length, out); } =20 -static int chksum_digest_arch(struct shash_desc *desc, const u8 *data, - unsigned int length, u8 *out) -{ - struct chksum_ctx *mctx =3D crypto_shash_ctx(desc->tfm); - - return __chksum_finup_arch(&mctx->key, data, length, out); -} - static int crc32c_cra_init(struct crypto_tfm *tfm) { struct chksum_ctx *mctx =3D crypto_tfm_ctx(tfm); =20 mctx->key =3D ~0; return 0; } =20 -static struct shash_alg algs[] =3D {{ +static struct shash_alg alg =3D { .digestsize =3D CHKSUM_DIGEST_SIZE, .setkey =3D chksum_setkey, .init =3D chksum_init, .update =3D chksum_update, .final =3D chksum_final, .finup =3D chksum_finup, .digest =3D chksum_digest, .descsize =3D sizeof(struct chksum_desc_ctx), =20 .base.cra_name =3D "crc32c", - .base.cra_driver_name =3D "crc32c-generic", + .base.cra_driver_name =3D "crc32c-lib", .base.cra_priority =3D 100, .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, .base.cra_ctxsize =3D sizeof(struct chksum_ctx), .base.cra_module =3D THIS_MODULE, .base.cra_init =3D crc32c_cra_init, -}, { - .digestsize =3D CHKSUM_DIGEST_SIZE, - .setkey =3D chksum_setkey, - .init =3D chksum_init, - .update =3D chksum_update_arch, - .final =3D chksum_final, - .finup =3D chksum_finup_arch, - .digest =3D chksum_digest_arch, - .descsize =3D sizeof(struct chksum_desc_ctx), - - .base.cra_name =3D "crc32c", - .base.cra_driver_name =3D "crc32c-" __stringify(ARCH), - .base.cra_priority =3D 150, - .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, - .base.cra_ctxsize =3D sizeof(struct chksum_ctx), - .base.cra_module =3D THIS_MODULE, - .base.cra_init =3D crc32c_cra_init, -}}; - -static int num_algs; +}; =20 static int __init crc32c_mod_init(void) { - /* register the arch flavor only if it differs from the generic one */ - num_algs =3D 1 + ((crc32_optimizations() & CRC32C_OPTIMIZATION) !=3D 0); - - return crypto_register_shashes(algs, num_algs); + return crypto_register_shash(&alg); } =20 static void __exit crc32c_mod_fini(void) { - crypto_unregister_shashes(algs, num_algs); + crypto_unregister_shash(&alg); } =20 module_init(crc32c_mod_init); module_exit(crc32c_mod_fini); =20 MODULE_AUTHOR("Clay Haapala "); MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32= c"); MODULE_LICENSE("GPL"); MODULE_ALIAS_CRYPTO("crc32c"); -MODULE_ALIAS_CRYPTO("crc32c-generic"); diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 72005074a5c26..3b947b828ff83 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -4544,17 +4544,19 @@ static const struct alg_test_desc alg_test_descs[] = =3D { .suite =3D { .hash =3D __VECS(sm4_cmac128_tv_template) } }, { .alg =3D "crc32", + .generic_driver =3D "crc32-lib", .test =3D alg_test_hash, .fips_allowed =3D 1, .suite =3D { .hash =3D __VECS(crc32_tv_template) } }, { .alg =3D "crc32c", + .generic_driver =3D "crc32c-lib", .test =3D alg_test_crc32c, .fips_allowed =3D 1, .suite =3D { .hash =3D __VECS(crc32c_tv_template) } --=20 2.49.0