From f12441364fb42268081dfb0b90815a954c0cafea Mon Sep 17 00:00:00 2001 From: JiangShui <1175135535@qq.com> Date: Fri, 8 Dec 2023 11:56:44 +0800 Subject: [PATCH] libwd: update the source code --- ...1-comp-add-comp-ctx-parameters-check.patch | 120 +++++ ...ether-the-data-address-pointer-is-no.patch | 409 +++++++++++++++++ ...e-print-actions-after-wd_get_cookies.patch | 66 +++ ...ix-header-file-is-not-self-contained.patch | 81 ++++ 0090-uadk-sec-modify-improper-comments.patch | 49 ++ ...some-input-parameter-checking-issues.patch | 126 +++++ 0092-uadk-code-cleanup.patch | 197 ++++++++ ...k-fix-sec-send-and-recv-check-failed.patch | 431 ++++++++++++++++++ ...up-for-error-codes-and-variable-type.patch | 94 ++++ ...adk-sec-add-a-return-value-judgement.patch | 37 ++ 0096-uadk-Add-file-association.patch | 31 ++ 0097-uadk-fix-the-failure-process-bug.patch | 39 ++ 0098-uadk-fix-the-failure-process-bug.patch | 28 ++ 0099-uadk-fix-the-failure-process-bug.patch | 36 ++ 0100-uadk-bugfix.patch | 28 ++ 0101-uadk-v1-adapter-code-cleanup.patch | 39 ++ ...k-v1-fix-wd_rng-resource-release-bug.patch | 40 ++ ...anup-for-error-codes-and-header-file.patch | 235 ++++++++++ ...adk-concentrate-the-same-definitions.patch | 160 +++++++ ...uadk-v1-optimize-the-function-length.patch | 133 ++++++ ...-v1-concentrate-the-same-definitions.patch | 159 +++++++ ...v1-hpre-fix-key-transfer-error-issue.patch | 87 ++++ ...si_hpre-fix-key-transfer-error-issue.patch | 87 ++++ ...adk-v1-remove-duplicate-header-files.patch | 54 +++ ...writing-data-to-uninitialized-memory.patch | 42 ++ ...resource-leak-by-add-qp-info-clear-p.patch | 36 ++ ...r-writing-data-to-uninitialized-memo.patch | 32 ++ ...ueue-status-before-sending-doorbells.patch | 155 +++++++ ...-fix-return-value-for-wd_zlib_uadk_i.patch | 31 ++ warpdrive.spec | 31 +- 30 files changed, 3092 insertions(+), 1 deletion(-) create mode 100644 0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch create mode 100644 0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch create mode 100644 0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch create mode 100644 0089-uadk-fix-header-file-is-not-self-contained.patch create mode 100644 0090-uadk-sec-modify-improper-comments.patch create mode 100644 0091-uadk-fixed-some-input-parameter-checking-issues.patch create mode 100644 0092-uadk-code-cleanup.patch create mode 100644 0093-uadk-fix-sec-send-and-recv-check-failed.patch create mode 100644 0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch create mode 100644 0095-uadk-sec-add-a-return-value-judgement.patch create mode 100644 0096-uadk-Add-file-association.patch create mode 100644 0097-uadk-fix-the-failure-process-bug.patch create mode 100644 0098-uadk-fix-the-failure-process-bug.patch create mode 100644 0099-uadk-fix-the-failure-process-bug.patch create mode 100644 0100-uadk-bugfix.patch create mode 100644 0101-uadk-v1-adapter-code-cleanup.patch create mode 100644 0102-uadk-v1-fix-wd_rng-resource-release-bug.patch create mode 100644 0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch create mode 100644 0104-uadk-concentrate-the-same-definitions.patch create mode 100644 0105-uadk-v1-optimize-the-function-length.patch create mode 100644 0106-uadk-v1-concentrate-the-same-definitions.patch create mode 100644 0107-v1-hpre-fix-key-transfer-error-issue.patch create mode 100644 0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch create mode 100644 0109-uadk-v1-remove-duplicate-header-files.patch create mode 100644 0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch create mode 100644 0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch create mode 100644 0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch create mode 100644 0113-uadk-check-queue-status-before-sending-doorbells.patch create mode 100644 0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch diff --git a/0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch b/0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch new file mode 100644 index 0000000..ac949ec --- /dev/null +++ b/0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch @@ -0,0 +1,120 @@ +From 4c08e19a760e2095a441e4f4e54449be090323c5 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Fri, 24 Nov 2023 11:53:49 +0800 +Subject: [PATCH 086/114] uadk/v1/comp: add comp ctx parameters check + +Add the check of ctx parameters before create ctx pool. + +Signed-off-by: Qi Tao +--- + v1/wd_comp.c | 75 ++++++++++++++++++++++++++++++++++++++++------------ + 1 file changed, 58 insertions(+), 17 deletions(-) + +diff --git a/v1/wd_comp.c b/v1/wd_comp.c +index f898c1d..154db19 100644 +--- a/v1/wd_comp.c ++++ b/v1/wd_comp.c +@@ -56,6 +56,62 @@ static void fill_comp_msg(struct wcrypto_comp_ctx *ctx, + msg->status = 0; + } + ++static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *setup) ++{ ++ struct q_info *qinfo; ++ ++ if (!q || !setup) { ++ WD_ERR("err: q or setup is NULL!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (strcmp(q->capa.alg, "zlib") && ++ strcmp(q->capa.alg, "gzip") && ++ strcmp(q->capa.alg, "deflate") && ++ strcmp(q->capa.alg, "lz77_zstd")) { ++ WD_ERR("err: algorithm is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ qinfo = q->qinfo; ++ if (qinfo->ctx_num >= WD_MAX_CTX_NUM) { ++ WD_ERR("err: create too many compress ctx!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->alg_type >= WCRYPTO_COMP_MAX_ALG) { ++ WD_ERR("err: alg_type is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->comp_lv > WCRYPTO_COMP_L9) { ++ WD_ERR("err: comp_lv is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->op_type > WCRYPTO_INFLATE) { ++ WD_ERR("err: op_type is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->stream_mode > WCRYPTO_FINISH) { ++ WD_ERR("err: stream_mode is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->win_size > WCRYPTO_COMP_WS_32K) { ++ WD_ERR("err: win_size is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (setup->data_fmt > WD_SGL_BUF) { ++ WD_ERR("err: data_fmt is invalid!\n"); ++ return -WD_EINVAL; ++ } ++ ++ return 0; ++} ++ + static int set_comp_ctx_br(struct q_info *qinfo, struct wd_mm_br *br) + { + if (!br->alloc || !br->free || +@@ -126,18 +182,9 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q, + __u32 ctx_id = 0; + int ret; + +- if (!q || !setup) { +- WD_ERR("err, input parameter invalid!\n"); +- return NULL; +- } +- +- if (strcmp(q->capa.alg, "zlib") && +- strcmp(q->capa.alg, "gzip") && +- strcmp(q->capa.alg, "deflate") && +- strcmp(q->capa.alg, "lz77_zstd")) { +- WD_ERR("algorithm mismatch!\n"); ++ ret = ctx_params_check(q, setup); ++ if (ret) + return NULL; +- } + + qinfo = q->qinfo; + +@@ -150,11 +197,6 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q, + goto unlock; + } + +- if (qinfo->ctx_num >= WD_MAX_CTX_NUM) { +- WD_ERR("err: create too many compress ctx!\n"); +- goto unlock; +- } +- + ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, &ctx_id, 0, + WD_MAX_CTX_NUM); + if (ret) { +@@ -357,4 +399,3 @@ void wcrypto_del_comp_ctx(void *ctx) + + free(cctx); + } +- +-- +2.25.1 + diff --git a/0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch b/0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch new file mode 100644 index 0000000..a5d6d22 --- /dev/null +++ b/0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch @@ -0,0 +1,409 @@ +From f669f0bf233a1441fd98b4fc79400af2bbeae78f Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Fri, 24 Nov 2023 11:57:05 +0800 +Subject: [PATCH 087/114] uadk/v1: check whether the data address pointer is + not null + +The data address pointers were used without address verification, +which may cause null pointer risks. + +Signed-off-by: Qi Tao +--- + v1/wd_aead.c | 22 +++++++++++++++++----- + v1/wd_cipher.c | 22 +++++++++++++++++----- + v1/wd_comp.c | 10 +++++----- + v1/wd_dh.c | 6 +++--- + v1/wd_digest.c | 19 +++++++++++++------ + v1/wd_ecc.c | 8 ++++---- + v1/wd_rng.c | 13 +++++++++---- + v1/wd_rsa.c | 12 +++++++++--- + v1/wd_util.c | 7 +++++++ + v1/wd_util.h | 1 + + 10 files changed, 85 insertions(+), 35 deletions(-) + +diff --git a/v1/wd_aead.c b/v1/wd_aead.c +index a82d51d..f688309 100644 +--- a/v1/wd_aead.c ++++ b/v1/wd_aead.c +@@ -124,7 +124,7 @@ static int get_iv_block_size(int mode) + static int create_ctx_para_check(struct wd_queue *q, + struct wcrypto_aead_ctx_setup *setup) + { +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("input param is NULL\n"); + return -WD_EINVAL; + } +@@ -542,26 +542,38 @@ static int param_check(struct wcrypto_aead_ctx *a_ctx, + void **tag, __u32 num) + { + __u32 i; ++ int ret; + + if (unlikely(!a_ctx || !a_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) { +- WD_ERR("input param err!\n"); ++ WD_ERR("invalid: input param err!\n"); + return -WD_EINVAL; + } + + for (i = 0; i < num; i++) { + if (unlikely(!a_opdata[i])) { +- WD_ERR("aead opdata[%u] is NULL!\n", i); ++ WD_ERR("invalid: aead opdata[%u] is NULL\n", i); ++ return -WD_EINVAL; ++ } ++ ++ ret = wd_check_src_dst(a_opdata[i]->in, a_opdata[i]->in_bytes, a_opdata[i]->out, a_opdata[i]->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (unlikely(!a_opdata[i]->iv)) { ++ WD_ERR("invalid: aead input iv is NULL!\n"); + return -WD_EINVAL; + } + + if (unlikely(tag && !tag[i])) { +- WD_ERR("tag[%u] is NULL!\n", i); ++ WD_ERR("invalid: tag[%u] is NULL!\n", i); + return -WD_EINVAL; + } + } + + if (unlikely(tag && !a_ctx->setup.cb)) { +- WD_ERR("aead ctx call back is NULL!\n"); ++ WD_ERR("invalid: aead ctx call back is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c +index 3e6fb3d..60a0f25 100644 +--- a/v1/wd_cipher.c ++++ b/v1/wd_cipher.c +@@ -107,7 +107,7 @@ static __u32 get_iv_block_size(int alg, int mode) + static int create_ctx_para_check(struct wd_queue *q, + struct wcrypto_cipher_ctx_setup *setup) + { +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("%s: input param err!\n", __func__); + return -WD_EINVAL; + } +@@ -426,26 +426,38 @@ static int param_check(struct wcrypto_cipher_ctx *c_ctx, + void **tag, __u32 num) + { + __u32 i; ++ int ret; + + if (unlikely(!c_ctx || !c_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) { +- WD_ERR("input param err!\n"); ++ WD_ERR("invalid: input param err!\n"); + return -WD_EINVAL; + } + + for (i = 0; i < num; i++) { + if (unlikely(!c_opdata[i])) { +- WD_ERR("cipher opdata[%u] is NULL!\n", i); ++ WD_ERR("invalid: cipher opdata[%u] is NULL!\n", i); ++ return -WD_EINVAL; ++ } ++ ++ ret = wd_check_src_dst(c_opdata[i]->in, c_opdata[i]->in_bytes, c_opdata[i]->out, c_opdata[i]->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (c_ctx->setup.mode != WCRYPTO_CIPHER_ECB && !c_opdata[i]->iv) { ++ WD_ERR("invalid: cipher input iv is NULL!\n"); + return -WD_EINVAL; + } + + if (unlikely(tag && !tag[i])) { +- WD_ERR("tag[%u] is NULL!\n", i); ++ WD_ERR("invalid: tag[%u] is NULL!\n", i); + return -WD_EINVAL; + } + } + + if (unlikely(tag && !c_ctx->setup.cb)) { +- WD_ERR("cipher ctx call back is NULL!\n"); ++ WD_ERR("invalid: cipher ctx call back is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_comp.c b/v1/wd_comp.c +index 154db19..3d2fcf1 100644 +--- a/v1/wd_comp.c ++++ b/v1/wd_comp.c +@@ -60,8 +60,8 @@ static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *s + { + struct q_info *qinfo; + +- if (!q || !setup) { +- WD_ERR("err: q or setup is NULL!\n"); ++ if (!q || !q->qinfo || !setup) { ++ WD_ERR("%s: input param err!\n", __func__); + return -WD_EINVAL; + } + +@@ -255,8 +255,8 @@ int wcrypto_do_comp(void *ctx, struct wcrypto_comp_op_data *opdata, void *tag) + __u64 recv_count = 0; + int ret; + +- if (!ctx || !opdata) { +- WD_ERR("input parameter err!\n"); ++ if (unlikely(!ctx || !opdata || !opdata->in || !opdata->out)) { ++ WD_ERR("invalid: comp input parameter err!\n"); + return -EINVAL; + } + +@@ -267,7 +267,7 @@ int wcrypto_do_comp(void *ctx, struct wcrypto_comp_op_data *opdata, void *tag) + msg = &cookie->msg; + if (tag) { + if (!cctx->cb) { +- WD_ERR("ctx call back is null!\n"); ++ WD_ERR("invalid: ctx call back is null!\n"); + ret = -WD_EINVAL; + goto err_put_cookie; + } +diff --git a/v1/wd_dh.c b/v1/wd_dh.c +index 9ed0e0d..27bcb5a 100644 +--- a/v1/wd_dh.c ++++ b/v1/wd_dh.c +@@ -56,7 +56,7 @@ struct wcrypto_dh_ctx { + static int create_ctx_param_check(struct wd_queue *q, + struct wcrypto_dh_ctx_setup *setup) + { +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("%s(): input parameter err!\n", __func__); + return -WD_EINVAL; + } +@@ -299,12 +299,12 @@ static int do_dh_prepare(struct wcrypto_dh_op_data *opdata, + int ret; + + if (unlikely(!ctxt || !opdata)) { +- WD_ERR("input parameter err!\n"); ++ WD_ERR("invalid: dh input parameter err!\n"); + return -WD_EINVAL; + } + + if (unlikely(tag && !ctxt->setup.cb)) { +- WD_ERR("ctx call back is null!\n"); ++ WD_ERR("invalid: ctx call back is null!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_digest.c b/v1/wd_digest.c +index f6c8b84..b617350 100644 +--- a/v1/wd_digest.c ++++ b/v1/wd_digest.c +@@ -89,7 +89,7 @@ static void del_ctx_key(struct wcrypto_digest_ctx *ctx) + static int create_ctx_para_check(struct wd_queue *q, + struct wcrypto_digest_ctx_setup *setup) + { +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("%s: input param err!\n", __func__); + return -WD_EINVAL; + } +@@ -377,6 +377,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + { + enum wcrypto_digest_alg alg; + __u32 i; ++ int ret; + + if (unlikely(!d_ctx || !d_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) { + WD_ERR("input param err!\n"); +@@ -387,7 +388,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + + for (i = 0; i < num; i++) { + if (unlikely(!d_opdata[i])) { +- WD_ERR("digest opdata[%u] is NULL!\n", i); ++ WD_ERR("invalid: digest opdata[%u] is NULL!\n", i); + return -WD_EINVAL; + } + +@@ -396,6 +397,12 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + return -WD_EINVAL; + } + ++ ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, d_opdata[i]->out, d_opdata[i]->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ + if (d_opdata[i]->has_next) { + if (unlikely(num != 1)) { + WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n"); +@@ -414,8 +421,8 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + WD_ERR("failed to check digest mac length!\n"); + return -WD_EINVAL; + } +- if (d_ctx->setup.alg == WCRYPTO_AES_GMAC && +- d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN) { ++ if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC && ++ (!d_opdata[i]->iv || d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN))) { + WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n", + d_opdata[i]->iv_bytes); + return -WD_EINVAL; +@@ -423,13 +430,13 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + } + + if (unlikely(tag && !tag[i])) { +- WD_ERR("tag[%u] is NULL!\n", i); ++ WD_ERR("invalid: tag[%u] is NULL!\n", i); + return -WD_EINVAL; + } + } + + if (unlikely(tag && !d_ctx->setup.cb)) { +- WD_ERR("digest ctx call back is NULL!\n"); ++ WD_ERR("invalid: digest ctx call back is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c +index c4fab63..7650b2b 100644 +--- a/v1/wd_ecc.c ++++ b/v1/wd_ecc.c +@@ -1006,7 +1006,7 @@ static bool is_key_width_support(__u32 key_bits) + + static int param_check(struct wd_queue *q, struct wcrypto_ecc_ctx_setup *setup) + { +- if (unlikely(!q || !setup)) { ++ if (unlikely(!q || !q->qinfo || !setup)) { + WD_ERR("input parameter error!\n"); + return -WD_EINVAL; + } +@@ -1663,7 +1663,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num) + int wcrypto_do_ecxdh(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag) + { + if (unlikely(!opdata)) { +- WD_ERR("do ecxdh: opdata null!\n"); ++ WD_ERR("invalid: do ecxdh: opdata null!\n"); + return -WD_EINVAL; + } + +@@ -2176,7 +2176,7 @@ void wcrypto_get_ecdsa_sign_in_params(struct wcrypto_ecc_in *in, + int wcrypto_do_ecdsa(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag) + { + if (unlikely(!opdata)) { +- WD_ERR("do ecdsa: opdata null!\n"); ++ WD_ERR("invalid: do ecdsa: opdata null!\n"); + return -WD_EINVAL; + } + +@@ -2463,7 +2463,7 @@ int wcrypto_do_sm2(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag) + struct wcrypto_ecc_in *in; + + if (unlikely(!opdata)) { +- WD_ERR("do sm2: opdata null!\n"); ++ WD_ERR("invalid: do sm2: opdata null!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_rng.c b/v1/wd_rng.c +index cc8a594..927665f 100644 +--- a/v1/wd_rng.c ++++ b/v1/wd_rng.c +@@ -48,7 +48,7 @@ static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup, + struct q_info *qinfo; + int ret = -WD_EINVAL; + +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("input parameter err!\n"); + return ret; + } +@@ -202,8 +202,13 @@ static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr, + struct wcrypto_rng_msg *req; + int ret; + +- if (!ctxt || !opdata) { +- WD_ERR("input parameter err!\n"); ++ if (unlikely(!ctxt || !opdata)) { ++ WD_ERR("invalid: rng input parameter err!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (unlikely((opdata->in_bytes && !opdata->out))) { ++ WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n"); + return -WD_EINVAL; + } + +@@ -213,7 +218,7 @@ static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr, + + if (tag) { + if (!ctxt->setup.cb) { +- WD_ERR("ctx call back is null!\n"); ++ WD_ERR("invalid: ctx call back is null!\n"); + wd_put_cookies(&ctxt->pool, (void **)&cookie, 1); + return -WD_EINVAL; + } +diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c +index 4a2a5b5..9e467d0 100644 +--- a/v1/wd_rsa.c ++++ b/v1/wd_rsa.c +@@ -549,7 +549,7 @@ static void del_ctx(struct wcrypto_rsa_ctx *c) + + static int check_q_setup(struct wd_queue *q, struct wcrypto_rsa_ctx_setup *setup) + { +- if (!q || !setup) { ++ if (!q || !q->qinfo || !setup) { + WD_ERR("create rsa ctx input parameter err!\n"); + return -WD_EINVAL; + } +@@ -957,12 +957,18 @@ static int do_rsa_prepare(struct wcrypto_rsa_ctx *ctxt, + int ret; + + if (unlikely(!ctxt || !opdata)) { +- WD_ERR("input parameter err!\n"); ++ WD_ERR("invalid: input parameter err!\n"); ++ return -WD_EINVAL; ++ } ++ ++ ret = wd_check_src_dst(opdata->in, opdata->in_bytes, opdata->out, opdata->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } + + if (unlikely(tag && !ctxt->setup.cb)) { +- WD_ERR("ctx call back is null!\n"); ++ WD_ERR("invalid: ctx call back is null!\n"); + return -WD_EINVAL; + } + +diff --git a/v1/wd_util.c b/v1/wd_util.c +index a1d08b4..f31d138 100644 +--- a/v1/wd_util.c ++++ b/v1/wd_util.c +@@ -182,3 +182,10 @@ int wd_burst_recv(struct wd_queue *q, void **resp, __u32 num) + { + return drv_recv(q, resp, num); + } ++ ++int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes) ++{ ++ if (unlikely((in_bytes && !src) || (out_bytes && !dst))) ++ return -WD_EINVAL; ++ return 0; ++} +diff --git a/v1/wd_util.h b/v1/wd_util.h +index a8c6b15..bf17058 100644 +--- a/v1/wd_util.h ++++ b/v1/wd_util.h +@@ -404,5 +404,6 @@ void drv_set_sgl_pri(struct wd_sgl *sgl, void *priv); + void *drv_get_sgl_pri(struct wd_sgl *sgl); + struct wd_mm_br *drv_get_br(void *pool); + void wd_sgl_memset(struct wd_sgl *sgl, int ch); ++int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes); + + #endif +-- +2.25.1 + diff --git a/0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch b/0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch new file mode 100644 index 0000000..2e6b6b6 --- /dev/null +++ b/0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch @@ -0,0 +1,66 @@ +From 80f2ff4c5181dac5fc5dff113d06c4429d3aa029 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 16:51:02 +0800 +Subject: [PATCH 088/114] uadk/v1: remove print actions after wd_get_cookies + +Print information after wd_get_cookies returning EBUSY +can seriously affect performance,so remove it. + +Signed-off-by: Wenkai Lin +--- + v1/wd_aead.c | 4 +--- + v1/wd_cipher.c | 4 +--- + v1/wd_digest.c | 4 +--- + 3 files changed, 3 insertions(+), 9 deletions(-) + +diff --git a/v1/wd_aead.c b/v1/wd_aead.c +index f688309..38429fc 100644 +--- a/v1/wd_aead.c ++++ b/v1/wd_aead.c +@@ -593,10 +593,8 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **opdata, + return -WD_EINVAL; + + ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); +- if (unlikely(ret)) { +- WD_ERR("failed to get cookies %d!\n", ret); ++ if (unlikely(ret)) + return ret; +- } + + for (i = 0; i < num; i++) { + cookies[i]->tag.priv = opdata[i]->priv; +diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c +index 60a0f25..f95015d 100644 +--- a/v1/wd_cipher.c ++++ b/v1/wd_cipher.c +@@ -477,10 +477,8 @@ int wcrypto_burst_cipher(void *ctx, struct wcrypto_cipher_op_data **c_opdata, + return -WD_EINVAL; + + ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); +- if (unlikely(ret)) { +- WD_ERR("failed to get cookies %d!\n", ret); ++ if (unlikely(ret)) + return ret; +- } + + for (i = 0; i < num; i++) { + cookies[i]->tag.priv = c_opdata[i]->priv; +diff --git a/v1/wd_digest.c b/v1/wd_digest.c +index b617350..b8ea5ce 100644 +--- a/v1/wd_digest.c ++++ b/v1/wd_digest.c +@@ -456,10 +456,8 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata, + return -WD_EINVAL; + + ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); +- if (unlikely(ret)) { +- WD_ERR("failed to get cookies %d!\n", ret); ++ if (unlikely(ret)) + return ret; +- } + + for (i = 0; i < num; i++) { + cookies[i]->tag.priv = opdata[i]->priv; +-- +2.25.1 + diff --git a/0089-uadk-fix-header-file-is-not-self-contained.patch b/0089-uadk-fix-header-file-is-not-self-contained.patch new file mode 100644 index 0000000..1df7ea7 --- /dev/null +++ b/0089-uadk-fix-header-file-is-not-self-contained.patch @@ -0,0 +1,81 @@ +From 2edce8cc047c73341d5fde1ec6639e3a61681f64 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 16:54:46 +0800 +Subject: [PATCH 089/114] uadk: fix header file is not self contained + +Header files are not self contained, fix it. + +Signed-off-by: Wenkai Lin +--- + include/wd.h | 1 + + include/wd_alg_common.h | 1 + + include/wd_cipher.h | 1 + + include/wd_sched.h | 1 + + include/wd_util.h | 2 ++ + 5 files changed, 6 insertions(+) + +diff --git a/include/wd.h b/include/wd.h +index 0e67cad..6ee2ef5 100644 +--- a/include/wd.h ++++ b/include/wd.h +@@ -7,6 +7,7 @@ + #ifndef __WD_H + #define __WD_H + #include ++#include + #include + #include + #include +diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h +index 77845a4..5652db3 100644 +--- a/include/wd_alg_common.h ++++ b/include/wd_alg_common.h +@@ -9,6 +9,7 @@ + + #include + #include ++#include + #include "wd.h" + #include "wd_alg.h" + +diff --git a/include/wd_cipher.h b/include/wd_cipher.h +index 7e63402..a712b53 100644 +--- a/include/wd_cipher.h ++++ b/include/wd_cipher.h +@@ -8,6 +8,7 @@ + #define __WD_CIPHER_H + + #include ++#include + #include "wd_alg_common.h" + + #ifdef __cplusplus +diff --git a/include/wd_sched.h b/include/wd_sched.h +index a492d70..b145172 100644 +--- a/include/wd_sched.h ++++ b/include/wd_sched.h +@@ -6,6 +6,7 @@ + + #ifndef SCHED_SAMPLE_h + #define SCHED_SAMPLE_h ++#include + #include "wd_alg_common.h" + + #ifdef __cplusplus +diff --git a/include/wd_util.h b/include/wd_util.h +index be9798c..78c5d23 100644 +--- a/include/wd_util.h ++++ b/include/wd_util.h +@@ -13,7 +13,9 @@ + #include + #include + ++#include "wd.h" + #include "wd_sched.h" ++#include "wd_alg.h" + + #ifdef __cplusplus + extern "C" { +-- +2.25.1 + diff --git a/0090-uadk-sec-modify-improper-comments.patch b/0090-uadk-sec-modify-improper-comments.patch new file mode 100644 index 0000000..88c133c --- /dev/null +++ b/0090-uadk-sec-modify-improper-comments.patch @@ -0,0 +1,49 @@ +From 5de69884dea416eea90b2f5a76ac1fcf1a70f8a9 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:00:48 +0800 +Subject: [PATCH 090/114] uadk\sec: modify improper comments. + +Modify or delete improper comments in uadk/sec module. + +Signed-off-by: Qi Tao +--- + wd_digest.c | 2 +- + wd_util.c | 2 -- + 2 files changed, 1 insertion(+), 3 deletions(-) + +diff --git a/wd_digest.c b/wd_digest.c +index 2307bf1..bc67878 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -131,7 +131,7 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) + int ret; + + if (!key || !sess) { +- WD_ERR("failed to check key param!\n"); ++ WD_ERR("invalid: failed to check input param, sess or key is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/wd_util.c b/wd_util.c +index a9640c3..d1d4037 100644 +--- a/wd_util.c ++++ b/wd_util.c +@@ -408,7 +408,6 @@ void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool) + pool->pool_num = 0; + } + +-/* fix me: this is old wd_get_req_from_pool */ + void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, + int ctx_idx, __u32 tag) + { +@@ -1344,7 +1343,6 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config, + return head + offset; + } + +-/* fix me: all return value here, and no config input */ + int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx) + { + struct async_task_queue *task_queue; +-- +2.25.1 + diff --git a/0091-uadk-fixed-some-input-parameter-checking-issues.patch b/0091-uadk-fixed-some-input-parameter-checking-issues.patch new file mode 100644 index 0000000..e4a8568 --- /dev/null +++ b/0091-uadk-fixed-some-input-parameter-checking-issues.patch @@ -0,0 +1,126 @@ +From 81d5593a3f9f6e5c763f81f6e7d393dc5efda961 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:02:26 +0800 +Subject: [PATCH 091/114] uadk: fixed some input parameter checking issues + +Inside the asynchronous packet receiving interface of all submodules. +When the number of expected received packets is 0. Failure to intercept +will result in abnormal packet recycling. +As a result, the number of normal service packets does not match. + +In addition, when the expected value is 0, it will cause the while loop +control adjustment to flip, resulting in other receiving operations. + +Signed-off-by: Longfang Liu +--- + wd_aead.c | 2 +- + wd_cipher.c | 2 +- + wd_comp.c | 4 ++-- + wd_dh.c | 4 ++-- + wd_digest.c | 2 +- + wd_ecc.c | 4 ++-- + wd_rsa.c | 4 ++-- + 7 files changed, 11 insertions(+), 11 deletions(-) + +diff --git a/wd_aead.c b/wd_aead.c +index 87d61c3..ff43086 100644 +--- a/wd_aead.c ++++ b/wd_aead.c +@@ -816,7 +816,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { ++ if (unlikely(!count || !expt)) { + WD_ERR("invalid: aead poll ctx input param is NULL!\n"); + return -WD_EINVAL; + } +diff --git a/wd_cipher.c b/wd_cipher.c +index 58d34f7..0187c9c 100644 +--- a/wd_cipher.c ++++ b/wd_cipher.c +@@ -730,7 +730,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { ++ if (unlikely(!count || !expt)) { + WD_ERR("invalid: cipher poll ctx input param is NULL!\n"); + return -WD_EINVAL; + } +diff --git a/wd_comp.c b/wd_comp.c +index 21c9928..57e8b8f 100644 +--- a/wd_comp.c ++++ b/wd_comp.c +@@ -340,8 +340,8 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { +- WD_ERR("invalid: comp poll count is 0!\n"); ++ if (unlikely(!count || !expt)) { ++ WD_ERR("invalid: comp poll count or expt is 0!\n"); + return -WD_EINVAL; + } + +diff --git a/wd_dh.c b/wd_dh.c +index 40a52e5..dac55ca 100644 +--- a/wd_dh.c ++++ b/wd_dh.c +@@ -438,8 +438,8 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { +- WD_ERR("invalid: count is NULL!\n"); ++ if (unlikely(!count || !expt)) { ++ WD_ERR("invalid: dh poll count or expt is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/wd_digest.c b/wd_digest.c +index bc67878..1f2b3b2 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -701,7 +701,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { ++ if (unlikely(!count || !expt)) { + WD_ERR("invalid: digest poll ctx input param is NULL!\n"); + return -WD_EINVAL; + } +diff --git a/wd_ecc.c b/wd_ecc.c +index 4323e54..b5e7e36 100644 +--- a/wd_ecc.c ++++ b/wd_ecc.c +@@ -2272,8 +2272,8 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { +- WD_ERR("invalid: param count is NULL!\n"); ++ if (unlikely(!count || !expt)) { ++ WD_ERR("invalid: ecc poll param count or expt is NULL!\n"); + return -WD_EINVAL; + } + +diff --git a/wd_rsa.c b/wd_rsa.c +index 1813676..b71540f 100644 +--- a/wd_rsa.c ++++ b/wd_rsa.c +@@ -495,8 +495,8 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) + __u32 tmp = expt; + int ret; + +- if (unlikely(!count)) { +- WD_ERR("invalid: param count is NULL!\n"); ++ if (unlikely(!count || !expt)) { ++ WD_ERR("invalid: rsa poll count or expt is NULL!\n"); + return -WD_EINVAL; + } + +-- +2.25.1 + diff --git a/0092-uadk-code-cleanup.patch b/0092-uadk-code-cleanup.patch new file mode 100644 index 0000000..290490b --- /dev/null +++ b/0092-uadk-code-cleanup.patch @@ -0,0 +1,197 @@ +From 7a129d1ee851524a6166341c492e874705540ca2 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:05:32 +0800 +Subject: [PATCH 092/114] uadk: code cleanup + +Add the input pointer checking. + +Signed-off-by: Chenghai Huang +--- + include/wd_util.h | 12 ++++++++++++ + wd.c | 2 +- + wd_aead.c | 11 +++++++++++ + wd_cipher.c | 11 +++++++++++ + wd_digest.c | 8 +++++++- + wd_sched.c | 14 ++++++++++++-- + wd_util.c | 8 ++++++++ + 7 files changed, 62 insertions(+), 4 deletions(-) + +diff --git a/include/wd_util.h b/include/wd_util.h +index 78c5d23..3059ac1 100644 +--- a/include/wd_util.h ++++ b/include/wd_util.h +@@ -235,6 +235,18 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, + void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int ctx_idx, + __u32 tag); + ++/* ++ * wd_check_src_dst() - Check the request input and output ++ * @src: input data pointer. ++ * @in_bytes: input data length. ++ * @dst: output data pointer. ++ * @out_bytes: output data length. ++ * ++ * Return -WD_EINVAL when in_bytes or out_bytes is non-zero, the ++ * corresponding input or output pointers is NULL, otherwise return 0. ++ */ ++int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes); ++ + /* + * wd_check_datalist() - Check the data list length + * @head: Data list's head pointer. +diff --git a/wd.c b/wd.c +index ddde38d..a6e207d 100644 +--- a/wd.c ++++ b/wd.c +@@ -756,7 +756,7 @@ struct uacce_dev *wd_find_dev_by_numa(struct uacce_dev_list *list, int numa_id) + } + + while (p) { +- if (numa_id != p->dev->numa_id) { ++ if (p->dev && numa_id != p->dev->numa_id) { + p = p->next; + continue; + } +diff --git a/wd_aead.c b/wd_aead.c +index ff43086..6d49d76 100644 +--- a/wd_aead.c ++++ b/wd_aead.c +@@ -361,6 +361,11 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, + return -WD_EINVAL; + } + ++ if (unlikely(!req->iv || !req->mac)) { ++ WD_ERR("invalid: aead input iv or mac is NULL!\n"); ++ return -WD_EINVAL; ++ } ++ + if (unlikely(sess->cmode == WD_CIPHER_CBC && req->in_bytes == 0)) { + WD_ERR("aead input data length is zero!\n"); + return -WD_EINVAL; +@@ -384,6 +389,12 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, + return -WD_EINVAL; + } + ++ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ + if (req->data_fmt == WD_SGL_BUF) { + len = req->in_bytes + req->assoc_bytes; + ret = wd_check_datalist(req->list_src, len); +diff --git a/wd_cipher.c b/wd_cipher.c +index 0187c9c..47c0bf8 100644 +--- a/wd_cipher.c ++++ b/wd_cipher.c +@@ -542,6 +542,11 @@ static int cipher_iv_len_check(struct wd_cipher_req *req, + if (sess->mode == WD_CIPHER_ECB) + return 0; + ++ if (!req->iv) { ++ WD_ERR("invalid: cipher input iv is NULL!\n"); ++ ret = -WD_EINVAL; ++ } ++ + switch (sess->alg) { + case WD_CIPHER_AES: + case WD_CIPHER_SM4: +@@ -589,6 +594,12 @@ static int wd_cipher_check_params(handle_t h_sess, + return -WD_EINVAL; + } + ++ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ + if (req->data_fmt == WD_SGL_BUF) { + ret = wd_check_datalist(req->list_src, req->in_bytes); + if (unlikely(ret)) { +diff --git a/wd_digest.c b/wd_digest.c +index 1f2b3b2..9008bcb 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -514,12 +514,18 @@ static int wd_digest_param_check(struct wd_digest_sess *sess, + return ret; + + if (unlikely(sess->alg == WD_DIGEST_AES_GMAC && +- req->iv_bytes != GMAC_IV_LEN)) { ++ (!req->iv || req->iv_bytes != GMAC_IV_LEN))) { + WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n", + req->iv_bytes); + return -WD_EINVAL; + } + ++ ret = wd_check_src_dst(req->in, req->in_bytes, req->out, req->out_bytes); ++ if (unlikely(ret)) { ++ WD_ERR("invalid: in/out addr is NULL when in/out size is non-zero!\n"); ++ return -WD_EINVAL; ++ } ++ + if (req->data_fmt == WD_SGL_BUF) { + ret = wd_check_datalist(req->list_in, req->in_bytes); + if (unlikely(ret)) { +diff --git a/wd_sched.c b/wd_sched.c +index d1c829f..7aeea73 100644 +--- a/wd_sched.c ++++ b/wd_sched.c +@@ -311,8 +311,8 @@ static int session_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 * + __u16 i; + int ret; + +- if (unlikely(!count || !sched_ctx)) { +- WD_ERR("invalid: sched ctx is NULL or count is zero!\n"); ++ if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) { ++ WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n"); + return -WD_EINVAL; + } + +@@ -375,6 +375,11 @@ static int sched_none_poll_policy(handle_t h_sched_ctx, + __u32 poll_num = 0; + int ret; + ++ if (!sched_ctx || !sched_ctx->poll_func) { ++ WD_ERR("invalid: sched ctx or poll_func is NULL!\n"); ++ return -WD_EINVAL; ++ } ++ + while (loop_times > 0) { + /* Default use ctx 0 */ + loop_times--; +@@ -417,6 +422,11 @@ static int sched_single_poll_policy(handle_t h_sched_ctx, + __u32 poll_num = 0; + int ret; + ++ if (!sched_ctx || !sched_ctx->poll_func) { ++ WD_ERR("invalid: sched ctx or poll_func is NULL!\n"); ++ return -WD_EINVAL; ++ } ++ + while (loop_times > 0) { + /* Default async mode use ctx 0 */ + loop_times--; +diff --git a/wd_util.c b/wd_util.c +index d1d4037..10b0ab9 100644 +--- a/wd_util.c ++++ b/wd_util.c +@@ -459,6 +459,14 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag) + __atomic_clear(&p->used[tag - 1], __ATOMIC_RELEASE); + } + ++int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes) ++{ ++ if ((in_bytes && !src) || (out_bytes && !dst)) ++ return -WD_EINVAL; ++ ++ return 0; ++} ++ + int wd_check_datalist(struct wd_datalist *head, __u32 size) + { + struct wd_datalist *tmp = head; +-- +2.25.1 + diff --git a/0093-uadk-fix-sec-send-and-recv-check-failed.patch b/0093-uadk-fix-sec-send-and-recv-check-failed.patch new file mode 100644 index 0000000..b878772 --- /dev/null +++ b/0093-uadk-fix-sec-send-and-recv-check-failed.patch @@ -0,0 +1,431 @@ +From e0ace2af02926648ec44070ac3b5e5328365f849 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:08:58 +0800 +Subject: [PATCH 093/114] uadk: fix sec send and recv check failed + +The send and recv pointers should be assigned at the beginning, +not during wd initialization. + +Signed-off-by: Wenkai Lin +--- + drv/hisi_sec.c | 260 ++++++++++++++++++++++++++++--------------------- + 1 file changed, 149 insertions(+), 111 deletions(-) + +diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c +index 03e7037..9bf7e68 100644 +--- a/drv/hisi_sec.c ++++ b/drv/hisi_sec.c +@@ -539,12 +539,93 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = { + static int hisi_sec_init(struct wd_alg_driver *drv, void *conf); + static void hisi_sec_exit(struct wd_alg_driver *drv); + ++static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++ ++static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++ ++static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); ++ ++static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_cipher_send(drv, ctx, msg); ++ return hisi_sec_cipher_send_v3(drv, ctx, msg); ++} ++ ++static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_cipher_recv(drv, ctx, msg); ++ return hisi_sec_cipher_recv_v3(drv, ctx, msg); ++} ++ ++static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_digest_send(drv, ctx, msg); ++ return hisi_sec_digest_send_v3(drv, ctx, msg); ++} ++ ++static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_digest_recv(drv, ctx, msg); ++ return hisi_sec_digest_recv_v3(drv, ctx, msg); ++} ++ ++static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_aead_send(drv, ctx, msg); ++ return hisi_sec_aead_send_v3(drv, ctx, msg); ++} ++ ++static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) ++{ ++ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct hisi_qp *qp = (struct hisi_qp *)h_qp; ++ struct hisi_qm_queue_info q_info = qp->q_info; ++ ++ if (q_info.hw_type == HISI_QM_API_VER2_BASE) ++ return hisi_sec_aead_recv(drv, ctx, msg); ++ return hisi_sec_aead_recv_v3(drv, ctx, msg); ++} ++ + static int hisi_sec_get_usage(void *param) + { + return 0; + } + +-#define GEN_SEC_ALG_DRIVER(sec_alg_name) \ ++#define GEN_SEC_ALG_DRIVER(sec_alg_name, alg_type) \ + {\ + .drv_name = "hisi_sec2",\ + .alg_name = (sec_alg_name),\ +@@ -555,57 +636,59 @@ static int hisi_sec_get_usage(void *param) + .fallback = 0,\ + .init = hisi_sec_init,\ + .exit = hisi_sec_exit,\ ++ .send = alg_type##_send,\ ++ .recv = alg_type##_recv,\ + .get_usage = hisi_sec_get_usage,\ + } + + static struct wd_alg_driver cipher_alg_driver[] = { +- GEN_SEC_ALG_DRIVER("ecb(aes)"), +- GEN_SEC_ALG_DRIVER("cbc(aes)"), +- GEN_SEC_ALG_DRIVER("xts(aes)"), +- GEN_SEC_ALG_DRIVER("ecb(sm4)"), +- GEN_SEC_ALG_DRIVER("cbc(sm4)"), +- GEN_SEC_ALG_DRIVER("ctr(sm4)"), +- GEN_SEC_ALG_DRIVER("xts(sm4)"), +- GEN_SEC_ALG_DRIVER("ecb(des)"), +- GEN_SEC_ALG_DRIVER("cbc(des)"), +- GEN_SEC_ALG_DRIVER("ecb(des3_ede)"), +- GEN_SEC_ALG_DRIVER("cbc(des3_ede)"), +- +- GEN_SEC_ALG_DRIVER("ctr(aes)"), +- GEN_SEC_ALG_DRIVER("ofb(aes)"), +- GEN_SEC_ALG_DRIVER("cfb(aes)"), +- GEN_SEC_ALG_DRIVER("cbc-cs1(aes)"), +- GEN_SEC_ALG_DRIVER("cbc-cs2(aes)"), +- GEN_SEC_ALG_DRIVER("cbc-cs3(aes)"), +- GEN_SEC_ALG_DRIVER("ofb(sm4)"), +- GEN_SEC_ALG_DRIVER("cfb(sm4)"), +- GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)"), +- GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)"), +- GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)"), ++ GEN_SEC_ALG_DRIVER("ecb(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("xts(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("ecb(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("ctr(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("xts(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("ecb(des)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc(des)", cipher), ++ GEN_SEC_ALG_DRIVER("ecb(des3_ede)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc(des3_ede)", cipher), ++ ++ GEN_SEC_ALG_DRIVER("ctr(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("ofb(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("cfb(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs1(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs2(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs3(aes)", cipher), ++ GEN_SEC_ALG_DRIVER("ofb(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("cfb(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)", cipher), ++ GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)", cipher), + }; + + static struct wd_alg_driver digest_alg_driver[] = { +- GEN_SEC_ALG_DRIVER("sm3"), +- GEN_SEC_ALG_DRIVER("md5"), +- GEN_SEC_ALG_DRIVER("sha1"), +- GEN_SEC_ALG_DRIVER("sha224"), +- GEN_SEC_ALG_DRIVER("sha256"), +- GEN_SEC_ALG_DRIVER("sha384"), +- GEN_SEC_ALG_DRIVER("sha512"), +- GEN_SEC_ALG_DRIVER("sha512-224"), +- GEN_SEC_ALG_DRIVER("sha512-256"), +- GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)"), +- GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)"), +- GEN_SEC_ALG_DRIVER("cmac(aes)"), +- GEN_SEC_ALG_DRIVER("gmac(aes)"), ++ GEN_SEC_ALG_DRIVER("sm3", digest), ++ GEN_SEC_ALG_DRIVER("md5", digest), ++ GEN_SEC_ALG_DRIVER("sha1", digest), ++ GEN_SEC_ALG_DRIVER("sha224", digest), ++ GEN_SEC_ALG_DRIVER("sha256", digest), ++ GEN_SEC_ALG_DRIVER("sha384", digest), ++ GEN_SEC_ALG_DRIVER("sha512", digest), ++ GEN_SEC_ALG_DRIVER("sha512-224", digest), ++ GEN_SEC_ALG_DRIVER("sha512-256", digest), ++ GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)", digest), ++ GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)", digest), ++ GEN_SEC_ALG_DRIVER("cmac(aes)", digest), ++ GEN_SEC_ALG_DRIVER("gmac(aes)", digest), + }; + + static struct wd_alg_driver aead_alg_driver[] = { +- GEN_SEC_ALG_DRIVER("ccm(aes)"), +- GEN_SEC_ALG_DRIVER("gcm(aes)"), +- GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))"), +- GEN_SEC_ALG_DRIVER("ccm(sm4)"), +- GEN_SEC_ALG_DRIVER("gcm(sm4)"), ++ GEN_SEC_ALG_DRIVER("ccm(aes)", aead), ++ GEN_SEC_ALG_DRIVER("gcm(aes)", aead), ++ GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))", aead), ++ GEN_SEC_ALG_DRIVER("ccm(sm4)", aead), ++ GEN_SEC_ALG_DRIVER("gcm(sm4)", aead), + }; + + static void dump_sec_msg(void *msg, const char *alg) +@@ -1092,10 +1175,10 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) + return 0; + } + +-int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) ++static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_cipher_msg *msg = cipher_msg; ++ struct wd_cipher_msg *msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -1137,10 +1220,10 @@ int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_m + return 0; + } + +-int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) ++static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_cipher_msg *recv_msg = cipher_msg; ++ struct wd_cipher_msg *recv_msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -1295,10 +1378,10 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) + return 0; + } + +-int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) ++static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_cipher_msg *msg = cipher_msg; ++ struct wd_cipher_msg *msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -1385,10 +1468,10 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, + dump_sec_msg(temp_msg, "cipher"); + } + +-int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) ++static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_cipher_msg *recv_msg = cipher_msg; ++ struct wd_cipher_msg *recv_msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -1658,10 +1741,10 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) + return 0; + } + +-int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) ++static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_digest_msg *msg = digest_msg; ++ struct wd_digest_msg *msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + __u8 scene; +@@ -1725,10 +1808,10 @@ put_sgl: + return ret; + } + +-int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) ++static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_digest_msg *recv_msg = digest_msg; ++ struct wd_digest_msg *recv_msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -1902,10 +1985,10 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe, + sqe->bd_param |= (__u16)(de | scene); + } + +-int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) ++static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_digest_msg *msg = digest_msg; ++ struct wd_digest_msg *msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -2001,10 +2084,10 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, + dump_sec_msg(temp_msg, "digest"); + } + +-int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) ++static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_digest_msg *recv_msg = digest_msg; ++ struct wd_digest_msg *recv_msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -2473,10 +2556,10 @@ int aead_msg_state_check(struct wd_aead_msg *msg) + return 0; + } + +-int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) ++static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_aead_msg *msg = aead_msg; ++ struct wd_aead_msg *msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -2595,10 +2678,10 @@ static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg) + qp->q_info.qp_mode == CTX_MODE_SYNC; + } + +-int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) ++static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_aead_msg *recv_msg = aead_msg; ++ struct wd_aead_msg *recv_msg = wd_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -2857,10 +2940,10 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) + return 0; + } + +-int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) ++static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_aead_msg *msg = aead_msg; ++ struct wd_aead_msg *msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -2957,10 +3040,10 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, + dump_sec_msg(temp_msg, "aead"); + } + +-int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) ++static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); +- struct wd_aead_msg *recv_msg = aead_msg; ++ struct wd_aead_msg *recv_msg = wd_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -2985,50 +3068,6 @@ int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_ms + return 0; + } + +-static void hisi_sec_driver_adapter(struct hisi_qp *qp) +-{ +- struct hisi_qm_queue_info q_info = qp->q_info; +- int alg_num, i; +- +- if (q_info.hw_type == HISI_QM_API_VER2_BASE) { +- WD_INFO("hisi sec init HIP08!\n"); +- alg_num = ARRAY_SIZE(cipher_alg_driver); +- for (i = 0; i < alg_num; i++) { +- cipher_alg_driver[i].send = hisi_sec_cipher_send; +- cipher_alg_driver[i].recv = hisi_sec_cipher_recv; +- } +- +- alg_num = ARRAY_SIZE(digest_alg_driver); +- for (i = 0; i < alg_num; i++) { +- digest_alg_driver[i].send = hisi_sec_digest_send; +- digest_alg_driver[i].recv = hisi_sec_digest_recv; +- } +- alg_num = ARRAY_SIZE(aead_alg_driver); +- for (i = 0; i < alg_num; i++) { +- aead_alg_driver[i].send = hisi_sec_aead_send; +- aead_alg_driver[i].recv = hisi_sec_aead_recv; +- } +- } else { +- WD_INFO("hisi sec init HIP09!\n"); +- alg_num = ARRAY_SIZE(cipher_alg_driver); +- for (i = 0; i < alg_num; i++) { +- cipher_alg_driver[i].send = hisi_sec_cipher_send_v3; +- cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3; +- } +- +- alg_num = ARRAY_SIZE(digest_alg_driver); +- for (i = 0; i < alg_num; i++) { +- digest_alg_driver[i].send = hisi_sec_digest_send_v3; +- digest_alg_driver[i].recv = hisi_sec_digest_recv_v3; +- } +- alg_num = ARRAY_SIZE(aead_alg_driver); +- for (i = 0; i < alg_num; i++) { +- aead_alg_driver[i].send = hisi_sec_aead_send_v3; +- aead_alg_driver[i].recv = hisi_sec_aead_recv_v3; +- } +- } +-} +- + static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) + { + struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv; +@@ -3069,7 +3108,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) + config->ctxs[i].sqn = qm_priv.sqn; + } + memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); +- hisi_sec_driver_adapter((struct hisi_qp *)h_qp); + drv->priv = priv; + + return 0; +-- +2.25.1 + diff --git a/0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch b/0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch new file mode 100644 index 0000000..384ca9b --- /dev/null +++ b/0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch @@ -0,0 +1,94 @@ +From 90511556722f51dcd6a6a4172943ee32e52db267 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:12:17 +0800 +Subject: [PATCH 094/114] uadk: code cleanup for error codes and variable type + +Unify the use of error return name. Modify the variable +type in hisi_sec to reduce variable conversion. + +Signed-off-by: Chenghai Huang +--- + drv/hisi_sec.c | 12 ++++++------ + wd.c | 4 ++-- + 2 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c +index 9bf7e68..2f03d1f 100644 +--- a/drv/hisi_sec.c ++++ b/drv/hisi_sec.c +@@ -517,12 +517,12 @@ struct hisi_sec_sqe3 { + __le32 counter; + } __attribute__((packed, aligned(4))); + +-static int g_digest_a_alg[WD_DIGEST_TYPE_MAX] = { ++static __u32 g_digest_a_alg[WD_DIGEST_TYPE_MAX] = { + A_ALG_SM3, A_ALG_MD5, A_ALG_SHA1, A_ALG_SHA256, A_ALG_SHA224, + A_ALG_SHA384, A_ALG_SHA512, A_ALG_SHA512_224, A_ALG_SHA512_256 + }; + +-static int g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = { ++static __u32 g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = { + A_ALG_HMAC_SM3, A_ALG_HMAC_MD5, A_ALG_HMAC_SHA1, + A_ALG_HMAC_SHA256, A_ALG_HMAC_SHA224, A_ALG_HMAC_SHA384, + A_ALG_HMAC_SHA512, A_ALG_HMAC_SHA512_224, A_ALG_HMAC_SHA512_256, +@@ -1518,7 +1518,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, + + if (msg->mode == WD_DIGEST_NORMAL) + sqe->type2.mac_key_alg |= +- (__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET; ++ g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET; + else if (msg->mode == WD_DIGEST_HMAC) { + if (msg->key_bytes & WORD_ALIGNMENT_MASK) { + WD_ERR("failed to check digest key_bytes, size = %u\n", +@@ -1530,7 +1530,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, + sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->key; + + sqe->type2.mac_key_alg |= +- (__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET; ++ g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET; + } else { + WD_ERR("failed to check digest mode, mode = %u\n", msg->mode); + return -WD_EINVAL; +@@ -1887,7 +1887,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, + + if (msg->mode == WD_DIGEST_NORMAL) { + sqe->auth_mac_key |= +- (__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; ++ g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; + } else if (msg->mode == WD_DIGEST_HMAC) { + ret = hmac_key_len_check(msg); + if (ret) +@@ -1897,7 +1897,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, + WORD_BYTES) << SEC_AKEY_OFFSET_V3; + sqe->a_key_addr = (__u64)(uintptr_t)msg->key; + sqe->auth_mac_key |= +- (__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; ++ g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; + + if (msg->alg == WD_DIGEST_AES_GMAC) { + sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3; +diff --git a/wd.c b/wd.c +index a6e207d..be374f5 100644 +--- a/wd.c ++++ b/wd.c +@@ -228,7 +228,7 @@ static int get_dev_info(struct uacce_dev *dev) + return ret; + else if (value == 1) { + WD_ERR("skip isolated uacce device!\n"); +- return -ENODEV; ++ return -WD_ENODEV; + } + } + +@@ -237,7 +237,7 @@ static int get_dev_info(struct uacce_dev *dev) + return ret; + else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) { + WD_ERR("skip none sva uacce device!\n"); +- return -ENODEV; ++ return -WD_ENODEV; + } + + ret = get_int_attr(dev, "region_mmio_size", &value); +-- +2.25.1 + diff --git a/0095-uadk-sec-add-a-return-value-judgement.patch b/0095-uadk-sec-add-a-return-value-judgement.patch new file mode 100644 index 0000000..337f6a1 --- /dev/null +++ b/0095-uadk-sec-add-a-return-value-judgement.patch @@ -0,0 +1,37 @@ +From f118a291c4aacebf60c3c532d004581d125df6a1 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 17:14:45 +0800 +Subject: [PATCH 095/114] uadk/sec: add a return value judgement + +Add return value judgement of aead_get_aes_key_len(). + +Signed-off-by: Zhiqi Song +--- + drv/hisi_sec.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c +index 2f03d1f..9102a27 100644 +--- a/drv/hisi_sec.c ++++ b/drv/hisi_sec.c +@@ -2152,6 +2152,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, + case WD_CIPHER_AES: + sqe->type2.c_alg = C_ALG_AES; + ret = aead_get_aes_key_len(msg, &c_key_len); ++ if (ret) ++ return ret; + sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET; + break; + default: +@@ -2721,6 +2723,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg, + case WD_CIPHER_AES: + sqe->c_mode_alg |= C_ALG_AES << SEC_CALG_OFFSET_V3; + ret = aead_get_aes_key_len(msg, &c_key_len); ++ if (ret) ++ return ret; + sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3; + break; + default: +-- +2.25.1 + diff --git a/0096-uadk-Add-file-association.patch b/0096-uadk-Add-file-association.patch new file mode 100644 index 0000000..0941076 --- /dev/null +++ b/0096-uadk-Add-file-association.patch @@ -0,0 +1,31 @@ +From 697b131a5a08586fb731c160c89c86e107f11984 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:17:22 +0800 +Subject: [PATCH 096/114] uadk: Add file association + +Add wd_comp file to zip. + +Signed-off-by: Chenghai Huang +--- + Makefile.am | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Makefile.am b/Makefile.am +index 657ed20..e9ec47a 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -121,9 +121,9 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma + libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) + libwd_crypto_la_DEPENDENCIES= libwd.la + +-libhisi_zip_la_LIBADD= -lwd -ldl ++libhisi_zip_la_LIBADD= -lwd -ldl -lwd_comp + libhisi_zip_la_LDFLAGS=$(UADK_VERSION) +-libhisi_zip_la_DEPENDENCIES= libwd.la ++libhisi_zip_la_DEPENDENCIES= libwd.la libwd_comp.la + + libhisi_sec_la_LIBADD= -lwd -lwd_crypto + libhisi_sec_la_LDFLAGS=$(UADK_VERSION) +-- +2.25.1 + diff --git a/0097-uadk-fix-the-failure-process-bug.patch b/0097-uadk-fix-the-failure-process-bug.patch new file mode 100644 index 0000000..29d9467 --- /dev/null +++ b/0097-uadk-fix-the-failure-process-bug.patch @@ -0,0 +1,39 @@ +From 044afdf1f90573c3a44187f7759461f496bf7bf8 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:18:43 +0800 +Subject: [PATCH 097/114] uadk: fix the failure process bug + +After a failure message is returned due to a calloc exception, +the mp-ref count must be decreased by 1. Otherwise, an infinite +loop occurs when the process invokes the mp command to destroy +the process and cannot exit. + +Signed-off-by: Chenghai Huang +--- + wd_mempool.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/wd_mempool.c b/wd_mempool.c +index cb8c80b..ed107d1 100644 +--- a/wd_mempool.c ++++ b/wd_mempool.c +@@ -573,7 +573,7 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size, + bp = calloc(1, sizeof(struct blkpool)); + if (!bp) { + WD_ERR("failed to alloc memory for blkpool!\n"); +- return (handle_t)(-WD_ENOMEM); ++ goto err_sub_ref; + } + + bp->top = block_num; +@@ -597,6 +597,7 @@ err_free_mem: + free_mem_to_mempool(bp); + err_free_bp: + free(bp); ++err_sub_ref: + wd_atomic_sub(&mp->ref, 1); + return (handle_t)(-WD_ENOMEM); + } +-- +2.25.1 + diff --git a/0098-uadk-fix-the-failure-process-bug.patch b/0098-uadk-fix-the-failure-process-bug.patch new file mode 100644 index 0000000..bc08feb --- /dev/null +++ b/0098-uadk-fix-the-failure-process-bug.patch @@ -0,0 +1,28 @@ +From f7a2fb057185759708d8b9712608150c9dccafef Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:20:38 +0800 +Subject: [PATCH 098/114] uadk: fix the failure process bug + +After the sem_post operation of full_sem fails, it need to +restore empty_sem to ensure that resources are available. + +Signed-off-by: Chenghai Huang +--- + wd_util.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/wd_util.c b/wd_util.c +index 10b0ab9..4867d63 100644 +--- a/wd_util.c ++++ b/wd_util.c +@@ -1398,6 +1398,7 @@ err_out: + task_queue->cur_task--; + task_queue->prod = curr_prod; + pthread_mutex_unlock(&task_queue->lock); ++ sem_post(&task_queue->empty_sem); + + return ret; + } +-- +2.25.1 + diff --git a/0099-uadk-fix-the-failure-process-bug.patch b/0099-uadk-fix-the-failure-process-bug.patch new file mode 100644 index 0000000..decc55e --- /dev/null +++ b/0099-uadk-fix-the-failure-process-bug.patch @@ -0,0 +1,36 @@ +From 9de8de67355430cfa9764109655af988cb7c031e Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:23:32 +0800 +Subject: [PATCH 099/114] uadk: fix the failure process+bug + +Assign numa_num to sched_ctx before err_out +for wd_scheduling_rr_release release memoryc orrectly. + +Signed-off-by: Chenghai Huang +--- + wd_sched.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/wd_sched.c b/wd_sched.c +index 7aeea73..419280e 100644 +--- a/wd_sched.c ++++ b/wd_sched.c +@@ -642,6 +642,7 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, + WD_ERR("failed to alloc memory for sched_ctx!\n"); + goto err_out; + } ++ sched_ctx->numa_num = numa_num; + + sched->h_sched_ctx = (handle_t)sched_ctx; + if (sched_type == SCHED_POLICY_NONE || +@@ -662,7 +663,6 @@ simple_ok: + sched_ctx->poll_func = func; + sched_ctx->policy = sched_type; + sched_ctx->type_num = type_num; +- sched_ctx->numa_num = numa_num; + memset(sched_ctx->numa_map, -1, sizeof(int) * NUMA_NUM_NODES); + + sched->sched_init = sched_table[sched_type].sched_init; +-- +2.25.1 + diff --git a/0100-uadk-bugfix.patch b/0100-uadk-bugfix.patch new file mode 100644 index 0000000..fdb868d --- /dev/null +++ b/0100-uadk-bugfix.patch @@ -0,0 +1,28 @@ +From bf5a2e34368228538436a3856fd69167a6897516 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:25:47 +0800 +Subject: [PATCH 100/114] uadk: bugfix + +Replace strncpy with memcpy to avoid compilation warnings. + +Signed-off-by: Chenghai Huang +--- + wd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/wd.c b/wd.c +index be374f5..b08abab 100644 +--- a/wd.c ++++ b/wd.c +@@ -426,7 +426,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev) + + wd_ctx_init_qfrs_offs(ctx); + +- strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN); ++ memcpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN); + ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0'; + + return (handle_t)ctx; +-- +2.25.1 + diff --git a/0101-uadk-v1-adapter-code-cleanup.patch b/0101-uadk-v1-adapter-code-cleanup.patch new file mode 100644 index 0000000..2a2cc08 --- /dev/null +++ b/0101-uadk-v1-adapter-code-cleanup.patch @@ -0,0 +1,39 @@ +From 111d3b3688063ec0f40171f837f0f0bde68b7e25 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:29:22 +0800 +Subject: [PATCH 101/114] uadk v1: adapter code cleanup + +Delete unnecessary processing. + +Signed-off-by: Chenghai Huang +--- + v1/wd_adapter.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c +index 6b0b4d8..6e95562 100644 +--- a/v1/wd_adapter.c ++++ b/v1/wd_adapter.c +@@ -209,9 +209,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size) + + ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, tmp); + if (ptr == MAP_FAILED) { +- int value = errno; +- +- WD_ERR("wd drv mmap fail!(err =%d)\n", value); ++ WD_ERR("wd drv mmap fail!(err = %d)\n", errno); + return NULL; + } + +@@ -219,7 +217,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size) + qinfo->ss_size = tmp; + tmp = 0; + while (ret > 0) { +- info = (unsigned long)i; ++ info = i; + ret = ioctl(qinfo->fd, WD_UACCE_CMD_GET_SS_DMA, &info); + if (ret < 0) { + drv_show_ss_slices(q); +-- +2.25.1 + diff --git a/0102-uadk-v1-fix-wd_rng-resource-release-bug.patch b/0102-uadk-v1-fix-wd_rng-resource-release-bug.patch new file mode 100644 index 0000000..6477fbd --- /dev/null +++ b/0102-uadk-v1-fix-wd_rng-resource-release-bug.patch @@ -0,0 +1,40 @@ +From f99c4bfe4aec8110043bd88df0f52b47ed8e05e8 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:30:23 +0800 +Subject: [PATCH 102/114] uadk v1: fix wd_rng resource release bug + +Before wd_free_id and ctx_num are released, check +whether ctx_num is less than or equal to 0 to +avoid repeated release. + +Signed-off-by: Chenghai Huang +--- + v1/wd_rng.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/v1/wd_rng.c b/v1/wd_rng.c +index 927665f..24a4b7a 100644 +--- a/v1/wd_rng.c ++++ b/v1/wd_rng.c +@@ -144,14 +144,14 @@ void wcrypto_del_rng_ctx(void *ctx) + + wd_uninit_cookie_pool(&cx->pool); + wd_spinlock(&qinfo->qlock); +- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1, +- WD_MAX_CTX_NUM); +- qinfo->ctx_num--; +- if (qinfo->ctx_num < 0) { ++ if (qinfo->ctx_num <= 0) { + wd_unspinlock(&qinfo->qlock); + WD_ERR("repeat delete trng ctx!\n"); + return; + } ++ qinfo->ctx_num--; ++ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1, ++ WD_MAX_CTX_NUM); + wd_unspinlock(&qinfo->qlock); + + free(ctx); +-- +2.25.1 + diff --git a/0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch b/0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch new file mode 100644 index 0000000..e598059 --- /dev/null +++ b/0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch @@ -0,0 +1,235 @@ +From 294719db475aeb6f13dbc8b364b6ce1e48846f40 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:33:19 +0800 +Subject: [PATCH 103/114] uadk v1: code cleanup for error codes and header + files + +Unify the use of error return name. Adjusting the +sequence of header files. + +Signed-off-by: Chenghai Huang +--- + v1/wd.c | 63 +++++++++++++++++++++++++++++---------------------------- + 1 file changed, 32 insertions(+), 31 deletions(-) + +diff --git a/v1/wd.c b/v1/wd.c +index 3839304..26e7af3 100644 +--- a/v1/wd.c ++++ b/v1/wd.c +@@ -14,18 +14,18 @@ + * limitations under the License. + */ + +-#include +-#include +-#include +-#include ++#include ++#include + #include ++#include ++#include ++#include ++#include + #include +-#include + #include +-#include +-#include + #include +-#include ++#include ++#include + + #include "v1/wd_util.h" + #include "v1/wd_adapter.h" +@@ -94,12 +94,12 @@ static int get_raw_attr(const char *dev_root, const char *attr, + fd = open(attr_path, O_RDONLY, 0); + if (fd < 0) { + WD_ERR("open %s fail, errno = %d!\n", attr_path, errno); +- return -ENODEV; ++ return -WD_ENODEV; + } + size = read(fd, buf, sz); + if (size <= 0) { + WD_ERR("read nothing at %s!\n", attr_path); +- size = -ENODEV; ++ size = -WD_ENODEV; + } + + close(fd); +@@ -214,7 +214,7 @@ static bool is_weight_more(unsigned int new, unsigned int old) + ins_old = GET_AVAILABLE_INSTANCES(old); + dis_old = GET_NODE_DISTANCE(old); + +- dbg("dis_new %u, ins_new %u,dis_old %u, ins_old %u\n", ++ dbg("dis_new %u, ins_new %u, dis_old %u, ins_old %u\n", + dis_new, ins_new, dis_old, ins_old); + + if (dis_new > dis_old) +@@ -240,16 +240,16 @@ static int get_int_attr_all(struct dev_info *dinfo) + /* ret == 1 means device has been isolated */ + ret = get_int_attr(dinfo, "isolate"); + if (ret < 0) +- return -ENODEV; ++ return -WD_ENODEV; + else if (ret == 1) +- return -EBUSY; ++ return -WD_EBUSY; + + /* ret == 0 means device has no available queues */ + ret = get_int_attr(dinfo, "available_instances"); + if (ret < 0) +- return -ENODEV; ++ return -WD_ENODEV; + else if (ret == 0) +- return -EBUSY; ++ return -WD_EBUSY; + + dinfo->available_instances = ret; + +@@ -318,13 +318,13 @@ static int get_dev_info(struct dev_info *dinfo, const char *alg) + LINUX_DEV_DIR, dinfo->name); + if (ret <= 0) { + WD_ERR("snprintf err, ret %d!\n", ret); +- return -EINVAL; ++ return -WD_EINVAL; + } + + ret = access(buf, F_OK); + if (ret < 0) { + WD_ERR("failed to check file path %s, ret: %d\n", buf, ret); +- return -ENODEV; ++ return -WD_ENODEV; + } + + ret = get_str_attr_all(dinfo, alg); +@@ -407,7 +407,7 @@ static int get_denoted_dev(struct wd_capa *capa, const char *dev, + if (!get_dev_info(dinfop, capa->alg)) + return 0; + WD_ERR("%s not available, will try other devices\n", dev); +- return -ENODEV; ++ return -WD_ENODEV; + } + + static int find_available_dev(struct dev_info *dinfop, +@@ -425,7 +425,7 @@ static int find_available_dev(struct dev_info *dinfop, + wd_class = opendir(WD_UACCE_CLASS_DIR); + if (!wd_class) { + WD_ERR("WD framework is not enabled on the system, errno = %d!\n", errno); +- return -ENODEV; ++ return -WD_ENODEV; + } + + while (true) { +@@ -444,7 +444,7 @@ static int find_available_dev(struct dev_info *dinfop, + find_node = true; + break; + } +- } else if (ret == -EPFNOSUPPORT || ret == -EBUSY || ret == -ENODEV) { ++ } else if (ret == -EPFNOSUPPORT || ret == -WD_EBUSY || ret == -WD_ENODEV) { + continue; + } else { + closedir(wd_class); +@@ -470,12 +470,12 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, + if (dev[0] && dev[0] != '/' && !strstr(dev, "../")) { + if (!dinfop) { + WD_ERR("dinfop NULL!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + + if (q->node_mask) { + WD_ERR("dev and node cannot be denoted together!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + + if (!get_denoted_dev(capa, dev, dinfop)) +@@ -485,7 +485,7 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, + ret = find_available_dev(dinfop, capa, q->node_mask); + if (ret <= 0 && dinfop) { + WD_ERR("get /%s path fail!\n", dinfop->name); +- return -ENODEV; ++ return -WD_ENODEV; + } + + if (num) { +@@ -496,14 +496,14 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, + dev_path: + if (!dinfop) { + WD_ERR("dinfop NULL!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + + ret = snprintf(q->dev_path, PATH_STR_SIZE, "%s/%s", + LINUX_DEV_DIR, dinfop->name); + if (ret <= 0) { + WD_ERR("snprintf err, ret %d!\n", ret); +- return -EINVAL; ++ return -WD_EINVAL; + } + return 0; + } +@@ -654,7 +654,7 @@ int wd_send(struct wd_queue *q, void *req) + { + if (unlikely(!q || !req)) { + WD_ERR("wd send input parameter null!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + return wd_burst_send(q, &req, 1); + } +@@ -663,7 +663,7 @@ int wd_recv(struct wd_queue *q, void **resp) + { + if (unlikely(!q || !resp)) { + WD_ERR("wd recv input parameter null!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + return wd_burst_recv(q, resp, 1); + } +@@ -676,11 +676,11 @@ int wd_wait(struct wd_queue *q, __u16 ms) + int ret; + + if (unlikely(!q)) +- return -EINVAL; ++ return -WD_EINVAL; + + priv = &q->capa.priv; + if (unlikely(!priv->is_poll)) +- return -EINVAL; ++ return -WD_EINVAL; + + qinfo = q->qinfo; + fds[0].fd = qinfo->fd; +@@ -688,7 +688,7 @@ int wd_wait(struct wd_queue *q, __u16 ms) + + ret = poll(fds, 1, ms); + if (unlikely(ret < 0)) +- return -ENODEV; ++ return -WD_ENODEV; + + /* return 0 for no data, 1 for new message */ + return ret; +@@ -735,7 +735,7 @@ int wd_share_reserved_memory(struct wd_queue *q, + /* Just share DMA memory from 'q' in NO-IOMMU mode */ + if (qinfo->iommu_type) { + WD_ERR("IOMMU opened, not support share mem!\n"); +- return -EINVAL; ++ return -WD_EINVAL; + } + + if (qinfo->iommu_type != tqinfo->iommu_type) { +@@ -871,6 +871,7 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr, + else + munmap(addr, size); + } ++ + int wd_register_log(wd_log log) + { + if (!log) { +-- +2.25.1 + diff --git a/0104-uadk-concentrate-the-same-definitions.patch b/0104-uadk-concentrate-the-same-definitions.patch new file mode 100644 index 0000000..17a07cf --- /dev/null +++ b/0104-uadk-concentrate-the-same-definitions.patch @@ -0,0 +1,160 @@ +From 98c371e0c0ff955befb8a10a9b426bb5c0aea776 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:35:02 +0800 +Subject: [PATCH 104/114] uadk: concentrate the same definitions + +The sec algorithm has multiple common header files, +so they are centrally stored in wd_alg_common. + +Signed-off-by: Chenghai Huang +--- + drv/hisi_sec.c | 11 ++--------- + include/wd_alg_common.h | 13 +++++++++++++ + include/wd_cipher.h | 1 - + include/wd_digest.h | 2 -- + wd_aead.c | 9 --------- + wd_cipher.c | 7 ------- + wd_digest.c | 9 --------- + 7 files changed, 15 insertions(+), 37 deletions(-) + +diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c +index 9102a27..5b114f6 100644 +--- a/drv/hisi_sec.c ++++ b/drv/hisi_sec.c +@@ -63,13 +63,6 @@ + #define SEC_MAC_LEN_MASK 0x1F + #define SEC_AUTH_LEN_MASK 0x3F + +-#define DES_KEY_SIZE 8 +-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) +-#define AES_KEYSIZE_128 16 +-#define AES_KEYSIZE_192 24 +-#define AES_KEYSIZE_256 32 +- + #define DES3_BLOCK_SIZE 8 + #define AES_BLOCK_SIZE 16 + #define CTR_128BIT_COUNTER 16 +@@ -823,9 +816,9 @@ static void update_iv_sgl(struct wd_cipher_msg *msg) + + static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len) + { +- if (msg->key_bytes == SEC_3DES_2KEY_SIZE) { ++ if (msg->key_bytes == DES3_2KEY_SIZE) { + *c_key_len = CKEY_LEN_3DES_2KEY; +- } else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) { ++ } else if (msg->key_bytes == DES3_3KEY_SIZE) { + *c_key_len = CKEY_LEN_3DES_3KEY; + } else { + WD_ERR("failed to check 3des key size, size = %u\n", +diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h +index 5652db3..32b8630 100644 +--- a/include/wd_alg_common.h ++++ b/include/wd_alg_common.h +@@ -29,6 +29,19 @@ extern "C" { + #define CTX_TYPE_INVALID 9999 + #define POLL_TIME 1000 + ++/* Key size of chiper */ ++#define MAX_CIPHER_KEY_SIZE 64 ++#define AES_KEYSIZE_128 16 ++#define AES_KEYSIZE_192 24 ++#define AES_KEYSIZE_256 32 ++#define SM4_KEY_SIZE 16 ++#define DES_KEY_SIZE 8 ++#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) ++#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) ++ ++/* Key size of digest */ ++#define MAX_HMAC_KEY_SIZE 128U ++ + enum alg_task_type { + TASK_MIX = 0x0, + TASK_HW, +diff --git a/include/wd_cipher.h b/include/wd_cipher.h +index a712b53..d54f7fe 100644 +--- a/include/wd_cipher.h ++++ b/include/wd_cipher.h +@@ -18,7 +18,6 @@ extern "C" { + #define AES_BLOCK_SIZE 16 + #define GCM_IV_SIZE 12 + #define DES3_BLOCK_SIZE 8 +-#define MAX_CIPHER_KEY_SIZE 64 + #define MAX_IV_SIZE AES_BLOCK_SIZE + + /** +diff --git a/include/wd_digest.h b/include/wd_digest.h +index ad4d579..f0916c3 100644 +--- a/include/wd_digest.h ++++ b/include/wd_digest.h +@@ -14,8 +14,6 @@ + extern "C" { + #endif + +-#define MAX_HMAC_KEY_SIZE 128U +- + /** + * wd_digest_type - Algorithm type of digest + * algorithm should be offered by struct wd_digest_arg +diff --git a/wd_aead.c b/wd_aead.c +index 6d49d76..34a3b86 100644 +--- a/wd_aead.c ++++ b/wd_aead.c +@@ -10,15 +10,6 @@ + #include "include/drv/wd_aead_drv.h" + #include "wd_aead.h" + +-#define XTS_MODE_KEY_DIVISOR 2 +-#define SM4_KEY_SIZE 16 +-#define DES_KEY_SIZE 8 +-#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) +-#define AES_KEYSIZE_128 16 +-#define AES_KEYSIZE_192 24 +-#define AES_KEYSIZE_256 32 +- + #define WD_AEAD_CCM_GCM_MIN 4U + #define WD_AEAD_CCM_GCM_MAX 16 + +diff --git a/wd_cipher.c b/wd_cipher.c +index 47c0bf8..f35ce6f 100644 +--- a/wd_cipher.c ++++ b/wd_cipher.c +@@ -13,13 +13,6 @@ + + #define XTS_MODE_KEY_SHIFT 1 + #define XTS_MODE_KEY_LEN_MASK 0x1 +-#define SM4_KEY_SIZE 16 +-#define DES_KEY_SIZE 8 +-#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) +-#define AES_KEYSIZE_128 16 +-#define AES_KEYSIZE_192 24 +-#define AES_KEYSIZE_256 32 + + #define DES_WEAK_KEY_NUM 16 + +diff --git a/wd_digest.c b/wd_digest.c +index 9008bcb..acf341a 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -10,16 +10,7 @@ + #include "include/drv/wd_digest_drv.h" + #include "wd_digest.h" + +-#define XTS_MODE_KEY_DIVISOR 2 +-#define SM4_KEY_SIZE 16 +-#define DES_KEY_SIZE 8 +-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) + #define GMAC_IV_LEN 16 +-#define AES_KEYSIZE_128 16 +-#define AES_KEYSIZE_192 24 +-#define AES_KEYSIZE_256 32 +- +-#define DES_WEAK_KEY_NUM 4 + + static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { + WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN, +-- +2.25.1 + diff --git a/0105-uadk-v1-optimize-the-function-length.patch b/0105-uadk-v1-optimize-the-function-length.patch new file mode 100644 index 0000000..9832c32 --- /dev/null +++ b/0105-uadk-v1-optimize-the-function-length.patch @@ -0,0 +1,133 @@ +From 6ca1f2190a37490b5dc84f04f70cca945355da1e Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:36:12 +0800 +Subject: [PATCH 105/114] uadk v1: optimize the function length + +The number of lines in the param_check function exceeds 50, +so subfunctions are added for optimization. + +Signed-off-by: Chenghai Huang +--- + v1/wd_digest.c | 83 ++++++++++++++++++++++++++++++++------------------ + 1 file changed, 53 insertions(+), 30 deletions(-) + +diff --git a/v1/wd_digest.c b/v1/wd_digest.c +index b8ea5ce..df8a8af 100644 +--- a/v1/wd_digest.c ++++ b/v1/wd_digest.c +@@ -371,21 +371,62 @@ static int digest_recv_sync(struct wcrypto_digest_ctx *d_ctx, + return recv_count; + } + ++static int stream_mode_param_check(struct wcrypto_digest_ctx *d_ctx, ++ struct wcrypto_digest_op_data *d_opdata, __u32 num) ++{ ++ enum wcrypto_digest_alg alg = d_ctx->setup.alg; ++ ++ if (unlikely(num != 1)) { ++ WD_ERR("invalid: wcrypto_burst_digest does not support stream mode, num = %u!\n", ++ num); ++ return -WD_EINVAL; ++ } ++ ++ if (unlikely(d_opdata->in_bytes % d_ctx->align_sz)) { ++ WD_ERR("invalid: digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz); ++ return -WD_EINVAL; ++ } ++ ++ if (unlikely(d_opdata->out_bytes < g_digest_mac_full_len[alg])) { ++ WD_ERR("invalid: digest stream mode out buffer space is not enough!\n"); ++ return -WD_EINVAL; ++ } ++ ++ return WD_SUCCESS; ++} ++ ++static int block_mode_param_check(struct wcrypto_digest_ctx *d_ctx, ++ struct wcrypto_digest_op_data *d_opdata) ++{ ++ enum wcrypto_digest_alg alg = d_ctx->setup.alg; ++ ++ if (unlikely(d_opdata->out_bytes > g_digest_mac_len[alg])) { ++ WD_ERR("invalid: failed to check digest mac length!\n"); ++ return -WD_EINVAL; ++ } ++ ++ if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC && ++ (!d_opdata->iv || d_opdata->iv_bytes != SEC_GMAC_IV_LEN))) { ++ WD_ERR("invalid: failed to check digest aes_gmac iv length, iv_bytes = %u\n", ++ d_opdata->iv_bytes); ++ return -WD_EINVAL; ++ } ++ ++ return 0; ++} ++ + static int param_check(struct wcrypto_digest_ctx *d_ctx, + struct wcrypto_digest_op_data **d_opdata, + void **tag, __u32 num) + { +- enum wcrypto_digest_alg alg; + __u32 i; + int ret; + + if (unlikely(!d_ctx || !d_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) { +- WD_ERR("input param err!\n"); ++ WD_ERR("invalid: input param err!\n"); + return -WD_EINVAL; + } + +- alg = d_ctx->setup.alg; +- + for (i = 0; i < num; i++) { + if (unlikely(!d_opdata[i])) { + WD_ERR("invalid: digest opdata[%u] is NULL!\n", i); +@@ -397,37 +438,19 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, + return -WD_EINVAL; + } + +- ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, d_opdata[i]->out, d_opdata[i]->out_bytes); ++ ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, ++ d_opdata[i]->out, d_opdata[i]->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } + +- if (d_opdata[i]->has_next) { +- if (unlikely(num != 1)) { +- WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n"); +- return -WD_EINVAL; +- } +- if (unlikely(d_opdata[i]->in_bytes % d_ctx->align_sz)) { +- WD_ERR("digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz); +- return -WD_EINVAL; +- } +- if (unlikely(d_opdata[i]->out_bytes < g_digest_mac_full_len[alg])) { +- WD_ERR("digest stream mode out buffer space is not enough!\n"); +- return -WD_EINVAL; +- } +- } else { +- if (unlikely(d_opdata[i]->out_bytes > g_digest_mac_len[alg])) { +- WD_ERR("failed to check digest mac length!\n"); +- return -WD_EINVAL; +- } +- if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC && +- (!d_opdata[i]->iv || d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN))) { +- WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n", +- d_opdata[i]->iv_bytes); +- return -WD_EINVAL; +- } +- } ++ if (d_opdata[i]->has_next) ++ ret = stream_mode_param_check(d_ctx, d_opdata[i], num); ++ else ++ ret = block_mode_param_check(d_ctx, d_opdata[i]); ++ if (unlikely(ret)) ++ return ret; + + if (unlikely(tag && !tag[i])) { + WD_ERR("invalid: tag[%u] is NULL!\n", i); +-- +2.25.1 + diff --git a/0106-uadk-v1-concentrate-the-same-definitions.patch b/0106-uadk-v1-concentrate-the-same-definitions.patch new file mode 100644 index 0000000..7d15a3c --- /dev/null +++ b/0106-uadk-v1-concentrate-the-same-definitions.patch @@ -0,0 +1,159 @@ +From 0580da2ecffbd20a392c987e28a0d164c6aa2b56 Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Mon, 4 Dec 2023 17:37:24 +0800 +Subject: [PATCH 106/114] uadk v1: concentrate the same definitions + +The sec algorithm has multiple common header files, +so they are centrally stored in wd_alg_common. + +Signed-off-by: Chenghai Huang +--- + v1/drv/hisi_sec_udrv.c | 11 ++--------- + v1/wd_aead.c | 15 --------------- + v1/wd_cipher.c | 9 +-------- + v1/wd_digest.c | 1 - + v1/wd_util.h | 17 +++++++++++++++++ + 5 files changed, 20 insertions(+), 33 deletions(-) + +diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c +index 02a63c2..d046327 100644 +--- a/v1/drv/hisi_sec_udrv.c ++++ b/v1/drv/hisi_sec_udrv.c +@@ -31,10 +31,6 @@ + #include "config.h" + #include "hisi_sec_udrv.h" + +-#define DES_KEY_SIZE 8 +-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) +- + #define SEC_HW_TASK_DONE 1 + #define SEC_HW_ICV_ERR 0x2 + #define SEC_SM4_XTS_GB_V3 0x1 +@@ -47,11 +43,8 @@ + #define CTR_128BIT_COUNTER 16 + #define CTR_128BIT_FLIP 0x2 + #define DIF_VERIFY_FAIL 2 +-#define AES_BLOCK_SIZE 16 + #define WCRYPTO_CIPHER_THEN_DIGEST 0 + #define WCRYPTO_DIGEST_THEN_CIPHER 1 +-#define CBC_3DES_BLOCK_SIZE 8 +-#define CBC_AES_BLOCK_SIZE 16 + #define AEAD_IV_MAX_BYTES 64 + #define MAX_CCM_AAD_LEN 65279 + #define SEC_GMAC_IV_LEN 16 +@@ -111,9 +104,9 @@ static int get_aes_c_key_len(__u8 mode, __u16 key_bytes, __u8 *c_key_len) + + static int get_3des_c_key_len(struct wcrypto_cipher_msg *msg, __u8 *c_key_len) + { +- if (msg->key_bytes == SEC_3DES_2KEY_SIZE) ++ if (msg->key_bytes == DES3_2KEY_SIZE) + *c_key_len = CKEY_LEN_3DES_2KEY; +- else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) ++ else if (msg->key_bytes == DES3_3KEY_SIZE) + *c_key_len = CKEY_LEN_3DES_3KEY; + else { + WD_ERR("Invalid 3DES key size!\n"); +diff --git a/v1/wd_aead.c b/v1/wd_aead.c +index 38429fc..380daf0 100644 +--- a/v1/wd_aead.c ++++ b/v1/wd_aead.c +@@ -26,24 +26,9 @@ + #include "wd_util.h" + #include "wd_aead.h" + +-#define MAX_AEAD_KEY_SIZE 64 +-#define MAX_AEAD_MAC_SIZE 64 +-#define MAX_CIPHER_KEY_SIZE 64 + #define MAX_AEAD_AUTH_SIZE 64 +-#define MAX_AEAD_ASSOC_SIZE 65536 +-#define MAX_HMAC_KEY_SIZE 128 + #define MAX_AEAD_RETRY_CNT 20000000 + +-#define DES_KEY_SIZE 8 +-#define SM4_KEY_SIZE 16 +-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) +- +-#define AES_BLOCK_SIZE 16 +-#define GCM_BLOCK_SIZE 12 +- +-#define MAX_BURST_NUM 16 +- + static int g_aead_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { + WCRYPTO_SM3_LEN, WCRYPTO_MD5_LEN, WCRYPTO_SHA1_LEN, + WCRYPTO_SHA256_LEN, WCRYPTO_SHA224_LEN, +diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c +index f95015d..0877993 100644 +--- a/v1/wd_cipher.c ++++ b/v1/wd_cipher.c +@@ -26,17 +26,10 @@ + #include "v1/wd_util.h" + #include "v1/wd_cipher.h" + +-#define MAX_CIPHER_KEY_SIZE 64 + #define MAX_CIPHER_RETRY_CNT 20000000 + + #define XTS_MODE_KEY_LEN_MASK 0x1 +-#define DES_KEY_SIZE 8 +-#define SM4_KEY_SIZE 16 +-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) +-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) + +-#define CBC_3DES_BLOCK_SIZE 8 +-#define CBC_AES_BLOCK_SIZE 16 + #define DES_WEAK_KEY_NUM 4 + static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {0x0101010101010101, 0xFEFEFEFEFEFEFEFE, + 0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E}; +@@ -300,7 +293,7 @@ static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup, + ret = -WD_EINVAL; + break; + case WCRYPTO_CIPHER_3DES: +- if ((key_len != SEC_3DES_2KEY_SIZE) && (key_len != SEC_3DES_3KEY_SIZE)) ++ if ((key_len != DES3_2KEY_SIZE) && (key_len != DES3_3KEY_SIZE)) + ret = -WD_EINVAL; + break; + default: +diff --git a/v1/wd_digest.c b/v1/wd_digest.c +index df8a8af..cb9b6e0 100644 +--- a/v1/wd_digest.c ++++ b/v1/wd_digest.c +@@ -26,7 +26,6 @@ + #include "wd_util.h" + #include "wd_digest.h" + +-#define MAX_HMAC_KEY_SIZE 128 + #define MAX_DIGEST_RETRY_CNT 20000000 + #define SEC_SHA1_ALIGN_SZ 64 + #define SEC_SHA512_ALIGN_SZ 128 +diff --git a/v1/wd_util.h b/v1/wd_util.h +index bf17058..9e5fa90 100644 +--- a/v1/wd_util.h ++++ b/v1/wd_util.h +@@ -76,6 +76,23 @@ + #define X_DH_OUT_PARAM_NUM 1 + #define X_DH_HW_KEY_PARAM_NUM 3 + ++/* Key size and block size of aead */ ++#define MAX_AEAD_KEY_SIZE 64 ++#define GCM_BLOCK_SIZE 12 ++ ++/* Key size and block size of chiper */ ++#define MAX_CIPHER_KEY_SIZE 64 ++#define AES_BLOCK_SIZE 16 ++#define DES_KEY_SIZE 8 ++#define SM4_KEY_SIZE 16 ++#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) ++#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) ++#define CBC_AES_BLOCK_SIZE 16 ++#define CBC_3DES_BLOCK_SIZE 8 ++ ++/* Key size and block size of digest */ ++#define MAX_HMAC_KEY_SIZE 128 ++ + #define X_DH_OUT_PARAMS_SZ(hsz) ((hsz) * X_DH_OUT_PARAM_NUM) + #define X_DH_HW_KEY_SZ(hsz) ((hsz) * X_DH_HW_KEY_PARAM_NUM) + #define SM2_KG_OUT_PARAMS_SZ(hsz) ((hsz) * SM2_KG_OUT_PARAM_NUM) +-- +2.25.1 + diff --git a/0107-v1-hpre-fix-key-transfer-error-issue.patch b/0107-v1-hpre-fix-key-transfer-error-issue.patch new file mode 100644 index 0000000..21d733d --- /dev/null +++ b/0107-v1-hpre-fix-key-transfer-error-issue.patch @@ -0,0 +1,87 @@ +From d465cfbe854a2b0719de48e9973f1a3aa091c3f7 Mon Sep 17 00:00:00 2001 +From: Weili Qian +Date: Thu, 30 Nov 2023 15:51:26 +0800 +Subject: [PATCH 107/114] v1/hpre: fix key transfer error issue + +Currently, the RSA algorithm calls qm_crypto_bin_to_hpre_bin() to +transfer the key when sending request. However, the key +needs to be transferred only once, repeated transfer may cause +data inconsistency with original user's data, resulting in +incorrect calculation results. + +Therefore, after the key is transferred, the 'dsize' is changed to +the 'bsize', When 'disze' and 'bsize' are equal, no transfer is performed. + +Signed-off-by: Weili Qian +--- + v1/drv/hisi_hpre_udrv.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c +index 193ba56..0d0c3b4 100644 +--- a/v1/drv/hisi_hpre_udrv.c ++++ b/v1/drv/hisi_hpre_udrv.c +@@ -136,27 +136,32 @@ static int qm_fill_rsa_crt_prikey2(struct wcrypto_rsa_prikey *prikey, + wd_dq->bsize, wd_dq->dsize, "rsa crt dq"); + if (unlikely(ret)) + return ret; ++ wd_dq->dsize = wd_dq->bsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_dp->data, (const char *)wd_dp->data, + wd_dp->bsize, wd_dp->dsize, "rsa crt dp"); + if (unlikely(ret)) + return ret; ++ wd_dp->dsize = wd_dp->bsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_q->data, (const char *)wd_q->data, + wd_q->bsize, wd_q->dsize, "rsa crt q"); + if (unlikely(ret)) + return ret; ++ wd_q->dsize = wd_q->bsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_p->data, + (const char *)wd_p->data, wd_p->bsize, wd_p->dsize, "rsa crt p"); + if (unlikely(ret)) + return ret; ++ wd_p->dsize = wd_p->bsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_qinv->data, + (const char *)wd_qinv->data, wd_qinv->bsize, + wd_qinv->dsize, "rsa crt qinv"); + if (unlikely(ret)) + return ret; ++ wd_qinv->dsize = wd_qinv->bsize; + + *data = wd_dq->data; + return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize + +@@ -179,11 +184,13 @@ static int qm_fill_rsa_prikey1(struct wcrypto_rsa_prikey *prikey, void **data) + wd_d->bsize, wd_d->dsize, "rsa prikey1 d"); + if (unlikely(ret)) + return ret; ++ wd_d->dsize = wd_d->bsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, + wd_n->bsize, wd_n->dsize, "rsa prikey1 n"); + if (unlikely(ret)) + return ret; ++ wd_n->dsize = wd_n->bsize; + + *data = wd_d->data; + return (int)(wd_n->bsize + wd_d->bsize); +@@ -200,11 +207,13 @@ static int qm_fill_rsa_pubkey(struct wcrypto_rsa_pubkey *pubkey, void **data) + wd_e->bsize, wd_e->dsize, "rsa pubkey e"); + if (unlikely(ret)) + return ret; ++ wd_e->dsize = wd_e->dsize; + + ret = qm_crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, + wd_n->bsize, wd_n->dsize, "rsa pubkey n"); + if (unlikely(ret)) + return ret; ++ wd_n->dsize = wd_n->dsize; + + *data = wd_e->data; + return (int)(wd_n->bsize + wd_e->bsize); +-- +2.25.1 + diff --git a/0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch b/0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch new file mode 100644 index 0000000..9b7e98b --- /dev/null +++ b/0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch @@ -0,0 +1,87 @@ +From 40a78df99ab6e13ca8a2fda51a885c089c811f2e Mon Sep 17 00:00:00 2001 +From: Weili Qian +Date: Thu, 30 Nov 2023 16:40:39 +0800 +Subject: [PATCH 108/114] uadk/hisi_hpre: fix key transfer error issue + +Currently, the RSA algorithm calls crypto_bin_to_hpre_bin() to +transfer the key when sending request. However, the key +needs to be transferred only once, repeated transfer may cause +data inconsistency with original user's data, resulting in +incorrect calculation results. + +Therefore, after the key is transferred, the 'dsize' is changed to +the 'bsize', When 'disze' and 'bsize' are equal, no transfer is performed. + +Signed-off-by: Weili Qian +--- + drv/hisi_hpre.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c +index c7bb70e..61c7855 100644 +--- a/drv/hisi_hpre.c ++++ b/drv/hisi_hpre.c +@@ -212,27 +212,32 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey, + wd_dq->bsize, wd_dq->dsize, "rsa crt dq"); + if (ret) + return ret; ++ wd_dq->dsize = wd_dq->bsize; + + ret = crypto_bin_to_hpre_bin(wd_dp->data, (const char *)wd_dp->data, + wd_dp->bsize, wd_dp->dsize, "rsa crt dp"); + if (ret) + return ret; ++ wd_dp->dsize = wd_dp->bsize; + + ret = crypto_bin_to_hpre_bin(wd_q->data, (const char *)wd_q->data, + wd_q->bsize, wd_q->dsize, "rsa crt q"); + if (ret) + return ret; ++ wd_q->dsize = wd_q->bsize; + + ret = crypto_bin_to_hpre_bin(wd_p->data, + (const char *)wd_p->data, wd_p->bsize, wd_p->dsize, "rsa crt p"); + if (ret) + return ret; ++ wd_p->dsize = wd_p->bsize; + + ret = crypto_bin_to_hpre_bin(wd_qinv->data, + (const char *)wd_qinv->data, wd_qinv->bsize, + wd_qinv->dsize, "rsa crt qinv"); + if (ret) + return ret; ++ wd_qinv->dsize = wd_qinv->bsize; + + *data = wd_dq->data; + +@@ -249,11 +254,13 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data) + wd_d->bsize, wd_d->dsize, "rsa d"); + if (ret) + return ret; ++ wd_d->dsize = wd_d->bsize; + + ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, + wd_n->bsize, wd_n->dsize, "rsa n"); + if (ret) + return ret; ++ wd_n->dsize = wd_n->bsize; + + *data = wd_d->data; + +@@ -270,11 +277,13 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data) + wd_e->bsize, wd_e->dsize, "rsa e"); + if (ret) + return ret; ++ wd_e->dsize = wd_e->bsize; + + ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, + wd_n->bsize, wd_n->dsize, "rsa n"); + if (ret) + return ret; ++ wd_n->dsize = wd_n->bsize; + + *data = wd_e->data; + +-- +2.25.1 + diff --git a/0109-uadk-v1-remove-duplicate-header-files.patch b/0109-uadk-v1-remove-duplicate-header-files.patch new file mode 100644 index 0000000..75b88df --- /dev/null +++ b/0109-uadk-v1-remove-duplicate-header-files.patch @@ -0,0 +1,54 @@ +From 6bb23a7d5d8bf7afda47bddd52e16bf72b446f6b Mon Sep 17 00:00:00 2001 +From: Weili Qian +Date: Thu, 30 Nov 2023 15:51:28 +0800 +Subject: [PATCH 109/114] uadk/v1: remove duplicate header files + +Some of the header files are already included in wd.h, +and hisi_rng_udrv.h already includes wd.h. Therefore, +the hisi_rng_udrv.c file does not need to include these +header files repeatedly. + +Signed-off-by: Weili Qian +--- + v1/drv/hisi_rng_udrv.c | 6 ------ + v1/drv/hisi_rng_udrv.h | 1 - + 2 files changed, 7 deletions(-) + +diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c +index 09fa2c3..86a20cb 100644 +--- a/v1/drv/hisi_rng_udrv.c ++++ b/v1/drv/hisi_rng_udrv.c +@@ -18,18 +18,12 @@ + #include + #include + #include +-#include + #include + #include +-#include +-#include +-#include + #include + #include + #include +-#include + +-#include "config.h" + #include "hisi_rng_udrv.h" + + #define HISI_RNG_BYTES 4 +diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h +index 93f2f91..56814a4 100644 +--- a/v1/drv/hisi_rng_udrv.h ++++ b/v1/drv/hisi_rng_udrv.h +@@ -18,7 +18,6 @@ + #define __HISI_RNG_UDRV_H__ + + #include +-#include "config.h" + #include "v1/wd.h" + #include "v1/wd_util.h" + #include "v1/wd_rng.h" +-- +2.25.1 + diff --git a/0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch b/0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch new file mode 100644 index 0000000..de177b6 --- /dev/null +++ b/0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch @@ -0,0 +1,42 @@ +From 4d64eedcb418802a8c6ae376b8d6fdda62ea61eb Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 15:51:29 +0800 +Subject: [PATCH 110/114] uadk: fix error writing data to uninitialized memory + +After the memory is applied for, the memory +must be initialized before being written. + +Signed-off-by: Qi Tao +--- + drv/hisi_qm_udrv.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c +index d86a692..8e4c0bb 100644 +--- a/drv/hisi_qm_udrv.c ++++ b/drv/hisi_qm_udrv.c +@@ -252,11 +252,10 @@ static int hisi_qm_setup_db(handle_t h_ctx, struct hisi_qm_queue_info *q_info) + static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config, + struct hisi_qm_queue_info *q_info) + { +- struct hisi_qp_info qp_cfg; +- struct hisi_qp_ctx qp_ctx; ++ struct hisi_qp_info qp_cfg = {0}; ++ struct hisi_qp_ctx qp_ctx = {0}; + int ret; + +- memset(&qp_ctx, 0, sizeof(struct hisi_qp_ctx)); + qp_ctx.qc_type = config->op_type; + q_info->qc_type = qp_ctx.qc_type; + ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_QM_SET_QP_CTX, &qp_ctx); +@@ -264,6 +263,7 @@ static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config, + WD_DEV_ERR(h_ctx, "failed to set qc_type!\n"); + return ret; + } ++ + q_info->sqn = qp_ctx.id; + config->sqn = qp_ctx.id; + +-- +2.25.1 + diff --git a/0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch b/0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch new file mode 100644 index 0000000..fd1553b --- /dev/null +++ b/0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch @@ -0,0 +1,36 @@ +From d1b4b282c104cc2643e8d2eb83ec74df796b2c24 Mon Sep 17 00:00:00 2001 +From: Hao Fang +Date: Thu, 30 Nov 2023 15:51:30 +0800 +Subject: [PATCH 111/114] uadk: drv/qm: fix resource leak by add qp info clear + process + +The spin_lock need to destroy and mem region need +to unmap, hisi_qm_clear_info() can do this. + +Signed-off-by: Hao Fang +--- + drv/hisi_qm_udrv.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c +index 8e4c0bb..76a270e 100644 +--- a/drv/hisi_qm_udrv.c ++++ b/drv/hisi_qm_udrv.c +@@ -449,10 +449,10 @@ void hisi_qm_free_qp(handle_t h_qp) + } + + wd_release_ctx_force(qp->h_ctx); +- wd_ctx_unmap_qfr(qp->h_ctx, UACCE_QFRT_MMIO); +- wd_ctx_unmap_qfr(qp->h_ctx, UACCE_QFRT_DUS); +- if (qp->h_sgl_pool) +- hisi_qm_destroy_sglpool(qp->h_sgl_pool); ++ ++ hisi_qm_destroy_sglpool(qp->h_sgl_pool); ++ ++ hisi_qm_clear_info(qp); + + free(qp); + } +-- +2.25.1 + diff --git a/0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch b/0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch new file mode 100644 index 0000000..bd64ee8 --- /dev/null +++ b/0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch @@ -0,0 +1,32 @@ +From fef7c7a3191e55c6daeb67df5c29b4b841445efe Mon Sep 17 00:00:00 2001 +From: Qi Tao +Date: Thu, 30 Nov 2023 15:51:31 +0800 +Subject: [PATCH 112/114] uadk/v1: fix error writing data to uninitialized + memory + +After the memory is applied for, the memory +must be initialized before being written. + +Signed-off-by: Qi Tao +--- + v1/drv/hisi_qm_udrv.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c +index 6cbcdf5..0ca38d2 100644 +--- a/v1/drv/hisi_qm_udrv.c ++++ b/v1/drv/hisi_qm_udrv.c +@@ -458,8 +458,8 @@ static int qm_init_queue_info(struct wd_queue *q) + struct wcrypto_paras *priv = &q->capa.priv; + struct q_info *qinfo = q->qinfo; + struct qm_queue_info *info = qinfo->priv; +- struct hisi_qp_info qp_info; +- struct hisi_qp_ctx qp_ctx; ++ struct hisi_qp_info qp_info = {0}; ++ struct hisi_qp_ctx qp_ctx = {0}; + int ret; + + info->sq_tail_index = 0; +-- +2.25.1 + diff --git a/0113-uadk-check-queue-status-before-sending-doorbells.patch b/0113-uadk-check-queue-status-before-sending-doorbells.patch new file mode 100644 index 0000000..0e9ab14 --- /dev/null +++ b/0113-uadk-check-queue-status-before-sending-doorbells.patch @@ -0,0 +1,155 @@ +From 3e309b7dbcb2f9308a8ccb1b7cb7876f808a7394 Mon Sep 17 00:00:00 2001 +From: Weili Qian +Date: Thu, 30 Nov 2023 16:41:27 +0800 +Subject: [PATCH] uadk: check queue status before sending doorbells + +When the device needs to be reset, the queue status is +set to disable before resetting. The user process checks +the queue status before sending the doorbell. If the queue +is disable, the user process returns failure. + +Currently, the task execution order in user mode is as follows: +1. check the queue status. +2. fill in or parse the BD. +3. send the doorbell to the hardware. + +To reduce the possibility of sending doorbells during reset, +the task execution order is modified as follows: +1. fill in or parse the BD. +2. check the queue status. +3. send the doorbell to the hardware. + +In addition, a rmb() is added before the doorbell is +sent to ensure that the queue status check is complete. + +rmb() and wmb() can be replaced by mb() in hisi_qm_send(). +Therefore, the barrier on the wd_ioread() and wd_iowrite() +can be deleted. + +Signed-off-by: Weili Qian +--- + drv/hisi_qm_udrv.c | 39 ++++++++++++++++++++++++++++----------- + include/wd.h | 6 ++---- + 2 files changed, 30 insertions(+), 15 deletions(-) + +diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c +index 4c80959..d8b5271 100644 +--- a/drv/hisi_qm_udrv.c ++++ b/drv/hisi_qm_udrv.c +@@ -469,11 +469,6 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count) + + q_info = &qp->q_info; + +- if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) { +- WD_ERR("wd queue hw error happened before qm send!\n"); +- return -WD_HW_EACCESS; +- } +- + pthread_spin_lock(&q_info->sd_lock); + free_num = get_free_num(q_info); + if (!free_num) { +@@ -486,14 +481,26 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count) + tail = q_info->sq_tail_index; + hisi_qm_fill_sqe(req, q_info, tail, send_num); + tail = (tail + send_num) % q_info->sq_depth; ++ ++ /* ++ * Before sending doorbell, check the queue status, ++ * if the queue is disable, return failure. ++ */ ++ if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) { ++ pthread_spin_unlock(&q_info->sd_lock); ++ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened before qm send!\n"); ++ return -WD_HW_EACCESS; ++ } ++ ++ /* Make sure sqe is filled before db ring and queue status check is complete. */ ++ mb(); + q_info->db(q_info, QM_DBELL_CMD_SQ, tail, 0); + q_info->sq_tail_index = tail; + + /* Make sure used_num is changed before the next thread gets free sqe. */ + __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED); +- *count = send_num; +- + pthread_spin_unlock(&q_info->sd_lock); ++ *count = send_num; + + return 0; + } +@@ -509,6 +516,8 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp) + cqe = q_info->cq_base + i * sizeof(struct cqe); + + if (q_info->cqc_phase == CQE_PHASE(cqe)) { ++ /* Make sure cqe valid bit is set */ ++ rmb(); + j = CQE_SQ_HEAD_INDEX(cqe); + if (unlikely(j >= q_info->sq_depth)) { + pthread_spin_unlock(&q_info->rv_lock); +@@ -529,6 +538,18 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp) + i++; + } + ++ /* ++ * Before sending doorbell, check the queue status, ++ * if the queue is disable, return failure. ++ */ ++ if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { ++ pthread_spin_unlock(&q_info->rv_lock); ++ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened after qm receive!\n"); ++ return -WD_HW_EACCESS; ++ } ++ ++ /* Make sure queue status check is complete. */ ++ rmb(); + q_info->db(q_info, QM_DBELL_CMD_CQ, i, q_info->epoll_en); + + /* only support one thread poll one queue, so no need protect */ +@@ -568,10 +589,6 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) + } + + *count = recv_num; +- if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { +- WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n"); +- return -WD_HW_EACCESS; +- } + + return ret; + } +diff --git a/include/wd.h b/include/wd.h +index 0e67cad..0a654d6 100644 +--- a/include/wd.h ++++ b/include/wd.h +@@ -167,7 +167,7 @@ static inline uint32_t wd_ioread32(void *addr) + uint32_t ret; + + ret = *((volatile uint32_t *)addr); +- rmb(); ++ + return ret; + } + +@@ -176,19 +176,17 @@ static inline uint64_t wd_ioread64(void *addr) + uint64_t ret; + + ret = *((volatile uint64_t *)addr); +- rmb(); ++ + return ret; + } + + static inline void wd_iowrite32(void *addr, uint32_t value) + { +- wmb(); + *((volatile uint32_t *)addr) = value; + } + + static inline void wd_iowrite64(void *addr, uint64_t value) + { +- wmb(); + *((volatile uint64_t *)addr) = value; + } + +-- +2.25.1 + diff --git a/0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch b/0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch new file mode 100644 index 0000000..e03993b --- /dev/null +++ b/0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch @@ -0,0 +1,31 @@ +From d491b5480de01ea64360c24b6a89db3ddaf640e1 Mon Sep 17 00:00:00 2001 +From: Yang Shen +Date: Thu, 30 Nov 2023 14:25:14 +0800 +Subject: [PATCH 114/114] uadk: zlibwrapper - fix return value for + wd_zlib_uadk_init + +It means the UADK compression library has been initialized when +wd_comp_init2_ return -WD_EEXIST. Wd_zlibwrapper doesn't need to +do it again. But WD_EEXIST is not a valid return value for zlib +APIs. So change it to 0. + +Signed-off-by: Yang Shen +--- + wd_zlibwrapper.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c +index 7189b7f..e562910 100644 +--- a/wd_zlibwrapper.c ++++ b/wd_zlibwrapper.c +@@ -73,6 +73,7 @@ static int wd_zlib_uadk_init(void) + goto out_freebmp; + } + ++ ret = 0; + zlib_config.status = WD_ZLIB_INIT; + + out_freebmp: +-- +2.25.1 + diff --git a/warpdrive.spec b/warpdrive.spec index 30039b1..f765707 100644 --- a/warpdrive.spec +++ b/warpdrive.spec @@ -100,6 +100,35 @@ Patch0082: 0082-uadk-wd_util-fix-a-theoretically-infinite-loop.patch Patch0083: 0083-uadk-wd-fix-fscanf-infinite-loop.patch Patch0084: 0084-uadk-zlibwrapper-fix-wrong-request-check.patch Patch0085: 0085-uadk-drv-hisi-fix-sgl-copy-offset-error.patch +Patch0086: 0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch +Patch0087: 0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch +Patch0088: 0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch +Patch0089: 0089-uadk-fix-header-file-is-not-self-contained.patch +Patch0090: 0090-uadk-sec-modify-improper-comments.patch +Patch0091: 0091-uadk-fixed-some-input-parameter-checking-issues.patch +Patch0092: 0092-uadk-code-cleanup.patch +Patch0093: 0093-uadk-fix-sec-send-and-recv-check-failed.patch +Patch0094: 0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch +Patch0095: 0095-uadk-sec-add-a-return-value-judgement.patch +Patch0096: 0096-uadk-Add-file-association.patch +Patch0097: 0097-uadk-fix-the-failure-process-bug.patch +Patch0098: 0098-uadk-fix-the-failure-process-bug.patch +Patch0099: 0099-uadk-fix-the-failure-process-bug.patch +Patch0100: 0100-uadk-bugfix.patch +Patch0101: 0101-uadk-v1-adapter-code-cleanup.patch +Patch0102: 0102-uadk-v1-fix-wd_rng-resource-release-bug.patch +Patch0103: 0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch +Patch0104: 0104-uadk-concentrate-the-same-definitions.patch +Patch0105: 0105-uadk-v1-optimize-the-function-length.patch +Patch0106: 0106-uadk-v1-concentrate-the-same-definitions.patch +Patch0107: 0107-v1-hpre-fix-key-transfer-error-issue.patch +Patch0108: 0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch +Patch0109: 0109-uadk-v1-remove-duplicate-header-files.patch +Patch0110: 0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch +Patch0111: 0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch +Patch0112: 0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch +Patch0113: 0113-uadk-check-queue-status-before-sending-doorbells.patch +Patch0114: 0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch %description This package contains the User Space Accelerator Library @@ -272,7 +301,7 @@ fi /sbin/ldconfig %changelog -* Thu Nov 23 2023 JiangShui Yang 2.5.0-6 +* Tue Dec 05 2023 JiangShui Yang 2.5.0-6 - libwd: update the source code * Tue Oct 31 2023 JiangShui Yang 2.5.0-5