crypto: remove CONFIG_CRYPTO_STATS
Subsystems (2)
PATCH v2 1/1 crypto: remove CONFIG_CRYPTO_STATS
From: Eric Biggers <[email protected]>
Remove support for the "Crypto usage statistics" feature (CONFIG_CRYPTO_STATS). This feature does not appear to have ever been used, and it is harmful because it significantly reduces performance and is a large maintenance burden.
Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink, it's fairly straightforward to look for programs that use them. I'm unable to find any evidence that any such programs exist. For example, Debian Code Search returns no hits except the kernel header and kernel code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/[email protected]/)
said "The goal is to have an ifconfig for crypto device." This doesn't appear to have happened.
It's not clear that there is real demand for crypto statistics. Just because the kernel provides other types of statistics such as I/O and networking statistics and some people find those useful does not mean that crypto statistics are useful too.
Further evidence that programs are not using CONFIG_CRYPTO_STATS is that it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
Even further evidence comes from the fact that there are and have been bugs in how the stats work, but they were never reported. For example, before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it might be hard to use even if someone wanted to.
2. CONFIG_CRYPTO_STATS significantly reduces performance
Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of the crypto API, even if no program ever retrieves the statistics. This primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported that Lustre client encryption performance improved from 21.7GB/s to 48.2GB/s by disabling CONFIG_CRYPTO_STATS.
It can be argued that this means that CONFIG_CRYPTO_STATS should be optimized with per-cpu counters similar to many of the networking counters. But no one has done this in 5+ years. This is consistent with the fact that the feature appears to be unused, so there seems to be little interest in improving it as opposed to just disabling it.
It can be argued that because CONFIG_CRYPTO_STATS is off by default, performance doesn't matter. But Linux distros tend to error on the side of enabling options. The option is enabled in Ubuntu and Arch Linux, and until recently was enabled in RHEL and Fedora (see above). So, even just having the option available is harmful to users.
3. CONFIG_CRYPTO_STATS is a large maintenance burden
There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS, spread among 32 files. It significantly complicates much of the implementation of the crypto API. After the initial submission, many fixes and refactorings have consumed effort of multiple people to keep this feature "working". We should be spending this effort elsewhere.
---
Changed in v2:
- Keep struct comp_alg_common, as per the request at
https://lore.kernel.org/linux-crypto/[email protected]/,
even though the struct becomes trivial with the stats removed.
- Use consistent comments in include/uapi/linux/cryptouser.h, and add one to CRYPTO_MSG_GETSTAT which was missing one.
- In crypto/compress.h, remove the forward declaration of sk_buff because the function prototype that needed it is being removed.
- In crypto_shash_digest(), don't read desc->tfm redundantly.
arch/s390/configs/debug_defconfig | 1 -
arch/s390/configs/defconfig | 1 -
crypto/Kconfig | 20 ---
crypto/Makefile | 2 -
crypto/acompress.c | 33 ----
crypto/aead.c | 84 +--------
crypto/ahash.c | 63 +------
crypto/akcipher.c | 31 ----
crypto/compress.h | 3 -
crypto/{crypto_user_base.c => crypto_user.c} | 10 +-
crypto/crypto_user_stat.c | 176 -------------------
crypto/hash.h | 30 ----
crypto/kpp.c | 30 ----
crypto/lskcipher.c | 73 +-------
crypto/rng.c | 44 +----
crypto/scompress.c | 3 -
crypto/shash.c | 75 +-------
crypto/sig.c | 13 --
crypto/skcipher.c | 86 +--------
crypto/skcipher.h | 10 --
include/crypto/acompress.h | 73 +-------
include/crypto/aead.h | 21 ---
include/crypto/akcipher.h | 78 +-------
include/crypto/algapi.h | 3 -
include/crypto/hash.h | 22 ---
include/crypto/internal/acompress.h | 1 -
include/crypto/internal/cryptouser.h | 16 --
include/crypto/internal/scompress.h | 1 -
include/crypto/kpp.h | 58 +-----
include/crypto/rng.h | 51 +-----
include/crypto/skcipher.h | 25 ---
include/uapi/linux/cryptouser.h | 30 ++--
32 files changed, 71 insertions(+), 1096 deletions(-)
rename crypto/{crypto_user_base.c => crypto_user.c} (98%)
delete mode 100644 crypto/crypto_user_stat.c
delete mode 100644 include/crypto/internal/cryptouser.harch/s390/configs/debug_defconfig +0 -1
@@ -764,11 +764,10 @@ CONFIG_CRYPTO_ZSTD=m CONFIG_CRYPTO_ANSI_CPRNG=m CONFIG_CRYPTO_USER_API_HASH=m CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m -CONFIG_CRYPTO_STATS=y CONFIG_CRYPTO_CRC32_S390=y CONFIG_CRYPTO_SHA512_S390=m CONFIG_CRYPTO_SHA1_S390=m CONFIG_CRYPTO_SHA256_S390=m CONFIG_CRYPTO_SHA3_256_S390=m
arch/s390/configs/defconfig +0 -1
@@ -750,11 +750,10 @@ CONFIG_CRYPTO_ZSTD=m CONFIG_CRYPTO_ANSI_CPRNG=m CONFIG_CRYPTO_USER_API_HASH=m CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m -CONFIG_CRYPTO_STATS=y CONFIG_CRYPTO_CRC32_S390=y CONFIG_CRYPTO_SHA512_S390=m CONFIG_CRYPTO_SHA1_S390=m CONFIG_CRYPTO_SHA256_S390=m CONFIG_CRYPTO_SHA3_256_S390=m
crypto/Kconfig +0 -20
@@ -1454,30 +1454,10 @@ config CRYPTO_USER_API_ENABLE_OBSOLETE help Allow obsolete cryptographic algorithms to be selected that have already been phased out from internal use by the kernel, and are only useful for userspace clients that still rely on them. -config CRYPTO_STATS - bool "Crypto usage statistics" - depends on CRYPTO_USER - help - Enable the gathering of crypto stats. - - Enabling this option reduces the performance of the crypto API. It - should only be enabled when there is actually a use case for it. - - This collects data sizes, numbers of requests, and numbers - of errors processed by: - - AEAD ciphers (encrypt, decrypt) - - asymmetric key ciphers (encrypt, decrypt, verify, sign) - - symmetric key ciphers (encrypt, decrypt) - - compression algorithms (compress, decompress) - - hash algorithms (hash) - - key-agreement protocol primitives (setsecret, generate - public key, compute shared secret) - - RNG (generate, seed) - endmenu config CRYPTO_HASH_INFO bool
crypto/Makefile +0 -2
@@ -67,12 +67,10 @@ obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o cryptomgr-y := algboss.o testmgr.o obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o obj-$(CONFIG_CRYPTO_USER) += crypto_user.o -crypto_user-y := crypto_user_base.o -crypto_user-$(CONFIG_CRYPTO_STATS) += crypto_user_stat.o obj-$(CONFIG_CRYPTO_CMAC) += cmac.o obj-$(CONFIG_CRYPTO_HMAC) += hmac.o obj-$(CONFIG_CRYPTO_VMAC) += vmac.o obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o obj-$(CONFIG_CRYPTO_NULL2) += crypto_null.o
crypto/acompress.c +0 -33
@@ -91,47 +91,18 @@ static unsigned int crypto_acomp_extsize(struct crypto_alg *alg) extsize +=sizeof (struct crypto_scomp *);return extsize; } -static inline int __crypto_acomp_report_stat (struct sk_buff *skb, -struct crypto_alg *alg) -{ -struct comp_alg_common *calg =__crypto_comp_alg_common (alg); -struct crypto_istat_compress *istat =comp_get_stat (calg); -struct crypto_stat_compress racomp; - -memset (&racomp,0 ,sizeof (racomp)); - -strscpy (racomp.type,"acomp" ,sizeof (racomp.type)); - racomp.stat_compress_cnt =atomic64_read (&istat->compress_cnt); - racomp.stat_compress_tlen =atomic64_read (&istat->compress_tlen); - racomp.stat_decompress_cnt =atomic64_read (&istat->decompress_cnt); - racomp.stat_decompress_tlen =atomic64_read (&istat->decompress_tlen); - racomp.stat_err_cnt =atomic64_read (&istat->err_cnt); - -return nla_put (skb,CRYPTOCFGA_STAT_ACOMP ,sizeof (racomp), &racomp); -} - -#ifdef CONFIG_CRYPTO_STATS -int crypto_acomp_report_stat (struct sk_buff *skb,struct crypto_alg *alg) -{ -return __crypto_acomp_report_stat (skb, alg); -} -#endif -static const struct crypto_type crypto_acomp_type = { .extsize = crypto_acomp_extsize, .init_tfm = crypto_acomp_init_tfm, #ifdef CONFIG_PROC_FS .show = crypto_acomp_show, #endif #if IS_ENABLED(CONFIG_CRYPTO_USER) .report = crypto_acomp_report, -#endif -#ifdef CONFIG_CRYPTO_STATS - .report_stat = crypto_acomp_report_stat, #endif .maskclear = ~CRYPTO_ALG_TYPE_MASK , .maskset =CRYPTO_ALG_TYPE_ACOMPRESS_MASK , .type =CRYPTO_ALG_TYPE_ACOMPRESS , .tfmsize = offsetof(struct crypto_acomp , base),
@@ -182,17 +153,13 @@ void acomp_request_free(struct acomp_req *req) }EXPORT_SYMBOL_GPL (acomp_request_free);void comp_prepare_alg (struct comp_alg_common *alg) { -struct crypto_istat_compress *istat =comp_get_stat (alg);struct crypto_alg *base = &alg->base; base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK ; - -if (IS_ENABLED (CONFIG_CRYPTO_STATS )) -memset (istat,0 ,sizeof (*istat)); }int crypto_register_acomp (struct acomp_alg *alg) {struct crypto_alg *base = &alg->calg.base;
crypto/aead.c +7 -77
158 lines not on this page · raw message
crypto/ahash.c +5 -58
138 lines not on this page · raw message
crypto/akcipher.c +0 -31
@@ -68,46 +68,19 @@ static void crypto_akcipher_free_instance(struct crypto_instance *inst)struct akcipher_instance *akcipher =akcipher_instance (inst); akcipher->free (akcipher); } -static int __maybe_unused crypto_akcipher_report_stat ( -struct sk_buff *skb,struct crypto_alg *alg) -{ -struct akcipher_alg *akcipher =__crypto_akcipher_alg (alg); -struct crypto_istat_akcipher *istat; -struct crypto_stat_akcipher rakcipher; - - istat =akcipher_get_stat (akcipher); - -memset (&rakcipher,0 ,sizeof (rakcipher)); - -strscpy (rakcipher.type,"akcipher" ,sizeof (rakcipher.type)); - rakcipher.stat_encrypt_cnt =atomic64_read (&istat->encrypt_cnt); - rakcipher.stat_encrypt_tlen =atomic64_read (&istat->encrypt_tlen); - rakcipher.stat_decrypt_cnt =atomic64_read (&istat->decrypt_cnt); - rakcipher.stat_decrypt_tlen =atomic64_read (&istat->decrypt_tlen); - rakcipher.stat_sign_cnt =atomic64_read (&istat->sign_cnt); - rakcipher.stat_verify_cnt =atomic64_read (&istat->verify_cnt); - rakcipher.stat_err_cnt =atomic64_read (&istat->err_cnt); - -return nla_put (skb,CRYPTOCFGA_STAT_AKCIPHER , -sizeof (rakcipher), &rakcipher); -} -static const struct crypto_type crypto_akcipher_type = { .extsize = crypto_alg_extsize, .init_tfm = crypto_akcipher_init_tfm, .free = crypto_akcipher_free_instance, #ifdef CONFIG_PROC_FS .show = crypto_akcipher_show, #endif #if IS_ENABLED(CONFIG_CRYPTO_USER) .report = crypto_akcipher_report, -#endif -#ifdef CONFIG_CRYPTO_STATS - .report_stat = crypto_akcipher_report_stat, #endif .maskclear = ~CRYPTO_ALG_TYPE_MASK , .maskset =CRYPTO_ALG_TYPE_AHASH_MASK , .type =CRYPTO_ALG_TYPE_AKCIPHER , .tfmsize = offsetof(struct crypto_akcipher , base),
@@ -129,19 +102,15 @@ struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, }EXPORT_SYMBOL_GPL (crypto_alloc_akcipher);static void akcipher_prepare_alg (struct akcipher_alg *alg) { -struct crypto_istat_akcipher *istat =akcipher_get_stat (alg);struct crypto_alg *base = &alg->base; base->cra_type = &crypto_akcipher_type; base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK ; base->cra_flags |=CRYPTO_ALG_TYPE_AKCIPHER ; - -if (IS_ENABLED (CONFIG_CRYPTO_STATS )) -memset (istat,0 ,sizeof (*istat)); }static int akcipher_default_op (struct akcipher_request *req) {return -ENOSYS ;
crypto/compress.h +0 -3
@@ -11,16 +11,13 @@#include "internal.h" struct acomp_req ;struct comp_alg_common ; -struct sk_buff ;int crypto_init_scomp_ops_async (struct crypto_tfm *tfm);struct acomp_req *crypto_acomp_scomp_alloc_ctx (struct acomp_req *req);void crypto_acomp_scomp_free_ctx (struct acomp_req *req); -int crypto_acomp_report_stat (struct sk_buff *skb,struct crypto_alg *alg); -void comp_prepare_alg (struct comp_alg_common *alg);#endif /* _LOCAL_CRYPTO_COMPRESS_H */
crypto/crypto_user.c renamed from crypto/crypto_user_base.c +8 -2
@@ -16,11 +16,10 @@#include <net/sock.h> #include <crypto/internal/skcipher.h> #include <crypto/internal/rng.h> #include <crypto/akcipher.h> #include <crypto/kpp.h> -#include <crypto/internal/cryptouser.h> #include "internal.h" #define null_terminated (x) (strnlen(x, sizeof(x)) < sizeof(x))
@@ -31,11 +30,11 @@ struct crypto_dump_info {struct sk_buff *out_skb;u32 nlmsg_seq;u16 nlmsg_flags; }; -struct crypto_alg *crypto_alg_match (struct crypto_user_alg *p,int exact) +static struct crypto_alg *crypto_alg_match (struct crypto_user_alg *p,int exact) {struct crypto_alg *q, *alg =NULL ;down_read (&crypto_alg_sem);
@@ -385,10 +384,17 @@ static int crypto_del_rng(struct sk_buff *skb, struct nlmsghdr *nlh,if (!netlink_capable (skb,CAP_NET_ADMIN ))return -EPERM ;return crypto_del_default_rng (); } +static int crypto_reportstat (struct sk_buff *in_skb,struct nlmsghdr *in_nlh, +struct nlattr **attrs) +{ +/* No longer supported */ +return -ENOTSUPP ; +} +#define MSGSIZE (type) sizeof(struct type)static const int crypto_msg_min[CRYPTO_NR_MSGTYPES ] = { [CRYPTO_MSG_NEWALG -CRYPTO_MSG_BASE ] =MSGSIZE (crypto_user_alg), [CRYPTO_MSG_DELALG -CRYPTO_MSG_BASE ] =MSGSIZE (crypto_user_alg),
crypto/crypto_user_stat.c deleted +0 -176
176 lines not on this page · raw message
crypto/hash.h +0 -30
@@ -6,43 +6,13 @@*/ #ifndef _LOCAL_CRYPTO_HASH_H#define _LOCAL_CRYPTO_HASH_H#include <crypto/internal/hash.h> -#include <linux/cryptouser.h> #include "internal.h" -static inline struct crypto_istat_hash *hash_get_stat ( -struct hash_alg_common *alg) -{ -#ifdef CONFIG_CRYPTO_STATS -return &alg->stat; -#else -return NULL ; -#endif -} - -static inline int crypto_hash_report_stat (struct sk_buff *skb, -struct crypto_alg *alg, -const char *type) -{ -struct hash_alg_common *halg =__crypto_hash_alg_common (alg); -struct crypto_istat_hash *istat =hash_get_stat (halg); -struct crypto_stat_hash rhash; - -memset (&rhash,0 ,sizeof (rhash)); - -strscpy (rhash.type, type,sizeof (rhash.type)); - - rhash.stat_hash_cnt =atomic64_read (&istat->hash_cnt); - rhash.stat_hash_tlen =atomic64_read (&istat->hash_tlen); - rhash.stat_err_cnt =atomic64_read (&istat->err_cnt); - -return nla_put (skb,CRYPTOCFGA_STAT_HASH ,sizeof (rhash), &rhash); -} -extern const struct crypto_type crypto_shash_type;int hash_prepare_alg (struct hash_alg_common *alg);#endif /* _LOCAL_CRYPTO_HASH_H */
crypto/kpp.c +0 -30
@@ -64,45 +64,19 @@ static void crypto_kpp_free_instance(struct crypto_instance *inst)struct kpp_instance *kpp =kpp_instance (inst); kpp->free (kpp); } -static int __maybe_unused crypto_kpp_report_stat ( -struct sk_buff *skb,struct crypto_alg *alg) -{ -struct kpp_alg *kpp =__crypto_kpp_alg (alg); -struct crypto_istat_kpp *istat; -struct crypto_stat_kpp rkpp; - - istat =kpp_get_stat (kpp); - -memset (&rkpp,0 ,sizeof (rkpp)); - -strscpy (rkpp.type,"kpp" ,sizeof (rkpp.type)); - - rkpp.stat_setsecret_cnt =atomic64_read (&istat->setsecret_cnt); - rkpp.stat_generate_public_key_cnt = -atomic64_read (&istat->generate_public_key_cnt); - rkpp.stat_compute_shared_secret_cnt = -atomic64_read (&istat->compute_shared_secret_cnt); - rkpp.stat_err_cnt =atomic64_read (&istat->err_cnt); - -return nla_put (skb,CRYPTOCFGA_STAT_KPP ,sizeof (rkpp), &rkpp); -} -static const struct crypto_type crypto_kpp_type = { .extsize = crypto_alg_extsize, .init_tfm = crypto_kpp_init_tfm, .free = crypto_kpp_free_instance, #ifdef CONFIG_PROC_FS .show = crypto_kpp_show, #endif #if IS_ENABLED(CONFIG_CRYPTO_USER) .report = crypto_kpp_report, -#endif -#ifdef CONFIG_CRYPTO_STATS - .report_stat = crypto_kpp_report_stat, #endif .maskclear = ~CRYPTO_ALG_TYPE_MASK , .maskset =CRYPTO_ALG_TYPE_MASK , .type =CRYPTO_ALG_TYPE_KPP , .tfmsize = offsetof(struct crypto_kpp , base),
@@ -129,19 +103,15 @@ int crypto_has_kpp(const char *alg_name, u32 type, u32 mask) }EXPORT_SYMBOL_GPL (crypto_has_kpp);static void kpp_prepare_alg (struct kpp_alg *alg) { -struct crypto_istat_kpp *istat =kpp_get_stat (alg);struct crypto_alg *base = &alg->base; base->cra_type = &crypto_kpp_type; base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK ; base->cra_flags |=CRYPTO_ALG_TYPE_KPP ; - -if (IS_ENABLED (CONFIG_CRYPTO_STATS )) -memset (istat,0 ,sizeof (*istat)); }int crypto_register_kpp (struct kpp_alg *alg) {struct crypto_alg *base = &alg->base;
crypto/lskcipher.c +4 -69
131 lines not on this page · raw message
crypto/rng.c +5 -39
104 lines not on this page · raw message
crypto/scompress.c +0 -3
@@ -268,13 +268,10 @@ static const struct crypto_type crypto_scomp_type = {#ifdef CONFIG_PROC_FS .show = crypto_scomp_show,#endif #if IS_ENABLED (CONFIG_CRYPTO_USER ) .report = crypto_scomp_report, -#endif -#ifdef CONFIG_CRYPTO_STATS - .report_stat = crypto_acomp_report_stat, #endif .maskclear = ~CRYPTO_ALG_TYPE_MASK, .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_SCOMPRESS, .tfmsize = offsetof(struct crypto_scomp, base),
crypto/shash.c +5 -70
162 lines not on this page · raw message
crypto/sig.c +0 -13
@@ -43,31 +43,18 @@ static int __maybe_unused crypto_sig_report(struct sk_buff *skb,strscpy (rsig.type,"sig" ,sizeof (rsig.type));return nla_put (skb,CRYPTOCFGA_REPORT_AKCIPHER ,sizeof (rsig), &rsig); } -static int __maybe_unused crypto_sig_report_stat (struct sk_buff *skb, -struct crypto_alg *alg) -{ -struct crypto_stat_akcipher rsig = {}; - -strscpy (rsig.type,"sig" ,sizeof (rsig.type)); - -return nla_put (skb,CRYPTOCFGA_STAT_AKCIPHER ,sizeof (rsig), &rsig); -} -static const struct crypto_type crypto_sig_type = { .extsize = crypto_alg_extsize, .init_tfm = crypto_sig_init_tfm, #ifdef CONFIG_PROC_FS .show = crypto_sig_show, #endif #if IS_ENABLED(CONFIG_CRYPTO_USER) .report = crypto_sig_report, -#endif -#ifdef CONFIG_CRYPTO_STATS - .report_stat = crypto_sig_report_stat, #endif .maskclear = ~CRYPTO_ALG_TYPE_MASK , .maskset =CRYPTO_ALG_TYPE_SIG_MASK , .type =CRYPTO_ALG_TYPE_SIG , .tfmsize = offsetof(struct crypto_sig , base),
crypto/skcipher.c +8 -78
156 lines not on this page · raw message
crypto/skcipher.h +0 -10
@@ -8,20 +8,10 @@#define _LOCAL_CRYPTO_SKCIPHER_H#include <crypto/internal/skcipher.h> #include "internal.h" -static inline struct crypto_istat_cipher *skcipher_get_stat_common ( -struct skcipher_alg_common *alg) -{ -#ifdef CONFIG_CRYPTO_STATS -return &alg->stat; -#else -return NULL ; -#endif -} -int crypto_lskcipher_encrypt_sg (struct skcipher_request *req);int crypto_lskcipher_decrypt_sg (struct skcipher_request *req);int crypto_init_lskcipher_ops_sg (struct crypto_tfm *tfm);int skcipher_prepare_alg_common (struct skcipher_alg_common *alg);
include/crypto/acompress.h +2 -71
112 lines not on this page · raw message
include/crypto/aead.h +0 -21
@@ -99,26 +99,10 @@ struct aead_request {struct scatterlist *dst; void *__ctx[] CRYPTO_MINALIGN_ATTR; }; -/* -* struct crypto_istat_aead - statistics for AEAD algorithm -* @encrypt_cnt: number of encrypt requests -* @encrypt_tlen: total data size handled by encrypt requests -* @decrypt_cnt: number of decrypt requests -* @decrypt_tlen: total data size handled by decrypt requests -* @err_cnt: number of error for AEAD requests -*/ -struct crypto_istat_aead { -atomic64_t encrypt_cnt; -atomic64_t encrypt_tlen; -atomic64_t decrypt_cnt; -atomic64_t decrypt_tlen; -atomic64_t err_cnt; -}; -/** * struct aead_alg - AEAD cipher definition * @maxauthsize: Set the maximum authentication tag size supported by the * transformation. A transformation may support smaller tag sizes. * As the authentication tag is a message digest to ensure the
@@ -133,11 +117,10 @@ struct crypto_istat_aead {* responsible for checking the authentication tag size for * validity. * @setkey: see struct skcipher_alg * @encrypt: see struct skcipher_alg * @decrypt: see struct skcipher_alg -* @stat: statistics for AEAD algorithm * @ivsize: see struct skcipher_alg * @chunksize: see struct skcipher_alg * @init: Initialize the cryptographic transformation object. This function * is used to initialize the cryptographic transformation object. * This function is called only once at the instantiation time, right
@@ -160,14 +143,10 @@ struct aead_alg {int (*encrypt)(struct aead_request *req);int (*decrypt)(struct aead_request *req);int (*init)(struct crypto_aead *tfm);void (*exit)(struct crypto_aead *tfm); -#ifdef CONFIG_CRYPTO_STATS -struct crypto_istat_aead stat; -#endif -unsigned int ivsize;unsigned int maxauthsize;unsigned int chunksize;struct crypto_alg base;
include/crypto/akcipher.h +4 -74
162 lines not on this page · raw message
include/crypto/algapi.h +0 -3
@@ -59,13 +59,10 @@ struct crypto_type {unsigned int (*extsize)(struct crypto_alg *alg);int (*init_tfm)(struct crypto_tfm *tfm);void (*show)(struct seq_file *m,struct crypto_alg *alg);int (*report)(struct sk_buff *skb,struct crypto_alg *alg);void (*free)(struct crypto_instance *inst); -#ifdef CONFIG_CRYPTO_STATS -int (*report_stat)(struct sk_buff *skb,struct crypto_alg *alg); -#endif unsigned int type;unsigned int maskclear;unsigned int maskset;unsigned int tfmsize;
include/crypto/hash.h +0 -22
@@ -21,31 +21,12 @@ struct crypto_ahash;* implementations, managed via crypto_register_ahash(), * crypto_register_shash(), crypto_unregister_ahash() and * crypto_unregister_shash(). */ -/* -* struct crypto_istat_hash - statistics for has algorithm -* @hash_cnt: number of hash requests -* @hash_tlen: total data size hashed -* @err_cnt: number of error for hash requests -*/ -struct crypto_istat_hash { -atomic64_t hash_cnt; -atomic64_t hash_tlen; -atomic64_t err_cnt; -}; - -#ifdef CONFIG_CRYPTO_STATS -#define HASH_ALG_COMMON_STAT struct crypto_istat_hash stat; -#else -#define HASH_ALG_COMMON_STAT -#endif -/* * struct hash_alg_common - define properties of message digest -* @stat: Statistics for hash algorithm. * @digestsize: Size of the result of the transformation. A buffer of this size * must be available to the @final and @finup calls, so they can * store the resulting hash into it. For various predefined sizes, * search include/crypto/ using * git grep _DIGEST_SIZE include/crypto.
@@ -58,12 +39,10 @@ struct crypto_istat_hash {* structure of crypto_alg contains information common to all ciphers. * The hash_alg_common data structure now adds the hash-specific * information. */ #define HASH_ALG_COMMON { \ - HASH_ALG_COMMON_STAT \ - \ unsigned int digestsize; \ unsigned int statesize; \ \ struct crypto_alg base; \ }
@@ -241,11 +220,10 @@ struct shash_alg {struct HASH_ALG_COMMON ;struct hash_alg_common halg; }; };#undef HASH_ALG_COMMON -#undef HASH_ALG_COMMON_STATstruct crypto_ahash {bool using_shash;/* Underlying algorithm is shash, not ahash */ unsigned int statesize;unsigned int reqsize;
include/crypto/internal/acompress.h +0 -1
@@ -29,11 +29,10 @@* @exit: Deinitialize the cryptographic transformation object. This is a * counterpart to @init, used to remove various changes set in * @init. * * @reqsize: Context size for (de)compression requests -* @stat: Statistics for compress algorithm * @base: Common crypto API algorithm data structure * @calg: Cmonn algorithm data structure shared with scomp */ struct acomp_alg {int (*compress)(struct acomp_req *req);
include/crypto/internal/cryptouser.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <linux/cryptouser.h> -#include <net/netlink.h> - -struct crypto_alg *crypto_alg_match (struct crypto_user_alg *p,int exact); - -#ifdef CONFIG_CRYPTO_STATS -int crypto_reportstat (struct sk_buff *in_skb,struct nlmsghdr *in_nlh,struct nlattr **attrs); -#else -static inline int crypto_reportstat (struct sk_buff *in_skb, -struct nlmsghdr *in_nlh, -struct nlattr **attrs) -{ -return -ENOTSUPP ; -} -#endif
include/crypto/internal/scompress.h +0 -1
@@ -25,11 +25,10 @@ struct crypto_scomp {* * @alloc_ctx: Function allocates algorithm specific context * @free_ctx: Function frees context allocated with alloc_ctx * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation -* @stat: Statistics for compress algorithm * @base: Common crypto API algorithm data structure * @calg: Cmonn algorithm data structure shared with acomp */ struct scomp_alg {void *(*alloc_ctx)(struct crypto_scomp *tfm);
include/crypto/kpp.h +3 -55
130 lines not on this page · raw message
include/crypto/rng.h +1 -50
101 lines not on this page · raw message
include/crypto/skcipher.h +0 -25
@@ -62,32 +62,10 @@ struct crypto_sync_skcipher {struct crypto_lskcipher {struct crypto_tfm base; }; -/* -* struct crypto_istat_cipher - statistics for cipher algorithm -* @encrypt_cnt: number of encrypt requests -* @encrypt_tlen: total data size handled by encrypt requests -* @decrypt_cnt: number of decrypt requests -* @decrypt_tlen: total data size handled by decrypt requests -* @err_cnt: number of error for cipher requests -*/ -struct crypto_istat_cipher { -atomic64_t encrypt_cnt; -atomic64_t encrypt_tlen; -atomic64_t decrypt_cnt; -atomic64_t decrypt_tlen; -atomic64_t err_cnt; -}; - -#ifdef CONFIG_CRYPTO_STATS -#define SKCIPHER_ALG_COMMON_STAT struct crypto_istat_cipher stat; -#else -#define SKCIPHER_ALG_COMMON_STAT -#endif -/* * struct skcipher_alg_common - common properties of skcipher_alg * @min_keysize: Minimum key size supported by the transformation. This is the * smallest key length supported by this transformation algorithm. * This must be set to one of the pre-defined values as this is
@@ -101,22 +79,19 @@ struct crypto_istat_cipher {* @ivsize: IV size applicable for transformation. The consumer must provide an * IV of exactly that size to perform the encrypt or decrypt operation. * @chunksize: Equal to the block size except for stream ciphers such as * CTR where it is set to the underlying block size. * @statesize: Size of the internal state for the algorithm. -* @stat: Statistics for cipher algorithm * @base: Definition of a generic crypto algorithm. */ #define SKCIPHER_ALG_COMMON { \ unsigned int min_keysize; \ unsigned int max_keysize; \ unsigned int ivsize; \ unsigned int chunksize; \ unsigned int statesize; \ \ - SKCIPHER_ALG_COMMON_STAT \ - \ struct crypto_alg base; \ }struct skcipher_alg_common SKCIPHER_ALG_COMMON ;/**
include/uapi/linux/cryptouser.h +19 -11
@@ -30,11 +30,11 @@ enum {CRYPTO_MSG_NEWALG =0x10 ,CRYPTO_MSG_DELALG ,CRYPTO_MSG_UPDATEALG ,CRYPTO_MSG_GETALG ,CRYPTO_MSG_DELRNG , -CRYPTO_MSG_GETSTAT , +CRYPTO_MSG_GETSTAT ,/* No longer supported, do not use. */ __CRYPTO_MSG_MAX };#define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1)#define CRYPTO_NR_MSGTYPES (CRYPTO_MSG_MAX + 1 - CRYPTO_MSG_BASE)
@@ -52,20 +52,20 @@ enum crypto_attr_type_t {CRYPTOCFGA_REPORT_RNG ,/* struct crypto_report_rng */ CRYPTOCFGA_REPORT_CIPHER ,/* struct crypto_report_cipher */ CRYPTOCFGA_REPORT_AKCIPHER ,/* struct crypto_report_akcipher */ CRYPTOCFGA_REPORT_KPP ,/* struct crypto_report_kpp */ CRYPTOCFGA_REPORT_ACOMP ,/* struct crypto_report_acomp */ -CRYPTOCFGA_STAT_LARVAL ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_HASH ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_BLKCIPHER ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_AEAD ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_COMPRESS ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_RNG ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_CIPHER ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_AKCIPHER ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_KPP ,/* struct crypto_stat */ -CRYPTOCFGA_STAT_ACOMP ,/* struct crypto_stat */ +CRYPTOCFGA_STAT_LARVAL ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_HASH ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_BLKCIPHER ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_AEAD ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_COMPRESS ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_RNG ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_CIPHER ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_AKCIPHER ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_KPP ,/* No longer supported, do not use. */ +CRYPTOCFGA_STAT_ACOMP ,/* No longer supported, do not use. */ __CRYPTOCFGA_MAX #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1) };
@@ -77,19 +77,21 @@ struct crypto_user_alg {__u32 cru_mask;__u32 cru_refcnt;__u32 cru_flags; }; +/* No longer supported, do not use. */ struct crypto_stat_aead {char type[CRYPTO_MAX_NAME ];__u64 stat_encrypt_cnt;__u64 stat_encrypt_tlen;__u64 stat_decrypt_cnt;__u64 stat_decrypt_tlen;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_akcipher {char type[CRYPTO_MAX_NAME ];__u64 stat_encrypt_cnt;__u64 stat_encrypt_tlen;__u64 stat_decrypt_cnt;
@@ -97,51 +99,57 @@ struct crypto_stat_akcipher {__u64 stat_verify_cnt;__u64 stat_sign_cnt;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_cipher {char type[CRYPTO_MAX_NAME ];__u64 stat_encrypt_cnt;__u64 stat_encrypt_tlen;__u64 stat_decrypt_cnt;__u64 stat_decrypt_tlen;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_compress {char type[CRYPTO_MAX_NAME ];__u64 stat_compress_cnt;__u64 stat_compress_tlen;__u64 stat_decompress_cnt;__u64 stat_decompress_tlen;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_hash {char type[CRYPTO_MAX_NAME ];__u64 stat_hash_cnt;__u64 stat_hash_tlen;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_kpp {char type[CRYPTO_MAX_NAME ];__u64 stat_setsecret_cnt;__u64 stat_generate_public_key_cnt;__u64 stat_compute_shared_secret_cnt;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_rng {char type[CRYPTO_MAX_NAME ];__u64 stat_generate_cnt;__u64 stat_generate_tlen;__u64 stat_seed_cnt;__u64 stat_err_cnt; }; +/* No longer supported, do not use. */ struct crypto_stat_larval {char type[CRYPTO_MAX_NAME ]; };struct crypto_report_larval {
base-commit: 6a8dbd71a70620c42d4fa82509204ba18231f28d
Signature · 1 line
2.44.0
Herbert Xu
maintainerQuoted 119 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Remove support for the "Crypto usage statistics" feature (
CONFIG_CRYPTO_STATS). This feature does not appear to have ever been used, and it is harmful because it significantly reduces performance and is a large maintenance burden.Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink, it's fairly straightforward to look for programs that use them. I'm unable to find any evidence that any such programs exist. For example, Debian Code Search returns no hits except the kernel header and kernel code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/[email protected]/)
said "The goal is to have an ifconfig for crypto device." This doesn't appear to have happened.It's not clear that there is real demand for crypto statistics. Just because the kernel provides other types of statistics such as I/O and networking statistics and some people find those useful does not mean that crypto statistics are useful too.
Further evidence that programs are not using
CONFIG_CRYPTO_STATSis that it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).Even further evidence comes from the fact that there are and have been bugs in how the stats work, but they were never reported. For example, before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it might be hard to use even if someone wanted to.
2.
CONFIG_CRYPTO_STATSsignificantly reduces performanceEnabling
CONFIG_CRYPTO_STATSsignificantly reduces the performance of the crypto API, even if no program ever retrieves the statistics. This primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported that Lustre client encryption performance improved from 21.7GB/s to 48.2GB/s by disablingCONFIG_CRYPTO_STATS.It can be argued that this means that
CONFIG_CRYPTO_STATSshould be optimized with per-cpu counters similar to many of the networking counters. But no one has done this in 5+ years. This is consistent with the fact that the feature appears to be unused, so there seems to be little interest in improving it as opposed to just disabling it.It can be argued that because
CONFIG_CRYPTO_STATSis off by default, performance doesn't matter. But Linux distros tend to error on the side of enabling options. The option is enabled in Ubuntu and Arch Linux, and until recently was enabled in RHEL and Fedora (see above). So, even just having the option available is harmful to users.3.
CONFIG_CRYPTO_STATSis a large maintenance burdenThere are over 1000 lines of code associated with
CONFIG_CRYPTO_STATS, spread among 32 files. It significantly complicates much of the implementation of the crypto API. After the initial submission, many fixes and refactorings have consumed effort of multiple people to keep this feature "working". We should be spending this effort elsewhere.Acked-by Ard Biesheuvel <[email protected]>Acked-by Corentin Labbe <[email protected]>Signed-off-by Eric Biggers <[email protected]>---
Changed in v2:
- Keep structcomp_alg_common, as per the request at
https://lore.kernel.org/linux-crypto/[email protected]/,
even though the struct becomes trivial with the stats removed.- Use consistent comments in
include/uapi/linux/cryptouser.h, and add one toCRYPTO_MSG_GETSTATwhich was missing one.- In
crypto/compress.h, remove the forward declaration ofsk_buffbecause the function prototype that needed it is being removed.- In
crypto_shash_digest(), don't readdesc->tfmredundantly.arch/s390/configs/debug_defconfig | 1 - arch/s390/configs/defconfig | 1 - crypto/Kconfig | 20 --- crypto/Makefile | 2 - crypto/acompress.c | 33 ---- crypto/aead.c | 84 +-------- crypto/ahash.c | 63 +------ crypto/akcipher.c | 31 ---- crypto/compress.h | 3 - crypto/{crypto_user_base.c => crypto_user.c} | 10 +- crypto/crypto_user_stat.c | 176 ------------------- crypto/hash.h | 30 ---- crypto/kpp.c | 30 ---- crypto/lskcipher.c | 73 +------- crypto/rng.c | 44 +---- crypto/scompress.c | 3 - crypto/shash.c | 75 +------- crypto/sig.c | 13 -- crypto/skcipher.c | 86 +-------- crypto/skcipher.h | 10 -- include/crypto/acompress.h | 73 +------- include/crypto/aead.h | 21 --- include/crypto/akcipher.h | 78 +------- include/crypto/algapi.h | 3 - include/crypto/hash.h | 22 --- include/crypto/internal/acompress.h | 1 - include/crypto/internal/cryptouser.h | 16 -- include/crypto/internal/scompress.h | 1 - include/crypto/kpp.h | 58 +----- include/crypto/rng.h | 51 +----- include/crypto/skcipher.h | 25 --- include/uapi/linux/cryptouser.h | 30 ++-- 32 files changed, 71 insertions(+), 1096 deletions(-)
Quoted 3 lines
rename
crypto/{crypto_user_base.c=>crypto_user.c} (98%) delete mode 100644crypto/crypto_user_stat.cdelete mode 100644include/crypto/internal/cryptouser.h
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt