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: hisilicon/sec2 - support skcipher/aead fallback for hardware queue unavailable

When all hardware queues are busy and no shareable queue,
new processes fail to apply for queues. To avoid affecting
tasks, support fallback mechanism when hardware queues are
unavailable.

Fixes: c16a70c1f253 ("crypto: hisilicon/sec - add new algorithm mode for AEAD")
Signed-off-by: Qi Tao <taoqi10@huawei.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Qi Tao and committed by
Herbert Xu
e7507439 6aff4d97

+47 -15
+47 -15
drivers/crypto/hisilicon/sec2/sec_crypto.c
··· 663 663 int i, ret; 664 664 665 665 ctx->qps = sec_create_qps(); 666 - if (!ctx->qps) { 667 - pr_err("Can not create sec qps!\n"); 666 + if (!ctx->qps) 668 667 return -ENODEV; 669 - } 670 668 671 669 sec = container_of(ctx->qps[0]->qm, struct sec_dev, qm); 672 670 ctx->sec = sec; ··· 700 702 { 701 703 int i; 702 704 705 + if (!ctx->qps) 706 + return; 707 + 703 708 for (i = 0; i < ctx->sec->ctx_q_num; i++) 704 709 sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]); 705 710 ··· 713 712 static int sec_cipher_init(struct sec_ctx *ctx) 714 713 { 715 714 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 715 + 716 + if (!ctx->qps) 717 + return 0; 716 718 717 719 c_ctx->c_key = dma_alloc_coherent(ctx->dev, SEC_MAX_KEY_SIZE, 718 720 &c_ctx->c_key_dma, GFP_KERNEL); ··· 728 724 static void sec_cipher_uninit(struct sec_ctx *ctx) 729 725 { 730 726 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 727 + 728 + if (!ctx->qps) 729 + return; 731 730 732 731 memzero_explicit(c_ctx->c_key, SEC_MAX_KEY_SIZE); 733 732 dma_free_coherent(ctx->dev, SEC_MAX_KEY_SIZE, ··· 752 745 static void sec_auth_uninit(struct sec_ctx *ctx) 753 746 { 754 747 struct sec_auth_ctx *a_ctx = &ctx->a_ctx; 748 + 749 + if (!ctx->qps) 750 + return; 755 751 756 752 memzero_explicit(a_ctx->a_key, SEC_MAX_AKEY_SIZE); 757 753 dma_free_coherent(ctx->dev, SEC_MAX_AKEY_SIZE, ··· 793 783 } 794 784 795 785 ret = sec_ctx_base_init(ctx); 796 - if (ret) 786 + if (ret && ret != -ENODEV) 797 787 return ret; 798 788 799 789 ret = sec_cipher_init(ctx); ··· 902 892 struct device *dev = ctx->dev; 903 893 int ret; 904 894 895 + if (!ctx->qps) 896 + goto set_soft_key; 897 + 905 898 if (c_mode == SEC_CMODE_XTS) { 906 899 ret = xts_verify_key(tfm, key, keylen); 907 900 if (ret) { ··· 935 922 } 936 923 937 924 memcpy(c_ctx->c_key, key, keylen); 938 - if (c_ctx->fbtfm) { 939 - ret = crypto_sync_skcipher_setkey(c_ctx->fbtfm, key, keylen); 940 - if (ret) { 941 - dev_err(dev, "failed to set fallback skcipher key!\n"); 942 - return ret; 943 - } 925 + 926 + set_soft_key: 927 + ret = crypto_sync_skcipher_setkey(c_ctx->fbtfm, key, keylen); 928 + if (ret) { 929 + dev_err(dev, "failed to set fallback skcipher key!\n"); 930 + return ret; 944 931 } 932 + 945 933 return 0; 946 934 } 947 935 ··· 1405 1391 struct device *dev = ctx->dev; 1406 1392 struct crypto_authenc_keys keys; 1407 1393 int ret; 1394 + 1395 + if (!ctx->qps) 1396 + return sec_aead_fallback_setkey(a_ctx, tfm, key, keylen); 1408 1397 1409 1398 ctx->a_ctx.a_alg = a_alg; 1410 1399 ctx->c_ctx.c_alg = c_alg; ··· 2065 2048 if (ret) 2066 2049 return ret; 2067 2050 2051 + if (!ctx->qps) 2052 + return 0; 2053 + 2068 2054 if (ctx->sec->qm.ver < QM_HW_V3) { 2069 2055 ctx->type_supported = SEC_BD_TYPE2; 2070 2056 ctx->req_op = &sec_skcipher_req_ops; ··· 2076 2056 ctx->req_op = &sec_skcipher_req_ops_v3; 2077 2057 } 2078 2058 2079 - return ret; 2059 + return 0; 2080 2060 } 2081 2061 2082 2062 static void sec_skcipher_ctx_exit(struct crypto_skcipher *tfm) ··· 2144 2124 int ret; 2145 2125 2146 2126 ret = sec_aead_init(tfm); 2147 - if (ret) { 2127 + if (ret && ret != -ENODEV) { 2148 2128 pr_err("hisi_sec2: aead init error!\n"); 2149 2129 return ret; 2150 2130 } ··· 2186 2166 int ret; 2187 2167 2188 2168 ret = sec_aead_init(tfm); 2189 - if (ret) { 2169 + if (ret && ret != -ENODEV) { 2190 2170 dev_err(ctx->dev, "hisi_sec2: aead xcm init error!\n"); 2191 2171 return ret; 2192 2172 } ··· 2331 2311 bool need_fallback = false; 2332 2312 int ret; 2333 2313 2314 + if (!ctx->qps) 2315 + goto soft_crypto; 2316 + 2334 2317 if (!sk_req->cryptlen) { 2335 2318 if (ctx->c_ctx.c_mode == SEC_CMODE_XTS) 2336 2319 return -EINVAL; ··· 2351 2328 return -EINVAL; 2352 2329 2353 2330 if (unlikely(ctx->c_ctx.fallback || need_fallback)) 2354 - return sec_skcipher_soft_crypto(ctx, sk_req, encrypt); 2331 + goto soft_crypto; 2355 2332 2356 2333 return ctx->req_op->process(ctx, req); 2334 + 2335 + soft_crypto: 2336 + return sec_skcipher_soft_crypto(ctx, sk_req, encrypt); 2357 2337 } 2358 2338 2359 2339 static int sec_skcipher_encrypt(struct skcipher_request *sk_req) ··· 2564 2538 bool need_fallback = false; 2565 2539 int ret; 2566 2540 2541 + if (!ctx->qps) 2542 + goto soft_crypto; 2543 + 2567 2544 req->flag = a_req->base.flags; 2568 2545 req->aead_req.aead_req = a_req; 2569 2546 req->c_req.encrypt = encrypt; ··· 2577 2548 ret = sec_aead_param_check(ctx, req, &need_fallback); 2578 2549 if (unlikely(ret)) { 2579 2550 if (need_fallback) 2580 - return sec_aead_soft_crypto(ctx, a_req, encrypt); 2551 + goto soft_crypto; 2581 2552 return -EINVAL; 2582 2553 } 2583 2554 2584 2555 return ctx->req_op->process(ctx, req); 2556 + 2557 + soft_crypto: 2558 + return sec_aead_soft_crypto(ctx, a_req, encrypt); 2585 2559 } 2586 2560 2587 2561 static int sec_aead_encrypt(struct aead_request *a_req)