Skip to content

Commit 17c18f9

Browse files
montjoieherbertx
authored andcommitted
crypto: user - Split stats in multiple structures
Like for userspace, this patch splits stats into multiple structures, one for each algorithm class. Signed-off-by: Corentin Labbe <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 5fff817 commit 17c18f9

File tree

3 files changed

+210
-160
lines changed

3 files changed

+210
-160
lines changed

crypto/algapi.c

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,7 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
259259
list_add(&larval->alg.cra_list, &crypto_alg_list);
260260

261261
#ifdef CONFIG_CRYPTO_STATS
262-
atomic64_set(&alg->encrypt_cnt, 0);
263-
atomic64_set(&alg->decrypt_cnt, 0);
264-
atomic64_set(&alg->encrypt_tlen, 0);
265-
atomic64_set(&alg->decrypt_tlen, 0);
266-
atomic64_set(&alg->verify_cnt, 0);
267-
atomic64_set(&alg->cipher_err_cnt, 0);
268-
atomic64_set(&alg->sign_cnt, 0);
262+
memset(&alg->stats, 0, sizeof(alg->stats));
269263
#endif
270264

271265
out:
@@ -1089,10 +1083,10 @@ void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret,
10891083
struct crypto_alg *alg)
10901084
{
10911085
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1092-
atomic64_inc(&alg->cipher_err_cnt);
1086+
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
10931087
} else {
1094-
atomic64_inc(&alg->encrypt_cnt);
1095-
atomic64_add(nbytes, &alg->encrypt_tlen);
1088+
atomic64_inc(&alg->stats.cipher.encrypt_cnt);
1089+
atomic64_add(nbytes, &alg->stats.cipher.encrypt_tlen);
10961090
}
10971091
crypto_alg_put(alg);
10981092
}
@@ -1102,10 +1096,10 @@ void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret,
11021096
struct crypto_alg *alg)
11031097
{
11041098
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1105-
atomic64_inc(&alg->cipher_err_cnt);
1099+
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
11061100
} else {
1107-
atomic64_inc(&alg->decrypt_cnt);
1108-
atomic64_add(nbytes, &alg->decrypt_tlen);
1101+
atomic64_inc(&alg->stats.cipher.decrypt_cnt);
1102+
atomic64_add(nbytes, &alg->stats.cipher.decrypt_tlen);
11091103
}
11101104
crypto_alg_put(alg);
11111105
}
@@ -1115,10 +1109,10 @@ void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg,
11151109
int ret)
11161110
{
11171111
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1118-
atomic64_inc(&alg->aead_err_cnt);
1112+
atomic64_inc(&alg->stats.aead.aead_err_cnt);
11191113
} else {
1120-
atomic64_inc(&alg->encrypt_cnt);
1121-
atomic64_add(cryptlen, &alg->encrypt_tlen);
1114+
atomic64_inc(&alg->stats.aead.encrypt_cnt);
1115+
atomic64_add(cryptlen, &alg->stats.aead.encrypt_tlen);
11221116
}
11231117
crypto_alg_put(alg);
11241118
}
@@ -1128,10 +1122,10 @@ void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg,
11281122
int ret)
11291123
{
11301124
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1131-
atomic64_inc(&alg->aead_err_cnt);
1125+
atomic64_inc(&alg->stats.aead.aead_err_cnt);
11321126
} else {
1133-
atomic64_inc(&alg->decrypt_cnt);
1134-
atomic64_add(cryptlen, &alg->decrypt_tlen);
1127+
atomic64_inc(&alg->stats.aead.decrypt_cnt);
1128+
atomic64_add(cryptlen, &alg->stats.aead.decrypt_tlen);
11351129
}
11361130
crypto_alg_put(alg);
11371131
}
@@ -1141,10 +1135,10 @@ void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret,
11411135
struct crypto_alg *alg)
11421136
{
11431137
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1144-
atomic64_inc(&alg->akcipher_err_cnt);
1138+
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
11451139
} else {
1146-
atomic64_inc(&alg->encrypt_cnt);
1147-
atomic64_add(src_len, &alg->encrypt_tlen);
1140+
atomic64_inc(&alg->stats.akcipher.encrypt_cnt);
1141+
atomic64_add(src_len, &alg->stats.akcipher.encrypt_tlen);
11481142
}
11491143
crypto_alg_put(alg);
11501144
}
@@ -1154,10 +1148,10 @@ void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret,
11541148
struct crypto_alg *alg)
11551149
{
11561150
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1157-
atomic64_inc(&alg->akcipher_err_cnt);
1151+
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
11581152
} else {
1159-
atomic64_inc(&alg->decrypt_cnt);
1160-
atomic64_add(src_len, &alg->decrypt_tlen);
1153+
atomic64_inc(&alg->stats.akcipher.decrypt_cnt);
1154+
atomic64_add(src_len, &alg->stats.akcipher.decrypt_tlen);
11611155
}
11621156
crypto_alg_put(alg);
11631157
}
@@ -1166,30 +1160,30 @@ EXPORT_SYMBOL_GPL(crypto_stats_akcipher_decrypt);
11661160
void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg)
11671161
{
11681162
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
1169-
atomic64_inc(&alg->akcipher_err_cnt);
1163+
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
11701164
else
1171-
atomic64_inc(&alg->sign_cnt);
1165+
atomic64_inc(&alg->stats.akcipher.sign_cnt);
11721166
crypto_alg_put(alg);
11731167
}
11741168
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_sign);
11751169

11761170
void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg)
11771171
{
11781172
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
1179-
atomic64_inc(&alg->akcipher_err_cnt);
1173+
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
11801174
else
1181-
atomic64_inc(&alg->verify_cnt);
1175+
atomic64_inc(&alg->stats.akcipher.verify_cnt);
11821176
crypto_alg_put(alg);
11831177
}
11841178
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_verify);
11851179

11861180
void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg)
11871181
{
11881182
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1189-
atomic64_inc(&alg->compress_err_cnt);
1183+
atomic64_inc(&alg->stats.compress.compress_err_cnt);
11901184
} else {
1191-
atomic64_inc(&alg->compress_cnt);
1192-
atomic64_add(slen, &alg->compress_tlen);
1185+
atomic64_inc(&alg->stats.compress.compress_cnt);
1186+
atomic64_add(slen, &alg->stats.compress.compress_tlen);
11931187
}
11941188
crypto_alg_put(alg);
11951189
}
@@ -1198,10 +1192,10 @@ EXPORT_SYMBOL_GPL(crypto_stats_compress);
11981192
void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg)
11991193
{
12001194
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1201-
atomic64_inc(&alg->compress_err_cnt);
1195+
atomic64_inc(&alg->stats.compress.compress_err_cnt);
12021196
} else {
1203-
atomic64_inc(&alg->decompress_cnt);
1204-
atomic64_add(slen, &alg->decompress_tlen);
1197+
atomic64_inc(&alg->stats.compress.decompress_cnt);
1198+
atomic64_add(slen, &alg->stats.compress.decompress_tlen);
12051199
}
12061200
crypto_alg_put(alg);
12071201
}
@@ -1211,9 +1205,9 @@ void crypto_stats_ahash_update(unsigned int nbytes, int ret,
12111205
struct crypto_alg *alg)
12121206
{
12131207
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
1214-
atomic64_inc(&alg->hash_err_cnt);
1208+
atomic64_inc(&alg->stats.hash.hash_err_cnt);
12151209
else
1216-
atomic64_add(nbytes, &alg->hash_tlen);
1210+
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
12171211
crypto_alg_put(alg);
12181212
}
12191213
EXPORT_SYMBOL_GPL(crypto_stats_ahash_update);
@@ -1222,10 +1216,10 @@ void crypto_stats_ahash_final(unsigned int nbytes, int ret,
12221216
struct crypto_alg *alg)
12231217
{
12241218
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1225-
atomic64_inc(&alg->hash_err_cnt);
1219+
atomic64_inc(&alg->stats.hash.hash_err_cnt);
12261220
} else {
1227-
atomic64_inc(&alg->hash_cnt);
1228-
atomic64_add(nbytes, &alg->hash_tlen);
1221+
atomic64_inc(&alg->stats.hash.hash_cnt);
1222+
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
12291223
}
12301224
crypto_alg_put(alg);
12311225
}
@@ -1234,39 +1228,39 @@ EXPORT_SYMBOL_GPL(crypto_stats_ahash_final);
12341228
void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret)
12351229
{
12361230
if (ret)
1237-
atomic64_inc(&alg->kpp_err_cnt);
1231+
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
12381232
else
1239-
atomic64_inc(&alg->setsecret_cnt);
1233+
atomic64_inc(&alg->stats.kpp.setsecret_cnt);
12401234
crypto_alg_put(alg);
12411235
}
12421236
EXPORT_SYMBOL_GPL(crypto_stats_kpp_set_secret);
12431237

12441238
void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret)
12451239
{
12461240
if (ret)
1247-
atomic64_inc(&alg->kpp_err_cnt);
1241+
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
12481242
else
1249-
atomic64_inc(&alg->generate_public_key_cnt);
1243+
atomic64_inc(&alg->stats.kpp.generate_public_key_cnt);
12501244
crypto_alg_put(alg);
12511245
}
12521246
EXPORT_SYMBOL_GPL(crypto_stats_kpp_generate_public_key);
12531247

12541248
void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret)
12551249
{
12561250
if (ret)
1257-
atomic64_inc(&alg->kpp_err_cnt);
1251+
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
12581252
else
1259-
atomic64_inc(&alg->compute_shared_secret_cnt);
1253+
atomic64_inc(&alg->stats.kpp.compute_shared_secret_cnt);
12601254
crypto_alg_put(alg);
12611255
}
12621256
EXPORT_SYMBOL_GPL(crypto_stats_kpp_compute_shared_secret);
12631257

12641258
void crypto_stats_rng_seed(struct crypto_alg *alg, int ret)
12651259
{
12661260
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
1267-
atomic64_inc(&alg->rng_err_cnt);
1261+
atomic64_inc(&alg->stats.rng.rng_err_cnt);
12681262
else
1269-
atomic64_inc(&alg->seed_cnt);
1263+
atomic64_inc(&alg->stats.rng.seed_cnt);
12701264
crypto_alg_put(alg);
12711265
}
12721266
EXPORT_SYMBOL_GPL(crypto_stats_rng_seed);
@@ -1275,10 +1269,10 @@ void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen,
12751269
int ret)
12761270
{
12771271
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1278-
atomic64_inc(&alg->rng_err_cnt);
1272+
atomic64_inc(&alg->stats.rng.rng_err_cnt);
12791273
} else {
1280-
atomic64_inc(&alg->generate_cnt);
1281-
atomic64_add(dlen, &alg->generate_tlen);
1274+
atomic64_inc(&alg->stats.rng.generate_cnt);
1275+
atomic64_add(dlen, &alg->stats.rng.generate_tlen);
12821276
}
12831277
crypto_alg_put(alg);
12841278
}
@@ -1288,10 +1282,10 @@ void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret,
12881282
struct crypto_alg *alg)
12891283
{
12901284
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1291-
atomic64_inc(&alg->cipher_err_cnt);
1285+
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
12921286
} else {
1293-
atomic64_inc(&alg->encrypt_cnt);
1294-
atomic64_add(cryptlen, &alg->encrypt_tlen);
1287+
atomic64_inc(&alg->stats.cipher.encrypt_cnt);
1288+
atomic64_add(cryptlen, &alg->stats.cipher.encrypt_tlen);
12951289
}
12961290
crypto_alg_put(alg);
12971291
}
@@ -1301,10 +1295,10 @@ void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret,
13011295
struct crypto_alg *alg)
13021296
{
13031297
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1304-
atomic64_inc(&alg->cipher_err_cnt);
1298+
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
13051299
} else {
1306-
atomic64_inc(&alg->decrypt_cnt);
1307-
atomic64_add(cryptlen, &alg->decrypt_tlen);
1300+
atomic64_inc(&alg->stats.cipher.decrypt_cnt);
1301+
atomic64_add(cryptlen, &alg->stats.cipher.decrypt_tlen);
13081302
}
13091303
crypto_alg_put(alg);
13101304
}

0 commit comments

Comments
 (0)