Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto/crc32[c]: register only "-lib" drivers

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 commits make those static functions.

Since this commit removes the "crc32-generic" and "crc32c-generic"
driver names which crypto/testmgr.c expects to exist, update testmgr.c
accordingly. This does mean that 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 commit
fixed, no code appears to have been relying on the "crc32-generic" or
"crc32c-generic" driver names specifically.

btrfs does export the checksum name and checksum driver name in
/sys/fs/btrfs/$uuid/checksum. This commit makes the driver name portion
of that file contain "crc32c-lib" instead of "crc32c-generic" or
"crc32c-$(ARCH)". This should be fine, since in practice the purpose of
the driver name portion 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
the driver name portion of this is basically obsolete. (Also, note that
the crc32c driver name already changed in 6.14.)

Acked-by: David Sterba <dsterba@suse.com>
Link: https://lore.kernel.org/r/20250613183753.31864-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+13 -122
-2
crypto/Makefile
··· 154 154 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o 155 155 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c-cryptoapi.o 156 156 crc32c-cryptoapi-y := crc32c.o 157 - CFLAGS_crc32c.o += -DARCH=$(ARCH) 158 157 obj-$(CONFIG_CRYPTO_CRC32) += crc32-cryptoapi.o 159 158 crc32-cryptoapi-y := crc32.o 160 - CFLAGS_crc32.o += -DARCH=$(ARCH) 161 159 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o 162 160 obj-$(CONFIG_CRYPTO_KRB5ENC) += krb5enc.o 163 161 obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o
+6 -59
crypto/crc32.c
··· 59 59 { 60 60 u32 *crcp = shash_desc_ctx(desc); 61 61 62 - *crcp = crc32_le_base(*crcp, data, len); 63 - return 0; 64 - } 65 - 66 - static int crc32_update_arch(struct shash_desc *desc, const u8 *data, 67 - unsigned int len) 68 - { 69 - u32 *crcp = shash_desc_ctx(desc); 70 - 71 62 *crcp = crc32_le(*crcp, data, len); 72 63 return 0; 73 64 } 74 65 75 66 /* No final XOR 0xFFFFFFFF, like crc32_le */ 76 - static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, 77 - u8 *out) 78 - { 79 - put_unaligned_le32(crc32_le_base(*crcp, data, len), out); 80 - return 0; 81 - } 82 - 83 - static int __crc32_finup_arch(u32 *crcp, const u8 *data, unsigned int len, 84 - u8 *out) 67 + static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) 85 68 { 86 69 put_unaligned_le32(crc32_le(*crcp, data, len), out); 87 70 return 0; ··· 74 91 unsigned int len, u8 *out) 75 92 { 76 93 return __crc32_finup(shash_desc_ctx(desc), data, len, out); 77 - } 78 - 79 - static int crc32_finup_arch(struct shash_desc *desc, const u8 *data, 80 - unsigned int len, u8 *out) 81 - { 82 - return __crc32_finup_arch(shash_desc_ctx(desc), data, len, out); 83 94 } 84 95 85 96 static int crc32_final(struct shash_desc *desc, u8 *out) ··· 90 113 return __crc32_finup(crypto_shash_ctx(desc->tfm), data, len, out); 91 114 } 92 115 93 - static int crc32_digest_arch(struct shash_desc *desc, const u8 *data, 94 - unsigned int len, u8 *out) 95 - { 96 - return __crc32_finup_arch(crypto_shash_ctx(desc->tfm), data, len, out); 97 - } 98 - 99 - static struct shash_alg algs[] = {{ 116 + static struct shash_alg alg = { 100 117 .setkey = crc32_setkey, 101 118 .init = crc32_init, 102 119 .update = crc32_update, ··· 101 130 .digestsize = CHKSUM_DIGEST_SIZE, 102 131 103 132 .base.cra_name = "crc32", 104 - .base.cra_driver_name = "crc32-generic", 133 + .base.cra_driver_name = "crc32-lib", 105 134 .base.cra_priority = 100, 106 135 .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 107 136 .base.cra_blocksize = CHKSUM_BLOCK_SIZE, 108 137 .base.cra_ctxsize = sizeof(u32), 109 138 .base.cra_module = THIS_MODULE, 110 139 .base.cra_init = crc32_cra_init, 111 - }, { 112 - .setkey = crc32_setkey, 113 - .init = crc32_init, 114 - .update = crc32_update_arch, 115 - .final = crc32_final, 116 - .finup = crc32_finup_arch, 117 - .digest = crc32_digest_arch, 118 - .descsize = sizeof(u32), 119 - .digestsize = CHKSUM_DIGEST_SIZE, 120 - 121 - .base.cra_name = "crc32", 122 - .base.cra_driver_name = "crc32-" __stringify(ARCH), 123 - .base.cra_priority = 150, 124 - .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 125 - .base.cra_blocksize = CHKSUM_BLOCK_SIZE, 126 - .base.cra_ctxsize = sizeof(u32), 127 - .base.cra_module = THIS_MODULE, 128 - .base.cra_init = crc32_cra_init, 129 - }}; 130 - 131 - static int num_algs; 140 + }; 132 141 133 142 static int __init crc32_mod_init(void) 134 143 { 135 - /* register the arch flavor only if it differs from the generic one */ 136 - num_algs = 1 + ((crc32_optimizations() & CRC32_LE_OPTIMIZATION) != 0); 137 - 138 - return crypto_register_shashes(algs, num_algs); 144 + return crypto_register_shash(&alg); 139 145 } 140 146 141 147 static void __exit crc32_mod_fini(void) 142 148 { 143 - crypto_unregister_shashes(algs, num_algs); 149 + crypto_unregister_shash(&alg); 144 150 } 145 151 146 152 module_init(crc32_mod_init); ··· 127 179 MODULE_DESCRIPTION("CRC32 calculations wrapper for lib/crc32"); 128 180 MODULE_LICENSE("GPL"); 129 181 MODULE_ALIAS_CRYPTO("crc32"); 130 - MODULE_ALIAS_CRYPTO("crc32-generic");
+5 -61
crypto/crc32c.c
··· 85 85 { 86 86 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc); 87 87 88 - ctx->crc = crc32c_base(ctx->crc, data, length); 89 - return 0; 90 - } 91 - 92 - static int chksum_update_arch(struct shash_desc *desc, const u8 *data, 93 - unsigned int length) 94 - { 95 - struct chksum_desc_ctx *ctx = shash_desc_ctx(desc); 96 - 97 88 ctx->crc = crc32c(ctx->crc, data, length); 98 89 return 0; 99 90 } ··· 99 108 100 109 static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) 101 110 { 102 - put_unaligned_le32(~crc32c_base(*crcp, data, len), out); 103 - return 0; 104 - } 105 - 106 - static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len, 107 - u8 *out) 108 - { 109 111 put_unaligned_le32(~crc32c(*crcp, data, len), out); 110 112 return 0; 111 113 } ··· 111 127 return __chksum_finup(&ctx->crc, data, len, out); 112 128 } 113 129 114 - static int chksum_finup_arch(struct shash_desc *desc, const u8 *data, 115 - unsigned int len, u8 *out) 116 - { 117 - struct chksum_desc_ctx *ctx = shash_desc_ctx(desc); 118 - 119 - return __chksum_finup_arch(&ctx->crc, data, len, out); 120 - } 121 - 122 130 static int chksum_digest(struct shash_desc *desc, const u8 *data, 123 131 unsigned int length, u8 *out) 124 132 { 125 133 struct chksum_ctx *mctx = crypto_shash_ctx(desc->tfm); 126 134 127 135 return __chksum_finup(&mctx->key, data, length, out); 128 - } 129 - 130 - static int chksum_digest_arch(struct shash_desc *desc, const u8 *data, 131 - unsigned int length, u8 *out) 132 - { 133 - struct chksum_ctx *mctx = crypto_shash_ctx(desc->tfm); 134 - 135 - return __chksum_finup_arch(&mctx->key, data, length, out); 136 136 } 137 137 138 138 static int crc32c_cra_init(struct crypto_tfm *tfm) ··· 127 159 return 0; 128 160 } 129 161 130 - static struct shash_alg algs[] = {{ 162 + static struct shash_alg alg = { 131 163 .digestsize = CHKSUM_DIGEST_SIZE, 132 164 .setkey = chksum_setkey, 133 165 .init = chksum_init, ··· 138 170 .descsize = sizeof(struct chksum_desc_ctx), 139 171 140 172 .base.cra_name = "crc32c", 141 - .base.cra_driver_name = "crc32c-generic", 173 + .base.cra_driver_name = "crc32c-lib", 142 174 .base.cra_priority = 100, 143 175 .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 144 176 .base.cra_blocksize = CHKSUM_BLOCK_SIZE, 145 177 .base.cra_ctxsize = sizeof(struct chksum_ctx), 146 178 .base.cra_module = THIS_MODULE, 147 179 .base.cra_init = crc32c_cra_init, 148 - }, { 149 - .digestsize = CHKSUM_DIGEST_SIZE, 150 - .setkey = chksum_setkey, 151 - .init = chksum_init, 152 - .update = chksum_update_arch, 153 - .final = chksum_final, 154 - .finup = chksum_finup_arch, 155 - .digest = chksum_digest_arch, 156 - .descsize = sizeof(struct chksum_desc_ctx), 157 - 158 - .base.cra_name = "crc32c", 159 - .base.cra_driver_name = "crc32c-" __stringify(ARCH), 160 - .base.cra_priority = 150, 161 - .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 162 - .base.cra_blocksize = CHKSUM_BLOCK_SIZE, 163 - .base.cra_ctxsize = sizeof(struct chksum_ctx), 164 - .base.cra_module = THIS_MODULE, 165 - .base.cra_init = crc32c_cra_init, 166 - }}; 167 - 168 - static int num_algs; 180 + }; 169 181 170 182 static int __init crc32c_mod_init(void) 171 183 { 172 - /* register the arch flavor only if it differs from the generic one */ 173 - num_algs = 1 + ((crc32_optimizations() & CRC32C_OPTIMIZATION) != 0); 174 - 175 - return crypto_register_shashes(algs, num_algs); 184 + return crypto_register_shash(&alg); 176 185 } 177 186 178 187 static void __exit crc32c_mod_fini(void) 179 188 { 180 - crypto_unregister_shashes(algs, num_algs); 189 + crypto_unregister_shash(&alg); 181 190 } 182 191 183 192 module_init(crc32c_mod_init); ··· 164 219 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32c"); 165 220 MODULE_LICENSE("GPL"); 166 221 MODULE_ALIAS_CRYPTO("crc32c"); 167 - MODULE_ALIAS_CRYPTO("crc32c-generic");
+2
crypto/testmgr.c
··· 4502 4502 } 4503 4503 }, { 4504 4504 .alg = "crc32", 4505 + .generic_driver = "crc32-lib", 4505 4506 .test = alg_test_hash, 4506 4507 .fips_allowed = 1, 4507 4508 .suite = { ··· 4510 4509 } 4511 4510 }, { 4512 4511 .alg = "crc32c", 4512 + .generic_driver = "crc32c-lib", 4513 4513 .test = alg_test_hash, 4514 4514 .fips_allowed = 1, 4515 4515 .suite = {