aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2017-12-17 03:29:04 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2017-12-28 01:56:41 -0500
commite161c5930c150abab95d2ccad428d68ce1780ea1 (patch)
tree20b88a86c03d4f225b2cdf5dba90ccb576ef4de6 /crypto/tcrypt.c
parentb34a0f67ba62027394598e3c47fd3549c5c8e294 (diff)
crypto: tcrypt - add multibuf skcipher speed test
The performance of some skcipher tfm providers is affected by the amount of parallelism possible with the processing. Introduce an async skcipher concurrent multiple buffer processing speed test to be able to test performance of such tfm providers. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c460
1 files changed, 460 insertions, 0 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e406b00db89c..d617c1956533 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -818,6 +818,254 @@ static void test_hash_speed(const char *algo, unsigned int secs,
818 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC); 818 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
819} 819}
820 820
821struct test_mb_skcipher_data {
822 struct scatterlist sg[XBUFSIZE];
823 struct skcipher_request *req;
824 struct crypto_wait wait;
825 char *xbuf[XBUFSIZE];
826};
827
828static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
829 u32 num_mb)
830{
831 int i, rc[num_mb], err = 0;
832
833 /* Fire up a bunch of concurrent requests */
834 for (i = 0; i < num_mb; i++) {
835 if (enc == ENCRYPT)
836 rc[i] = crypto_skcipher_encrypt(data[i].req);
837 else
838 rc[i] = crypto_skcipher_decrypt(data[i].req);
839 }
840
841 /* Wait for all requests to finish */
842 for (i = 0; i < num_mb; i++) {
843 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
844
845 if (rc[i]) {
846 pr_info("concurrent request %d error %d\n", i, rc[i]);
847 err = rc[i];
848 }
849 }
850
851 return err;
852}
853
854static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
855 int blen, int secs, u32 num_mb)
856{
857 unsigned long start, end;
858 int bcount;
859 int ret;
860
861 for (start = jiffies, end = start + secs * HZ, bcount = 0;
862 time_before(jiffies, end); bcount++) {
863 ret = do_mult_acipher_op(data, enc, num_mb);
864 if (ret)
865 return ret;
866 }
867
868 pr_cont("%d operations in %d seconds (%ld bytes)\n",
869 bcount * num_mb, secs, (long)bcount * blen * num_mb);
870 return 0;
871}
872
873static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
874 int blen, u32 num_mb)
875{
876 unsigned long cycles = 0;
877 int ret = 0;
878 int i;
879
880 /* Warm-up run. */
881 for (i = 0; i < 4; i++) {
882 ret = do_mult_acipher_op(data, enc, num_mb);
883 if (ret)
884 goto out;
885 }
886
887 /* The real thing. */
888 for (i = 0; i < 8; i++) {
889 cycles_t start, end;
890
891 start = get_cycles();
892 ret = do_mult_acipher_op(data, enc, num_mb);
893 end = get_cycles();
894
895 if (ret)
896 goto out;
897
898 cycles += end - start;
899 }
900
901out:
902 if (ret == 0)
903 pr_cont("1 operation in %lu cycles (%d bytes)\n",
904 (cycles + 4) / (8 * num_mb), blen);
905
906 return ret;
907}
908
909static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
910 struct cipher_speed_template *template,
911 unsigned int tcount, u8 *keysize, u32 num_mb)
912{
913 struct test_mb_skcipher_data *data;
914 struct crypto_skcipher *tfm;
915 unsigned int i, j, iv_len;
916 const char *key;
917 const char *e;
918 u32 *b_size;
919 char iv[128];
920 int ret;
921
922 if (enc == ENCRYPT)
923 e = "encryption";
924 else
925 e = "decryption";
926
927 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
928 if (!data)
929 return;
930
931 tfm = crypto_alloc_skcipher(algo, 0, 0);
932 if (IS_ERR(tfm)) {
933 pr_err("failed to load transform for %s: %ld\n",
934 algo, PTR_ERR(tfm));
935 goto out_free_data;
936 }
937
938 for (i = 0; i < num_mb; ++i)
939 if (testmgr_alloc_buf(data[i].xbuf)) {
940 while (i--)
941 testmgr_free_buf(data[i].xbuf);
942 goto out_free_tfm;
943 }
944
945
946 for (i = 0; i < num_mb; ++i)
947 if (testmgr_alloc_buf(data[i].xbuf)) {
948 while (i--)
949 testmgr_free_buf(data[i].xbuf);
950 goto out_free_tfm;
951 }
952
953
954 for (i = 0; i < num_mb; ++i) {
955 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
956 if (!data[i].req) {
957 pr_err("alg: skcipher: Failed to allocate request for %s\n",
958 algo);
959 while (i--)
960 skcipher_request_free(data[i].req);
961 goto out_free_xbuf;
962 }
963 }
964
965 for (i = 0; i < num_mb; ++i) {
966 skcipher_request_set_callback(data[i].req,
967 CRYPTO_TFM_REQ_MAY_BACKLOG,
968 crypto_req_done, &data[i].wait);
969 crypto_init_wait(&data[i].wait);
970 }
971
972 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
973 get_driver_name(crypto_skcipher, tfm), e);
974
975 i = 0;
976 do {
977 b_size = block_sizes;
978 do {
979 if (*b_size > XBUFSIZE * PAGE_SIZE) {
980 pr_err("template (%u) too big for bufufer (%lu)\n",
981 *b_size, XBUFSIZE * PAGE_SIZE);
982 goto out;
983 }
984
985 pr_info("test %u (%d bit key, %d byte blocks): ", i,
986 *keysize * 8, *b_size);
987
988 /* Set up tfm global state, i.e. the key */
989
990 memset(tvmem[0], 0xff, PAGE_SIZE);
991 key = tvmem[0];
992 for (j = 0; j < tcount; j++) {
993 if (template[j].klen == *keysize) {
994 key = template[j].key;
995 break;
996 }
997 }
998
999 crypto_skcipher_clear_flags(tfm, ~0);
1000
1001 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1002 if (ret) {
1003 pr_err("setkey() failed flags=%x\n",
1004 crypto_skcipher_get_flags(tfm));
1005 goto out;
1006 }
1007
1008 iv_len = crypto_skcipher_ivsize(tfm);
1009 if (iv_len)
1010 memset(&iv, 0xff, iv_len);
1011
1012 /* Now setup per request stuff, i.e. buffers */
1013
1014 for (j = 0; j < num_mb; ++j) {
1015 struct test_mb_skcipher_data *cur = &data[j];
1016 unsigned int k = *b_size;
1017 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1018 unsigned int p = 0;
1019
1020 sg_init_table(cur->sg, pages);
1021
1022 while (k > PAGE_SIZE) {
1023 sg_set_buf(cur->sg + p, cur->xbuf[p],
1024 PAGE_SIZE);
1025 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1026 p++;
1027 k -= PAGE_SIZE;
1028 }
1029
1030 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1031 memset(cur->xbuf[p], 0xff, k);
1032
1033 skcipher_request_set_crypt(cur->req, cur->sg,
1034 cur->sg, *b_size,
1035 iv);
1036 }
1037
1038 if (secs)
1039 ret = test_mb_acipher_jiffies(data, enc,
1040 *b_size, secs,
1041 num_mb);
1042 else
1043 ret = test_mb_acipher_cycles(data, enc,
1044 *b_size, num_mb);
1045
1046 if (ret) {
1047 pr_err("%s() failed flags=%x\n", e,
1048 crypto_skcipher_get_flags(tfm));
1049 break;
1050 }
1051 b_size++;
1052 i++;
1053 } while (*b_size);
1054 keysize++;
1055 } while (*keysize);
1056
1057out:
1058 for (i = 0; i < num_mb; ++i)
1059 skcipher_request_free(data[i].req);
1060out_free_xbuf:
1061 for (i = 0; i < num_mb; ++i)
1062 testmgr_free_buf(data[i].xbuf);
1063out_free_tfm:
1064 crypto_free_skcipher(tfm);
1065out_free_data:
1066 kfree(data);
1067}
1068
821static inline int do_one_acipher_op(struct skcipher_request *req, int ret) 1069static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
822{ 1070{
823 struct crypto_wait *wait = req->base.data; 1071 struct crypto_wait *wait = req->base.data;
@@ -2102,6 +2350,218 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
2102 speed_template_8_32); 2350 speed_template_8_32);
2103 break; 2351 break;
2104 2352
2353 case 600:
2354 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2355 speed_template_16_24_32, num_mb);
2356 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2357 speed_template_16_24_32, num_mb);
2358 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2359 speed_template_16_24_32, num_mb);
2360 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2361 speed_template_16_24_32, num_mb);
2362 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2363 speed_template_32_40_48, num_mb);
2364 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2365 speed_template_32_40_48, num_mb);
2366 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2367 speed_template_32_64, num_mb);
2368 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2369 speed_template_32_64, num_mb);
2370 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2371 speed_template_16_24_32, num_mb);
2372 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2373 speed_template_16_24_32, num_mb);
2374 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2375 speed_template_16_24_32, num_mb);
2376 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2377 speed_template_16_24_32, num_mb);
2378 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2379 speed_template_16_24_32, num_mb);
2380 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2381 speed_template_16_24_32, num_mb);
2382 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2383 speed_template_16_24_32, num_mb);
2384 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2385 speed_template_16_24_32, num_mb);
2386 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2387 0, speed_template_20_28_36, num_mb);
2388 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2389 0, speed_template_20_28_36, num_mb);
2390 break;
2391
2392 case 601:
2393 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2394 des3_speed_template, DES3_SPEED_VECTORS,
2395 speed_template_24, num_mb);
2396 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2397 des3_speed_template, DES3_SPEED_VECTORS,
2398 speed_template_24, num_mb);
2399 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2400 des3_speed_template, DES3_SPEED_VECTORS,
2401 speed_template_24, num_mb);
2402 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2403 des3_speed_template, DES3_SPEED_VECTORS,
2404 speed_template_24, num_mb);
2405 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2406 des3_speed_template, DES3_SPEED_VECTORS,
2407 speed_template_24, num_mb);
2408 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2409 des3_speed_template, DES3_SPEED_VECTORS,
2410 speed_template_24, num_mb);
2411 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2412 des3_speed_template, DES3_SPEED_VECTORS,
2413 speed_template_24, num_mb);
2414 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2415 des3_speed_template, DES3_SPEED_VECTORS,
2416 speed_template_24, num_mb);
2417 break;
2418
2419 case 602:
2420 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2421 speed_template_8, num_mb);
2422 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2423 speed_template_8, num_mb);
2424 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2425 speed_template_8, num_mb);
2426 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2427 speed_template_8, num_mb);
2428 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2429 speed_template_8, num_mb);
2430 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2431 speed_template_8, num_mb);
2432 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2433 speed_template_8, num_mb);
2434 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2435 speed_template_8, num_mb);
2436 break;
2437
2438 case 603:
2439 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2440 speed_template_16_32, num_mb);
2441 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2442 speed_template_16_32, num_mb);
2443 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2444 speed_template_16_32, num_mb);
2445 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2446 speed_template_16_32, num_mb);
2447 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2448 speed_template_16_32, num_mb);
2449 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2450 speed_template_16_32, num_mb);
2451 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2452 speed_template_32_48, num_mb);
2453 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2454 speed_template_32_48, num_mb);
2455 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2456 speed_template_32_64, num_mb);
2457 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2458 speed_template_32_64, num_mb);
2459 break;
2460
2461 case 604:
2462 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2463 speed_template_16_24_32, num_mb);
2464 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2465 speed_template_16_24_32, num_mb);
2466 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2467 speed_template_16_24_32, num_mb);
2468 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2469 speed_template_16_24_32, num_mb);
2470 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2471 speed_template_16_24_32, num_mb);
2472 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2473 speed_template_16_24_32, num_mb);
2474 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2475 speed_template_32_40_48, num_mb);
2476 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2477 speed_template_32_40_48, num_mb);
2478 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2479 speed_template_32_48_64, num_mb);
2480 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2481 speed_template_32_48_64, num_mb);
2482 break;
2483
2484 case 605:
2485 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2486 speed_template_8, num_mb);
2487 break;
2488
2489 case 606:
2490 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2491 speed_template_8_16, num_mb);
2492 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2493 speed_template_8_16, num_mb);
2494 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2495 speed_template_8_16, num_mb);
2496 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2497 speed_template_8_16, num_mb);
2498 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2499 speed_template_8_16, num_mb);
2500 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2501 speed_template_8_16, num_mb);
2502 break;
2503
2504 case 607:
2505 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2506 speed_template_16_32, num_mb);
2507 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2508 speed_template_16_32, num_mb);
2509 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2510 speed_template_16_32, num_mb);
2511 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2512 speed_template_16_32, num_mb);
2513 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2514 speed_template_16_32, num_mb);
2515 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2516 speed_template_16_32, num_mb);
2517 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2518 speed_template_32_48, num_mb);
2519 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2520 speed_template_32_48, num_mb);
2521 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2522 speed_template_32_64, num_mb);
2523 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2524 speed_template_32_64, num_mb);
2525 break;
2526
2527 case 608:
2528 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2529 speed_template_16_32, num_mb);
2530 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2531 speed_template_16_32, num_mb);
2532 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2533 speed_template_16_32, num_mb);
2534 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2535 speed_template_16_32, num_mb);
2536 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2537 speed_template_16_32, num_mb);
2538 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2539 speed_template_16_32, num_mb);
2540 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2541 speed_template_32_48, num_mb);
2542 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2543 speed_template_32_48, num_mb);
2544 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2545 speed_template_32_64, num_mb);
2546 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2547 speed_template_32_64, num_mb);
2548 break;
2549
2550 case 609:
2551 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2552 speed_template_8_32, num_mb);
2553 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2554 speed_template_8_32, num_mb);
2555 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2556 speed_template_8_32, num_mb);
2557 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2558 speed_template_8_32, num_mb);
2559 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2560 speed_template_8_32, num_mb);
2561 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2562 speed_template_8_32, num_mb);
2563 break;
2564
2105 case 1000: 2565 case 1000:
2106 test_available(); 2566 test_available();
2107 break; 2567 break;