Acc
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 417 discussions
10 Jun '26
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
When the AEAD algorithm fails during the execution of a service,
it fails to switch to software-based computation for processing.
After the current modification, even if it fails, it can still
switch to software-based computation for processing.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
src/uadk_prov_aead.c | 150 ++++++++++++++++++++++++++++---------------
1 file changed, 99 insertions(+), 51 deletions(-)
diff --git a/src/uadk_prov_aead.c b/src/uadk_prov_aead.c
index 26eeb66..88ec8e4 100644
--- a/src/uadk_prov_aead.c
+++ b/src/uadk_prov_aead.c
@@ -434,21 +434,6 @@ static int do_aes_gcm_prepare(struct aead_priv_ctx *priv)
return UADK_AEAD_SUCCESS;
}
-static void uadk_do_aead_async_prepare(struct aead_priv_ctx *priv, unsigned char *output,
- const unsigned char *input, size_t inlen)
-{
- priv->req.in_bytes = inlen;
- /* AAD data will be input and output together with plaintext or ciphertext. */
- if (priv->req.assoc_bytes) {
- memcpy(priv->data + priv->req.assoc_bytes, input, inlen);
- priv->req.src = priv->data;
- priv->req.dst = priv->data + AEAD_BLOCK_SIZE;
- } else {
- priv->req.src = (unsigned char *)input;
- priv->req.dst = output;
- }
-}
-
static int uadk_do_aead_sync_inner(struct aead_priv_ctx *priv, unsigned char *out,
const unsigned char *in, size_t inlen,
enum wd_aead_msg_state state)
@@ -511,14 +496,15 @@ static int uadk_do_aead_sync(struct aead_priv_ctx *priv, unsigned char *out,
return UADK_AEAD_SUCCESS;
}
-static int uadk_do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
- unsigned char *out, const unsigned char *in, size_t inlen)
+static int uadk_do_aead_async_inner(struct aead_priv_ctx *priv, struct async_op *op,
+ unsigned char *out, const unsigned char *in, size_t inlen)
{
struct uadk_e_cb_info cb_param;
int cnt = 0;
int ret;
- if (!priv->enc && priv->tag_set != SET_TAG) {
+ if ((priv->req.msg_state == AEAD_MSG_BLOCK || priv->req.msg_state == AEAD_MSG_END)
+ && !priv->enc && priv->tag_set != SET_TAG) {
UADK_ERR("The tag for asynchronous decryption is not set.\n");
return UADK_AEAD_FAIL;
}
@@ -528,14 +514,19 @@ static int uadk_do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
return UADK_AEAD_FAIL;
}
- uadk_do_aead_async_prepare(priv, out, in, inlen);
-
cb_param.op = op;
cb_param.priv = &priv->req;
priv->req.cb = uadk_prov_aead_cb;
priv->req.cb_param = &cb_param;
- priv->req.msg_state = AEAD_MSG_BLOCK;
priv->req.state = POLL_ERROR;
+ priv->req.src = (unsigned char *)in;
+ priv->req.dst = out;
+ priv->req.in_bytes = inlen;
+
+ if (unlikely(!priv->sess)) {
+ UADK_ERR("uadk session is NULL!\n");
+ return UADK_AEAD_FAIL;
+ }
ret = async_get_free_task(&op->idx);
if (unlikely(!ret))
@@ -559,19 +550,17 @@ static int uadk_do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
ret = async_pause_job(priv, op, ASYNC_TASK_AEAD);
if (unlikely(!ret || priv->req.state)) {
UADK_ERR("do aead async job failed, ret: %d, state: %u!\n",
- ret, priv->req.state);
+ ret, priv->req.state);
return UADK_AEAD_FAIL;
}
- if (priv->req.assoc_bytes)
- memcpy(out, priv->req.dst + priv->req.assoc_bytes, inlen);
-
return ret;
}
static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char *out,
const unsigned char *in, size_t inlen)
{
+ struct async_op op;
int ret;
if (inlen > MAX_AAD_LEN || !inlen)
@@ -579,9 +568,20 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char
priv->req.assoc_bytes = inlen;
- /* Asynchronous jobs use the block mode. */
if (priv->mode == ASYNC_MODE) {
- memcpy(priv->data, in, inlen);
+ ret = async_setup_async_event_notification(&op);
+ if (unlikely(!ret)) {
+ UADK_ERR("failed to setup async event notification.\n");
+ goto soft;
+ }
+
+ priv->req.msg_state = AEAD_MSG_FIRST;
+ ret = uadk_do_aead_async_inner(priv, &op, out, in, inlen);
+ if (unlikely(ret < 0)) {
+ UADK_ERR("aead async first failed, switch to soft.\n");
+ goto free_notification;
+ }
+
return UADK_AEAD_SUCCESS;
}
@@ -591,58 +591,105 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char
return UADK_AEAD_SUCCESS;
+free_notification:
+ (void)async_clear_async_event_notification();
soft:
UADK_ERR("aead failed to update aad, switch to soft.\n");
return SWITCH_TO_SOFT;
}
-static int uadk_prov_do_aes_gcm_update(struct aead_priv_ctx *priv, unsigned char *out,
- const unsigned char *in, size_t inlen)
+static int uadk_do_aead_async(struct aead_priv_ctx *priv, unsigned char *out,
+ const unsigned char *in, size_t inlen)
{
- struct async_op *op;
+ size_t nbytes, tail, processing_len, max_mid_len;
+ const unsigned char *in_block = in;
+ unsigned char *out_block = out;
+ struct async_op op;
int ret;
- if (priv->mode == ASYNC_MODE) {
- op = malloc(sizeof(struct async_op));
- if (unlikely(!op))
- return UADK_AEAD_FAIL;
+ ret = async_setup_async_event_notification(&op);
+ if (unlikely(!ret)) {
+ UADK_ERR("failed to setup async event notification.\n");
+ return UADK_AEAD_FAIL;
+ }
- ret = async_setup_async_event_notification(op);
- if (unlikely(!ret)) {
- UADK_ERR("failed to setup async event notification.\n");
- goto free_op;
- }
+ tail = inlen % AES_BLOCK_SIZE;
+ nbytes = inlen - tail;
+ max_mid_len = AEAD_BLOCK_SIZE - priv->req.assoc_bytes;
- ret = uadk_do_aead_async(priv, op, out, in, inlen);
+ /* Middle packets processing */
+ while (nbytes > 0) {
+ processing_len = nbytes > max_mid_len ? max_mid_len : nbytes;
+ processing_len -= (processing_len % AES_BLOCK_SIZE);
+
+ priv->req.msg_state = AEAD_MSG_MIDDLE;
+ ret = uadk_do_aead_async_inner(priv, &op, out_block, in_block,
+ processing_len);
if (unlikely(ret < 0)) {
- UADK_ERR("uadk_do_aead_async failed ret = %d.\n", ret);
+ UADK_ERR("aead async middle failed!\n");
goto free_notification;
}
-
- free(op);
- return UADK_AEAD_SUCCESS;
+ nbytes -= processing_len;
+ in_block = in_block + processing_len;
+ out_block = out_block + processing_len;
}
- if (priv->stream_switch_flag == UADK_DO_SOFT)
- return SWITCH_TO_SOFT;
+ /* Tail packet processing */
+ if (tail) {
+ priv->req.msg_state = AEAD_MSG_END;
+ ret = uadk_do_aead_async_inner(priv, &op, out_block, in_block, tail);
+ if (unlikely(ret < 0)) {
+ UADK_ERR("aead async tail failed!\n");
+ goto free_notification;
+ }
+ }
- return uadk_do_aead_sync(priv, out, in, inlen);
+ return UADK_AEAD_SUCCESS;
free_notification:
(void)async_clear_async_event_notification();
-free_op:
- free(op);
+
return UADK_AEAD_FAIL;
}
+static int uadk_prov_do_aes_gcm_update(struct aead_priv_ctx *priv, unsigned char *out,
+ const unsigned char *in, size_t inlen)
+{
+ if (priv->stream_switch_flag == UADK_DO_SOFT)
+ return SWITCH_TO_SOFT;
+
+ if (priv->mode == ASYNC_MODE)
+ return uadk_do_aead_async(priv, out, in, inlen);
+
+ return uadk_do_aead_sync(priv, out, in, inlen);
+}
+
static int uadk_prov_do_aes_gcm_final(struct aead_priv_ctx *priv, unsigned char *out,
const unsigned char *in, size_t inlen)
{
+ struct async_op op;
int ret;
- if (priv->mode == ASYNC_MODE || !priv->req.assoc_bytes ||
- priv->req.msg_state == AEAD_MSG_END)
+ if (!priv->req.assoc_bytes || priv->req.msg_state == AEAD_MSG_END)
+ goto out;
+
+ if (priv->mode == ASYNC_MODE) {
+ ret = async_setup_async_event_notification(&op);
+ if (unlikely(!ret)) {
+ UADK_ERR("failed to setup async event notification.\n");
+ return UADK_AEAD_FAIL;
+ }
+
+ priv->req.msg_state = AEAD_MSG_END;
+ ret = uadk_do_aead_async_inner(priv, &op, out, in, inlen);
+ if (unlikely(ret < 0)) {
+ UADK_ERR("aead async final failed!\n");
+ (void)async_clear_async_event_notification();
+ return UADK_AEAD_FAIL;
+ }
+
goto out;
+ }
ret = uadk_do_aead_sync_inner(priv, out, in, inlen, AEAD_MSG_END);
if (unlikely(ret < 0))
@@ -655,6 +702,7 @@ out:
priv->tag_set = INIT_TAG;
priv->mode = UNINIT_MODE;
+
return UADK_AEAD_SUCCESS;
}
--
2.43.0
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
Upstream: YES
AR: AR20230706877748
Feature or Bugfix: Bugfix
DTS: DTS2026041602458
Implement backlog mechanism to queue requests when hardware is busy,
This prevents request failures during hardware congestion and provides
a fallback function in the event of a hardware reset.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 313 ++++++++++++++--------
1 file changed, 203 insertions(+), 110 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 108ad882393d..7603a07d7e55 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -29,6 +29,7 @@
#define HZIP_ALG_DEFLATE GENMASK(5, 4)
#define HZIP_ALG_LZ4 BIT(8)
+#define HZIP_INVAL_REQ_ID ((u16)0xFFFF)
static DEFINE_MUTEX(zip_algs_lock);
static unsigned int zip_available_devs;
@@ -56,11 +57,11 @@ struct hisi_zip_req {
dma_addr_t dma_src;
dma_addr_t dma_dst;
struct hisi_zip_qp_ctx *qp_ctx;
+ struct list_head list;
u16 req_id;
};
struct hisi_zip_req_q {
- struct hisi_zip_req *q;
unsigned long *req_bitmap;
spinlock_t req_lock;
u16 size;
@@ -126,6 +127,9 @@ static int hisi_zip_fallback_do_work(struct crypto_comp *tfm, struct acomp_req *
const char *algo;
int ret;
+ if (!tfm)
+ return -EINVAL;
+
input = kmap_local_page(sg_page(acomp_req->src)) + acomp_req->src->offset;
output = kmap_local_page(sg_page(acomp_req->dst)) + acomp_req->dst->offset;
@@ -146,12 +150,10 @@ static int hisi_zip_fallback_do_work(struct crypto_comp *tfm, struct acomp_req *
return ret;
}
-static struct hisi_zip_req *hisi_zip_create_req(struct hisi_zip_qp_ctx *qp_ctx,
- struct acomp_req *req)
+static int hisi_zip_create_req(struct hisi_zip_req *req)
{
+ struct hisi_zip_qp_ctx *qp_ctx = req->qp_ctx;
struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
- struct hisi_zip_req *q = req_q->q;
- struct hisi_zip_req *req_cache;
int req_id;
spin_lock(&req_q->req_lock);
@@ -160,28 +162,26 @@ static struct hisi_zip_req *hisi_zip_create_req(struct hisi_zip_qp_ctx *qp_ctx,
if (req_id >= req_q->size) {
spin_unlock(&req_q->req_lock);
dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n");
- return ERR_PTR(-EAGAIN);
+ return -EBUSY;
}
set_bit(req_id, req_q->req_bitmap);
spin_unlock(&req_q->req_lock);
- req_cache = q + req_id;
- req_cache->req_id = req_id;
- req_cache->req = req;
- req_cache->qp_ctx = qp_ctx;
+ req->req_id = req_id;
- return req_cache;
+ return 0;
}
-static void hisi_zip_remove_req(struct hisi_zip_qp_ctx *qp_ctx,
- struct hisi_zip_req *req)
+static void hisi_zip_remove_req(struct hisi_zip_req *req)
{
- struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
+ struct hisi_zip_req_q *req_q = &req->qp_ctx->req_q;
spin_lock(&req_q->req_lock);
clear_bit(req->req_id, req_q->req_bitmap);
spin_unlock(&req_q->req_lock);
+
+ req->req_id = HZIP_INVAL_REQ_ID;
}
static void hisi_zip_fill_addr(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req)
@@ -258,19 +258,21 @@ static void hisi_zip_fill_sqe(struct hisi_zip_ctx *ctx, struct hisi_zip_sqe *sqe
ops->fill_sqe_type(sqe, ops->sqe_type);
}
-static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
- struct hisi_zip_req *req)
+static void hisi_zip_enqueue_backlog(struct hisi_zip_req *req)
{
+ struct hisi_qp *qp = req->qp_ctx->qp;
+
+ spin_lock_bh(&qp->backlog.lock);
+ list_add_tail(&req->list, &qp->backlog.list);
+ spin_unlock_bh(&qp->backlog.lock);
+}
+
+static int hisi_zip_map_req_buffers(struct hisi_zip_req *req)
+{
+ struct hisi_zip_qp_ctx *qp_ctx = req->qp_ctx;
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
- struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
+ struct device *dev = &qp_ctx->qp->qm->pdev->dev;
struct acomp_req *a_req = req->req;
- struct hisi_qp *qp = qp_ctx->qp;
- struct device *dev = &qp->qm->pdev->dev;
- struct hisi_zip_sqe zip_sqe;
- int ret;
-
- if (unlikely(!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen))
- return -EINVAL;
req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool,
req->req_id << 1, &req->dma_src,
@@ -285,33 +287,114 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
(req->req_id << 1) + 1,
&req->dma_dst, DMA_FROM_DEVICE);
if (IS_ERR(req->hw_dst)) {
- ret = PTR_ERR(req->hw_dst);
- dev_err(dev, "failed to map the dst buffer to hw sgl (%d)!\n",
- ret);
- goto err_unmap_input;
+ dev_err(dev, "failed to map the dst buffer to hw sgl (%ld)!\n",
+ PTR_ERR(req->hw_dst));
+ hisi_acc_sg_buf_unmap(dev, a_req->src, req->hw_src, DMA_TO_DEVICE);
+ return PTR_ERR(req->hw_dst);
}
+ return 0;
+}
+
+static void hisi_zip_unmap_req_buffers(struct hisi_zip_req *req)
+{
+ struct device *dev = &req->qp_ctx->qp->qm->pdev->dev;
+ struct acomp_req *a_req = req->req;
+
+ hisi_acc_sg_buf_unmap(dev, a_req->dst, req->hw_dst, DMA_FROM_DEVICE);
+ hisi_acc_sg_buf_unmap(dev, a_req->src, req->hw_src, DMA_TO_DEVICE);
+}
+
+static int hisi_zip_do_work(struct hisi_zip_req *req)
+{
+ struct hisi_zip_qp_ctx *qp_ctx = req->qp_ctx;
+ struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
+ struct hisi_qp *qp = qp_ctx->qp;
+ struct hisi_zip_sqe zip_sqe;
+ int ret;
+
hisi_zip_fill_sqe(qp_ctx->ctx, &zip_sqe, qp_ctx->req_type, req);
/* send command to start a task */
- atomic64_inc(&dfx->send_cnt);
ret = hisi_qp_send(qp, &zip_sqe);
- if (unlikely(ret < 0)) {
- atomic64_inc(&dfx->send_busy_cnt);
- ret = -EAGAIN;
- dev_dbg_ratelimited(dev, "failed to send request!\n");
- goto err_unmap_output;
+ if (likely(!ret)) {
+ atomic64_inc(&dfx->send_cnt);
+ return -EINPROGRESS;
}
- return -EINPROGRESS;
+ if (ret == -EBUSY)
+ atomic64_inc(&dfx->send_busy_cnt);
-err_unmap_output:
- hisi_acc_sg_buf_unmap(dev, a_req->dst, req->hw_dst, DMA_FROM_DEVICE);
-err_unmap_input:
- hisi_acc_sg_buf_unmap(dev, a_req->src, req->hw_src, DMA_TO_DEVICE);
return ret;
}
+static void hisi_zip_send_backlog_soft(struct hisi_zip_qp_ctx *qp_ctx)
+{
+ struct hisi_zip_ctx *ctx = qp_ctx->ctx;
+ bool is_decomp = qp_ctx->qp->alg_type;
+ struct hisi_zip_req *req, *tmp;
+ int ret;
+
+ list_for_each_entry_safe(req, tmp, &qp_ctx->qp->backlog.list, list) {
+ list_del(&req->list);
+
+ if (req->req_id != HZIP_INVAL_REQ_ID) {
+ hisi_zip_unmap_req_buffers(req);
+ hisi_zip_remove_req(req);
+ }
+
+ ret = hisi_zip_fallback_do_work(ctx->soft_tfm, req->req,
+ is_decomp);
+
+ /* Wake up the busy thread first, then return the errno. */
+ if (req->req->base.complete) {
+ acomp_request_complete(req->req, -EINPROGRESS);
+ acomp_request_complete(req->req, ret);
+ }
+ }
+}
+
+static void hisi_zip_send_backlog(struct hisi_qp *qp)
+{
+ struct hisi_zip_req *req, *tmp;
+ struct hisi_zip_req_q *req_q;
+ int ret;
+
+ spin_lock_bh(&qp->backlog.lock);
+ list_for_each_entry_safe(req, tmp, &qp->backlog.list, list) {
+ req_q = &req->qp_ctx->req_q;
+ if (req->req_id == HZIP_INVAL_REQ_ID) {
+ ret = hisi_zip_create_req(req);
+ if (ret)
+ continue;
+
+ ret = hisi_zip_map_req_buffers(req);
+ if (unlikely(ret)) {
+ hisi_zip_remove_req(req);
+ hisi_zip_send_backlog_soft(req->qp_ctx);
+ goto unlock;
+ }
+ }
+
+ ret = hisi_zip_do_work(req);
+ switch (ret) {
+ case -EINPROGRESS:
+ list_del(&req->list);
+ if (req->req->base.complete)
+ acomp_request_complete(req->req, -EINPROGRESS);
+ break;
+ case -EBUSY:
+ goto unlock;
+ default:
+ hisi_zip_send_backlog_soft(req->qp_ctx);
+ goto unlock;
+ }
+ }
+
+unlock:
+ spin_unlock_bh(&qp->backlog.lock);
+}
+
static u32 hisi_zip_get_status(struct hisi_zip_sqe *sqe)
{
return sqe->dw3 & HZIP_BD_STATUS_M;
@@ -344,75 +427,101 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data)
err = -EIO;
}
- hisi_acc_sg_buf_unmap(dev, acomp_req->dst, req->hw_dst, DMA_FROM_DEVICE);
- hisi_acc_sg_buf_unmap(dev, acomp_req->src, req->hw_src, DMA_TO_DEVICE);
+ hisi_zip_unmap_req_buffers(req);
acomp_req->dlen = ops->get_dstlen(sqe);
+ hisi_zip_remove_req(req);
if (acomp_req->base.complete)
acomp_request_complete(acomp_req, err);
- hisi_zip_remove_req(qp_ctx, req);
+ hisi_zip_send_backlog(qp);
}
-static int hisi_zip_acompress(struct acomp_req *acomp_req)
+static int hisi_zip_do_comp(struct hisi_zip_req *req, bool is_decompress)
{
+ struct acomp_req *acomp_req = req->req;
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
- struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
- struct hisi_zip_req *req;
- struct device *dev;
+ struct hisi_qp *qp = req->qp_ctx->qp;
int ret;
- if (ctx->fallback)
- return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req, 0);
+ if (unlikely(!acomp_req->src || !acomp_req->slen ||
+ !acomp_req->dst || !acomp_req->dlen))
+ return -EINVAL;
- dev = &qp_ctx->qp->qm->pdev->dev;
+ if (ctx->fallback)
+ return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req,
+ is_decompress);
+
+ /* Check whether any request is being queued */
+ if ((acomp_req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG) &&
+ !list_empty(&qp->backlog.list)) {
+ req->req_id = HZIP_INVAL_REQ_ID;
+ hisi_zip_enqueue_backlog(req);
+ return -EBUSY;
+ }
- req = hisi_zip_create_req(qp_ctx, acomp_req);
- if (IS_ERR(req))
- return PTR_ERR(req);
+ ret = hisi_zip_create_req(req);
+ if (ret && (acomp_req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
+ /* all req bitmaps are used add to backlog list */
+ req->req_id = HZIP_INVAL_REQ_ID;
+ hisi_zip_enqueue_backlog(req);
+ return -EBUSY;
+ } else if (unlikely(ret)) {
+ return -ENOSPC;
+ }
- ret = hisi_zip_do_work(qp_ctx, req);
- if (unlikely(ret != -EINPROGRESS)) {
- dev_info_ratelimited(dev, "failed to do compress (%d)!\n", ret);
- hisi_zip_remove_req(qp_ctx, req);
+ ret = hisi_zip_map_req_buffers(req);
+ if (unlikely(ret))
+ goto remove_req;
+
+ ret = hisi_zip_do_work(req);
+ if (ret == -EBUSY && (acomp_req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
+ /* hardwre busy add to backlog list */
+ hisi_zip_enqueue_backlog(req);
+ } else if (unlikely(ret != -EINPROGRESS)) {
+ dev_info_ratelimited(&qp->qm->pdev->dev,
+ "failed to do %scompress (%d)!\n",
+ qp->alg_type ? "de" : "", ret);
+ ret = -ENOSPC;
+ goto unmap_req;
}
return ret;
+
+unmap_req:
+ hisi_zip_unmap_req_buffers(req);
+remove_req:
+ hisi_zip_remove_req(req);
+ return ret;
}
-static int hisi_zip_adecompress(struct acomp_req *acomp_req)
+static int hisi_zip_acompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
- struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP];
- struct hisi_zip_req *req;
- struct device *dev;
- int ret;
-
- if (ctx->fallback)
- return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req, 1);
-
- dev = &qp_ctx->qp->qm->pdev->dev;
+ struct hisi_zip_req *req = acomp_request_ctx(acomp_req);
- req = hisi_zip_create_req(qp_ctx, acomp_req);
- if (IS_ERR(req))
- return PTR_ERR(req);
+ req->req = acomp_req;
+ req->qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
+ return hisi_zip_do_comp(req, HZIP_ALG_TYPE_COMP);
+}
- ret = hisi_zip_do_work(qp_ctx, req);
- if (unlikely(ret != -EINPROGRESS)) {
- dev_info_ratelimited(dev, "failed to do decompress (%d)!\n",
- ret);
- hisi_zip_remove_req(qp_ctx, req);
- }
+static int hisi_zip_adecompress(struct acomp_req *acomp_req)
+{
+ struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
+ struct hisi_zip_req *req = acomp_request_ctx(acomp_req);
- return ret;
+ req->req = acomp_req;
+ req->qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP];
+ return hisi_zip_do_comp(req, HZIP_ALG_TYPE_DECOMP);
}
static int hisi_zip_decompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
- return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req, 1);
+ return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req,
+ HZIP_ALG_TYPE_DECOMP);
}
static const struct hisi_zip_sqe_ops hisi_zip_ops = {
@@ -476,7 +585,7 @@ static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
{
u16 q_depth = ctx->qp_ctx[0].qp->sq_depth;
struct hisi_zip_req_q *req_q;
- int i, ret;
+ int i;
for (i = 0; i < HZIP_CTX_Q_NUM; i++) {
req_q = &ctx->qp_ctx[i].req_q;
@@ -484,44 +593,21 @@ static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
req_q->req_bitmap = bitmap_zalloc(req_q->size, GFP_KERNEL);
if (!req_q->req_bitmap) {
- ret = -ENOMEM;
- if (i == 0)
- return ret;
-
- goto err_free_comp_q;
+ bitmap_free(ctx->qp_ctx[HZIP_QPC_COMP].req_q.req_bitmap);
+ return -ENOMEM;
}
spin_lock_init(&req_q->req_lock);
-
- req_q->q = kcalloc(req_q->size, sizeof(struct hisi_zip_req),
- GFP_KERNEL);
- if (!req_q->q) {
- ret = -ENOMEM;
- if (i == 0)
- goto err_free_comp_bitmap;
- else
- goto err_free_decomp_bitmap;
- }
}
return 0;
-
-err_free_decomp_bitmap:
- bitmap_free(ctx->qp_ctx[HZIP_QPC_DECOMP].req_q.req_bitmap);
-err_free_comp_q:
- kfree(ctx->qp_ctx[HZIP_QPC_COMP].req_q.q);
-err_free_comp_bitmap:
- bitmap_free(ctx->qp_ctx[HZIP_QPC_COMP].req_q.req_bitmap);
- return ret;
}
static void hisi_zip_release_req_q(struct hisi_zip_ctx *ctx)
{
int i;
- for (i = 0; i < HZIP_CTX_Q_NUM; i++) {
- kfree(ctx->qp_ctx[i].req_q.q);
+ for (i = 0; i < HZIP_CTX_Q_NUM; i++)
bitmap_free(ctx->qp_ctx[i].req_q.req_bitmap);
- }
}
static int hisi_zip_create_sgl_pool(struct hisi_zip_ctx *ctx)
@@ -571,7 +657,7 @@ static void hisi_zip_set_acomp_cb(struct hisi_zip_ctx *ctx,
static int hisi_zip_fallback_init(struct hisi_zip_ctx *ctx, const char *alg_name)
{
- if (!IS_ERR_OR_NULL(ctx->soft_tfm))
+ if (ctx->soft_tfm)
return 0;
if (!crypto_has_comp(alg_name, 0, 0))
@@ -580,7 +666,8 @@ static int hisi_zip_fallback_init(struct hisi_zip_ctx *ctx, const char *alg_name
ctx->soft_tfm = crypto_alloc_comp(alg_name, 0, 0);
if (IS_ERR_OR_NULL(ctx->soft_tfm)) {
pr_err("could not alloc soft tfm %s\n", alg_name);
- return PTR_ERR(ctx->soft_tfm);
+ ctx->soft_tfm = NULL;
+ return -ENOMEM;
}
return 0;
@@ -588,7 +675,7 @@ static int hisi_zip_fallback_init(struct hisi_zip_ctx *ctx, const char *alg_name
static void hisi_zip_fallback_uninit(struct hisi_zip_ctx *ctx)
{
- if (IS_ERR_OR_NULL(ctx->soft_tfm))
+ if (!ctx->soft_tfm)
return;
crypto_free_comp(ctx->soft_tfm);
@@ -599,8 +686,10 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm)
{
const char *alg_name = crypto_tfm_alg_name(&tfm->base);
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base);
+ int ret, fallback_err;
struct device *dev;
- int ret;
+
+ fallback_err = hisi_zip_fallback_init(ctx, alg_name);
ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name), tfm->base.node);
if (ret) {
@@ -631,8 +720,10 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm)
err_ctx_exit:
hisi_zip_ctx_exit(ctx);
switch_to_soft:
- ctx->fallback = true;
- return hisi_zip_fallback_init(ctx, alg_name);
+ if (!fallback_err)
+ ctx->fallback = true;
+
+ return fallback_err;
}
static int hisi_zip_acomp_init_fb(struct crypto_acomp *tfm)
@@ -672,6 +763,7 @@ static struct acomp_alg hisi_zip_acomp_deflate = {
.exit = hisi_zip_acomp_exit,
.compress = hisi_zip_acompress,
.decompress = hisi_zip_adecompress,
+ .reqsize = sizeof(struct hisi_zip_req),
.base = {
.cra_name = "deflate",
.cra_driver_name = "hisi-deflate-acomp",
@@ -710,6 +802,7 @@ static struct acomp_alg hisi_zip_acomp_lz4 = {
.exit = hisi_zip_acomp_exit,
.compress = hisi_zip_acompress,
.decompress = hisi_zip_decompress,
+ .reqsize = sizeof(struct hisi_zip_req),
.base = {
.cra_name = "lz4",
.cra_driver_name = "hisi-lz4-acomp",
--
2.43.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
Some bug fixes and code cleanup for uadk.
Longfang Liu (2):
uadk: modify the queue lookup method for the compression algorithm
uadk: update compression algorithm memory pool creation
Weili Qian (7):
uadk: remove unused inner async poll
uadk: fix memory leak when wd_get_alg_type() fails
uadk: check the strdup() return value
uadk/v1: replaced the deprecated <sys/poll.h> with <poll.h>
uadk: remove redundant check
uadk: include missing header file
uadk: move library dependencies to LIBADD
Zhushuai Yin (1):
uadk/v1:fix integer overflow problem
Makefile.am | 24 +-
docs/wd_environment_variable | 7 -
include/wd_aead.h | 3 +-
include/wd_cipher.h | 3 +-
include/wd_comp.h | 3 +-
include/wd_digest.h | 3 +-
include/wd_ecc.h | 3 +-
include/wd_rsa.h | 3 +-
include/wd_util.h | 41 +--
test/sanity_test.sh | 2 -
uadk_tool/benchmark/zip_uadk_benchmark.c | 9 +-
v1/wd.c | 2 +-
v1/wd_util.c | 2 +-
wd_aead.c | 27 +-
wd_cipher.c | 24 +-
wd_comp.c | 30 +-
wd_dh.c | 24 +-
wd_digest.c | 24 +-
wd_ecc.c | 24 +-
wd_rsa.c | 24 +-
wd_util.c | 439 +----------------------
21 files changed, 115 insertions(+), 606 deletions(-)
--
2.43.0
1
11
From: parm64 <parm64(a)huawei.com>
Chenghai Huang (1):
crypto: hisilicon/zip - add backlog support for zip
Wenkai Lin (1):
crypto: hisilicon/sec2 - fix UAF in sec_alg_send_backlog
lizhi (1):
crypto: hisilicon/hpre: implement full backlog support for hpre driver
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 287 ++++++++++++------
drivers/crypto/hisilicon/sec2/sec_crypto.c | 23 +-
drivers/crypto/hisilicon/zip/zip_crypto.c | 308 +++++++++++++-------
3 files changed, 409 insertions(+), 209 deletions(-)
--
2.43.0
1
3
[PATCH 0/7] uadk_provider: asynchronous SEC switching to software computing is supported
by ZongYu Wu 09 May '26
by ZongYu Wu 09 May '26
09 May '26
From: parm64 <parm64(a)huawei.com>
Weili Qian (3):
uadk_provider/sm2: fix compilation warning
uadk_engine: add asynchronous request sending return value check
uadk_provider: modify the return value check for asynchronous request
sending
Zhushuai Yin (2):
uadk_provider: asynchronous SEC switching to software computing is
supported
uadk_provider: asynchronous aead switching to software computing is
supported
lizhi (2):
uadk_provider/ecdh: ensure proper ECDH key length and add RSA-PSS
query function
uadk_provider/rsa: add input length validation and initialization
parameter checks
src/uadk_dh.c | 11 +++--
src/uadk_ec.c | 15 ++++++-
src/uadk_pkey.c | 11 +++--
src/uadk_prov_aead.c | 15 +------
src/uadk_prov_cipher.c | 43 ++++++++++---------
src/uadk_prov_dh.c | 7 ++-
src/uadk_prov_digest.c | 47 +++++++++------------
src/uadk_prov_ecdh_exch.c | 6 ++-
src/uadk_prov_hmac.c | 49 +++++++++------------
src/uadk_prov_pkey.c | 7 ++-
src/uadk_prov_rsa.c | 66 +++++++++++++++++++++++++----
src/uadk_prov_rsa.h | 4 +-
src/uadk_prov_rsa_enc.c | 25 ++++++-----
src/uadk_prov_rsa_kmgmt.c | 12 +++++-
src/uadk_prov_rsa_sign.c | 14 +++++-
src/uadk_prov_sm2_kmgmt.c | 2 +-
src/uadk_rsa.c | 89 ++++++++++++++++++++++++++++++++-------
17 files changed, 278 insertions(+), 145 deletions(-)
--
2.43.0
1
7
08 May '26
From: Weili Qian <qianweili(a)huawei.com>
The 'ret' value is assigned in the case of 'req->op_type == WD_RSA_GENKEY'.
When 'op_type' is not 'WD_RSA_GENKEY', 'ret' is not initialized. If
'ret' is directly returned, the caller may incorrectly determine that
the operation fails. Therefore, 'WD_SUCCESS' instead of 'ret' is
directly returned.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_hpre.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index e114da3..e806fc7 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -599,7 +599,7 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
return -WD_ENOMEM;
fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return ret;
+ return WD_SUCCESS;
}
static int rsa_prepare_iot(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
--
2.33.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
The internal asynchronous polling interface is not
used in any scenario, remove it.
Upstream: YES
Feature or Bugfix:Bugfix
AR:AR20230706877890
DTS:DTS2026042322013
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
include/wd_aead.h | 3 +-
include/wd_cipher.h | 3 +-
include/wd_comp.h | 3 +-
include/wd_digest.h | 3 +-
include/wd_ecc.h | 3 +-
include/wd_rsa.h | 3 +-
include/wd_util.h | 37 ----
wd_aead.c | 24 +--
wd_cipher.c | 24 +--
wd_comp.c | 28 +--
wd_dh.c | 24 +--
wd_digest.c | 24 +--
wd_ecc.c | 24 +--
wd_rsa.c | 24 +--
wd_util.c | 418 +-------------------------------------------
15 files changed, 70 insertions(+), 575 deletions(-)
diff --git a/include/wd_aead.h b/include/wd_aead.h
index 4b5095f..3585c86 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -254,7 +254,8 @@ void wd_aead_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*
* If the current algorithm library does not require the type parameter,
* the type parameter is invalid. The function returns 0 to indicate that
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index a6f8be1..383d315 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -218,7 +218,8 @@ void wd_cipher_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 8579f93..890799a 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -252,7 +252,8 @@ void wd_comp_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*
* If the current algorithm library does not require the type parameter,
* the type parameter is invalid. The function returns 0 to indicate that
diff --git a/include/wd_digest.h b/include/wd_digest.h
index 42a95db..410c7f9 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -278,7 +278,8 @@ void wd_digest_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 18c1c0d..d868951 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -548,7 +548,8 @@ void wd_ecc_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 9c91432..b0ead0a 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -239,7 +239,8 @@ void wd_rsa_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_util.h b/include/wd_util.h
index 42270d9..c24c554 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -78,16 +78,10 @@ struct wd_env_config_per_numa {
/* Resource begin */
struct uacce_dev *dev;
int dev_num;
- /* This can be made statically currently */
- unsigned long async_poll_num;
- void *async_task_queue_array;
};
struct wd_env_config {
struct wd_env_config_per_numa *config_per_numa;
- /* Let's make it as a gobal config, not per numa */
- bool enable_internal_poll;
-
/* resource config */
struct wd_sched *sched;
bool internal_sched;
@@ -273,28 +267,6 @@ int wd_check_datalist(struct wd_datalist *head, __u64 size);
*/
int wd_parse_ctx_num(struct wd_env_config *config, const char *s);
-/*
- * wd_parse_async_poll_en() - Parse async polling thread related environment
- * variable and store it.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @s: Related environment variable string.
- *
- * More information, please see docs/wd_environment_variable.
- */
-int wd_parse_async_poll_en(struct wd_env_config *config, const char *s);
-
-/*
- * wd_parse_async_poll_num() - Parse async polling thread related environment
- * variable and store it.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @s: Related environment variable string.
- *
- * More information, please see docs/wd_environment_variable.
- */
-int wd_parse_async_poll_num(struct wd_env_config *config, const char *s);
-
/*
* wd_alg_env_init() - Init wd algorithm environment variable configurations.
* This is a help function which can be used by specific
@@ -323,15 +295,6 @@ int wd_alg_env_init(struct wd_env_config *env_config,
void wd_alg_env_uninit(struct wd_env_config *env_config,
const struct wd_alg_ops *ops);
-/*
- * wd_add_task_to_async_queue() - Add an async request to its related async
- * task queue.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @idx: Index of ctx in config.
- */
-int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx);
-
/*
* dump_env_info() - dump wd algorithm ctx info.
* @config: Pointer of wd_env_config which is used to store environment
diff --git a/wd_aead.c b/wd_aead.c
index 748bf95..3e993a1 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -957,9 +957,6 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_aead_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -1039,15 +1036,10 @@ int wd_aead_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_AEAD_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_AEAD_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_AEAD_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_aead_ops = {
@@ -1062,8 +1054,8 @@ int wd_aead_env_init(struct wd_sched *sched)
{
wd_aead_env_config.sched = sched;
- return wd_alg_env_init(&wd_aead_env_config, table,
- &wd_aead_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_aead_env_config, &table,
+ &wd_aead_ops, 1, NULL);
}
void wd_aead_env_uninit(void)
@@ -1080,8 +1072,8 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_aead_env_config, table,
- &wd_aead_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_aead_env_config, &table,
+ &wd_aead_ops, 1, &ctx_attr);
}
void wd_aead_ctx_num_uninit(void)
diff --git a/wd_cipher.c b/wd_cipher.c
index abedfb3..a4d6c63 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -800,9 +800,6 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_cipher_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -883,15 +880,10 @@ int wd_cipher_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_CIPHER_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_CIPHER_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_CIPHER_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_cipher_ops = {
@@ -906,8 +898,8 @@ int wd_cipher_env_init(struct wd_sched *sched)
{
wd_cipher_env_config.sched = sched;
- return wd_alg_env_init(&wd_cipher_env_config, table,
- &wd_cipher_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_cipher_env_config, &table,
+ &wd_cipher_ops, 1, NULL);
}
void wd_cipher_env_uninit(void)
@@ -924,8 +916,8 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_cipher_env_config, table,
- &wd_cipher_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_cipher_env_config, &table,
+ &wd_cipher_ops, 1, &ctx_attr);
}
void wd_cipher_ctx_num_uninit(void)
diff --git a/wd_comp.c b/wd_comp.c
index 247eadd..84fb079 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -880,9 +880,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
- if (unlikely(ret))
- goto fail_with_msg;
return 0;
@@ -908,19 +905,10 @@ int wd_comp_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_sched_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_COMP_CTX_NUM",
- .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_COMP_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- },
- { .name = "WD_COMP_ASYNC_POLL_NUM",
- .def_val = "1@0",
- .parse_fn = wd_parse_async_poll_num
- }
+static const struct wd_config_variable table = {
+ .name = "WD_COMP_CTX_NUM",
+ .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_comp_ops = {
@@ -935,8 +923,8 @@ int wd_comp_env_init(struct wd_sched *sched)
{
wd_comp_env_config.sched = sched;
- return wd_alg_env_init(&wd_comp_env_config, table,
- &wd_comp_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_comp_env_config, &table,
+ &wd_comp_ops, 1, NULL);
}
void wd_comp_env_uninit(void)
@@ -958,8 +946,8 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_comp_env_config, table,
- &wd_comp_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_comp_env_config, &table,
+ &wd_comp_ops, 1, &ctx_attr);
}
void wd_comp_ctx_num_uninit(void)
diff --git a/wd_dh.c b/wd_dh.c
index 3395060..7837114 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -441,9 +441,6 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -654,15 +651,10 @@ void wd_dh_free_sess(handle_t sess)
free(sess_t);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_DH_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_DH_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_DH_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_dh_ops = {
@@ -677,8 +669,8 @@ int wd_dh_env_init(struct wd_sched *sched)
{
wd_dh_env_config.sched = sched;
- return wd_alg_env_init(&wd_dh_env_config, table,
- &wd_dh_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_dh_env_config, &table,
+ &wd_dh_ops, 1, NULL);
}
void wd_dh_env_uninit(void)
@@ -695,8 +687,8 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_dh_env_config, table,
- &wd_dh_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_dh_env_config, &table,
+ &wd_dh_ops, 1, &ctx_attr);
}
void wd_dh_ctx_num_uninit(void)
diff --git a/wd_digest.c b/wd_digest.c
index 8e5bf94..bd3dd05 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -746,9 +746,6 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_digest_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -830,15 +827,10 @@ int wd_digest_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_DIGEST_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_DIGEST_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_DIGEST_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_digest_ops = {
@@ -853,8 +845,8 @@ int wd_digest_env_init(struct wd_sched *sched)
{
wd_digest_env_config.sched = sched;
- return wd_alg_env_init(&wd_digest_env_config, table,
- &wd_digest_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_digest_env_config, &table,
+ &wd_digest_ops, 1, NULL);
}
void wd_digest_env_uninit(void)
@@ -871,8 +863,8 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_digest_env_config, table,
- &wd_digest_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_digest_env_config, &table,
+ &wd_digest_ops, 1, &ctx_attr);
}
void wd_digest_ctx_num_uninit(void)
diff --git a/wd_ecc.c b/wd_ecc.c
index c31495f..4c77a04 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2319,9 +2319,6 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -2401,15 +2398,10 @@ int wd_ecc_poll(__u32 expt, __u32 *count)
return wd_ecc_setting.sched.poll_policy(h_sched_sess, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_ECC_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_ECC_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_ECC_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_ecc_ops = {
@@ -2424,8 +2416,8 @@ int wd_ecc_env_init(struct wd_sched *sched)
{
wd_ecc_env_config.sched = sched;
- return wd_alg_env_init(&wd_ecc_env_config, table,
- &wd_ecc_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_ecc_env_config, &table,
+ &wd_ecc_ops, 1, NULL);
}
void wd_ecc_env_uninit(void)
@@ -2442,8 +2434,8 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_ecc_env_config, table,
- &wd_ecc_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_ecc_env_config, &table,
+ &wd_ecc_ops, 1, &ctx_attr);
}
void wd_ecc_ctx_num_uninit(void)
diff --git a/wd_rsa.c b/wd_rsa.c
index c020514..2242fed 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -502,9 +502,6 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -1266,15 +1263,10 @@ void wd_rsa_get_prikey(handle_t sess, struct wd_rsa_prikey **prikey)
*prikey = ((struct wd_rsa_sess *)sess)->prikey;
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_RSA_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_RSA_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_RSA_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_rsa_ops = {
@@ -1289,8 +1281,8 @@ int wd_rsa_env_init(struct wd_sched *sched)
{
wd_rsa_env_config.sched = sched;
- return wd_alg_env_init(&wd_rsa_env_config, table,
- &wd_rsa_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_rsa_env_config, &table,
+ &wd_rsa_ops, 1, NULL);
}
void wd_rsa_env_uninit(void)
@@ -1307,8 +1299,8 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_rsa_env_config, table,
- &wd_rsa_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_rsa_env_config, &table,
+ &wd_rsa_ops, 1, &ctx_attr);
}
void wd_rsa_ctx_num_uninit(void)
diff --git a/wd_util.c b/wd_util.c
index f97b558..c174d7c 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -8,7 +8,6 @@
#include <dirent.h>
#include <dlfcn.h>
#include <pthread.h>
-#include <semaphore.h>
#include <string.h>
#include <ctype.h>
#include "wd_sched.h"
@@ -72,27 +71,6 @@ static const char *wd_env_name[WD_TYPE_MAX] = {
"WD_JOIN_GATHER_CTX_NUM",
};
-struct async_task {
- __u32 idx;
-};
-
-struct async_task_queue {
- struct async_task *head;
- int depth;
- /* the producer offset of task queue */
- int prod;
- /* the consumer offset of task queue */
- int cons;
- int cur_task;
- int left_task;
- int end;
- sem_t empty_sem;
- sem_t full_sem;
- pthread_mutex_t lock;
- pthread_t tid;
- int (*alg_poll_ctx)(__u32, __u32, __u32 *);
-};
-
struct drv_lib_list {
void *dlhandle;
struct drv_lib_list *next;
@@ -784,17 +762,6 @@ static int str_to_bool(const char *s, bool *target)
return 0;
}
-int wd_parse_async_poll_en(struct wd_env_config *config, const char *s)
-{
- int ret;
-
- ret = str_to_bool(s, &config->enable_internal_poll);
- if (ret)
- WD_ERR("failed to parse async poll enable flag(%s)!\n", s);
-
- return ret;
-}
-
static int parse_num_on_numa(const char *s, int *num, int *node)
{
char *sep, *start, *left;
@@ -1036,41 +1003,6 @@ int wd_parse_ctx_num(struct wd_env_config *config, const char *s)
return parse_ctx_num(config, s);
}
-int wd_parse_async_poll_num(struct wd_env_config *config, const char *s)
-{
- struct wd_env_config_per_numa *config_numa;
- char *left, *section, *start;
- int node, poll_num, ret;
-
- if (!config->enable_internal_poll) {
- WD_ERR("internal poll not enabled, skip parse poll number!\n");
- return 0;
- }
-
- start = strdup(s);
- if (!start)
- return -ENOMEM;
-
- left = start;
- while ((section = strsep(&left, ","))) {
- ret = parse_num_on_numa(section, &poll_num, &node);
- if (ret)
- goto out;
- config_numa = wd_get_config_numa(config, node);
- if (!config_numa) {
- ret = -WD_EINVAL;
- goto out;
- }
- config_numa->async_poll_num = poll_num;
- }
-
- free(start);
- return 0;
-out:
- free(start);
- return ret;
-}
-
static int wd_parse_env(struct wd_env_config *config)
{
const struct wd_config_variable *var;
@@ -1119,8 +1051,6 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
/* Use default sched and disable internal poll */
env_config->sched = NULL;
- env_config->enable_internal_poll = 0;
- config_numa->async_poll_num = 0;
return 0;
}
@@ -1348,21 +1278,17 @@ static int wd_init_sched_config(struct wd_env_config *config,
{
struct wd_env_config_per_numa *config_numa;
int i, j, ret, max_node, type_num;
- void *func = NULL;
type_num = config->op_type_num;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -WD_EINVAL;
- if (!config->enable_internal_poll)
- func = alg_poll_ctx;
-
config->internal_sched = false;
if (!config->sched) {
WD_ERR("no sched is specified, alloc a default sched!\n");
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
- max_node, func);
+ max_node, alg_poll_ctx);
if (!config->sched)
return -WD_ENOMEM;
@@ -1389,339 +1315,6 @@ err_release_sched:
return ret;
}
-static struct async_task_queue *find_async_queue(struct wd_env_config *config,
- __u32 idx)
-{
- struct wd_env_config_per_numa *config_numa;
- struct wd_ctx_range **ctx_table;
- struct async_task_queue *head;
- unsigned long offset = 0;
- __u32 i, num = 0;
-
- FOREACH_NUMA(i, config, config_numa) {
- num += config_numa->sync_ctx_num + config_numa->async_ctx_num;
- if (idx < num)
- break;
- }
-
- if (i == config->numa_num) {
- WD_ERR("failed to find a proper numa node!\n");
- return NULL;
- }
-
- if (!config_numa->async_poll_num) {
- WD_ERR("invalid: async_poll_num of numa is zero!\n");
- return NULL;
- }
-
- ctx_table = config_numa->ctx_table;
- for (i = 0; i < config_numa->op_type_num; i++) {
- if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
- idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
- offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) %
- config_numa->async_poll_num;
- break;
- }
- }
-
- if (i == config_numa->op_type_num) {
- WD_ERR("failed to find async queue for ctx: idx %u!\n", idx);
- return NULL;
- }
-
- head = (struct async_task_queue *)config_numa->async_task_queue_array;
-
- return head + offset;
-}
-
-int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
-{
- struct async_task_queue *task_queue;
- struct async_task *task;
- int curr_prod, ret;
-
- if (!config->enable_internal_poll)
- return 0;
-
- task_queue = find_async_queue(config, idx);
- if (!task_queue)
- return -WD_EINVAL;
-
- ret = sem_wait(&task_queue->empty_sem);
- if (ret) {
- WD_ERR("failed to wait empty_sem!\n");
- return ret;
- }
-
- pthread_mutex_lock(&task_queue->lock);
-
- /* get an available async task and fill ctx idx */
- curr_prod = task_queue->prod;
- task = task_queue->head + curr_prod;
- task->idx = idx;
-
- /* update global information of task queue */
- task_queue->prod = (curr_prod + 1) % task_queue->depth;
- task_queue->cur_task++;
- task_queue->left_task--;
-
- pthread_mutex_unlock(&task_queue->lock);
-
- ret = sem_post(&task_queue->full_sem);
- if (ret) {
- WD_ERR("failed to post full_sem!\n");
- goto err_out;
- }
-
- return 0;
-
-err_out:
- pthread_mutex_lock(&task_queue->lock);
- task_queue->left_task++;
- task_queue->cur_task--;
- task_queue->prod = curr_prod;
- pthread_mutex_unlock(&task_queue->lock);
- sem_post(&task_queue->empty_sem);
-
- return ret;
-}
-
-static void *async_poll_process_func(void *args)
-{
- struct async_task_queue *task_queue = args;
- struct async_task *head, *task;
- __u32 count;
- int cons, ret;
-
- while (1) {
- if (sem_wait(&task_queue->full_sem)) {
- if (errno == EINTR) {
- continue;
- }
- }
- if (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE)) {
- __atomic_store_n(&task_queue->end, 0, __ATOMIC_RELEASE);
- goto out;
- }
-
- pthread_mutex_lock(&task_queue->lock);
-
- /* async sending message isn't submitted yet */
- if (task_queue->cons == task_queue->prod) {
- pthread_mutex_unlock(&task_queue->lock);
- sem_post(&task_queue->full_sem);
- continue;
- }
-
- cons = task_queue->cons;
- head = task_queue->head;
- task = head + cons;
-
- task_queue->cons = (cons + 1) % task_queue->depth;
- task_queue->cur_task--;
- task_queue->left_task++;
-
- pthread_mutex_unlock(&task_queue->lock);
-
- ret = task_queue->alg_poll_ctx(task->idx, 1, &count);
- if (ret < 0) {
- pthread_mutex_lock(&task_queue->lock);
- task_queue->cons = cons;
- task_queue->cur_task++;
- task_queue->left_task--;
- pthread_mutex_unlock(&task_queue->lock);
- if (ret == -WD_EAGAIN) {
- sem_post(&task_queue->full_sem);
- continue;
- } else
- goto out;
- }
-
- if (sem_post(&task_queue->empty_sem))
- goto out;
- }
-out:
- return NULL;
-}
-
-static int wd_init_one_task_queue(struct async_task_queue *task_queue,
- void *alg_poll_ctx)
-
-{
- struct async_task *head;
- pthread_t thread_id;
- pthread_attr_t attr;
- int depth, ret;
-
- task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH;
-
- head = calloc(task_queue->depth, sizeof(*head));
- if (!head)
- return -WD_ENOMEM;
-
- task_queue->head = head;
- task_queue->left_task = depth;
- task_queue->alg_poll_ctx = alg_poll_ctx;
-
- if (sem_init(&task_queue->empty_sem, 0, depth)) {
- WD_ERR("failed to init empty_sem!\n");
- goto err_free_head;
- }
-
- if (sem_init(&task_queue->full_sem, 0, 0)) {
- WD_ERR("failed to init full_sem!\n");
- goto err_uninit_empty_sem;
- }
-
- if (pthread_mutex_init(&task_queue->lock, NULL)) {
- WD_ERR("failed to init task queue's mutex lock!\n");
- goto err_uninit_full_sem;
- }
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- task_queue->tid = 0;
- if (pthread_create(&thread_id, &attr, async_poll_process_func,
- task_queue)) {
- WD_ERR("failed to create poll thread!\n");
- goto err_destory_mutex;
- }
-
- task_queue->tid = thread_id;
- pthread_attr_destroy(&attr);
-
- return 0;
-
-err_destory_mutex:
- pthread_attr_destroy(&attr);
- pthread_mutex_destroy(&task_queue->lock);
-err_uninit_full_sem:
- sem_destroy(&task_queue->full_sem);
-err_uninit_empty_sem:
- sem_destroy(&task_queue->empty_sem);
-err_free_head:
- free(head);
- ret = -errno;
- return ret;
-}
-
-static void wd_uninit_one_task_queue(struct async_task_queue *task_queue)
-{
- /*
- * If there's no async task, async_poll_process_func() is sleeping
- * on task_queue->full_sem. It'll cause that threads could not
- * be end and memory leak.
- */
- sem_post(&task_queue->full_sem);
- __atomic_store_n(&task_queue->end, 1, __ATOMIC_RELEASE);
- while (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE))
- sched_yield();
-
- pthread_mutex_destroy(&task_queue->lock);
- sem_destroy(&task_queue->full_sem);
- sem_destroy(&task_queue->empty_sem);
- free(task_queue->head);
- task_queue->head = NULL;
-}
-
-static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
- struct wd_env_config_per_numa *config_numa,
- void *alg_poll_ctx)
-{
- struct async_task_queue *task_queue, *queue_head;
- int i, j, ret;
- double num;
-
- if (!config_numa->async_ctx_num)
- return 0;
-
- if (!config_numa->async_poll_num) {
- WD_ERR("invalid async poll num (%lu) is set.\n",
- config_numa->async_poll_num);
- WD_ERR("change to default value: %d\n", WD_ASYNC_DEF_POLL_NUM);
- config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM;
- }
-
- num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num);
-
- /* make max task queues as the number of async ctxs */
- queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head));
- if (!queue_head)
- return -WD_ENOMEM;
-
- task_queue = queue_head;
- for (i = 0; i < num; task_queue++, i++) {
- ret = wd_init_one_task_queue(task_queue, alg_poll_ctx);
- if (ret) {
- for (j = 0; j < i; task_queue++, j++)
- wd_uninit_one_task_queue(task_queue);
- free(queue_head);
- return ret;
- }
- }
-
- config_numa->async_task_queue_array = (void *)queue_head;
-
- return 0;
-}
-
-static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
- struct wd_env_config_per_numa *config_numa)
-{
- struct async_task_queue *task_queue, *head;
- double num;
- int i;
-
- if (!config_numa || !config_numa->async_task_queue_array)
- return;
-
- head = config_numa->async_task_queue_array;
- task_queue = head;
- num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num);
-
- for (i = 0; i < num; task_queue++, i++)
- wd_uninit_one_task_queue(task_queue);
- free(head);
- config_numa->async_task_queue_array = NULL;
-}
-
-static int wd_init_async_polling_thread(struct wd_env_config *config,
- void *alg_poll_ctx)
-{
- struct wd_env_config_per_numa *config_numa;
- int i, ret;
-
- if (!config->enable_internal_poll)
- return 0;
-
- FOREACH_NUMA(i, config, config_numa) {
- ret = wd_init_async_polling_thread_per_numa(config, config_numa,
- alg_poll_ctx);
- if (ret)
- goto out;
- }
-
- return 0;
-
-out:
- FOREACH_NUMA(i, config, config_numa)
- wd_uninit_async_polling_thread_per_numa(config, config_numa);
-
- return ret;
-}
-
-static void wd_uninit_async_polling_thread(struct wd_env_config *config)
-{
- struct wd_env_config_per_numa *config_numa;
- int i;
-
- if (!config->enable_internal_poll)
- return;
-
- FOREACH_NUMA(i, config, config_numa)
- wd_uninit_async_polling_thread_per_numa(config, config_numa);
-}
-
static int wd_init_resource(struct wd_env_config *config,
const struct wd_alg_ops *ops)
{
@@ -1739,14 +1332,8 @@ static int wd_init_resource(struct wd_env_config *config,
if (ret)
goto err_uninit_sched;
- ret = wd_init_async_polling_thread(config, ops->alg_poll_ctx);
- if (ret)
- goto err_uninit_alg;
-
return 0;
-err_uninit_alg:
- ops->alg_uninit();
err_uninit_sched:
wd_uninit_sched_config(config);
err_uninit_ctx:
@@ -1757,7 +1344,6 @@ err_uninit_ctx:
static void wd_uninit_resource(struct wd_env_config *config,
const struct wd_alg_ops *ops)
{
- wd_uninit_async_polling_thread(config);
ops->alg_uninit();
wd_uninit_sched_config(config);
wd_free_ctx(config);
@@ -1811,7 +1397,7 @@ int wd_alg_get_env_param(struct wd_env_config *env_config,
return -WD_EINVAL;
}
- *is_enable = env_config->enable_internal_poll;
+ *is_enable = 0;
config_numa = wd_get_config_numa(env_config, attr.node);
if (!config_numa)
--
2.43.0
1
4
From: Weili Qian <qianweili(a)huawei.com>
The OpenSSL version macro is used to solve the compatibility issues
between the uadk provider and OpenSSL 3.5.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
src/uadk_prov_ec_kmgmt.c | 13 ++++++++++++-
src/uadk_prov_ecdsa.c | 13 +++++++++++--
src/uadk_prov_ecx.c | 4 ++++
src/uadk_prov_pkey.h | 37 ++++++++++++++++++++++++++++++++++---
src/uadk_prov_rsa_enc.c | 5 ++++-
src/uadk_prov_rsa_sign.c | 7 +++++++
src/uadk_prov_sm2_sign.c | 14 +++++++++++---
7 files changed, 83 insertions(+), 10 deletions(-)
diff --git a/src/uadk_prov_ec_kmgmt.c b/src/uadk_prov_ec_kmgmt.c
index bd5cbd9..530929c 100644
--- a/src/uadk_prov_ec_kmgmt.c
+++ b/src/uadk_prov_ec_kmgmt.c
@@ -412,6 +412,7 @@ static void uadk_keymgmt_ec_gen_cleanup(void *genctx)
if (!gctx)
return;
+ OPENSSL_clear_free(gctx->dhkem_ikm, gctx->dhkem_ikmlen);
EC_GROUP_free(gctx->gen_group);
BN_free(gctx->p);
BN_free(gctx->a);
@@ -620,6 +621,13 @@ static int uadk_keymgmt_ec_gen_set_params(void *genctx, const OSSL_PARAM params[
if (!ret)
return ret;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ ret = ec_set_octet_param(OSSL_PKEY_PARAM_DHKEM_IKM, &gctx->dhkem_ikm,
+ &gctx->dhkem_ikmlen, params);
+ if (!ret)
+ return ret;
+# endif
+
return ec_set_octet_param(OSSL_PKEY_PARAM_EC_GENERATOR,
&gctx->gen, &gctx->gen_len, params);
}
@@ -640,8 +648,11 @@ static const OSSL_PARAM *uadk_keymgmt_ec_gen_settable_params(ossl_unused void *g
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_GENERATOR, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_ORDER, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_COFACTOR, NULL, 0),
- OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_SEED, NULL, 0),
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DHKEM_IKM, NULL, 0),
+# endif
+ OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_END
};
diff --git a/src/uadk_prov_ecdsa.c b/src/uadk_prov_ecdsa.c
index 3876488..44f64f6 100644
--- a/src/uadk_prov_ecdsa.c
+++ b/src/uadk_prov_ecdsa.c
@@ -53,7 +53,9 @@ struct ecdsa_ctx {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
+#endif
size_t aid_len;
size_t mdsize;
int operation;
@@ -174,6 +176,7 @@ err:
static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
{
+ unsigned char *aid = NULL;
WPACKET pkt;
ctx->aid_len = 0;
@@ -181,9 +184,11 @@ static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(&pkt, -1, ctx->ec, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &ctx->aid_len);
- ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && ctx->aid_len)
+ memmove(ctx->aid_buf, aid, ctx->aid_len);
}
/*
@@ -969,13 +974,17 @@ static int uadk_signature_ecdsa_digest_verify_final(void *vctx, const unsigned c
static int ecdsa_get_ctx_aid(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
{
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
+ if (ctx->aid_len)
+ aid = ctx->aid_buf;
+
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
if (!p)
return UADK_P_SUCCESS;
- return OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len);
+ return OSSL_PARAM_set_octet_string(p, aid, ctx->aid_len);
}
static int ecdsa_get_ctx_digest_size(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
diff --git a/src/uadk_prov_ecx.c b/src/uadk_prov_ecx.c
index 7353836..69494cc 100644
--- a/src/uadk_prov_ecx.c
+++ b/src/uadk_prov_ecx.c
@@ -147,6 +147,10 @@ typedef struct {
char *propq;
ECX_KEY_TYPE type;
int selection;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
+# endif
size_t keylen;
/* uadk sesssion */
handle_t sess;
diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h
index e82df34..aa7a07b 100644
--- a/src/uadk_prov_pkey.h
+++ b/src/uadk_prov_pkey.h
@@ -121,6 +121,8 @@ struct ec_gen_ctx {
int selection;
int ecdh_mode;
EC_GROUP *gen_group;
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
BIGNUM *priv_key;
};
@@ -129,12 +131,17 @@ typedef struct {
int id;
int name_id;
+#if OPENSSL_VERSION_NUMBER >= 0x30300000L
+ /* NID for the legacy alg if there is one */
+ int legacy_alg;
+# endif
char *type_name;
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+# endif
/* Constructor(s), destructor, information */
OSSL_FUNC_keymgmt_new_fn *new_fun;
OSSL_FUNC_keymgmt_free_fn *free;
@@ -146,6 +153,10 @@ typedef struct {
/* Generation, a complex constructor */
OSSL_FUNC_keymgmt_gen_init_fn *gen_init;
OSSL_FUNC_keymgmt_gen_set_template_fn *gen_set_template;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_keymgmt_gen_get_params_fn *gen_get_params;
+ OSSL_FUNC_keymgmt_gen_gettable_params_fn *gen_gettable_params;
+# endif
OSSL_FUNC_keymgmt_gen_set_params_fn *gen_set_params;
OSSL_FUNC_keymgmt_gen_settable_params_fn *gen_settable_params;
OSSL_FUNC_keymgmt_gen_fn *gen;
@@ -161,8 +172,14 @@ typedef struct {
/* Import and export routines */
OSSL_FUNC_keymgmt_import_fn *import;
OSSL_FUNC_keymgmt_import_types_fn *import_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_import_types_ex_fn *import_types_ex;
+# endif
OSSL_FUNC_keymgmt_export_fn *export_fun;
OSSL_FUNC_keymgmt_export_types_fn *export_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_export_types_ex_fn *export_types_ex;
+# endif
OSSL_FUNC_keymgmt_dup_fn *dup;
} UADK_PKEY_KEYMGMT;
@@ -228,13 +245,24 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_signature_newctx_fn *newctx;
OSSL_FUNC_signature_sign_init_fn *sign_init;
OSSL_FUNC_signature_sign_fn *sign;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_sign_message_init_fn *sign_message_init;
+ OSSL_FUNC_signature_sign_message_update_fn *sign_message_update;
+ OSSL_FUNC_signature_sign_message_final_fn *sign_message_final;
+#endif
OSSL_FUNC_signature_verify_init_fn *verify_init;
OSSL_FUNC_signature_verify_fn *verify;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_verify_message_init_fn *verify_message_init;
+ OSSL_FUNC_signature_verify_message_update_fn *verify_message_update;
+ OSSL_FUNC_signature_verify_message_final_fn *verify_message_final;
+#endif
OSSL_FUNC_signature_verify_recover_init_fn *verify_recover_init;
OSSL_FUNC_signature_verify_recover_fn *verify_recover;
OSSL_FUNC_signature_digest_sign_init_fn *digest_sign_init;
@@ -330,8 +358,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_asym_cipher_newctx_fn *newctx;
OSSL_FUNC_asym_cipher_encrypt_init_fn *encrypt_init;
OSSL_FUNC_asym_cipher_encrypt_fn *encrypt;
@@ -384,7 +413,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
+#endif
OSSL_FUNC_keyexch_newctx_fn *newctx;
OSSL_FUNC_keyexch_init_fn *init;
diff --git a/src/uadk_prov_rsa_enc.c b/src/uadk_prov_rsa_enc.c
index 50005f9..c0da4c9 100644
--- a/src/uadk_prov_rsa_enc.c
+++ b/src/uadk_prov_rsa_enc.c
@@ -44,7 +44,10 @@ struct PROV_RSA_ASYM_CTX {
/* TLS padding */
unsigned int client_version;
unsigned int alt_version;
-
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ /* PKCS#1 v1.5 decryption mode */
+ unsigned int implicit_rejection;
+# endif
unsigned int soft : 1;
};
diff --git a/src/uadk_prov_rsa_sign.c b/src/uadk_prov_rsa_sign.c
index 4db3ab7..8483b2e 100644
--- a/src/uadk_prov_rsa_sign.c
+++ b/src/uadk_prov_rsa_sign.c
@@ -44,6 +44,9 @@ struct PROV_RSA_SIG_CTX {
*/
unsigned int flag_allow_md : 1;
unsigned int mgf1_md_set : 1;
+ unsigned int flag_allow_update : 1;
+ unsigned int flag_allow_final : 1;
+ unsigned int flag_allow_oneshot : 1;
/* main digest */
EVP_MD *md;
@@ -61,6 +64,10 @@ struct PROV_RSA_SIG_CTX {
int saltlen;
/* Minimum salt length or -1 if no PSS parameter restriction */
int min_saltlen;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ unsigned char *sig;
+ size_t siglen;
+#endif
/* Temp buffer */
unsigned char *tbuf;
diff --git a/src/uadk_prov_sm2_sign.c b/src/uadk_prov_sm2_sign.c
index 27627c1..aa7049e 100644
--- a/src/uadk_prov_sm2_sign.c
+++ b/src/uadk_prov_sm2_sign.c
@@ -61,8 +61,10 @@ typedef struct {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
- size_t aid_len;
+#endif
+ size_t aid_len;
/* main digest */
EVP_MD *md;
@@ -755,6 +757,7 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
void *ec, const OSSL_PARAM params[])
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
int md_nid;
WPACKET pkt;
@@ -784,9 +787,11 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, psm2ctx->key, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &psm2ctx->aid_len);
- psm2ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && psm2ctx->aid_len)
+ memmove(psm2ctx->aid_buf, aid, psm2ctx->aid_len);
if (!EVP_DigestInit_ex2(psm2ctx->mdctx, psm2ctx->md, params)) {
UADK_ERR("failed to do digest init\n");
@@ -1240,6 +1245,7 @@ static const OSSL_PARAM *uadk_signature_sm2_gettable_ctx_params(ossl_unused void
static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
if (!psm2ctx) {
@@ -1247,8 +1253,10 @@ static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
return UADK_P_FAIL;
}
+ if (psm2ctx->aid_len)
+ aid = psm2ctx->aid_buf;
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
- if (p && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len)) {
+ if (p != NULL && !OSSL_PARAM_set_octet_string(p, aid, psm2ctx->aid_len)) {
UADK_ERR("failed to locate algorithm id\n");
return UADK_P_FAIL;
}
--
2.33.0
1
0
[PATCH 00/11] uadk: Fixing compression-related issues and functional enhancements
by ZongYu Wu 27 Apr '26
by ZongYu Wu 27 Apr '26
27 Apr '26
This patch set primarily fixes multiple issues related to compression in the uadk driver and adds some functional enhancements.
Main fixes include:
- Resolving the compression status issue when the storage buffer is not cleared
- Moving the tail packet append function to the hisi_comp.c file
- Removing redundant print information in v1/hisi_zip_udrv
- Fixing the hashjoin key alignment size issue
- Cleaning up wd_agg code
- Addressing some code parameter issues
- Fixing large number comparison issues
- Correcting the HPRE parameter comparison method
- Supporting empty final blocks in stream mode
- Fixing long timeout issues in synchronous mode when a device failure occurs.
Chenghai Huang (4):
uadk: clear the literal length in the ctx of all LZ77 algorithms
uadk: fix the status of compression when store buffer is not yet
cleared
uadk: move tail packet appending function to hisi_comp.c
uadk: delete redundant print messages for v1/hisi_zip_udrv
Longfang Liu (3):
uadk: bugfix some code parameter issues.
uadk: bugfix big number comparison issues
uadk: bugfix HPRE parameter comparison method
Wenkai Lin (2):
uadk: fix for hashjoin key align size
uadk: clean code for wd_agg
ZongYu Wu (1):
uadk: support empty final block for raw DEFLATE in stream mode
lizhi (1):
uadk/v1: fix long timeout of asymmetric algorithm in sync mode during
device failure
drv/hisi_comp.c | 111 +++++++++++++++++++++++++++++--------
drv/hisi_dae_join_gather.c | 2 +-
drv/hisi_hpre.c | 23 +++++---
drv/hisi_sec.c | 2 +-
include/drv/wd_comp_drv.h | 2 +
include/wd_internal.h | 2 +
libwd.map | 1 +
v1/drv/hisi_zip_udrv.c | 33 ++++-------
v1/wd_dh.c | 12 ++--
v1/wd_ecc.c | 12 ++--
v1/wd_rsa.c | 14 +++--
v1/wd_util.c | 31 +++++++++++
v1/wd_util.h | 2 +
wd.c | 19 +++++++
wd_aead.c | 4 +-
wd_agg.c | 34 ++++++------
wd_cipher.c | 2 +-
wd_comp.c | 72 +-----------------------
wd_join_gather.c | 2 +-
19 files changed, 218 insertions(+), 162 deletions(-)
--
2.33.0
1
11
From: Junchong Pan <panjunchong(a)h-partners.com>
Signed-off-by: Junchong Pan <panjunchong(a)h-partners.com>
---
Makefile.am | 2 +-
test/hisi_hpre_test/Makefile.am | 1 +
uadk_tool/Makefile.am | 14 +-
uadk_tool/benchmark/sec_soft3_benchmark.c | 1431 +++++++++++++++++++++
uadk_tool/benchmark/sec_soft3_benchmark.h | 8 +
uadk_tool/benchmark/uadk_benchmark.c | 18 +-
uadk_tool/test/comp_lib.c | 21 +-
uadk_tool/test/comp_lib.h | 10 +
uadk_tool/test/comp_main.c | 8 +-
uadk_tool/test/uadk_test.c | 4 +-
10 files changed, 1499 insertions(+), 18 deletions(-)
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.c
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.h
diff --git a/Makefile.am b/Makefile.am
index 84c97e9..fe619f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CFLAGS=-std=gnu11 -Wall -Werror -Wextra -Wno-unused-parameter -Wfloat-equal \
-fno-common -fno-strict-aliasing -I$(top_srcdir)/include
AM_CFLAGS+=-fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
- -O2 -ftrapv -Wl,-z,relro,-z,now -Wl,-s
+ -O0 -ftrapv -Wl,-z,relro,-z,now -g
AM_CFLAGS += -Wall -Wuninitialized -Wno-error -Wno-error=format -Wundef \
-Wunused -Wdate-time -Wfloat-equal -Wshadow -Wvla -Wdisabled-optimization \
-Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wtype-limits \
diff --git a/test/hisi_hpre_test/Makefile.am b/test/hisi_hpre_test/Makefile.am
index 6cc8a37..e32ac95 100644
--- a/test/hisi_hpre_test/Makefile.am
+++ b/test/hisi_hpre_test/Makefile.am
@@ -14,5 +14,6 @@ endif
test_hisi_hpre_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR
+test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto.so.3
test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto_wd.so
endif
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6fd9d95..ee7dea4 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,9 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
-AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
+AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
-pthread
AM_CFLAGS += -fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
--O2 -ftrapv -Wl,-z,now -Wl,-s
+-O0 -ftrapv -Wl,-z,now -g
#AUTOMAKE_OPTIONS = subdir-objects
@@ -50,14 +50,18 @@ endif
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR -I$(with_openssl_dir)/include
+AM_CFLAGS+= -DHAVE_OPENSSL3=$(shell echo '#include <openssl/opensslv.h>' | \
+ $(CC) -E -I$(with_openssl_dir)/include - | grep 'OPENSSL_VERSION_MAJOR' | sed 's/#define OPENSSL_VERSION_MAJOR //')
+
+uadk_tool_SOURCES+=test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
+# uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h
+uadk_tool_SOURCES+=benchmark/sec_soft3_benchmark.c benchmark/sec_soft3_benchmark.h
-uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h \
- test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
if WD_STATIC_DRV
uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.a
else
-uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.1.1
+uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.3
endif
endif
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.c b/uadk_tool/benchmark/sec_soft3_benchmark.c
new file mode 100644
index 0000000..8d40074
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.c
@@ -0,0 +1,1431 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#define _GNU_SOURCE
+#include "openssl/async.h"
+#include "openssl/bn.h"
+#include "openssl/crypto.h"
+#include "openssl/engine.h"
+#include "openssl/err.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+#include "openssl/objects.h"
+#include "openssl/ssl.h"
+#include "openssl/provider.h"
+#include "openssl/x509.h"
+#include "openssl/param_build.h"
+
+#include "include/wd_cipher.h"
+#include "include/wd_digest.h"
+#include "sec_soft3_benchmark.h"
+
+#define SSL_TST_PRT printf
+#define ENV_STRING_LEN 256
+
+struct soft_bd {
+ u8 *src;
+ u8 *dst;
+};
+
+struct bd_pool {
+ struct soft_bd *bds;
+};
+
+struct thread_pool {
+ struct bd_pool *pool;
+ u8 *iv;
+ u8 *key;
+} g_soft_pool;
+
+typedef struct soft_thread_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 engine_flag;
+ u32 sync_mode;
+} soft_thread;
+
+typedef struct soft_jobs_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 jobid;
+} jobs_data;
+
+typedef struct soft_loop_args {
+ ASYNC_JOB *in_job;
+ ASYNC_WAIT_CTX *wait_ctx;
+ bool job_valid;
+} jobs_args;
+
+#define MAX_IVK_LENTH 64
+#define DEF_IVK_DATA 0xAA
+#define MAX_JOBS_NUM MAX_CTX_NUM
+
+static unsigned int g_thread_num;
+static unsigned int g_jobsnum;
+static unsigned int g_pktlen;
+
+static int init_soft_bd_pool(void)
+{
+ unsigned long step;
+ int fill_size;
+ int i, j;
+
+ // make the block not align to 4K
+ step = sizeof(char) * g_pktlen * 2;
+ if (g_pktlen > MAX_IVK_LENTH)
+ fill_size = MAX_IVK_LENTH;
+ else
+ fill_size = g_pktlen;
+
+ g_soft_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+ g_soft_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+
+ g_soft_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
+ if (!g_soft_pool.pool) {
+ SSL_TST_PRT("init openssl pool alloc thread failed!\n");
+ return -ENOMEM;
+ } else {
+ for (i = 0; i < g_thread_num; i++) {
+ g_soft_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
+ sizeof(struct soft_bd));
+ if (!g_soft_pool.pool[i].bds) {
+ SSL_TST_PRT("init openssl bds alloc failed!\n");
+ goto malloc_error1;
+ }
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ g_soft_pool.pool[i].bds[j].src = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].src)
+ goto malloc_error2;
+ g_soft_pool.pool[i].bds[j].dst = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].dst)
+ goto malloc_error3;
+
+ get_rand_data(g_soft_pool.pool[i].bds[j].src, fill_size);
+ }
+ }
+ }
+
+ return 0;
+
+malloc_error3:
+ free(g_soft_pool.pool[i].bds[j].src);
+malloc_error2:
+ for (j--; j >= 0; j--) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+malloc_error1:
+ for (i--; i >= 0; i--) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+
+ SSL_TST_PRT("init openssl bd pool alloc failed!\n");
+ return -ENOMEM;
+}
+
+static void free_soft_bd_pool(void)
+{
+ int i, j;
+
+ for (i = 0; i < g_thread_num; i++) {
+ if (g_soft_pool.pool[i].bds) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+}
+
+/*-------------------------------openssl benchmark main code-------------------------------------*/
+static int sec_soft_param_parse(soft_thread *tddata, struct acc_option *options)
+{
+ u32 algtype = options->algtype;
+ u32 optype = options->optype;
+ u8 keysize = 0;
+ u8 mode;
+
+ tddata->evp_cipher = NULL;
+ tddata->evp_md = NULL;
+
+ switch(algtype) {
+ case AES_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_128_ecb();
+ break;
+ case AES_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_192_ecb();
+ break;
+ case AES_256_ECB:
+ keysize = 32;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_256_ecb();
+ break;
+ case AES_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+ case AES_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_128_ctr();
+ break;
+ case AES_192_CTR:
+ keysize = 24;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_192_ctr();
+ break;
+ case AES_256_CTR:
+ keysize = 32;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_256_ctr();
+ break;
+ case AES_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_128_ofb();
+ break;
+ case AES_192_OFB:
+ keysize = 24;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_192_ofb();
+ break;
+ case AES_256_OFB:
+ keysize = 32;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_256_ofb();
+ break;
+ case AES_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_128_cfb();
+ break;
+ case AES_192_CFB:
+ keysize = 24;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_192_cfb();
+ break;
+ case AES_256_CFB:
+ keysize = 32;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_256_cfb();
+ break;
+ case AES_256_XTS:
+ keysize = 32;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_128_xts();
+ break;
+ case AES_512_XTS:
+ keysize = 64;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_256_xts();
+ break;
+ case DES3_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede_ecb();
+ break;
+ case DES3_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede3_ecb();
+ break;
+ case DES3_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede_cbc();
+ break;
+ case DES3_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede3_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_sm4_ecb();
+ break;
+ case SM4_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_sm4_cbc();
+ break;
+ case SM4_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_sm4_ctr();
+ break;
+ case SM4_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_sm4_ofb();
+ break;
+ case SM4_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_sm4_cfb128();
+ break;
+ case SM4_128_XTS:
+ keysize = 16;
+ mode = WD_CIPHER_XTS;
+ break;
+#endif
+ case AES_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_128_ccm();
+ break;
+ case AES_192_CCM:
+ keysize = 24;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_192_ccm();
+ break;
+ case AES_256_CCM:
+ keysize = 32;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_256_ccm();
+ break;
+ case AES_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_128_gcm();
+ break;
+ case AES_192_GCM:
+ keysize = 24;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_192_gcm();
+ break;
+ case AES_256_GCM:
+ keysize = 32;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_256_gcm();
+ break;
+ case AES_128_CBC_SHA256_HMAC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC_SHA256_HMAC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC_SHA256_HMAC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ break;
+ case SM4_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ break;
+#endif
+ case SM3_ALG: // digest mode is optype
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sm3();
+ break;
+ case MD5_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_md5();
+ break;
+ case SHA1_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha1();
+ break;
+ case SHA256_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha256();
+ break;
+ case SHA224_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha224();
+ break;
+ case SHA384_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha384();
+ break;
+ case SHA512_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512();
+ break;
+ case SHA512_224:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_224();
+ break;
+ case SHA512_256:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_256();
+ break;
+ default:
+ SSL_TST_PRT("Fail to set sec alg\n");
+ return -EINVAL;
+ }
+
+ tddata->mode = mode;
+ tddata->keysize = keysize;
+ tddata->optype = options->optype;
+ tddata->subtype = options->subtype;
+
+ return 0;
+}
+
+static int sec_soft_cipher_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 count = 0;
+ u8 *src, *dst;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[4];
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+
+ params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+ params[2] = OSSL_PARAM_construct_int("padding", 0);
+ params[3] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+static int sec_soft_aead_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u8 aad[13] = {0xcc};
+ u8 in_tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ size_t taglen = 0;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM core_params[5];
+ int iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+
+ memset(core_params, 0, sizeof(core_params));
+
+ core_params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, key_len);
+ core_params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+
+ core_params[2] = OSSL_PARAM_construct_int("padding", 0);
+ core_params[3] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (jdata->mode == WD_CIPHER_CCM) {
+
+ taglen = 12;
+ OSSL_PARAM ccm_specific_params[3];
+ ccm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ int ccm_l = (iv_len - 1) - 1;
+ ccm_specific_params[1] = OSSL_PARAM_construct_int("L", &ccm_l);
+ ccm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, ccm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: CCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+ } else {
+
+ taglen = 16;
+ OSSL_PARAM gcm_specific_params[3];
+ gcm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ if (optype) {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", in_tag, sizeof(in_tag));
+ } else {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", out_tag, 0);
+ }
+ gcm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, gcm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params(aad) failed\n");
+ break;
+ }
+ }
+
+ if (!optype && jdata->mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+
+static int sec_soft_digest_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_MD *evp_md = jdata->evp_md;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ EVP_MD_CTX *md_ctx;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 ssl_size = 0;
+ u8 *priv_key, *src;
+ u32 count = 0;
+ size_t required_len = 0;
+ int i;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_md) {
+ SSL_TST_PRT("Error: openssl evp_md not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_DigestInit_ex2(md_ctx, evp_md, params);
+ EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+ EVP_MD_CTX_free(md_ctx);
+
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_MAC_init(m_ctx, priv_key, jdata->keysize, params);
+ EVP_MAC_update(m_ctx, src, g_pktlen);
+ EVP_MAC_final(m_ctx, mac, &required_len, EVP_MAX_MD_SIZE);
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+static void *sec_soft_async_run(void *arg)
+{
+ typedef int (*sec_soft_run)(void *arg);
+ sec_soft_run sec_soft_jobfunc = NULL;
+ soft_thread *pdata = (soft_thread *)arg;
+ jobs_args loop_jobs[MAX_JOBS_NUM];
+ OSSL_ASYNC_FD waitfd = 0;
+ jobs_data jobdata;
+ fd_set waitfdset;
+ size_t numfds = 0;
+ int i, j, k, ret;
+ int jobret = 0;
+ u32 valid_jobs = 0;
+ u32 jobs_num;
+
+ jobdata.evp_cipher = pdata->evp_cipher;
+ jobdata.evp_md = pdata->evp_md;
+ jobdata.keysize = pdata->keysize;
+ jobdata.mode = pdata->mode;
+ jobdata.optype = pdata->optype;
+ jobdata.subtype = pdata->subtype;
+ jobdata.td_id = pdata->td_id;
+ jobdata.engine = pdata->engine;
+
+ jobs_num = g_jobsnum;
+ if (jobs_num > MAX_JOBS_NUM) {
+ SSL_TST_PRT("Error: check async jobs num failed.\n");
+ return NULL;
+ }
+ memset(loop_jobs, 0x0, sizeof(jobs_args) * MAX_JOBS_NUM);
+
+ switch (pdata->subtype) {
+ case CIPHER_TYPE:
+ sec_soft_jobfunc = sec_soft_cipher_jobfunc;
+ break;
+ case AEAD_TYPE:
+ sec_soft_jobfunc = sec_soft_aead_jobfunc;
+ break;
+ case DIGEST_TYPE:
+ sec_soft_jobfunc = sec_soft_digest_jobfunc;
+ break;
+ }
+
+ /* one thread for one job */
+ for (i = 0; i < jobs_num; i++) {
+ loop_jobs[i].wait_ctx = ASYNC_WAIT_CTX_new();
+ if (!loop_jobs[i].wait_ctx) {
+ SSL_TST_PRT("Error: create ASYNC_WAIT_CTX failed\n");
+ goto async_error;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ SSL_TST_PRT("Error: start soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ loop_jobs[i].job_valid = true;
+ valid_jobs++;
+ break;
+ case ASYNC_FINISH:
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+
+ j = valid_jobs;
+ while (j > 0) {
+ for (i = 0; i < jobs_num; i++) {
+ FD_ZERO(&waitfdset);
+ if (!loop_jobs[i].job_valid)
+ continue;
+
+ /* Wait for the job to be woken */
+ if (!ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, NULL, &numfds) ||
+ numfds > 1) {
+ SSL_TST_PRT("Error: unexpected number of fds.\n");
+ continue;
+ }
+ ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, &waitfd, &numfds);
+
+ FD_SET(waitfd, &waitfdset);
+ ret = select(waitfd + 1, &waitfdset, NULL, NULL, NULL);
+ if (ret == -1) {
+ SSL_TST_PRT("Error: select soft async job error.\n");
+ goto async_finish;
+ } else if (ret == 0 || (ret == -1 && errno == EINTR)) {
+ SSL_TST_PRT("Infor: select soft async job result continue.\n");
+ continue;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ loop_jobs[i].job_valid = false;
+ j--;
+ SSL_TST_PRT("Error: restart soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ break;
+ case ASYNC_FINISH:
+ loop_jobs[i].job_valid = false;
+ j--;
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+ }
+
+async_finish:
+ i = jobs_num;
+async_error:
+ for (k = 0; k < i; k++)
+ ASYNC_WAIT_CTX_free(loop_jobs[k].wait_ctx);
+
+ add_send_complete();
+
+ return NULL;
+}
+
+static void *sec_soft_cipher_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret;
+ int outl = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+ while (1) {
+ u32 local_count = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[local_count].src;
+ dst = soft_pool->bds[local_count].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_aead_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ u32 mode = pdata->mode;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u8 aad[13] = {0xcc};
+ u8 tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret, i;
+ int outl = 0;
+ size_t taglen = 0;
+ int ccm_l = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM params[10];
+ int param_idx = 0;
+
+ params[param_idx++] = OSSL_PARAM_construct_utf8_string("cipher", (char *)EVP_CIPHER_get0_name(evp_cipher), 0);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("iv", priv_iv, EVP_CIPHER_get_iv_length(evp_cipher));
+
+ if (mode == WD_CIPHER_CCM) {
+ taglen = 12;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ } else {
+ taglen = 16;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ }
+ params[param_idx++] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ ret = EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ } else {
+ ret = EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ }
+
+ if (optype) {
+ OSSL_PARAM tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", tag, sizeof(tag)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, tag_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(tag) failed on decrypt\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on decrypt\n");
+ break;
+ }
+
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+
+ } else {
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on encrypt\n");
+ break;
+ }
+
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (!optype && mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_digest_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ const EVP_MD *evp_md = pdata->evp_md;
+ u32 optype = pdata->optype;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ struct bd_pool *soft_pool;
+ EVP_MD_CTX *md_ctx = NULL;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ u8 *priv_key, *src;
+ size_t mac_size = 0;
+ u32 count = 0;
+ int i;
+ int ret = 0;
+ u32 ssl_size = 0;
+
+ if (!evp_cipher && !evp_md) {
+ SSL_TST_PRT("Error: openssl not support! No cipher or md provided.\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return NULL;
+ }
+
+ OSSL_PARAM digest_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_DigestInit_ex2(md_ctx, evp_md, digest_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestInit_ex2 failed\n");
+ break;
+ }
+
+ ret = EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestUpdate failed\n");
+ break;
+ }
+
+ ret = EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestFinal_ex failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MD_CTX_free(md_ctx);
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ if (!f_mac) {
+ SSL_TST_PRT("Error: EVP_MAC_fetch(HMAC) failed\n");
+ return NULL;
+ }
+
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return NULL;
+ }
+
+ OSSL_PARAM mac_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0),
+ OSSL_PARAM_construct_octet_string("key", priv_key, pdata->keysize),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_MAC_init(m_ctx, priv_key, pdata->keysize, mac_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_init failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_update(m_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_update failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_final(m_ctx, mac, &mac_size, sizeof(mac));
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_final failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ if(optype && !f_mac) {
+ return NULL;
+ }
+ if(!optype && !md_ctx) {
+ return NULL;
+ }
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void uadk_engine_set_env(soft_thread *options)
+{
+ char env_string[ENV_STRING_LEN] = {0};
+ char *var_name = NULL;
+
+ switch(options->subtype) {
+ case CIPHER_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case AEAD_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case DIGEST_TYPE:
+ var_name = "WD_DIGEST_CTX_NUM";
+ break;
+ default:
+ return;
+ }
+
+ unsetenv(var_name);
+
+ /* uadk will request ctxs from env param */
+ if (options->sync_mode) // async mode
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "async:", g_jobsnum,"@0,async:", g_jobsnum, "@2");
+ else
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "sync:", g_jobsnum,"@0,sync:", g_jobsnum, "@2");
+ (void)setenv(var_name, env_string, 1);
+}
+
+static int uadk_provider_register(soft_thread *options, char *engine_name)
+{
+ if (!options->engine_flag)
+ return 0;
+
+ /* Set env param for uadk engine */
+ uadk_engine_set_env(options);
+ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+
+ options->engine = OSSL_PROVIDER_load(NULL, engine_name);
+ if (!options->engine) {
+ SSL_TST_PRT("setup uadk engine failed!\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void uadk_provider_unregister(soft_thread *options)
+{
+ if (!options->engine_flag)
+ return;
+
+ if (options->engine) {
+ OSSL_PROVIDER_unload(options->engine);
+ options->engine = NULL;
+ }
+}
+
+int sec_soft_sync_threads(struct acc_option *options)
+{
+ typedef void *(*sec_sync_run)(void *arg);
+ sec_sync_run soft_sec_sync_run = NULL;
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+
+ switch (options->subtype) {
+ case CIPHER_TYPE:
+ SSL_TST_PRT(" --- CIPHER_TYPE\n");
+ soft_sec_sync_run = sec_soft_cipher_sync;
+ break;
+ case AEAD_TYPE:
+ SSL_TST_PRT(" --- AEAD_TYPE\n");
+ soft_sec_sync_run = sec_soft_aead_sync;
+ break;
+ case DIGEST_TYPE:
+ SSL_TST_PRT(" --- DIGEST_TYPE\n");
+ soft_sec_sync_run = sec_soft_digest_sync;
+ break;
+ }
+
+
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, soft_sec_sync_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+sync_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft_async_threads(struct acc_option *options)
+{
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, sec_soft_async_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+async_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft3_benchmark(struct acc_option *options)
+{
+ u32 ptime;
+ int ret;
+
+ signal(SIGSEGV, segmentfault_handler);
+ g_thread_num = options->threads;
+ g_pktlen = options->pktlen;
+ g_jobsnum = options->ctxnums;
+ if (options->optype > WD_CIPHER_DECRYPTION) {
+ SSL_TST_PRT("SEC optype error: %u\n", options->optype);
+ return -EINVAL;
+ }
+
+ ret = init_soft_bd_pool();
+ if (ret)
+ return ret;
+
+ get_pid_cpu_time(&ptime);
+ time_start(options->times);
+ if (options->syncmode)
+ ret = sec_soft_async_threads(options);
+ else
+ ret = sec_soft_sync_threads(options);
+ cal_perfermance_data(options, ptime);
+ if (ret)
+ return ret;
+
+ free_soft_bd_pool();
+
+ return 0;
+}
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.h b/uadk_tool/benchmark/sec_soft3_benchmark.h
new file mode 100644
index 0000000..f10bcb2
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+#ifndef SEC_SOFT3_BENCHMARK_H
+#define SEC_SOFT3_BENCHMARK_H
+
+#include "uadk_benchmark.h"
+
+extern int sec_soft3_benchmark(struct acc_option *options);
+#endif /* SEC_SOFT_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index d8f066f..756c3ad 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -8,7 +8,11 @@
#include "uadk_benchmark.h"
#include "sec_uadk_benchmark.h"
#include "sec_wd_benchmark.h"
-#include "sec_soft_benchmark.h"
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// #include "sec_soft_benchmark.h"
+// # else
+#include "sec_soft3_benchmark.h"
+// # endif
#include "hpre_uadk_benchmark.h"
#include "hpre_wd_benchmark.h"
@@ -568,11 +572,17 @@ static int benchmark_run(struct acc_option *option)
ret = sec_wd_benchmark(option);
}
usleep(20000);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// if (option->modetype == SOFT_MODE) {
+// ret = sec_soft_benchmark(option);
+// }
+// # else
if (option->modetype == SOFT_MODE) {
- ret = sec_soft_benchmark(option);
+ ret = sec_soft3_benchmark(option);
}
-#endif
+// # endif
+// #endif
break;
case HPRE_TYPE:
if (option->modetype == SVA_MODE) {
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c
index 014aa98..39bc526 100644
--- a/uadk_tool/test/comp_lib.c
+++ b/uadk_tool/test/comp_lib.c
@@ -10,6 +10,12 @@
#include <math.h>
#include <sys/mman.h>
#include <zlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+// #include "openssl/md5.h"
+
+
#include "comp_lib.h"
@@ -255,9 +261,18 @@ int calculate_md5(comp_md5_t *md5, const void *buf, size_t len)
{
if (!md5 || !buf || !len)
return -EINVAL;
+
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_Init(&md5->md5_ctx);
MD5_Update(&md5->md5_ctx, buf, len);
MD5_Final(md5->md, &md5->md5_ctx);
+# else
+ md5->ctx = EVP_MD_CTX_new();
+ EVP_DigestInit_ex2(md5->ctx, EVP_md5(), NULL);
+ EVP_DigestUpdate(md5->ctx, buf, len);
+ EVP_DigestFinal_ex(md5->ctx, md5->md, NULL);
+ EVP_MD_CTX_free(md5->ctx);
+# endif
return 0;
}
@@ -425,7 +440,7 @@ static int chunk_inflate(void *in, size_t in_sz, void *out, size_t *out_sz,
do {
ret = inflate(&strm, Z_NO_FLUSH);
if ((ret < 0) || (ret == Z_NEED_DICT)) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, strm.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, strm.msg, __func__);
goto out;
}
if (!strm.avail_out) {
@@ -1319,7 +1334,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked,
do {
ret = inflate(&stream, Z_NO_FLUSH);
if (ret < 0 || ret == Z_NEED_DICT) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
}
@@ -1387,7 +1402,7 @@ int zlib_deflate(void *output, unsigned int out_size,
do {
ret = deflate(&stream, Z_FINISH);
if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
} else if (!stream.avail_in) {
diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h
index c37a226..9eb7a31 100644
--- a/uadk_tool/test/comp_lib.h
+++ b/uadk_tool/test/comp_lib.h
@@ -22,6 +22,12 @@
#include "include/wd_comp.h"
#include "include/wd_sched.h"
+# if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include "openssl/opensslv.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+# endif
+
#define SYS_ERR_COND(cond, msg, ...) \
do { \
if (cond) { \
@@ -120,7 +126,11 @@ struct test_options {
};
typedef struct _comp_md5_t {
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_CTX md5_ctx;
+# else
+ EVP_MD_CTX *ctx;
+# endif
unsigned char md[MD5_DIGEST_LENGTH];
} comp_md5_t;
diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c
index 24f52d2..81b213a 100644
--- a/uadk_tool/test/comp_main.c
+++ b/uadk_tool/test/comp_main.c
@@ -86,7 +86,7 @@ static void *sw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tout_sz;
@@ -230,7 +230,7 @@ static void *hw_dfl_sw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz;
@@ -374,7 +374,7 @@ static void *hw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz, tout_sz;
@@ -886,6 +886,7 @@ static int test_hw(struct test_options *opts, char *model)
goto out_src;
opts->total_len = statbuf.st_size;
info.in_size = opts->total_len;
+ COMP_TST_PRT("in_size : %d\n", info.in_size);
if (ifl_flag)
info.out_size = opts->total_len * INFLATION_RATIO;
else
@@ -898,6 +899,7 @@ static int test_hw(struct test_options *opts, char *model)
if (opts->is_file) {
ret = load_file_data(&info);
+ COMP_TST_PRT("file_size : %d\n", ret);
if (ret < 0)
goto out_buf;
} else {
diff --git a/uadk_tool/test/uadk_test.c b/uadk_tool/test/uadk_test.c
index 536861a..aa885d1 100644
--- a/uadk_tool/test/uadk_test.c
+++ b/uadk_tool/test/uadk_test.c
@@ -63,10 +63,10 @@ void acc_test_run(int argc, char *argv[])
(void)test_hpre_entry(argc, argv);
} else if (!strcmp(input_module, "sec")) {
(void)test_sec_entry(argc, argv);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
} else if (!strcmp(input_module, "zip")) {
(void)test_comp_entry(argc, argv);
-#endif
+// #endif
} else {
print_test_help();
printf("failed to parse module parameter!\n");
--
2.33.0
1
0