!79 libwd: update the source code
From: @xiao_jiang_shui Reviewed-by: @hao-fang Signed-off-by: @hao-fang
This commit is contained in:
commit
d51c3d5d63
33
0001-uadk-comp-fix-duplicate-release-of-comp.patch
Normal file
33
0001-uadk-comp-fix-duplicate-release-of-comp.patch
Normal file
@ -0,0 +1,33 @@
|
||||
From 20035bf190f89b6c8cac7e8e2d2d423add618b31 Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Thu, 15 Jun 2023 11:01:15 +0800
|
||||
Subject: [PATCH 01/26] uadk/comp: fix duplicate release of comp
|
||||
|
||||
In the current version, when the resource of comp is destroyed,
|
||||
there is no effective blanking operation for setting's priv
|
||||
|
||||
therefore, this operation needs to be performed directly on
|
||||
the priv of the setting.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
wd_comp.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 671baba..a8180c1 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -169,7 +169,8 @@ static int wd_comp_uninit_nolock(void)
|
||||
wd_clear_sched(&wd_comp_setting.sched);
|
||||
|
||||
wd_alg_uninit_driver(&wd_comp_setting.config,
|
||||
- wd_comp_setting.driver, &priv);
|
||||
+ wd_comp_setting.driver,
|
||||
+ &wd_comp_setting.priv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
47
0002-uadk_tool-use-DT_RUNPATH-instead-of-DT_RPATH.patch
Normal file
47
0002-uadk_tool-use-DT_RUNPATH-instead-of-DT_RPATH.patch
Normal file
@ -0,0 +1,47 @@
|
||||
From f30ffb911d097df62cf2d532d97e4bf65efadbec Mon Sep 17 00:00:00 2001
|
||||
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
Date: Fri, 19 May 2023 10:17:50 +0000
|
||||
Subject: [PATCH 02/26] uadk_tool: use DT_RUNPATH instead of DT_RPATH
|
||||
|
||||
Search dynamic lib sequence
|
||||
1. DT_RPATH: -Wl,-rpath,'/usr/local/lib'
|
||||
2. LD_LIBRARY_PATH
|
||||
3. DT_RUNPATH: -Wl,-rpath,'/usr/local/lib',--enable-new-dtags
|
||||
|
||||
If using DT_RPATH, LD_LIBRARY_PATH will be ignored, and uadk_tool
|
||||
will always search libwd.so under /usr/local/lib, except rm it.
|
||||
|
||||
If remove DT_RPATH, LD_LIBRARY_PATH has to be provided even when
|
||||
library is under /usr/local/lib
|
||||
|
||||
So use DT_RUNPATH, if LD_LIBRARY_PATH is provide, use it
|
||||
If LD_LIBRARY_PATH is not provide, use the default DT_RUNPAT.
|
||||
|
||||
Example
|
||||
./test.sh
|
||||
wd_get_lib_file_path file_path=/usr/local/lib/libwd_crypto.so.2
|
||||
|
||||
LD_LIBRARY_PATH=/tmp/build/lib ./test.sh
|
||||
wd_get_lib_file_path file_path=/tmp/build/lib/libwd_crypto.so.2
|
||||
|
||||
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
---
|
||||
uadk_tool/Makefile.am | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
|
||||
index 6d0450e..62372d8 100644
|
||||
--- a/uadk_tool/Makefile.am
|
||||
+++ b/uadk_tool/Makefile.am
|
||||
@@ -32,7 +32,7 @@ uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \
|
||||
-l:libwd_comp.so.2 -lnuma
|
||||
endif
|
||||
|
||||
-uadk_tool_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
+uadk_tool_LDFLAGS=-Wl,-rpath,'/usr/local/lib',--enable-new-dtags
|
||||
|
||||
if WITH_ZLIB_FSE_DIR
|
||||
AM_CFLAGS += -DZLIB_FSE
|
||||
--
|
||||
2.25.1
|
||||
|
||||
28
0003-uadk-cipher-fix-wd_cipher_init2-typo.patch
Normal file
28
0003-uadk-cipher-fix-wd_cipher_init2-typo.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 6639d6598a1629b55dcc08652f995975d7df92a4 Mon Sep 17 00:00:00 2001
|
||||
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
Date: Tue, 27 Jun 2023 15:13:05 +0000
|
||||
Subject: [PATCH 03/26] uadk/cipher: fix wd_cipher_init2 typo
|
||||
|
||||
The wd_cipher_init2 should define as wd_cipher_init2_
|
||||
|
||||
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
---
|
||||
include/wd_cipher.h | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
|
||||
index 46d3d31..8f043fd 100644
|
||||
--- a/include/wd_cipher.h
|
||||
+++ b/include/wd_cipher.h
|
||||
@@ -127,7 +127,7 @@ void wd_cipher_uninit(void);
|
||||
int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
|
||||
#define wd_cipher_init2(alg, sched_type, task_type) \
|
||||
- wd_cipher_init2(alg, sched_type, task_type, NULL)
|
||||
+ wd_cipher_init2_(alg, sched_type, task_type, NULL)
|
||||
|
||||
/**
|
||||
* wd_cipher_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
--
|
||||
2.25.1
|
||||
|
||||
29
0004-uadk-v1-fix-local-variable-type.patch
Normal file
29
0004-uadk-v1-fix-local-variable-type.patch
Normal file
@ -0,0 +1,29 @@
|
||||
From 94eb6ed029e2ee01d57339beb6153b6627a9765b Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 10 Jul 2023 11:41:08 +0800
|
||||
Subject: [PATCH 04/26] uadk/v1 - fix local variable type
|
||||
|
||||
The return type of 'wd_reg_read' is '__u32'. Therefore,
|
||||
change the local variable 'ret' type from 'int' to '__u32'.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_rng_udrv.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
|
||||
index b86a948..09fa2c3 100644
|
||||
--- a/v1/drv/hisi_rng_udrv.c
|
||||
+++ b/v1/drv/hisi_rng_udrv.c
|
||||
@@ -94,7 +94,7 @@ static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg)
|
||||
__u32 max = msg->in_bytes;
|
||||
__u32 currsize = 0;
|
||||
int recv_count = 0;
|
||||
- int val;
|
||||
+ __u32 val;
|
||||
|
||||
do {
|
||||
val = wd_reg_read((void *)((uintptr_t)info->mmio_base +
|
||||
--
|
||||
2.25.1
|
||||
|
||||
43
0005-drv-qm-fix-memory-leak-in-hisi_qm_create_sglpool.patch
Normal file
43
0005-drv-qm-fix-memory-leak-in-hisi_qm_create_sglpool.patch
Normal file
@ -0,0 +1,43 @@
|
||||
From 0c9553324e815f7a2814b223d28c1b29ab4f4011 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 10 Jul 2023 11:47:16 +0800
|
||||
Subject: [PATCH 05/26] drv/qm: fix memory leak in hisi_qm_create_sglpool()
|
||||
|
||||
In 'hisi_qm_create_sglpool()', if 'hisi_qm_create_sgl() failed',
|
||||
current 'sgl_pool->sgl_num == 0', the 'hisi_qm_free_sglpool()'
|
||||
cannot release the applied sgl.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_qm_udrv.c | 7 ++++---
|
||||
1 file changed, 4 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index acc2877..d86a692 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -648,8 +648,7 @@ static void hisi_qm_free_sglpool(struct hisi_sgl_pool *pool)
|
||||
|
||||
if (pool->sgl) {
|
||||
for (i = 0; i < pool->sgl_num; i++)
|
||||
- if (pool->sgl[i])
|
||||
- free(pool->sgl[i]);
|
||||
+ free(pool->sgl[i]);
|
||||
|
||||
free(pool->sgl);
|
||||
}
|
||||
@@ -692,8 +691,10 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
|
||||
/* base the sgl_num create the sgl chain */
|
||||
for (i = 0; i < sgl_num; i++) {
|
||||
sgl_pool->sgl[i] = hisi_qm_create_sgl(sge_num);
|
||||
- if (!sgl_pool->sgl[i])
|
||||
+ if (!sgl_pool->sgl[i]) {
|
||||
+ sgl_pool->sgl_num = i;
|
||||
goto err_out;
|
||||
+ }
|
||||
|
||||
sgl_pool->sgl_align[i] = hisi_qm_align_sgl(sgl_pool->sgl[i],
|
||||
sge_num);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
146
0006-uadk-v1-fix-memory-leak-in-wd_sgl.c.patch
Normal file
146
0006-uadk-v1-fix-memory-leak-in-wd_sgl.c.patch
Normal file
@ -0,0 +1,146 @@
|
||||
From a3236d7933ae96a82577fb7969b66fda07b8b93c Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 10 Jul 2023 11:49:33 +0800
|
||||
Subject: [PATCH 06/26] uadk/v1: fix memory leak in wd_sgl.c
|
||||
|
||||
Add missing free() upon failure of 'wd_alloc_sgl'
|
||||
and 'sgl_pool_init'.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
v1/wd_sgl.c | 58 +++++++++++++++++++++++++++++++++++------------------
|
||||
1 file changed, 39 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
|
||||
index a11190a..97e4b73 100644
|
||||
--- a/v1/wd_sgl.c
|
||||
+++ b/v1/wd_sgl.c
|
||||
@@ -119,6 +119,25 @@ static void sgl_sge_init(struct wd_sgl *sgl, __u8 num, void *buf)
|
||||
sgl->sge[num].flag &= ~FLAG_SGE_CHAIN;
|
||||
}
|
||||
|
||||
+static void sgl_chain_destory(struct wd_queue *q, struct wd_sglpool *pool)
|
||||
+{
|
||||
+ __u16 sgl_num = pool->setup.sgl_num;
|
||||
+ struct wd_mm_br br = pool->buf_br;
|
||||
+ struct wd_sgl *sgl;
|
||||
+ __u16 i, j;
|
||||
+
|
||||
+ for (i = 0; i < sgl_num; i++) {
|
||||
+ sgl = pool->sgl_blk[i];
|
||||
+ drv_uninit_sgl(q, pool, sgl);
|
||||
+
|
||||
+ for (j = 0; j < sgl->buf_num; j++)
|
||||
+ br.free(br.usr, sgl->sge[j].buf);
|
||||
+ }
|
||||
+
|
||||
+ free(pool->sgl_blk);
|
||||
+ pool->sgl_blk = NULL;
|
||||
+}
|
||||
+
|
||||
static int sgl_chain_build(struct wd_queue *q, struct wd_sglpool *pool)
|
||||
{
|
||||
struct wd_sglpool_setup *sp = &pool->setup;
|
||||
@@ -290,15 +309,14 @@ static int sgl_pool_init(struct wd_queue *q, struct wd_sglpool *pool)
|
||||
buf_pool = sgl_buf_pool_init(q, pool);
|
||||
if (!buf_pool) {
|
||||
WD_ERR("failed to create hardware buf pool.\n");
|
||||
- goto err;
|
||||
+ goto free_sgl_pool;
|
||||
}
|
||||
pool->buf_pool = buf_pool;
|
||||
|
||||
ret = sgl_chain_build(q, pool);
|
||||
if (ret) {
|
||||
WD_ERR("failed to build sgl chain, ret = %d.\n", ret);
|
||||
- sgl_buf_pool_uninit(buf_pool);
|
||||
- goto err;
|
||||
+ goto free_buf_pool;
|
||||
}
|
||||
|
||||
pool->q = q;
|
||||
@@ -309,14 +327,19 @@ static int sgl_pool_init(struct wd_queue *q, struct wd_sglpool *pool)
|
||||
ret = wd_blk_alloc_failures(sgl_pool, &pool->alloc_failures);
|
||||
if (ret != WD_SUCCESS) {
|
||||
WD_ERR("wd blk alloc failures failed, ret = %d.\n", ret);
|
||||
- goto err;
|
||||
+ goto free_sgl_chain;
|
||||
}
|
||||
|
||||
pool->free_sgl_num = pool->setup.sgl_num;
|
||||
pool->sgl_mem_sz = sp.buf_num_in_sgl * sp.buf_size;
|
||||
|
||||
return WD_SUCCESS;
|
||||
-err:
|
||||
+
|
||||
+free_sgl_chain:
|
||||
+ sgl_chain_destory(q, pool);
|
||||
+free_buf_pool:
|
||||
+ sgl_buf_pool_uninit(buf_pool);
|
||||
+free_sgl_pool:
|
||||
sgl_blk_pool_uninit(sgl_pool);
|
||||
return ret;
|
||||
}
|
||||
@@ -447,8 +470,6 @@ void wd_sglpool_destroy(void *pool)
|
||||
{
|
||||
struct wd_sglpool *p = pool;
|
||||
struct wd_sglpool_setup sp;
|
||||
- struct wd_sgl *sgl;
|
||||
- int i, j;
|
||||
|
||||
if (!p || !p->sgl_blk || !p->buf_pool || !p->sgl_pool) {
|
||||
WD_ERR("pool parameter is err!\n");
|
||||
@@ -461,20 +482,11 @@ void wd_sglpool_destroy(void *pool)
|
||||
return;
|
||||
}
|
||||
|
||||
- for (i = 0; i < sp.sgl_num; i++) {
|
||||
- sgl = p->sgl_blk[i];
|
||||
- drv_uninit_sgl(p->q, pool, sgl);
|
||||
-
|
||||
- for (j = 0; j < sp.buf_num_in_sgl; j++)
|
||||
- wd_free_blk(p->buf_pool, sgl->sge[j].buf);
|
||||
- }
|
||||
-
|
||||
+ sgl_chain_destory(p->q, p);
|
||||
wd_blkpool_destroy(p->sgl_pool);
|
||||
p->sgl_pool = NULL;
|
||||
wd_blkpool_destroy(p->buf_pool);
|
||||
p->buf_pool = NULL;
|
||||
- free(p->sgl_blk);
|
||||
- p->sgl_blk = NULL;
|
||||
|
||||
free(p);
|
||||
}
|
||||
@@ -510,18 +522,26 @@ struct wd_sgl *wd_alloc_sgl(void *pool, __u32 size)
|
||||
WD_ERR("alloc for sg2 failed!\n");
|
||||
__atomic_add_fetch(&p->alloc_failures, 1,
|
||||
__ATOMIC_RELAXED);
|
||||
- return NULL;
|
||||
+ goto free_sg1;
|
||||
}
|
||||
__atomic_sub_fetch(&p->free_sgl_num, 1, __ATOMIC_RELAXED);
|
||||
|
||||
ret = wd_sgl_merge(sg1, sg2);
|
||||
if (ret) {
|
||||
WD_ERR("merge two sgls failed for u!, ret = %d.\n", ret);
|
||||
- return NULL;
|
||||
+ goto free_sg2;
|
||||
}
|
||||
}
|
||||
|
||||
return sg1;
|
||||
+
|
||||
+free_sg2:
|
||||
+ wd_free_blk(p->sgl_pool, sg2);
|
||||
+ wd_get_free_blk_num(p->sgl_pool, &p->free_sgl_num);
|
||||
+free_sg1:
|
||||
+ wd_free_blk(p->sgl_pool, sg1);
|
||||
+ wd_get_free_blk_num(p->sgl_pool, &p->free_sgl_num);
|
||||
+ return NULL;
|
||||
}
|
||||
|
||||
void wd_free_sgl(void *pool, struct wd_sgl *sgl)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
114
0007-uadk-hisi_comp-free-sgl-when-send-request-error.patch
Normal file
114
0007-uadk-hisi_comp-free-sgl-when-send-request-error.patch
Normal file
@ -0,0 +1,114 @@
|
||||
From b8c2f96b0bbf8411bf44a9fd4eb7b5c0184bd116 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Fri, 7 Jul 2023 16:19:30 +0800
|
||||
Subject: [PATCH 07/26] uadk/hisi_comp - free sgl when send request error
|
||||
|
||||
Free hardware sgl in error branch to avoid memory leakage.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 60 +++++++++++++++++++++++++------------------------
|
||||
1 file changed, 31 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index b6f4d19..e17197d 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -843,6 +843,10 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
+ ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
|
||||
+ if (unlikely(ret))
|
||||
+ return ret;
|
||||
+
|
||||
ret = ops[alg_type].fill_buf[msg->req.data_fmt]((handle_t)qp, sqe, msg);
|
||||
if (unlikely(ret))
|
||||
return ret;
|
||||
@@ -853,10 +857,6 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
|
||||
ops[alg_type].fill_tag(sqe, msg->tag);
|
||||
|
||||
- ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
|
||||
- if (unlikely(ret))
|
||||
- return ret;
|
||||
-
|
||||
state = (msg->stream_mode == WD_COMP_STATEFUL) ? HZ_STATEFUL :
|
||||
HZ_STATELESS;
|
||||
stream_pos = (msg->stream_pos == WD_COMP_STREAM_NEW) ? HZ_STREAM_NEW :
|
||||
@@ -878,6 +878,31 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ enum wd_comp_alg_type alg_type)
|
||||
+{
|
||||
+ void *hw_sgl_in, *hw_sgl_out;
|
||||
+ handle_t h_sgl_pool;
|
||||
+
|
||||
+ h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
+ if (unlikely(!h_sgl_pool)) {
|
||||
+ WD_ERR("failed to get sglpool to free hw sgl!\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ hw_sgl_in = VA_ADDR(sqe->source_addr_h, sqe->source_addr_l);
|
||||
+ hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
+
|
||||
+ hw_sgl_out = VA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
|
||||
+ hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
|
||||
+
|
||||
+ if (alg_type == WD_LZ77_ZSTD) {
|
||||
+ hw_sgl_out = VA_ADDR(sqe->literals_addr_h,
|
||||
+ sqe->literals_addr_l);
|
||||
+ hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
|
||||
{
|
||||
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
|
||||
@@ -895,6 +920,8 @@ static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
|
||||
}
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
if (unlikely(ret < 0)) {
|
||||
+ if (msg->req.data_fmt == WD_SGL_BUF)
|
||||
+ free_hw_sgl(h_qp, &sqe, msg->alg_type);
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send to hardware, ret = %d!\n", ret);
|
||||
|
||||
@@ -929,31 +956,6 @@ static int get_alg_type(__u32 type)
|
||||
return alg_type;
|
||||
}
|
||||
|
||||
-static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- enum wd_comp_alg_type alg_type)
|
||||
-{
|
||||
- void *hw_sgl_in, *hw_sgl_out;
|
||||
- handle_t h_sgl_pool;
|
||||
-
|
||||
- h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
- if (unlikely(!h_sgl_pool)) {
|
||||
- WD_ERR("failed to get sglpool to free hw sgl!\n");
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- hw_sgl_in = VA_ADDR(sqe->source_addr_h, sqe->source_addr_l);
|
||||
- hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
-
|
||||
- hw_sgl_out = VA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
|
||||
- hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
|
||||
-
|
||||
- if (alg_type == WD_LZ77_ZSTD) {
|
||||
- hw_sgl_out = VA_ADDR(sqe->literals_addr_h,
|
||||
- sqe->literals_addr_l);
|
||||
- hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
|
||||
- }
|
||||
-}
|
||||
-
|
||||
static void get_ctx_buf(struct hisi_zip_sqe *sqe,
|
||||
struct wd_comp_msg *recv_msg)
|
||||
{
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
From 9ec9b1d7472c9f34dccb55fe49f03005ed7bdf34 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Fri, 7 Jul 2023 16:19:31 +0800
|
||||
Subject: [PATCH 08/26] uadk/hisi_comp - add output length check for lz77_zstd
|
||||
sgl mode
|
||||
|
||||
Algorithm lz77_zstd has some output buffer size limit due to hardware.
|
||||
So add the buffer size check.
|
||||
And unify related variables name style.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 32 +++++++++++++++++++++++---------
|
||||
1 file changed, 23 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index e17197d..d6c0a2a 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -420,7 +420,7 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
struct wd_comp_req *req = &msg->req;
|
||||
struct wd_lz77_zstd_data *data = req->priv;
|
||||
__u32 in_size = msg->req.src_len;
|
||||
- __u32 lit_size = in_size + ZSTD_LIT_RESV_SIZE;
|
||||
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
|
||||
__u32 out_size = msg->avail_out;
|
||||
void *ctx_buf = NULL;
|
||||
|
||||
@@ -442,12 +442,12 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
}
|
||||
|
||||
/*
|
||||
- * For lz77_zstd, the hardware need 784 Bytes buffer to output
|
||||
+ * For lz77_zstd, the hardware needs 784 Bytes buffer to output
|
||||
* the frequency information about input data.
|
||||
*/
|
||||
- if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lit_size)) {
|
||||
- WD_ERR("invalid: sequences output size(%u) is not enough!\n",
|
||||
- ZSTD_FREQ_DATA_SIZE + in_size);
|
||||
+ if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
|
||||
+ WD_ERR("invalid: output is not enough, %u bytes are minimum!\n",
|
||||
+ ZSTD_FREQ_DATA_SIZE + lits_size);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -458,13 +458,12 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
msg->ctx_buf + CTX_REPCODE2_OFFSET, REPCODE_SIZE);
|
||||
}
|
||||
|
||||
- fill_buf_size_lz77_zstd(sqe, in_size, lit_size, out_size - lit_size);
|
||||
+ fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
|
||||
|
||||
- fill_buf_addr_lz77_zstd(sqe, req->src, req->dst,
|
||||
- req->dst + lit_size, ctx_buf);
|
||||
+ fill_buf_addr_lz77_zstd(sqe, req->src, req->dst, req->dst + lits_size, ctx_buf);
|
||||
|
||||
data->literals_start = req->dst;
|
||||
- data->sequences_start = req->dst + lit_size;
|
||||
+ data->sequences_start = req->dst + lits_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -515,7 +514,22 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
data->literals_start = req->list_dst;
|
||||
data->sequences_start = seq_start;
|
||||
|
||||
+ /*
|
||||
+ * For lz77_zstd, the hardware needs 784 Bytes buffer to output
|
||||
+ * the frequency information about input data. The sequences
|
||||
+ * and frequency data need to be written to an independent sgl
|
||||
+ * splited from list_dst.
|
||||
+ */
|
||||
lits_size = hisi_qm_get_list_size(req->list_dst, seq_start);
|
||||
+ if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
|
||||
+ WD_ERR("invalid: output is not enough for literals, %u bytes are minimum!\n",
|
||||
+ ZSTD_FREQ_DATA_SIZE + lits_size);
|
||||
+ return -WD_EINVAL;
|
||||
+ } else if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
|
||||
+ WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
|
||||
+ ZSTD_FREQ_DATA_SIZE + lits_size - out_size);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
1251
0009-drivers-alloc-and-free-resources-by-themself.patch
Normal file
1251
0009-drivers-alloc-and-free-resources-by-themself.patch
Normal file
File diff suppressed because it is too large
Load Diff
39
0010-uadk-fix-for-get_str_attr.patch
Normal file
39
0010-uadk-fix-for-get_str_attr.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 3015d495313e86ee8ec72ef4f6ff7984eb05614a Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 8 Aug 2023 21:22:19 +0800
|
||||
Subject: [PATCH 10/26] uadk: fix for get_str_attr
|
||||
|
||||
If snprintf returns 0, (ret - 1) will be negative and used
|
||||
as an array index, fix it, also, the int type should be
|
||||
converted to unsigned int.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/v1/wd.c b/v1/wd.c
|
||||
index e0a86dc..3839304 100644
|
||||
--- a/v1/wd.c
|
||||
+++ b/v1/wd.c
|
||||
@@ -81,7 +81,7 @@ static int get_raw_attr(const char *dev_root, const char *attr,
|
||||
dev_root, attr);
|
||||
if (size <= 0) {
|
||||
WD_ERR("get %s/%s path fail!\n", dev_root, attr);
|
||||
- return size;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
ptrRet = realpath(attr_file, attr_path);
|
||||
@@ -140,7 +140,7 @@ static int get_str_attr(struct dev_info *dinfo, const char *attr, char *buf,
|
||||
return ret;
|
||||
}
|
||||
|
||||
- if ((size_t)ret == buf_sz)
|
||||
+ if ((__u32)ret == buf_sz)
|
||||
ret = ret - 1;
|
||||
|
||||
buf[ret] = '\0';
|
||||
--
|
||||
2.25.1
|
||||
|
||||
52
0011-uadk-remove-unused-information.patch
Normal file
52
0011-uadk-remove-unused-information.patch
Normal file
@ -0,0 +1,52 @@
|
||||
From 94bf2fb86beb02cf6e2db64d2fab3a8c67d3a442 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 8 Aug 2023 21:22:20 +0800
|
||||
Subject: [PATCH 11/26] uadk: remove unused information
|
||||
|
||||
Remove unused email address and description.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
ChangeLog | 6 +++---
|
||||
v1/drv/hisi_sec_udrv.h | 2 +-
|
||||
2 files changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/ChangeLog b/ChangeLog
|
||||
index 0cf3051..5824120 100644
|
||||
--- a/ChangeLog
|
||||
+++ b/ChangeLog
|
||||
@@ -2,15 +2,15 @@ UADK 2.3.11, Released Jul 9th, 2021
|
||||
|
||||
Feature list:
|
||||
|
||||
- Support SVA on ZIP/SEC/HPRE accelerator on kunpeng930.
|
||||
+ Support SVA on ZIP/SEC/HPRE accelerator on kunpeng.
|
||||
|
||||
Support of user space algorithm API layer of Warpdrive.
|
||||
|
||||
Offload Warpdrive WCRYPTO asymmetric algorithms with HPRE DH/RSA
|
||||
- on kunpeng920/930.
|
||||
+ on kunpeng.
|
||||
|
||||
Offload elliptic curve EC algorithms SM2/ECDH/ECDSA/X25519/X448 on
|
||||
- kunpeng930 HPRE in user space.
|
||||
+ kunpeng HPRE in user space.
|
||||
|
||||
Offload Warpdrive WCRYPTO symmetric algorithms AES/SM4/SM3/AEAD .etc
|
||||
algorithms.
|
||||
diff --git a/v1/drv/hisi_sec_udrv.h b/v1/drv/hisi_sec_udrv.h
|
||||
index 9c0da47..af96a76 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.h
|
||||
+++ b/v1/drv/hisi_sec_udrv.h
|
||||
@@ -326,7 +326,7 @@ struct bd3_tls_type_back {
|
||||
__u32 pad_len_1p3_back:16;
|
||||
};
|
||||
|
||||
-/* the kp930 sence */
|
||||
+/* the hw v2 sence */
|
||||
struct hisi_sec_bd3_sqe {
|
||||
__u32 type:4;
|
||||
__u32 inveld:1;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
296
0012-uadk-support-digest-to-parse-private-data.patch
Normal file
296
0012-uadk-support-digest-to-parse-private-data.patch
Normal file
@ -0,0 +1,296 @@
|
||||
From 0e6154d5fdc734ca531917d1fd1f6cce1f2ff17b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 8 Aug 2023 21:22:21 +0800
|
||||
Subject: [PATCH 12/26] uadk: support digest to parse private data
|
||||
|
||||
In digest storage scene, the address filled by users are DMA address,
|
||||
which are transferred to the WD through the opdata priv field.
|
||||
The WD only needs to parse the address and fill them in the hardware BD,
|
||||
the IOVA map is not required for address translation.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 162 ++++++++++++++++++++++++++++++++---------
|
||||
v1/wd_digest.c | 2 +-
|
||||
2 files changed, 128 insertions(+), 36 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 4d5ede5..f42022b 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -1088,7 +1088,7 @@ static int fill_digest_bd1_addr(struct wd_queue *q,
|
||||
}
|
||||
}
|
||||
|
||||
- /* for storage scene, data address using physical address */
|
||||
+ /* for bd1 udata scene, in/out address do not need to be mapped. */
|
||||
phy = (uintptr_t)msg->in;
|
||||
sqe->type1.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
sqe->type1.data_src_addr_h = HI_U32(phy);
|
||||
@@ -1100,8 +1100,7 @@ static int fill_digest_bd1_addr(struct wd_queue *q,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void fill_digest_bd1_udata(struct hisi_sec_sqe *sqe,
|
||||
- struct wd_sec_udata *udata)
|
||||
+static void fill_digest_bd1_udata(struct hisi_sec_sqe *sqe, struct wd_sec_udata *udata)
|
||||
{
|
||||
sqe->type1.gran_num = udata->gran_num;
|
||||
sqe->type1.src_skip_data_len = udata->src_offset;
|
||||
@@ -1167,17 +1166,11 @@ static int set_hmac_mode(struct wcrypto_digest_msg *msg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_digest_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
- struct wcrypto_digest_msg *msg, struct wcrypto_digest_tag *tag)
|
||||
+static int fill_digest_bd2_addr(struct wd_queue *q, struct wcrypto_digest_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
- int ret = -WD_ENOMEM;
|
||||
uintptr_t phy;
|
||||
-
|
||||
- sqe->type = BD_TYPE2;
|
||||
- sqe->scene = SCENE_IPSEC;
|
||||
-
|
||||
- sqe->auth = AUTH_MAC_CALCULATE;
|
||||
- sqe->type2.a_len = msg->in_bytes;
|
||||
+ int ret;
|
||||
|
||||
phy = (uintptr_t)drv_iova_map(q, msg->in, msg->in_bytes);
|
||||
if (unlikely(!phy)) {
|
||||
@@ -1199,28 +1192,107 @@ static int fill_digest_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
if (ret)
|
||||
goto map_key_error;
|
||||
|
||||
+ return WD_SUCCESS;
|
||||
+
|
||||
+map_key_error:
|
||||
+ unmap_addr(q, msg->out, msg->out_bytes, sqe->type2.mac_addr_l,
|
||||
+ sqe->type2.mac_addr_h, msg->data_fmt);
|
||||
+map_out_error:
|
||||
+ phy = DMA_ADDR(sqe->type2.data_src_addr_h, sqe->type2.data_src_addr_l);
|
||||
+ drv_iova_unmap(q, msg->in, (void *)(uintptr_t)phy, msg->in_bytes);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void fill_digest_bd2_udata_inner(struct wcrypto_digest_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
+{
|
||||
+ uintptr_t phy;
|
||||
+
|
||||
+ /* for bd2 udata scene, address do not need to be mapped. */
|
||||
+ phy = (uintptr_t)msg->in;
|
||||
+ sqe->type2.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.data_src_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->out;
|
||||
+ sqe->type2.mac_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.mac_addr_h = HI_U32(phy);
|
||||
+
|
||||
+ if (msg->mode == WCRYPTO_DIGEST_HMAC) {
|
||||
+ sqe->type2.a_key_len = msg->key_bytes / SEC_SQE_LEN_RATE;
|
||||
+ phy = (uintptr_t)msg->key;
|
||||
+ sqe->type2.a_key_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.a_key_addr_h = HI_U32(phy);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static int fill_digest_bd2_common(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_digest_msg *msg, struct wcrypto_digest_tag *tag)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ sqe->type = BD_TYPE2;
|
||||
+ sqe->scene = SCENE_IPSEC;
|
||||
+
|
||||
+ sqe->auth = AUTH_MAC_CALCULATE;
|
||||
+ sqe->type2.a_len = msg->in_bytes;
|
||||
+
|
||||
ret = fill_digest_bd2_alg(msg, sqe);
|
||||
if (ret != WD_SUCCESS) {
|
||||
WD_ERR("fill_digest_bd2_alg fail!\n");
|
||||
- goto map_alg_error;
|
||||
+ return ret;
|
||||
}
|
||||
- qm_fill_digest_long_bd(msg, sqe);
|
||||
|
||||
if (tag)
|
||||
sqe->type2.tag = tag->wcrypto_tag.ctx_id;
|
||||
|
||||
return ret;
|
||||
+}
|
||||
+
|
||||
+static int fill_digest_bd2_udata(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_digest_msg *msg, struct wcrypto_digest_tag *tag)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = fill_digest_bd2_common(q, sqe, msg, tag);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ fill_digest_bd2_udata_inner(msg, sqe);
|
||||
+ qm_fill_digest_long_bd(msg, sqe);
|
||||
+
|
||||
+ return WD_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+static int fill_digest_bd_udata(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_digest_msg *msg, struct wcrypto_digest_tag *tag)
|
||||
+{
|
||||
+ struct wd_sec_udata *udata = tag->priv;
|
||||
+
|
||||
+ if (udata->key) {
|
||||
+ msg->key = udata->key;
|
||||
+ msg->key_bytes = udata->key_bytes;
|
||||
+ }
|
||||
+
|
||||
+ if (udata->gran_num)
|
||||
+ return fill_digest_bd1(q, sqe, msg, tag);
|
||||
+
|
||||
+ return fill_digest_bd2_udata(q, sqe, msg, tag);
|
||||
+}
|
||||
+
|
||||
+static int fill_digest_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_digest_msg *msg, struct wcrypto_digest_tag *tag)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = fill_digest_bd2_common(q, sqe, msg, tag);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ ret = fill_digest_bd2_addr(q, msg, sqe);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ qm_fill_digest_long_bd(msg, sqe);
|
||||
|
||||
-map_alg_error:
|
||||
- unmap_addr(q, msg->key, msg->key_bytes, sqe->type2.a_key_addr_l,
|
||||
- sqe->type2.a_key_addr_h, msg->data_fmt);
|
||||
-map_key_error:
|
||||
- unmap_addr(q, msg->out, msg->out_bytes, sqe->type2.mac_addr_l,
|
||||
- sqe->type2.mac_addr_h, msg->data_fmt);
|
||||
-map_out_error:
|
||||
- phy = DMA_ADDR(sqe->type2.data_src_addr_h,
|
||||
- sqe->type2.data_src_addr_l);
|
||||
- drv_iova_unmap(q, msg->in, (void *)(uintptr_t)phy, msg->in_bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1231,12 +1303,12 @@ map_out_error:
|
||||
*/
|
||||
int qm_fill_digest_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
- struct hisi_sec_sqe *sqe;
|
||||
struct wcrypto_digest_msg *msg = message;
|
||||
- struct wd_queue *q = info->q;
|
||||
struct wcrypto_digest_tag *tag = (void *)(uintptr_t)msg->usr_data;
|
||||
- int ret;
|
||||
+ struct wd_queue *q = info->q;
|
||||
+ struct hisi_sec_sqe *sqe;
|
||||
uintptr_t temp;
|
||||
+ int ret;
|
||||
|
||||
temp = (uintptr_t)info->sq_base + i * info->sqe_size;
|
||||
sqe = (struct hisi_sec_sqe *)temp;
|
||||
@@ -1246,7 +1318,7 @@ int qm_fill_digest_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
fill_bd_addr_type(msg->data_fmt, sqe);
|
||||
|
||||
if (tag->priv)
|
||||
- ret = fill_digest_bd1(q, sqe, msg, tag);
|
||||
+ ret = fill_digest_bd_udata(q, sqe, msg, tag);
|
||||
else
|
||||
ret = fill_digest_bd2(q, sqe, msg, tag);
|
||||
|
||||
@@ -1406,19 +1478,25 @@ int qm_fill_digest_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
struct wcrypto_digest_msg *msg = message;
|
||||
struct wcrypto_digest_tag *tag = (void *)(uintptr_t)msg->usr_data;
|
||||
- struct hisi_sec_bd3_sqe *sqe;
|
||||
struct wd_queue *q = info->q;
|
||||
+ struct hisi_sec_bd3_sqe *sqe;
|
||||
+ struct hisi_sec_sqe *sqe2;
|
||||
uintptr_t temp;
|
||||
int ret;
|
||||
|
||||
temp = (uintptr_t)info->sq_base + i * info->sqe_size;
|
||||
- sqe = (struct hisi_sec_bd3_sqe *)temp;
|
||||
-
|
||||
- memset(sqe, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
|
||||
- fill_bd3_addr_type(msg->data_fmt, sqe);
|
||||
-
|
||||
- ret = fill_digest_bd3(q, sqe, msg, tag);
|
||||
+ if (tag->priv) {
|
||||
+ sqe2 = (struct hisi_sec_sqe *)temp;
|
||||
+ memset(sqe2, 0, sizeof(struct hisi_sec_sqe));
|
||||
+ fill_bd_addr_type(msg->data_fmt, sqe2);
|
||||
+ ret = fill_digest_bd_udata(q, sqe2, msg, tag);
|
||||
+ } else {
|
||||
+ sqe = (struct hisi_sec_bd3_sqe *)temp;
|
||||
+ memset(sqe, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
+ fill_bd3_addr_type(msg->data_fmt, sqe);
|
||||
+ ret = fill_digest_bd3(q, sqe, msg, tag);
|
||||
+ }
|
||||
if (ret != WD_SUCCESS)
|
||||
return ret;
|
||||
|
||||
@@ -1660,6 +1738,7 @@ static void parse_digest_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
static void parse_digest_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
struct wcrypto_digest_msg *digest_msg)
|
||||
{
|
||||
+ struct wcrypto_digest_tag *tag;
|
||||
__u64 dma_addr;
|
||||
|
||||
if (sqe->type2.done != SEC_HW_TASK_DONE
|
||||
@@ -1670,6 +1749,10 @@ static void parse_digest_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
} else
|
||||
digest_msg->result = WD_SUCCESS;
|
||||
|
||||
+ tag = (void *)(uintptr_t)digest_msg->usr_data;
|
||||
+ if (tag->priv)
|
||||
+ return;
|
||||
+
|
||||
dma_addr = DMA_ADDR(sqe->type2.data_src_addr_h,
|
||||
sqe->type2.data_src_addr_l);
|
||||
drv_iova_unmap(q, digest_msg->in, (void *)(uintptr_t)dma_addr,
|
||||
@@ -2283,6 +2366,7 @@ int qm_parse_digest_bd3_sqe(void *msg, const struct qm_queue_info *info,
|
||||
{
|
||||
struct wcrypto_digest_msg *digest_msg = info->req_cache[i];
|
||||
struct hisi_sec_bd3_sqe *sqe = msg;
|
||||
+ struct hisi_sec_sqe *sqe2 = msg;
|
||||
struct wd_queue *q = info->q;
|
||||
|
||||
if (unlikely(!digest_msg)) {
|
||||
@@ -2294,6 +2378,14 @@ int qm_parse_digest_bd3_sqe(void *msg, const struct qm_queue_info *info,
|
||||
if (usr && sqe->tag_l != usr)
|
||||
return 0;
|
||||
parse_digest_bd3(q, sqe, digest_msg);
|
||||
+ } else if (sqe->type == BD_TYPE2) {
|
||||
+ if (usr && sqe2->type2.tag != usr)
|
||||
+ return 0;
|
||||
+ parse_digest_bd2(q, sqe2, digest_msg);
|
||||
+ } else if (sqe->type == BD_TYPE1) {
|
||||
+ if (usr && sqe2->type1.tag != usr)
|
||||
+ return 0;
|
||||
+ parse_digest_bd1(q, sqe2, digest_msg);
|
||||
} else {
|
||||
WD_ERR("SEC Digest BD Type error\n");
|
||||
digest_msg->result = WD_IN_EPARA;
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index 86a7751..809aecd 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -64,7 +64,7 @@ static void del_ctx_key(struct wcrypto_digest_ctx *ctx)
|
||||
* want to clear the SGL buffer, we can only use 'wd_sgl_cp_from_pbuf'
|
||||
* whose 'pbuf' is all zero.
|
||||
*/
|
||||
- if (ctx->key) {
|
||||
+ if (ctx->key && ctx->key_bytes) {
|
||||
if (ctx->setup.data_fmt == WD_FLAT_BUF)
|
||||
memset(ctx->key, 0, MAX_HMAC_KEY_SIZE);
|
||||
else if (ctx->setup.data_fmt == WD_SGL_BUF)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
315
0013-uadk-support-aead-to-parse-user-private-data.patch
Normal file
315
0013-uadk-support-aead-to-parse-user-private-data.patch
Normal file
@ -0,0 +1,315 @@
|
||||
From 5d971d27ddfadea7a7f68749decc94a5ffbe6ae3 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 8 Aug 2023 21:22:22 +0800
|
||||
Subject: [PATCH 13/26] uadk: support aead to parse user private data
|
||||
|
||||
In aead storage scene, the address filled by users are DMA address,
|
||||
which are transferred to the WD through the opdata priv field.
|
||||
The WD only needs to parse the address and fill them in the hardware BD,
|
||||
the IOVA map is not required for address translation.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 142 ++++++++++++++++++++++++++++++++++++-----
|
||||
v1/wd_aead.c | 10 +--
|
||||
v1/wd_util.h | 13 ++++
|
||||
3 files changed, 142 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index f42022b..32bded4 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -64,6 +64,11 @@ static int g_hmac_a_alg[WCRYPTO_MAX_DIGEST_TYPE] = {
|
||||
A_ALG_HMAC_SHA512, A_ALG_HMAC_SHA512_224, A_ALG_HMAC_SHA512_256
|
||||
};
|
||||
|
||||
+static void parse_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_aead_msg *msg);
|
||||
+static int fill_aead_bd_udata(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_aead_msg *msg, struct wcrypto_aead_tag *tag);
|
||||
+
|
||||
#ifdef DEBUG_LOG
|
||||
static void sec_dump_bd(unsigned char *bd, unsigned int len)
|
||||
{
|
||||
@@ -2224,6 +2229,7 @@ int qm_fill_aead_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
struct wcrypto_aead_tag *tag = (void *)(uintptr_t)msg->usr_data;
|
||||
struct wd_queue *q = info->q;
|
||||
struct hisi_sec_bd3_sqe *sqe;
|
||||
+ struct hisi_sec_sqe *sqe2;
|
||||
uintptr_t temp;
|
||||
int ret;
|
||||
|
||||
@@ -2235,13 +2241,17 @@ int qm_fill_aead_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
}
|
||||
|
||||
temp = (uintptr_t)info->sq_base + i * info->sqe_size;
|
||||
- sqe = (struct hisi_sec_bd3_sqe *)temp;
|
||||
-
|
||||
- memset(sqe, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
-
|
||||
- fill_bd3_addr_type(msg->data_fmt, sqe);
|
||||
-
|
||||
- ret = fill_aead_bd3(q, sqe, msg, tag);
|
||||
+ if (tag->priv) {
|
||||
+ sqe2 = (struct hisi_sec_sqe *)temp;
|
||||
+ memset(sqe2, 0, sizeof(struct hisi_sec_sqe));
|
||||
+ fill_bd_addr_type(msg->data_fmt, sqe2);
|
||||
+ ret = fill_aead_bd_udata(q, sqe2, msg, tag);
|
||||
+ } else {
|
||||
+ sqe = (struct hisi_sec_bd3_sqe *)temp;
|
||||
+ memset(sqe, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
+ fill_bd3_addr_type(msg->data_fmt, sqe);
|
||||
+ ret = fill_aead_bd3(q, sqe, msg, tag);
|
||||
+ }
|
||||
if (ret != WD_SUCCESS)
|
||||
return ret;
|
||||
|
||||
@@ -2313,6 +2323,7 @@ int qm_parse_aead_bd3_sqe(void *msg, const struct qm_queue_info *info,
|
||||
{
|
||||
struct wcrypto_aead_msg *aead_msg = info->req_cache[i];
|
||||
struct hisi_sec_bd3_sqe *sqe = msg;
|
||||
+ struct hisi_sec_sqe *sqe2 = msg;
|
||||
struct wd_queue *q = info->q;
|
||||
|
||||
if (unlikely(!aead_msg)) {
|
||||
@@ -2324,6 +2335,10 @@ int qm_parse_aead_bd3_sqe(void *msg, const struct qm_queue_info *info,
|
||||
if (usr && sqe->tag_l != usr)
|
||||
return 0;
|
||||
parse_aead_bd3(q, sqe, aead_msg);
|
||||
+ } else if (sqe->type == BD_TYPE2) {
|
||||
+ if (usr && sqe2->type2.tag != usr)
|
||||
+ return 0;
|
||||
+ parse_aead_bd2(q, sqe2, aead_msg);
|
||||
} else {
|
||||
WD_ERR("SEC BD Type error\n");
|
||||
aead_msg->result = WD_IN_EPARA;
|
||||
@@ -2664,7 +2679,45 @@ static int aead_param_len_check(struct wcrypto_aead_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+static int fill_aead_bd2_udata_inner(struct wcrypto_aead_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe, struct wd_aead_udata *udata)
|
||||
+{
|
||||
+ uintptr_t phy;
|
||||
+
|
||||
+ sqe->type2.auth_src_offset = udata->src_offset;
|
||||
+ sqe->type2.cipher_src_offset = udata->src_offset + msg->assoc_bytes;
|
||||
+ /* for bd2 udata scene, address do not need to be mapped. */
|
||||
+ phy = (uintptr_t)msg->in;
|
||||
+ sqe->type2.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.data_src_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->out;
|
||||
+ sqe->type2.data_dst_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.data_dst_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->iv;
|
||||
+ sqe->type2.c_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.c_ivin_addr_h = HI_U32(phy);
|
||||
+
|
||||
+ phy = (uintptr_t)udata->ckey;
|
||||
+ sqe->type2.c_key_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.c_key_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)udata->mac;
|
||||
+ sqe->type2.mac_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.mac_addr_h = HI_U32(phy);
|
||||
+ if (msg->cmode == WCRYPTO_CIPHER_CCM || msg->cmode == WCRYPTO_CIPHER_GCM) {
|
||||
+ if (udata->aiv) {
|
||||
+ phy = (uintptr_t)udata->aiv;
|
||||
+ sqe->type2.a_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.a_ivin_addr_h = HI_U32(phy);
|
||||
+ } else {
|
||||
+ WD_ERR("Invalid aiv addr in CCM/GCM mode!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return WD_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+static int fill_aead_bd2_common(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
struct wcrypto_aead_msg *msg, struct wcrypto_aead_tag *tag)
|
||||
{
|
||||
int ret;
|
||||
@@ -2686,26 +2739,77 @@ static int fill_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
|
||||
ret = fill_aead_bd2_alg(msg, sqe);
|
||||
if (ret != WD_SUCCESS) {
|
||||
- WD_ERR("fill_cipher_bd2_alg fail!\n");
|
||||
+ WD_ERR("fill_aead_bd2_alg fail!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = fill_aead_bd2_mode(msg, sqe);
|
||||
if (ret != WD_SUCCESS) {
|
||||
- WD_ERR("fill_cipher_bd2_mode fail!\n");
|
||||
+ WD_ERR("fill_aead_bd2_mode fail!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
- ret = fill_aead_bd2_addr(q, msg, sqe);
|
||||
- if (ret != WD_SUCCESS)
|
||||
- return ret;
|
||||
-
|
||||
if (tag)
|
||||
sqe->type2.tag = tag->wcrypto_tag.ctx_id;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static int fill_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_aead_msg *msg, struct wcrypto_aead_tag *tag)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = fill_aead_bd2_common(q, sqe, msg, tag);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ return fill_aead_bd2_addr(q, msg, sqe);
|
||||
+}
|
||||
+
|
||||
+static int init_msg_with_udata(struct wcrypto_aead_msg *req, struct wd_aead_udata *udata)
|
||||
+{
|
||||
+ if (!udata->ckey || !udata->mac) {
|
||||
+ WD_ERR("invalid udata para!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if (req->cmode == WCRYPTO_CIPHER_CCM || req->cmode == WCRYPTO_CIPHER_GCM) {
|
||||
+ req->ckey_bytes = udata->ckey_bytes;
|
||||
+ req->auth_bytes = udata->mac_bytes;
|
||||
+ } else {
|
||||
+ WD_ERR("invalid cmode para!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ return WD_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+static int fill_aead_bd2_udata(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_aead_msg *msg, struct wcrypto_aead_tag *tag)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = fill_aead_bd2_common(q, sqe, msg, tag);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ return fill_aead_bd2_udata_inner(msg, sqe, (struct wd_aead_udata *)tag->priv);
|
||||
+}
|
||||
+
|
||||
+static int fill_aead_bd_udata(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
+ struct wcrypto_aead_msg *msg, struct wcrypto_aead_tag *tag)
|
||||
+{
|
||||
+ struct wd_aead_udata *udata = tag->priv;
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = init_msg_with_udata(msg, udata);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+
|
||||
+ return fill_aead_bd2_udata(q, sqe, msg, tag);
|
||||
+}
|
||||
+
|
||||
int qm_fill_aead_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
struct wcrypto_aead_msg *msg = message;
|
||||
@@ -2727,7 +2831,10 @@ int qm_fill_aead_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
|
||||
memset(sqe, 0, sizeof(struct hisi_sec_sqe));
|
||||
|
||||
- ret = fill_aead_bd2(q, sqe, msg, tag);
|
||||
+ if (tag->priv)
|
||||
+ ret = fill_aead_bd_udata(q, sqe, msg, tag);
|
||||
+ else
|
||||
+ ret = fill_aead_bd2(q, sqe, msg, tag);
|
||||
if (ret != WD_SUCCESS)
|
||||
return ret;
|
||||
|
||||
@@ -2743,6 +2850,7 @@ int qm_fill_aead_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
static void parse_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
struct wcrypto_aead_msg *msg)
|
||||
{
|
||||
+ struct wcrypto_aead_tag *tag;
|
||||
__u8 mac[64] = { 0 };
|
||||
__u64 dma_addr;
|
||||
int ret;
|
||||
@@ -2756,6 +2864,10 @@ static void parse_aead_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
msg->result = WD_SUCCESS;
|
||||
}
|
||||
|
||||
+ tag = (void *)(uintptr_t)msg->usr_data;
|
||||
+ if (tag->priv)
|
||||
+ return;
|
||||
+
|
||||
/*
|
||||
* We obtain a memory from IV SGL as a temporary address space for MAC,
|
||||
* After the encryption is completed, copy the data from this temporary
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index 7abb8a0..f81f327 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -79,14 +79,14 @@ static void del_ctx_key(struct wcrypto_aead_ctx *ctx)
|
||||
* want to clear the SGL buffer, we can only use 'wd_sgl_cp_from_pbuf'
|
||||
* whose 'pbuf' is all zero.
|
||||
*/
|
||||
- if (ctx->ckey) {
|
||||
+ if (ctx->ckey && ctx->ckey_bytes) {
|
||||
if (ctx->setup.data_fmt == WD_FLAT_BUF)
|
||||
memset(ctx->ckey, 0, MAX_CIPHER_KEY_SIZE);
|
||||
else if (ctx->setup.data_fmt == WD_SGL_BUF)
|
||||
wd_sgl_cp_from_pbuf(ctx->ckey, 0, tmp, MAX_CIPHER_KEY_SIZE);
|
||||
}
|
||||
|
||||
- if (ctx->akey) {
|
||||
+ if (ctx->akey && ctx->akey_bytes) {
|
||||
if (ctx->setup.data_fmt == WD_FLAT_BUF)
|
||||
memset(ctx->akey, 0, MAX_AEAD_KEY_SIZE);
|
||||
else if (ctx->setup.data_fmt == WD_SGL_BUF)
|
||||
@@ -445,7 +445,6 @@ static int aead_requests_init(struct wcrypto_aead_msg **req,
|
||||
struct wcrypto_aead_op_data **op,
|
||||
struct wcrypto_aead_ctx *ctx, __u32 num)
|
||||
{
|
||||
- struct wd_sec_udata *udata;
|
||||
int ret;
|
||||
__u32 i;
|
||||
|
||||
@@ -471,11 +470,6 @@ static int aead_requests_init(struct wcrypto_aead_msg **req,
|
||||
req[i]->out_bytes = op[i]->out_bytes;
|
||||
req[i]->assoc_bytes = op[i]->assoc_size;
|
||||
req[i]->auth_bytes = ctx->auth_size;
|
||||
- udata = op[i]->priv;
|
||||
- if (udata && udata->key) {
|
||||
- req[i]->ckey = udata->key;
|
||||
- req[i]->ckey_bytes = udata->key_bytes;
|
||||
- }
|
||||
|
||||
req[i]->aiv = ctx->setup.br.alloc(ctx->setup.br.usr,
|
||||
MAX_AEAD_KEY_SIZE);
|
||||
diff --git a/v1/wd_util.h b/v1/wd_util.h
|
||||
index fc4586c..617af3b 100644
|
||||
--- a/v1/wd_util.h
|
||||
+++ b/v1/wd_util.h
|
||||
@@ -175,6 +175,19 @@ struct wd_sec_udata {
|
||||
__u8 *key;
|
||||
};
|
||||
|
||||
+struct wd_aead_udata {
|
||||
+ __u32 src_offset;
|
||||
+ __u32 dst_offset;
|
||||
+ __u16 ckey_bytes;
|
||||
+ __u16 akey_bytes;
|
||||
+ __u16 aiv_bytes;
|
||||
+ __u16 mac_bytes;
|
||||
+ __u8 *ckey;
|
||||
+ __u8 *akey;
|
||||
+ __u8 *aiv;
|
||||
+ __u8 *mac;
|
||||
+};
|
||||
+
|
||||
/* Digest tag format of Warpdrive */
|
||||
struct wcrypto_digest_tag {
|
||||
struct wcrypto_cb_tag wcrypto_tag;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
40
0014-uadk-fix-sec-test.patch
Normal file
40
0014-uadk-fix-sec-test.patch
Normal file
@ -0,0 +1,40 @@
|
||||
From b9b90fd15c4d6de41e3501560ced2452cc1e9376 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 18 Aug 2023 10:31:29 +0800
|
||||
Subject: [PATCH 14/26] uadk: fix sec test
|
||||
|
||||
Fix for uadk sec test code moved to uadk_tool
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
test/sanity_test.sh | 8 ++++----
|
||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
|
||||
index 207eee5..dd8ed18 100755
|
||||
--- a/test/sanity_test.sh
|
||||
+++ b/test/sanity_test.sh
|
||||
@@ -374,16 +374,16 @@ run_zip_test_v2()
|
||||
# failed: return 1; success: return 0
|
||||
run_sec_test_v2()
|
||||
{
|
||||
- run_cmd test_hisi_sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
+ run_cmd uadk_tool test --m sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
--times 1 --sync --multi 1 $@
|
||||
|
||||
- run_cmd test_hisi_sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
+ run_cmd uadk_tool test --m sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
--times 1 --async --multi 1 $@
|
||||
|
||||
- run_cmd test_hisi_sec --digest 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
+ run_cmd uadk_tool test --m sec --digest 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
--times 1 --sync --multi 1 $@
|
||||
|
||||
- run_cmd test_hisi_sec --digest 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
+ run_cmd uadk_tool test --m sec test_hisi_sec --digest 0 --optype 0 --pktlen 16 --keylen 16 \
|
||||
--times 1 --async --multi 1 $@
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
28
0015-sanity_test-fix-to-show-messages-from-testcase.patch
Normal file
28
0015-sanity_test-fix-to-show-messages-from-testcase.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 3bb5d4bbc440ee9637dd487ea6aaf902d7cacf2a Mon Sep 17 00:00:00 2001
|
||||
From: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
Date: Thu, 17 Aug 2023 17:56:55 +0800
|
||||
Subject: [PATCH 15/26] sanity_test: fix to show messages from testcase
|
||||
|
||||
The messages should not be muted.
|
||||
|
||||
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
---
|
||||
test/sanity_test.sh | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
|
||||
index dd8ed18..6e763da 100755
|
||||
--- a/test/sanity_test.sh
|
||||
+++ b/test/sanity_test.sh
|
||||
@@ -65,7 +65,7 @@ run_cmd()
|
||||
if [ -z ${VALGRIND} ]; then
|
||||
# "|| exit_code=$?" is used to capature the return value.
|
||||
# It could prevent bash to stop scripts when error occurs.
|
||||
- $@ &> /dev/null || exit_code=$?
|
||||
+ $@ || exit_code=$?
|
||||
else
|
||||
${VALGRIND} $@
|
||||
fi
|
||||
--
|
||||
2.25.1
|
||||
|
||||
85
0016-sanity_test-append-run_cmd-for-zip.patch
Normal file
85
0016-sanity_test-append-run_cmd-for-zip.patch
Normal file
@ -0,0 +1,85 @@
|
||||
From adaa9dd6658240615921bd7547d972a160627882 Mon Sep 17 00:00:00 2001
|
||||
From: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
Date: Thu, 17 Aug 2023 18:00:19 +0800
|
||||
Subject: [PATCH 16/26] sanity_test: append run_cmd for zip
|
||||
|
||||
run_cmd is used to prevent bash script abruption too early before error
|
||||
handlering in the script. And it should be used for all the test
|
||||
programs that is invoked by the script.
|
||||
|
||||
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
---
|
||||
test/sanity_test.sh | 20 ++++++++++----------
|
||||
1 file changed, 10 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
|
||||
index 6e763da..81135e3 100755
|
||||
--- a/test/sanity_test.sh
|
||||
+++ b/test/sanity_test.sh
|
||||
@@ -87,10 +87,10 @@ hw_blk_deflate()
|
||||
case $3 in
|
||||
"gzip")
|
||||
${RM} -f /tmp/gzip_list.bin
|
||||
- zip_sva_perf --in $1 --out $2 --olist /tmp/gzip_list.bin $@
|
||||
+ run_cmd zip_sva_perf --in $1 --out $2 --olist /tmp/gzip_list.bin $@
|
||||
;;
|
||||
"zlib")
|
||||
- zip_sva_perf -z --in $1 --out $2 --olist /tmp/zlib_list.bin $@
|
||||
+ run_cmd zip_sva_perf -z --in $1 --out $2 --olist /tmp/zlib_list.bin $@
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported algorithm type: $3"
|
||||
@@ -104,10 +104,10 @@ hw_blk_inflate()
|
||||
{
|
||||
case $3 in
|
||||
"gzip")
|
||||
- zip_sva_perf -d --in $1 --out $2 --ilist /tmp/gzip_list.bin $@
|
||||
+ run_cmd zip_sva_perf -d --in $1 --out $2 --ilist /tmp/gzip_list.bin $@
|
||||
;;
|
||||
"zlib")
|
||||
- zip_sva_perf -z -d --in $1 --out $2 --ilist /tmp/zlib_list.bin $@
|
||||
+ run_cmd zip_sva_perf -z -d --in $1 --out $2 --ilist /tmp/zlib_list.bin $@
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported algorithm type: $3"
|
||||
@@ -121,10 +121,10 @@ hw_strm_deflate()
|
||||
{
|
||||
case $3 in
|
||||
"gzip")
|
||||
- zip_sva_perf -S --in $1 --out $2 $@
|
||||
+ run_cmd zip_sva_perf -S --in $1 --out $2 $@
|
||||
;;
|
||||
"zlib")
|
||||
- zip_sva_perf -z -S --in $1 --out $2 $@
|
||||
+ run_cmd zip_sva_perf -z -S --in $1 --out $2 $@
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported algorithm type: $3"
|
||||
@@ -138,10 +138,10 @@ hw_strm_inflate()
|
||||
{
|
||||
case $3 in
|
||||
"gzip")
|
||||
- zip_sva_perf -S -d --in $1 --out $2 $@
|
||||
+ run_cmd zip_sva_perf -S -d --in $1 --out $2 $@
|
||||
;;
|
||||
"zlib")
|
||||
- zip_sva_perf -z -S -d --in $1 --out $2 $@
|
||||
+ run_cmd zip_sva_perf -z -S -d --in $1 --out $2 $@
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported algorithm type: $3"
|
||||
@@ -365,9 +365,9 @@ run_zip_test_v2()
|
||||
WD_COMP_EPOLL_EN=1 hw_dfl_hw_ifl /tmp/syslog
|
||||
WD_COMP_EPOLL_EN=0 hw_dfl_hw_ifl /tmp/syslog
|
||||
# test without environment variables
|
||||
- #zip_sva_perf -b 8192 -s 81920 -l 1000 --self
|
||||
+ #run_cmd zip_sva_perf -b 8192 -s 81920 -l 1000 --self
|
||||
# test with environment variables
|
||||
- #zip_sva_perf -b 8192 -s 81920 -l 1000 --self --env
|
||||
+ #run_cmd zip_sva_perf -b 8192 -s 81920 -l 1000 --self --env
|
||||
}
|
||||
|
||||
# Accept more paraterms
|
||||
--
|
||||
2.25.1
|
||||
|
||||
32
0017-uadk-fix-hpre-test.patch
Normal file
32
0017-uadk-fix-hpre-test.patch
Normal file
@ -0,0 +1,32 @@
|
||||
From c910149f83b888b78984ca58c5bb82fd5ec64b96 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 18 Aug 2023 11:12:59 +0800
|
||||
Subject: [PATCH 17/26] uadk: fix hpre test
|
||||
|
||||
Hpre test should use dynamic dev path.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
test/sanity_test.sh | 5 +++--
|
||||
1 file changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
|
||||
index 81135e3..2fac5ee 100755
|
||||
--- a/test/sanity_test.sh
|
||||
+++ b/test/sanity_test.sh
|
||||
@@ -390,9 +390,10 @@ run_sec_test_v2()
|
||||
# failed: return 1; success: return 0
|
||||
run_hpre_test_v2()
|
||||
{
|
||||
- run_cmd test_hisi_hpre --trd_mode=sync
|
||||
+ dev_path=$(ls -1 /dev/hisi_hpre-* | head -1)
|
||||
+ run_cmd test_hisi_hpre --trd_mode=sync --dev_path=$dev_path
|
||||
|
||||
- run_cmd test_hisi_hpre --trd_mode=async
|
||||
+ run_cmd test_hisi_hpre --trd_mode=async --dev_path=$dev_path
|
||||
}
|
||||
|
||||
# failed: return 1; success: return 0
|
||||
--
|
||||
2.25.1
|
||||
|
||||
380
0018-uadk-add-the-msg-pool-depth-configuration.patch
Normal file
380
0018-uadk-add-the-msg-pool-depth-configuration.patch
Normal file
@ -0,0 +1,380 @@
|
||||
From 5523680f38335fb8abedd1b6a09d9df9a1078697 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 31 Jul 2023 14:50:48 +0800
|
||||
Subject: [PATCH 18/26] uadk: add the msg pool depth configuration
|
||||
|
||||
Add the message pool depth configuration. Users can use
|
||||
the 'ctx_msg_num' in 'struct wd_cap_config' to input the
|
||||
depth of message pool. If the input value ranges from 1 to 1024,
|
||||
the input value is used to initialize async message pool. Otherwise,
|
||||
the default value is used to initialize async message pool.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
include/wd_alg_common.h | 17 +++++++++++++++++
|
||||
include/wd_util.h | 9 ++++++---
|
||||
wd_aead.c | 5 ++---
|
||||
wd_cipher.c | 3 +--
|
||||
wd_comp.c | 6 ++----
|
||||
wd_dh.c | 3 +--
|
||||
wd_digest.c | 3 +--
|
||||
wd_ecc.c | 6 +-----
|
||||
wd_rsa.c | 6 +-----
|
||||
wd_util.c | 31 ++++++++++++++++++++++++++++---
|
||||
wd_zlibwrapper.c | 2 +-
|
||||
11 files changed, 61 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
||||
index 8a86656..77845a4 100644
|
||||
--- a/include/wd_alg_common.h
|
||||
+++ b/include/wd_alg_common.h
|
||||
@@ -55,6 +55,19 @@ struct wd_ctx {
|
||||
__u8 ctx_mode;
|
||||
};
|
||||
|
||||
+/**
|
||||
+ * struct wd_cap_config - Capabilities.
|
||||
+ * @ctx_msg_num: number of asynchronous msg pools that the user wants to allocate.
|
||||
+ * Optional, user can set ctx_msg_num based on the number of requests
|
||||
+ * and system memory, 1~1024 is valid. If the value is not set or invalid,
|
||||
+ * the default value 1024 is used to initialize msg pools.
|
||||
+ * @resv: Reserved data.
|
||||
+ */
|
||||
+struct wd_cap_config {
|
||||
+ __u32 ctx_msg_num;
|
||||
+ __u32 resv;
|
||||
+};
|
||||
+
|
||||
/**
|
||||
* struct wd_ctx_config - Define a ctx set and its related attributes, which
|
||||
* will be used in the scope of current process.
|
||||
@@ -62,11 +75,13 @@ struct wd_ctx {
|
||||
* @ctxs: Point to a ctx array, length is above ctx_num.
|
||||
* @priv: The attributes of ctx defined by user, which is used by user
|
||||
* defined scheduler.
|
||||
+ * @cap: Capabilities input by user. Support set NULL, use default value initialize.
|
||||
*/
|
||||
struct wd_ctx_config {
|
||||
__u32 ctx_num;
|
||||
struct wd_ctx *ctxs;
|
||||
void *priv;
|
||||
+ struct wd_cap_config *cap;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -89,11 +104,13 @@ struct wd_ctx_nums {
|
||||
* @ctx_set_num: Each operation type ctx sets numbers.
|
||||
* @bmp: Ctxs distribution. Means users want to run business process on these
|
||||
* numa or request ctx from devices located in these numa.
|
||||
+ * @cap: Capabilities input by user. Support set NULL, use default value initialize.
|
||||
*/
|
||||
struct wd_ctx_params {
|
||||
__u32 op_type_num;
|
||||
struct wd_ctx_nums *ctx_set_num;
|
||||
struct bitmask *bmp;
|
||||
+ struct wd_cap_config *cap;
|
||||
};
|
||||
|
||||
struct wd_ctx_internal {
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index 144ba59..cb07657 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -19,6 +19,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+#define WD_POOL_MAX_ENTRIES 1024
|
||||
+
|
||||
#define FOREACH_NUMA(i, config, config_numa) \
|
||||
for ((i) = 0, (config_numa) = (config)->config_per_numa; \
|
||||
(i) < (config)->numa_num; (config_numa)++, (i)++)
|
||||
@@ -167,9 +169,9 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in);
|
||||
void wd_memset_zero(void *data, __u32 size);
|
||||
|
||||
/*
|
||||
- * wd_init_async_request_pool() - Init message pools.
|
||||
+ * wd_init_async_request_pool() - Init async message pools.
|
||||
* @pool: Pointer of message pool.
|
||||
- * @pool_num: Message pool number.
|
||||
+ * @config: ctx configuration input by user.
|
||||
* @msg_num: Message entry number in one pool.
|
||||
* @msg_size: Size of each message entry.
|
||||
*
|
||||
@@ -186,7 +188,8 @@ void wd_memset_zero(void *data, __u32 size);
|
||||
* +-------+-------+----+-------+ -+-
|
||||
* |<------- msg_num ---------->|
|
||||
*/
|
||||
-int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num,
|
||||
+int wd_init_async_request_pool(struct wd_async_msg_pool *pool,
|
||||
+ struct wd_ctx_config *config,
|
||||
__u32 msg_num, __u32 msg_size);
|
||||
|
||||
/*
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 7c3f160..cd0812e 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#define WD_AEAD_CCM_GCM_MIN 4U
|
||||
#define WD_AEAD_CCM_GCM_MAX 16
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
|
||||
static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
||||
@@ -429,8 +428,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
|
||||
/* init async request pool */
|
||||
ret = wd_init_async_request_pool(&wd_aead_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
- sizeof(struct wd_aead_msg));
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
+ sizeof(struct wd_aead_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index adb6496..8acadcd 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -20,7 +20,6 @@
|
||||
#define AES_KEYSIZE_192 24
|
||||
#define AES_KEYSIZE_256 32
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
#define DES_WEAK_KEY_NUM 16
|
||||
|
||||
static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
|
||||
@@ -311,7 +310,7 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
|
||||
|
||||
/* allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_cipher_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_cipher_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 93c3031..a23dee1 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "drv/wd_comp_drv.h"
|
||||
#include "wd_comp.h"
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
#define HW_CTX_SIZE (64 * 1024)
|
||||
#define STREAM_CHUNK (128 * 1024)
|
||||
|
||||
@@ -130,9 +129,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
- /* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_comp_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_comp_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
@@ -222,7 +220,7 @@ void wd_comp_uninit(void)
|
||||
int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0};
|
||||
- struct wd_ctx_params comp_ctx_params;
|
||||
+ struct wd_ctx_params comp_ctx_params = {0};
|
||||
int ret = -WD_EINVAL;
|
||||
bool flag;
|
||||
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 50a1532..97df515 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "include/drv/wd_dh_drv.h"
|
||||
#include "wd_util.h"
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
#define DH_MAX_KEY_SIZE 512
|
||||
#define WD_DH_G2 2
|
||||
|
||||
@@ -105,7 +104,7 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
|
||||
|
||||
/* initialize async request pool */
|
||||
ret = wd_init_async_request_pool(&wd_dh_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_dh_msg));
|
||||
if (ret)
|
||||
goto out_clear_sched;
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index c5dbeca..9dc4bb3 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -19,7 +19,6 @@
|
||||
#define AES_KEYSIZE_192 24
|
||||
#define AES_KEYSIZE_256 32
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
#define DES_WEAK_KEY_NUM 4
|
||||
|
||||
static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
@@ -243,7 +242,7 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
||||
|
||||
/* allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_digest_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_digest_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 9f83fea..938e516 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -17,9 +17,6 @@
|
||||
#include "include/wd_ecc_curve.h"
|
||||
#include "wd_ecc.h"
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
-#define WD_ECC_CTX_MSG_NUM 64
|
||||
-#define WD_ECC_MAX_CTX 256
|
||||
#define ECC_MAX_HW_BITS 521
|
||||
#define ECC_MAX_KEY_SIZE BITS_TO_BYTES(ECC_MAX_HW_BITS)
|
||||
#define ECC_MAX_IN_NUM 4
|
||||
@@ -169,9 +166,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
- /* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_ecc_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_ecc_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 19a590f..2993637 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -15,9 +15,6 @@
|
||||
#include "include/drv/wd_rsa_drv.h"
|
||||
#include "wd_rsa.h"
|
||||
|
||||
-#define WD_POOL_MAX_ENTRIES 1024
|
||||
-#define WD_HW_EACCESS 62
|
||||
-
|
||||
#define RSA_MAX_KEY_SIZE 512
|
||||
|
||||
static __thread __u64 balance;
|
||||
@@ -144,9 +141,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
- /* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_rsa_setting.pool,
|
||||
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
+ config, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_rsa_msg));
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index ef67f1f..937ee2a 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -310,6 +310,20 @@ void wd_memset_zero(void *data, __u32 size)
|
||||
*s++ = 0;
|
||||
}
|
||||
|
||||
+static void get_ctx_msg_num(struct wd_cap_config *cap, __u32 *msg_num)
|
||||
+{
|
||||
+ if (!cap || !cap->ctx_msg_num)
|
||||
+ return;
|
||||
+
|
||||
+ if (cap->ctx_msg_num > WD_POOL_MAX_ENTRIES) {
|
||||
+ WD_INFO("ctx_msg_num %u is invalid, use default value: %u!\n",
|
||||
+ cap->ctx_msg_num, *msg_num);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ *msg_num = cap->ctx_msg_num;
|
||||
+}
|
||||
+
|
||||
static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
|
||||
{
|
||||
pool->msgs = calloc(1, msg_num * msg_size);
|
||||
@@ -335,6 +349,9 @@ static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
|
||||
|
||||
static void uninit_msg_pool(struct msg_pool *pool)
|
||||
{
|
||||
+ if (!pool->msg_num)
|
||||
+ return;
|
||||
+
|
||||
free(pool->msgs);
|
||||
free(pool->used);
|
||||
pool->msgs = NULL;
|
||||
@@ -342,21 +359,27 @@ static void uninit_msg_pool(struct msg_pool *pool)
|
||||
memset(pool, 0, sizeof(*pool));
|
||||
}
|
||||
|
||||
-int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num,
|
||||
+int wd_init_async_request_pool(struct wd_async_msg_pool *pool, struct wd_ctx_config *config,
|
||||
__u32 msg_num, __u32 msg_size)
|
||||
{
|
||||
+ __u32 pool_num = config->ctx_num;
|
||||
__u32 i, j;
|
||||
int ret;
|
||||
|
||||
pool->pool_num = pool_num;
|
||||
|
||||
- pool->pools = calloc(1, pool->pool_num * sizeof(struct msg_pool));
|
||||
+ pool->pools = calloc(1, pool_num * sizeof(struct msg_pool));
|
||||
if (!pool->pools) {
|
||||
WD_ERR("failed to alloc memory for async msg pools!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
- for (i = 0; i < pool->pool_num; i++) {
|
||||
+ /* If user set valid msg num, use user's. */
|
||||
+ get_ctx_msg_num(config->cap, &msg_num);
|
||||
+ for (i = 0; i < pool_num; i++) {
|
||||
+ if (config->ctxs[i].ctx_mode == CTX_MODE_SYNC)
|
||||
+ continue;
|
||||
+
|
||||
ret = init_msg_pool(&pool->pools[i], msg_num, msg_size);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
@@ -2089,6 +2112,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
|
||||
/* environment variable is not set, try to use user_ctx_params first */
|
||||
if (user_ctx_params) {
|
||||
copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp);
|
||||
+ ctx_params->cap = user_ctx_params->cap;
|
||||
ctx_params->ctx_set_num = user_ctx_params->ctx_set_num;
|
||||
ctx_params->op_type_num = user_ctx_params->op_type_num;
|
||||
if (ctx_params->op_type_num > (__u32)max_op_type) {
|
||||
@@ -2657,6 +2681,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
|
||||
goto out_freesched;
|
||||
}
|
||||
|
||||
+ ctx_config->cap = attrs->ctx_params->cap;
|
||||
ret = alg_init_func(ctx_config, alg_sched);
|
||||
if (ret)
|
||||
goto out_pre_init;
|
||||
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
|
||||
index 29b51fb..4b785ce 100644
|
||||
--- a/wd_zlibwrapper.c
|
||||
+++ b/wd_zlibwrapper.c
|
||||
@@ -40,8 +40,8 @@ static void wd_zlib_unlock(void)
|
||||
|
||||
static int wd_zlib_uadk_init(void)
|
||||
{
|
||||
+ struct wd_ctx_params cparams = {0};
|
||||
struct wd_ctx_nums *ctx_set_num;
|
||||
- struct wd_ctx_params cparams;
|
||||
int ret, i;
|
||||
|
||||
if (zlib_config.status == WD_ZLIB_INIT)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
476
0019-uadk-v1-add-the-cookie-depth-configuration.patch
Normal file
476
0019-uadk-v1-add-the-cookie-depth-configuration.patch
Normal file
@ -0,0 +1,476 @@
|
||||
From 85269d2fddbe03c53763a2c3214f41a3c19f9318 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 31 Jul 2023 14:50:55 +0800
|
||||
Subject: [PATCH 19/26] uadk/v1: add the cookie depth configuration
|
||||
|
||||
Add the cookie depth configuration. Users can use
|
||||
the 'flags 0~15bits' in 'struct wd_capa' to input the
|
||||
depth of cookie. If the input value ranges from 1 to 1024,
|
||||
the input value is used to initialize cookie. Otherwise,
|
||||
the default value is used to initialize cookie.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
v1/wd.h | 8 +++++++-
|
||||
v1/wd_aead.c | 26 +++++++++++++++++---------
|
||||
v1/wd_cipher.c | 27 +++++++++++++++++----------
|
||||
v1/wd_comp.c | 4 +++-
|
||||
v1/wd_dh.c | 8 +++++---
|
||||
v1/wd_digest.c | 28 ++++++++++++++++++----------
|
||||
v1/wd_ecc.c | 29 +++++++++++++++++++----------
|
||||
v1/wd_rng.c | 14 ++++++++------
|
||||
v1/wd_rsa.c | 12 +++++++-----
|
||||
v1/wd_util.c | 16 ++++++++++++++++
|
||||
v1/wd_util.h | 11 ++++++-----
|
||||
11 files changed, 123 insertions(+), 60 deletions(-)
|
||||
|
||||
diff --git a/v1/wd.h b/v1/wd.h
|
||||
index 1bd9669..176f2ef 100644
|
||||
--- a/v1/wd.h
|
||||
+++ b/v1/wd.h
|
||||
@@ -174,7 +174,13 @@ struct wd_capa {
|
||||
int throughput;
|
||||
/* latency capability */
|
||||
int latency;
|
||||
- /* other capabilities */
|
||||
+ /*
|
||||
+ * Other capabilities.
|
||||
+ * 0~15 bits: number of cookies that the user wants to allocate.
|
||||
+ * Optional, user can set value based on the number of requests and system memory,
|
||||
+ * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256)
|
||||
+ * is used to initialize cookies.
|
||||
+ */
|
||||
__u32 flags;
|
||||
|
||||
/* For algorithm parameters, now it is defined in extending notions */
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index f81f327..a82d51d 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -142,13 +142,23 @@ static int create_ctx_para_check(struct wd_queue *q,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void init_aead_cookie(struct wcrypto_aead_ctx *ctx,
|
||||
+static int init_aead_cookie(struct wcrypto_aead_ctx *ctx,
|
||||
struct wcrypto_aead_ctx_setup *setup)
|
||||
{
|
||||
struct wcrypto_aead_cookie *cookie;
|
||||
- __u32 i;
|
||||
+ __u32 flags = ctx->q->capa.flags;
|
||||
+ __u32 cookies_num, i;
|
||||
+ int ret;
|
||||
+
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
+ ret = wd_init_cookie_pool(&ctx->pool,
|
||||
+ sizeof(struct wcrypto_aead_cookie), cookies_num);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to init cookie pool!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.alg_type = WCRYPTO_AEAD;
|
||||
@@ -161,6 +171,8 @@ static void init_aead_cookie(struct wcrypto_aead_ctx *ctx,
|
||||
cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id;
|
||||
cookie->msg.usr_data = (uintptr_t)&cookie->tag;
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int wcrypto_setup_qinfo(struct wcrypto_aead_ctx_setup *setup,
|
||||
@@ -236,13 +248,9 @@ void *wcrypto_create_aead_ctx(struct wd_queue *q,
|
||||
}
|
||||
|
||||
ctx->iv_blk_size = get_iv_block_size(setup->cmode);
|
||||
- ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_aead_cookie), WD_CTX_MSG_NUM);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to init cookie pool!\n");
|
||||
+ ret = init_aead_cookie(ctx, setup);
|
||||
+ if (ret)
|
||||
goto free_ctx_akey;
|
||||
- }
|
||||
- init_aead_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 3d7d140..55bfbe2 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -122,13 +122,23 @@ static int create_ctx_para_check(struct wd_queue *q,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void init_cipher_cookie(struct wcrypto_cipher_ctx *ctx,
|
||||
+static int init_cipher_cookie(struct wcrypto_cipher_ctx *ctx,
|
||||
struct wcrypto_cipher_ctx_setup *setup)
|
||||
{
|
||||
struct wcrypto_cipher_cookie *cookie;
|
||||
- __u32 i;
|
||||
+ __u32 flags = ctx->q->capa.flags;
|
||||
+ __u32 cookies_num, i;
|
||||
+ int ret;
|
||||
+
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
+ ret = wd_init_cookie_pool(&ctx->pool,
|
||||
+ sizeof(struct wcrypto_cipher_cookie), cookies_num);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to init cookie pool!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.alg_type = WCRYPTO_CIPHER;
|
||||
@@ -139,6 +149,8 @@ static void init_cipher_cookie(struct wcrypto_cipher_ctx *ctx,
|
||||
cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id;
|
||||
cookie->msg.usr_data = (uintptr_t)&cookie->tag;
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int setup_qinfo(struct wcrypto_cipher_ctx_setup *setup,
|
||||
@@ -209,14 +221,9 @@ void *wcrypto_create_cipher_ctx(struct wd_queue *q,
|
||||
}
|
||||
|
||||
ctx->iv_blk_size = get_iv_block_size(setup->alg, setup->mode);
|
||||
-
|
||||
- ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_cipher_cookie), WD_CTX_MSG_NUM);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to init cookie pool!\n");
|
||||
+ ret = init_cipher_cookie(ctx, setup);
|
||||
+ if (ret)
|
||||
goto free_ctx_key;
|
||||
- }
|
||||
- init_cipher_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
|
||||
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
|
||||
index 9e7ec5a..f898c1d 100644
|
||||
--- a/v1/wd_comp.c
|
||||
+++ b/v1/wd_comp.c
|
||||
@@ -122,6 +122,7 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q,
|
||||
{
|
||||
struct wcrypto_comp_ctx *ctx;
|
||||
struct q_info *qinfo;
|
||||
+ __u32 cookies_num;
|
||||
__u32 ctx_id = 0;
|
||||
int ret;
|
||||
|
||||
@@ -169,8 +170,9 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q,
|
||||
goto free_ctx_id;
|
||||
}
|
||||
|
||||
+ cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_CTX_COOKIES_NUM);
|
||||
ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_comp_cookie), WD_CTX_MSG_NUM);
|
||||
+ sizeof(struct wcrypto_comp_cookie), cookies_num);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
goto free_ctx_buf;
|
||||
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
|
||||
index 714ae71..9ed0e0d 100644
|
||||
--- a/v1/wd_dh.c
|
||||
+++ b/v1/wd_dh.c
|
||||
@@ -90,17 +90,19 @@ static int wcrypto_init_dh_cookie(struct wcrypto_dh_ctx *ctx)
|
||||
{
|
||||
struct wcrypto_dh_ctx_setup *setup = &ctx->setup;
|
||||
struct wcrypto_dh_cookie *cookie;
|
||||
+ __u32 flags = ctx->q->capa.flags;
|
||||
+ __u32 cookies_num, i;
|
||||
int ret;
|
||||
- __u32 i;
|
||||
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_dh_cookie), WD_HPRE_CTX_MSG_NUM);
|
||||
+ sizeof(struct wcrypto_dh_cookie), cookies_num);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.is_g2 = (__u8)setup->is_g2;
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index 809aecd..cb0d4d8 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -98,13 +98,23 @@ static int create_ctx_para_check(struct wd_queue *q,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void init_digest_cookie(struct wcrypto_digest_ctx *ctx,
|
||||
- struct wcrypto_digest_ctx_setup *setup)
|
||||
+static int init_digest_cookie(struct wcrypto_digest_ctx *ctx,
|
||||
+ struct wcrypto_digest_ctx_setup *setup)
|
||||
{
|
||||
struct wcrypto_digest_cookie *cookie;
|
||||
- __u32 i;
|
||||
+ __u32 flags = ctx->q->capa.flags;
|
||||
+ __u32 cookies_num, i;
|
||||
+ int ret;
|
||||
+
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
+ ret = wd_init_cookie_pool(&ctx->pool,
|
||||
+ sizeof(struct wcrypto_digest_cookie), cookies_num);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to init cookie pool!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.alg_type = WCRYPTO_DIGEST;
|
||||
@@ -117,6 +127,8 @@ static void init_digest_cookie(struct wcrypto_digest_ctx *ctx,
|
||||
cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id;
|
||||
cookie->msg.usr_data = (uintptr_t)&cookie->tag;
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int setup_qinfo(struct wcrypto_digest_ctx_setup *setup,
|
||||
@@ -192,13 +204,9 @@ void *wcrypto_create_digest_ctx(struct wd_queue *q,
|
||||
else
|
||||
ctx->align_sz = SEC_SHA1_ALIGN_SZ;
|
||||
|
||||
- ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_digest_cookie), WD_CTX_MSG_NUM);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to init cookie pool!\n");
|
||||
+ ret = init_digest_cookie(ctx, setup);
|
||||
+ if (ret)
|
||||
goto free_ctx_key;
|
||||
- }
|
||||
- init_digest_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
|
||||
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
|
||||
index 93b4e1b..c4fab63 100644
|
||||
--- a/v1/wd_ecc.c
|
||||
+++ b/v1/wd_ecc.c
|
||||
@@ -1062,15 +1062,25 @@ static void del_ctx_key(struct wd_mm_br *br,
|
||||
}
|
||||
}
|
||||
|
||||
-static void init_ctx_cookies(struct wcrypto_ecc_ctx *ctx,
|
||||
- struct wcrypto_ecc_ctx_setup *setup)
|
||||
+static int init_ctx_cookies(struct wcrypto_ecc_ctx *ctx,
|
||||
+ struct wcrypto_ecc_ctx_setup *setup)
|
||||
{
|
||||
__u32 hsz = get_hw_keysize(ctx->key_size);
|
||||
struct q_info *qinfo = ctx->q->qinfo;
|
||||
struct wcrypto_ecc_cookie *cookie;
|
||||
- __u32 i;
|
||||
+ __u32 flags = ctx->q->capa.flags;
|
||||
+ __u32 cookies_num, i;
|
||||
+ int ret;
|
||||
+
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
+ ret = wd_init_cookie_pool(&ctx->pool,
|
||||
+ sizeof(struct wcrypto_ecc_cookie), cookies_num);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("fail to init cookie pool!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.curve_id = setup->cv.cfg.id;
|
||||
@@ -1082,6 +1092,8 @@ static void init_ctx_cookies(struct wcrypto_ecc_ctx *ctx,
|
||||
cookie->tag.ctx_id = ctx->ctx_id;
|
||||
cookie->msg.usr_data = (uintptr_t)&cookie->tag;
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int setup_qinfo(struct wcrypto_ecc_ctx_setup *setup,
|
||||
@@ -1147,13 +1159,10 @@ void *wcrypto_create_ecc_ctx(struct wd_queue *q,
|
||||
ctx->key_size = BITS_TO_BYTES(setup->key_bits);
|
||||
ctx->q = q;
|
||||
ctx->ctx_id = cid + 1;
|
||||
- ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_ecc_cookie), WD_HPRE_CTX_MSG_NUM);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to init cookie pool!\n");
|
||||
+
|
||||
+ ret = init_ctx_cookies(ctx, setup);
|
||||
+ if (ret)
|
||||
goto free_ctx;
|
||||
- }
|
||||
- init_ctx_cookies(ctx, setup);
|
||||
|
||||
ret = create_ctx_key(setup, ctx);
|
||||
if (unlikely(ret)) {
|
||||
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
|
||||
index a783f99..cc8a594 100644
|
||||
--- a/v1/wd_rng.c
|
||||
+++ b/v1/wd_rng.c
|
||||
@@ -26,9 +26,9 @@
|
||||
#include "wd_util.h"
|
||||
#include "wd_rng.h"
|
||||
|
||||
-#define MAX_NUM 10
|
||||
-#define RNG_RESEND_CNT 8
|
||||
-#define RNG_RECV_CNT 8
|
||||
+#define RNG_RESEND_CNT 8
|
||||
+#define RNG_RECV_CNT 8
|
||||
+#define WD_RNG_CTX_COOKIE_NUM 256
|
||||
|
||||
struct wcrypto_rng_cookie {
|
||||
struct wcrypto_cb_tag tag;
|
||||
@@ -84,7 +84,8 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q,
|
||||
struct wcrypto_rng_cookie *cookie;
|
||||
struct wcrypto_rng_ctx *ctx;
|
||||
struct q_info *qinfo;
|
||||
- __u32 i, ctx_id = 0;
|
||||
+ __u32 cookies_num, i;
|
||||
+ __u32 ctx_id = 0;
|
||||
int ret;
|
||||
|
||||
if (wcrypto_setup_qinfo(setup, q, &ctx_id))
|
||||
@@ -99,14 +100,15 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q,
|
||||
ctx->q = q;
|
||||
ctx->ctx_id = ctx_id + 1;
|
||||
|
||||
+ cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM);
|
||||
ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_rng_cookie), WD_RNG_CTX_MSG_NUM);
|
||||
+ sizeof(struct wcrypto_rng_cookie), cookies_num);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
free(ctx);
|
||||
goto free_ctx_id;
|
||||
}
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
cookie->msg.alg_type = WCRYPTO_RNG;
|
||||
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
|
||||
index 61de3cc..4a2a5b5 100644
|
||||
--- a/v1/wd_rsa.c
|
||||
+++ b/v1/wd_rsa.c
|
||||
@@ -496,19 +496,21 @@ static void del_ctx_key(struct wcrypto_rsa_ctx_setup *setup,
|
||||
}
|
||||
}
|
||||
|
||||
-struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, int ctx_id)
|
||||
+static struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup,
|
||||
+ int ctx_id, __u32 flags)
|
||||
{
|
||||
struct wcrypto_rsa_cookie *cookie;
|
||||
struct wcrypto_rsa_ctx *ctx;
|
||||
- __u32 i;
|
||||
+ __u32 cookies_num, i;
|
||||
int ret;
|
||||
|
||||
ctx = calloc(1, sizeof(struct wcrypto_rsa_ctx));
|
||||
if (!ctx)
|
||||
return ctx;
|
||||
|
||||
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM);
|
||||
ret = wd_init_cookie_pool(&ctx->pool,
|
||||
- sizeof(struct wcrypto_rsa_cookie), WD_HPRE_CTX_MSG_NUM);
|
||||
+ sizeof(struct wcrypto_rsa_cookie), cookies_num);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
free(ctx);
|
||||
@@ -518,7 +520,7 @@ struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, int ctx_
|
||||
memcpy(&ctx->setup, setup, sizeof(*setup));
|
||||
ctx->ctx_id = ctx_id;
|
||||
ctx->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
|
||||
- for (i = 0; i < ctx->pool.cookies_num; i++) {
|
||||
+ for (i = 0; i < cookies_num; i++) {
|
||||
cookie = (void *)((uintptr_t)ctx->pool.cookies +
|
||||
i * ctx->pool.cookies_size);
|
||||
if (setup->is_crt)
|
||||
@@ -611,7 +613,7 @@ void *wcrypto_create_rsa_ctx(struct wd_queue *q, struct wcrypto_rsa_ctx_setup *s
|
||||
qinfo->ctx_num++;
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
|
||||
- ctx = create_ctx(setup, cid + 1);
|
||||
+ ctx = create_ctx(setup, cid + 1, q->capa.flags);
|
||||
if (!ctx) {
|
||||
WD_ERR("create rsa ctx fail!\n");
|
||||
goto free_ctx_id;
|
||||
diff --git a/v1/wd_util.c b/v1/wd_util.c
|
||||
index 26f46d4..6b8f944 100644
|
||||
--- a/v1/wd_util.c
|
||||
+++ b/v1/wd_util.c
|
||||
@@ -157,6 +157,22 @@ put_cookies:
|
||||
return -WD_EBUSY;
|
||||
}
|
||||
|
||||
+__u32 wd_get_ctx_cookies_num(__u32 usr_cookies_num, __u32 def_num)
|
||||
+{
|
||||
+ __u32 usr_num = usr_cookies_num & WD_CTX_COOKIES_NUM_MASK;
|
||||
+
|
||||
+ if (!usr_num)
|
||||
+ return def_num;
|
||||
+
|
||||
+ if (usr_num > WD_MAX_CTX_COOKIES_NUM) {
|
||||
+ WD_ERR("user msg num %u is invalid, use default value: %u!\n",
|
||||
+ usr_num, def_num);
|
||||
+ return def_num;
|
||||
+ }
|
||||
+
|
||||
+ return usr_num;
|
||||
+}
|
||||
+
|
||||
int wd_burst_send(struct wd_queue *q, void **req, __u32 num)
|
||||
{
|
||||
return drv_send(q, req, num);
|
||||
diff --git a/v1/wd_util.h b/v1/wd_util.h
|
||||
index 617af3b..a8c6b15 100644
|
||||
--- a/v1/wd_util.h
|
||||
+++ b/v1/wd_util.h
|
||||
@@ -36,11 +36,11 @@
|
||||
#include "v1/wd_ecc.h"
|
||||
#include "v1/wd_adapter.h"
|
||||
|
||||
-#define WD_CTX_MSG_NUM 64
|
||||
-#define WD_HPRE_CTX_MSG_NUM 64
|
||||
-#define WD_RNG_CTX_MSG_NUM 256
|
||||
-#define WD_MAX_CTX_NUM 256
|
||||
-#define BYTE_BITS 8
|
||||
+#define WD_CTX_COOKIES_NUM 64
|
||||
+#define WD_MAX_CTX_COOKIES_NUM 1024
|
||||
+#define WD_CTX_COOKIES_NUM_MASK 0xffff
|
||||
+#define WD_MAX_CTX_NUM 256
|
||||
+#define BYTE_BITS 8
|
||||
#define BYTE_BITS_SHIFT 3
|
||||
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
|
||||
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
|
||||
@@ -393,6 +393,7 @@ int wd_alloc_id(__u8 *buf, __u32 size, __u32 *id, __u32 last_id, __u32 id_max);
|
||||
void wd_free_id(__u8 *buf, __u32 size, __u32 id, __u32 id_max);
|
||||
int wd_get_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num);
|
||||
void wd_put_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num);
|
||||
+__u32 wd_get_ctx_cookies_num(__u32 usr_cookies_num, __u32 def_num);
|
||||
const char *wd_get_drv(struct wd_queue *q);
|
||||
int wd_burst_send(struct wd_queue *q, void **req, __u32 num);
|
||||
int wd_burst_recv(struct wd_queue *q, void **resp, __u32 num);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
39
0020-uadk_tool-initialize-cparams-to-0.patch
Normal file
39
0020-uadk_tool-initialize-cparams-to-0.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 9fe805e5bf8fe6ef6ad351070a51148363de7991 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 31 Jul 2023 14:51:00 +0800
|
||||
Subject: [PATCH 20/26] uadk_tool: initialize cparams to 0
|
||||
|
||||
Initialize cparams to 0.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
uadk_tool/test/test_sec.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c
|
||||
index 657d123..9594e61 100644
|
||||
--- a/uadk_tool/test/test_sec.c
|
||||
+++ b/uadk_tool/test/test_sec.c
|
||||
@@ -1469,8 +1469,8 @@ out:
|
||||
|
||||
static int digest_init2(int type, int mode)
|
||||
{
|
||||
+ struct wd_ctx_params cparams = {0};
|
||||
struct wd_ctx_nums *ctx_set_num;
|
||||
- struct wd_ctx_params cparams;
|
||||
int ret;
|
||||
|
||||
if (g_testalg >= MAX_ALGO_PER_TYPE)
|
||||
@@ -2721,8 +2721,8 @@ out:
|
||||
|
||||
static int aead_init2(int type, int mode)
|
||||
{
|
||||
+ struct wd_ctx_params cparams = {0};
|
||||
struct wd_ctx_nums *ctx_set_num;
|
||||
- struct wd_ctx_params cparams;
|
||||
int ret;
|
||||
|
||||
if (g_testalg >= MAX_ALGO_PER_TYPE)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
380
0021-uadk-add-init-wait-timeout.patch
Normal file
380
0021-uadk-add-init-wait-timeout.patch
Normal file
@ -0,0 +1,380 @@
|
||||
From 9fe6d47a877510efc339a1d51c86915f42ea40e3 Mon Sep 17 00:00:00 2001
|
||||
From: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
Date: Sat, 26 Aug 2023 11:06:00 +0800
|
||||
Subject: [PATCH 21/26] uadk: add init wait timeout
|
||||
|
||||
Add init wait timeout judgment to prevent
|
||||
deadlocks when making loopback calls from
|
||||
the same thread.
|
||||
|
||||
Signed-off-by: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
---
|
||||
include/wd_util.h | 7 ++++---
|
||||
wd_aead.c | 16 +++++++---------
|
||||
wd_cipher.c | 15 +++++++--------
|
||||
wd_comp.c | 15 +++++++--------
|
||||
wd_dh.c | 16 +++++++---------
|
||||
wd_digest.c | 16 +++++++---------
|
||||
wd_ecc.c | 15 +++++++--------
|
||||
wd_rsa.c | 16 +++++++---------
|
||||
wd_util.c | 18 +++++++++++-------
|
||||
9 files changed, 64 insertions(+), 70 deletions(-)
|
||||
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index cb07657..be9798c 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -387,10 +387,11 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
* if need initialization.
|
||||
* @status: algorithm initialization status.
|
||||
*
|
||||
- * Return true if need initialization and false if initialized, otherwise will wait
|
||||
- * last initialization result.
|
||||
+ * Return 0 if need initialization.
|
||||
+ * Return -WD_EEXIST if the algorithm has been initialized.
|
||||
+ * Return -WD_ETIMEDOUT if wait timeout.
|
||||
*/
|
||||
-bool wd_alg_try_init(enum wd_status *status);
|
||||
+int wd_alg_try_init(enum wd_status *status);
|
||||
|
||||
/**
|
||||
* wd_alg_set_init() - Set the algorithm status as WD_INIT.
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index cd0812e..ed7b987 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -452,14 +452,13 @@ out_clear_ctx_config:
|
||||
|
||||
int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_aead_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_aead_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -524,14 +523,13 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
{
|
||||
struct wd_ctx_nums aead_ctx_num[WD_DIGEST_CIPHER_DECRYPTION + 1] = {0};
|
||||
struct wd_ctx_params aead_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
- bool flag;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_aead_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_aead_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 8acadcd..e5ed3c2 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -353,14 +353,13 @@ static int wd_cipher_common_uninit(void)
|
||||
|
||||
int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -401,14 +400,14 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p
|
||||
{
|
||||
struct wd_ctx_nums cipher_ctx_num[WD_CIPHER_DECRYPTION + 1] = {0};
|
||||
struct wd_ctx_params cipher_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
bool flag;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index a23dee1..21c9928 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -173,14 +173,13 @@ static int wd_comp_uninit_nolock(void)
|
||||
|
||||
int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_comp_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_comp_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_comp_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -221,14 +220,14 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
|
||||
{
|
||||
struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0};
|
||||
struct wd_ctx_params comp_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
bool flag;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_comp_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_comp_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_comp_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 97df515..40a52e5 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -140,14 +140,13 @@ static int wd_dh_common_uninit(void)
|
||||
|
||||
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_dh_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_dh_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -188,14 +187,13 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
|
||||
{
|
||||
struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0};
|
||||
struct wd_ctx_params dh_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
- bool flag;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_dh_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_dh_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 9dc4bb3..c8ccc8d 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -266,14 +266,13 @@ out_clear_ctx_config:
|
||||
|
||||
int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_digest_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_digest_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -334,14 +333,13 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
{
|
||||
struct wd_ctx_params digest_ctx_params = {0};
|
||||
struct wd_ctx_nums digest_ctx_num = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
- bool flag;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_digest_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_digest_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 938e516..4323e54 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -203,14 +203,13 @@ static int wd_ecc_common_uninit(void)
|
||||
|
||||
int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_ecc_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -251,14 +250,14 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
|
||||
{
|
||||
struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0};
|
||||
struct wd_ctx_params ecc_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
bool flag;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_ecc_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 2993637..1813676 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -178,14 +178,13 @@ static int wd_rsa_common_uninit(void)
|
||||
|
||||
int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_rsa_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ ret = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_param_check(config, sched);
|
||||
if (ret)
|
||||
@@ -226,14 +225,13 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
|
||||
{
|
||||
struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0};
|
||||
struct wd_ctx_params rsa_ctx_params = {0};
|
||||
- int ret = -WD_EINVAL;
|
||||
- bool flag;
|
||||
+ int state, ret = -WD_EINVAL;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_rsa_clear_status);
|
||||
|
||||
- flag = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
- if (!flag)
|
||||
- return -WD_EEXIST;
|
||||
+ state = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
+ if (state)
|
||||
+ return state;
|
||||
|
||||
if (!alg || sched_type >= SCHED_POLICY_BUTT ||
|
||||
task_type < 0 || task_type >= TASK_MAX_TYPE) {
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 937ee2a..cb89709 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#define WD_INIT_SLEEP_UTIME 1000
|
||||
#define WD_INIT_RETRY_TIMES 10000
|
||||
+#define US2S(us) ((us) >> 20)
|
||||
+#define WD_INIT_RETRY_TIMEOUT 3
|
||||
|
||||
#define DEF_DRV_LIB_FILE "libwd.so"
|
||||
|
||||
@@ -2322,10 +2324,10 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv)
|
||||
wd_release_drv(drv);
|
||||
}
|
||||
|
||||
-bool wd_alg_try_init(enum wd_status *status)
|
||||
+int wd_alg_try_init(enum wd_status *status)
|
||||
{
|
||||
enum wd_status expected;
|
||||
- int count = 0;
|
||||
+ __u32 count = 0;
|
||||
bool ret;
|
||||
|
||||
do {
|
||||
@@ -2334,15 +2336,17 @@ bool wd_alg_try_init(enum wd_status *status)
|
||||
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
|
||||
if (expected == WD_INIT) {
|
||||
WD_ERR("The algorithm has been initialized!\n");
|
||||
- return false;
|
||||
+ return -WD_EEXIST;
|
||||
}
|
||||
usleep(WD_INIT_SLEEP_UTIME);
|
||||
- if (!(++count % WD_INIT_RETRY_TIMES))
|
||||
- WD_ERR("The algorithm initizalite has been waiting for %ds!\n",
|
||||
- WD_INIT_SLEEP_UTIME * count / 1000000);
|
||||
+
|
||||
+ if (US2S(WD_INIT_SLEEP_UTIME * ++count) >= WD_INIT_RETRY_TIMEOUT) {
|
||||
+ WD_ERR("The algorithm initialize wait timeout!\n");
|
||||
+ return -WD_ETIMEDOUT;
|
||||
+ }
|
||||
} while (!ret);
|
||||
|
||||
- return true;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static __u32 wd_get_ctx_numbers(struct wd_ctx_params ctx_params, int end)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
96
0022-uadk-fix-key-length-check-error-in-xts-mode.patch
Normal file
96
0022-uadk-fix-key-length-check-error-in-xts-mode.patch
Normal file
@ -0,0 +1,96 @@
|
||||
From 1494a6461e2f835326ce0e745fa845ea5427bc80 Mon Sep 17 00:00:00 2001
|
||||
From: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
Date: Sat, 26 Aug 2023 11:06:07 +0800
|
||||
Subject: [PATCH 22/26] uadk: fix key length check error in xts mode
|
||||
|
||||
The input key in the xts mode is a combination of key1
|
||||
and key2, so the key length is even. When calculating
|
||||
the algorithm key length, it is necessary to check whether
|
||||
the input key is even.
|
||||
|
||||
Signed-off-by: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
---
|
||||
wd_cipher.c | 32 +++++++++++++++++++-------------
|
||||
1 file changed, 19 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index e5ed3c2..6f57e17 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -11,7 +11,8 @@
|
||||
#include "include/drv/wd_cipher_drv.h"
|
||||
#include "wd_cipher.h"
|
||||
|
||||
-#define XTS_MODE_KEY_DIVISOR 2
|
||||
+#define XTS_MODE_KEY_SHIFT 1
|
||||
+#define XTS_MODE_KEY_LEN_MASK 0x1
|
||||
#define SM4_KEY_SIZE 16
|
||||
#define DES_KEY_SIZE 8
|
||||
#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE)
|
||||
@@ -141,27 +142,36 @@ static int aes_key_len_check(__u32 length)
|
||||
|
||||
static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
|
||||
{
|
||||
+ __u32 key_len = length;
|
||||
int ret = 0;
|
||||
|
||||
- if (sess->mode == WD_CIPHER_XTS && length == AES_KEYSIZE_192) {
|
||||
- WD_ERR("unsupported XTS key length, length = %u\n", length);
|
||||
- return -WD_EINVAL;
|
||||
+ if (sess->mode == WD_CIPHER_XTS) {
|
||||
+ if (length & XTS_MODE_KEY_LEN_MASK) {
|
||||
+ WD_ERR("invalid: unsupported XTS key length, length = %u!\n", length);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ key_len = length >> XTS_MODE_KEY_SHIFT;
|
||||
+
|
||||
+ if (key_len == AES_KEYSIZE_192) {
|
||||
+ WD_ERR("invalid: unsupported XTS key length, length = %u!\n", length);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
}
|
||||
|
||||
switch (sess->alg) {
|
||||
case WD_CIPHER_SM4:
|
||||
- if (length != SM4_KEY_SIZE)
|
||||
+ if (key_len != SM4_KEY_SIZE)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
case WD_CIPHER_AES:
|
||||
- ret = aes_key_len_check(length);
|
||||
+ ret = aes_key_len_check(key_len);
|
||||
break;
|
||||
case WD_CIPHER_DES:
|
||||
- if (length != DES_KEY_SIZE)
|
||||
+ if (key_len != DES_KEY_SIZE)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
case WD_CIPHER_3DES:
|
||||
- if (length != DES3_2KEY_SIZE && length != DES3_3KEY_SIZE)
|
||||
+ if (key_len != DES3_2KEY_SIZE && key_len != DES3_3KEY_SIZE)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
default:
|
||||
@@ -193,7 +203,6 @@ static bool wd_cipher_alg_check(const char *alg_name)
|
||||
int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
{
|
||||
struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess;
|
||||
- __u32 length = key_len;
|
||||
int ret;
|
||||
|
||||
if (!key || !sess) {
|
||||
@@ -201,10 +210,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (sess->mode == WD_CIPHER_XTS)
|
||||
- length = key_len / XTS_MODE_KEY_DIVISOR;
|
||||
-
|
||||
- ret = cipher_key_len_check(sess, length);
|
||||
+ ret = cipher_key_len_check(sess, key_len);
|
||||
if (ret) {
|
||||
WD_ERR("cipher set key input key length err!\n");
|
||||
return -WD_EINVAL;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
102
0023-uadk-v1-fix-key-length-check-error-in-xts-mode.patch
Normal file
102
0023-uadk-v1-fix-key-length-check-error-in-xts-mode.patch
Normal file
@ -0,0 +1,102 @@
|
||||
From e54149308ba53f897bc6c36a447dd2f578c94555 Mon Sep 17 00:00:00 2001
|
||||
From: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
Date: Sat, 26 Aug 2023 11:06:16 +0800
|
||||
Subject: [PATCH 23/26] uadk/v1: fix key length check error in xts mode
|
||||
|
||||
The input key in the xts mode is a combination of key1
|
||||
and key2, so the key length is even. When calculating
|
||||
the algorithm key length, it is necessary to check whether
|
||||
the input key is even.
|
||||
|
||||
Signed-off-by: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
---
|
||||
v1/wd_cipher.c | 29 ++++++++++++++++-------------
|
||||
1 file changed, 16 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 55bfbe2..6c0ef69 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -29,6 +29,7 @@
|
||||
#define MAX_CIPHER_KEY_SIZE 64
|
||||
#define MAX_CIPHER_RETRY_CNT 20000000
|
||||
|
||||
+#define XTS_MODE_KEY_LEN_MASK 0x1
|
||||
#define DES_KEY_SIZE 8
|
||||
#define SM4_KEY_SIZE 16
|
||||
#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE)
|
||||
@@ -266,30 +267,36 @@ static int aes_key_len_check(__u16 length)
|
||||
static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup,
|
||||
__u16 length)
|
||||
{
|
||||
+ __u16 key_len = length;
|
||||
int ret = WD_SUCCESS;
|
||||
|
||||
if (setup->mode == WCRYPTO_CIPHER_XTS) {
|
||||
- if (length != AES_KEYSIZE_128 && length != AES_KEYSIZE_256) {
|
||||
- WD_ERR("unsupported XTS key length, length = %u.\n",
|
||||
- length);
|
||||
+ if (length & XTS_MODE_KEY_LEN_MASK) {
|
||||
+ WD_ERR("invalid: unsupported XTS key length, length = %u!\n", length);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ key_len = length >> XTS_MODE_KEY_SHIFT;
|
||||
+
|
||||
+ if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_256) {
|
||||
+ WD_ERR("invalid: unsupported XTS key length, length = %u!\n", length);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
switch (setup->alg) {
|
||||
case WCRYPTO_CIPHER_SM4:
|
||||
- if (length != SM4_KEY_SIZE)
|
||||
+ if (key_len != SM4_KEY_SIZE)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
case WCRYPTO_CIPHER_AES:
|
||||
- ret = aes_key_len_check(length);
|
||||
+ ret = aes_key_len_check(key_len);
|
||||
break;
|
||||
case WCRYPTO_CIPHER_DES:
|
||||
- if (length != DES_KEY_SIZE)
|
||||
+ if (key_len != DES_KEY_SIZE)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
case WCRYPTO_CIPHER_3DES:
|
||||
- if ((length != SEC_3DES_2KEY_SIZE) && (length != SEC_3DES_3KEY_SIZE))
|
||||
+ if ((key_len != SEC_3DES_2KEY_SIZE) && (key_len != SEC_3DES_3KEY_SIZE))
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
default:
|
||||
@@ -303,7 +310,6 @@ static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup,
|
||||
int wcrypto_set_cipher_key(void *ctx, __u8 *key, __u16 key_len)
|
||||
{
|
||||
struct wcrypto_cipher_ctx *ctxt = ctx;
|
||||
- __u16 length = key_len;
|
||||
int ret;
|
||||
|
||||
if (!ctx || !key) {
|
||||
@@ -311,17 +317,14 @@ int wcrypto_set_cipher_key(void *ctx, __u8 *key, __u16 key_len)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (ctxt->setup.mode == WCRYPTO_CIPHER_XTS)
|
||||
- length = key_len >> XTS_MODE_KEY_SHIFT;
|
||||
-
|
||||
- ret = cipher_key_len_check(&ctxt->setup, length);
|
||||
+ ret = cipher_key_len_check(&ctxt->setup, key_len);
|
||||
if (ret != WD_SUCCESS) {
|
||||
WD_ERR("%s: input key length err!\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ctxt->setup.alg == WCRYPTO_CIPHER_DES &&
|
||||
- is_des_weak_key((__u64 *)key, length)) {
|
||||
+ is_des_weak_key((__u64 *)key, key_len)) {
|
||||
WD_ERR("%s: des weak key!\n", __func__);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
From d3471d406fa3ec4d0289f82c8c690923390ab28a Mon Sep 17 00:00:00 2001
|
||||
From: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
Date: Thu, 7 Sep 2023 16:03:57 +0800
|
||||
Subject: [PATCH 24/26] uadk: support loading alg lib from specified
|
||||
directories
|
||||
|
||||
Solving the problem of traversing the entire library
|
||||
directory to load alg drv lib may result in unexpected
|
||||
results by specifying the loading directory 'uadk'.
|
||||
|
||||
Signed-off-by: Shangbin Liu <liushangbin@hisilicon.com>
|
||||
---
|
||||
Makefile.am | 6 ++++--
|
||||
wd_util.c | 26 +++++++++++++-------------
|
||||
2 files changed, 17 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index f04164f..657ed20 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -38,8 +38,10 @@ pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
|
||||
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
|
||||
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
|
||||
|
||||
-lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \
|
||||
- libhisi_hpre.la libhisi_sec.la
|
||||
+lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la
|
||||
+
|
||||
+uadk_driversdir=$(libdir)/uadk
|
||||
+uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la
|
||||
|
||||
libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
|
||||
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index cb89709..a9640c3 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -28,7 +28,7 @@
|
||||
#define US2S(us) ((us) >> 20)
|
||||
#define WD_INIT_RETRY_TIMEOUT 3
|
||||
|
||||
-#define DEF_DRV_LIB_FILE "libwd.so"
|
||||
+#define WD_DRV_LIB_DIR "uadk"
|
||||
|
||||
struct msg_pool {
|
||||
/* message array allocated dynamically */
|
||||
@@ -2151,7 +2151,7 @@ static void dladdr_empty(void)
|
||||
int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir)
|
||||
{
|
||||
char file_path[PATH_MAX] = {0};
|
||||
- char path[PATH_MAX];
|
||||
+ char path[PATH_MAX] = {0};
|
||||
Dl_info file_info;
|
||||
int len, rc, i;
|
||||
|
||||
@@ -2173,16 +2173,17 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir)
|
||||
}
|
||||
|
||||
if (is_dir) {
|
||||
- (void)snprintf(lib_path, PATH_MAX, "%s", file_path);
|
||||
- return 0;
|
||||
+ len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, WD_DRV_LIB_DIR);
|
||||
+ if (len >= PATH_MAX)
|
||||
+ return -WD_EINVAL;
|
||||
+ } else {
|
||||
+ len = snprintf(lib_path, PATH_MAX, "%s/%s/%s", file_path, WD_DRV_LIB_DIR, lib_file);
|
||||
+ if (len >= PATH_MAX)
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, lib_file);
|
||||
- if (len < 0)
|
||||
- return -WD_EINVAL;
|
||||
-
|
||||
if (realpath(lib_path, path) == NULL) {
|
||||
- WD_ERR("%s: no such file or directory!\n", path);
|
||||
+ WD_ERR("invalid: %s: no such file or directory!\n", path);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2205,11 +2206,10 @@ void *wd_dlopen_drv(const char *cust_lib_dir)
|
||||
if (ret)
|
||||
return NULL;
|
||||
} else {
|
||||
- (void)snprintf(lib_path, PATH_MAX, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE);
|
||||
- ret = access(lib_path, F_OK);
|
||||
- if (ret)
|
||||
+ if (realpath(cust_lib_dir, lib_path) == NULL) {
|
||||
+ WD_ERR("invalid: %s: no such file or directory!\n", lib_path);
|
||||
return NULL;
|
||||
-
|
||||
+ }
|
||||
strncpy(lib_dir_path, cust_lib_dir, PATH_MAX - 1);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
From 21df154794749bde9ea2dfd5e0fc15dd680af561 Mon Sep 17 00:00:00 2001
|
||||
From: Younger <shenyang39@huawei.com>
|
||||
Date: Fri, 15 Sep 2023 10:54:00 +0800
|
||||
Subject: [PATCH 25/26] uadk/zlibwrapper - fix failed to create multiple
|
||||
z_stream at same time
|
||||
|
||||
In wd_deflate_init/wd_inflate_init, the wd_comp_init2_ will be called
|
||||
to initialize wd_comp. wd_comp_init2_ will return -WD_EEXIST if wd_comp
|
||||
initialized.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
include/wd_zlibwrapper.h | 2 ++
|
||||
wd_zlibwrapper.c | 2 +-
|
||||
2 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
|
||||
index 847a315..58ad503 100644
|
||||
--- a/include/wd_zlibwrapper.h
|
||||
+++ b/include/wd_zlibwrapper.h
|
||||
@@ -6,6 +6,8 @@
|
||||
#ifndef UADK_ZLIBWRAPPER_H
|
||||
#define UADK_ZLIBWRAPPER_H
|
||||
|
||||
+#include <asm/types.h>
|
||||
+
|
||||
/*
|
||||
* These APIs are used to replace the ZLIB library. So if you don't use them.
|
||||
* Please do not use these. These APIs provide limited function, while the
|
||||
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
|
||||
index 4b785ce..7189b7f 100644
|
||||
--- a/wd_zlibwrapper.c
|
||||
+++ b/wd_zlibwrapper.c
|
||||
@@ -68,7 +68,7 @@ static int wd_zlib_uadk_init(void)
|
||||
ctx_set_num[i].sync_ctx_num = WD_DIR_MAX;
|
||||
|
||||
ret = wd_comp_init2_("zlib", 0, 0, &cparams);
|
||||
- if (ret) {
|
||||
+ if (ret && ret != -WD_EEXIST) {
|
||||
ret = Z_STREAM_ERROR;
|
||||
goto out_freebmp;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
From f5ce45e937378ba4475e0b63e11d7ed96a21b7af Mon Sep 17 00:00:00 2001
|
||||
From: Yu'an Wang <wangyuan46@huawei.com>
|
||||
Date: Fri, 15 Sep 2023 10:54:00 +0800
|
||||
Subject: [PATCH 26/26] uadk/v1: hisilicon/zip - add sqe_fill_priv and
|
||||
sqe_parse_priv
|
||||
|
||||
Support sqe_fill_priv and sqe_parse_priv for V3 api.
|
||||
|
||||
Signed-off-by: Yu'an Wang <wangyuan46@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_zip_udrv.c | 11 +++++++++++
|
||||
1 file changed, 11 insertions(+)
|
||||
|
||||
diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c
|
||||
index 1dec4d6..f820b7f 100644
|
||||
--- a/v1/drv/hisi_zip_udrv.c
|
||||
+++ b/v1/drv/hisi_zip_udrv.c
|
||||
@@ -256,6 +256,7 @@ int qm_parse_zip_sqe(void *hw_msg, const struct qm_queue_info *info,
|
||||
__u16 i, __u16 usr)
|
||||
{
|
||||
struct wcrypto_comp_msg *recv_msg = info->req_cache[i];
|
||||
+ struct wcrypto_comp_tag *tag = (void *)(uintptr_t)recv_msg->udata;
|
||||
struct hisi_zip_sqe *sqe = hw_msg;
|
||||
__u16 ctx_st = sqe->ctx_dw0 & HZ_CTX_ST_MASK;
|
||||
__u16 lstblk = sqe->dw3 & HZ_LSTBLK_MASK;
|
||||
@@ -301,6 +302,9 @@ int qm_parse_zip_sqe(void *hw_msg, const struct qm_queue_info *info,
|
||||
MAX_CTX_RSV_SIZE);
|
||||
}
|
||||
|
||||
+ if (tag && info->sqe_parse_priv)
|
||||
+ info->sqe_parse_priv(sqe, WCRYPTO_COMP, tag->priv);
|
||||
+
|
||||
qm_parse_zip_sqe_set_status(recv_msg, status, lstblk, ctx_st);
|
||||
|
||||
return 1;
|
||||
@@ -580,6 +584,7 @@ int qm_fill_zip_sqe_v3(void *smsg, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
struct hisi_zip_sqe_v3 *sqe = (struct hisi_zip_sqe_v3 *)info->sq_base + i;
|
||||
struct wcrypto_comp_msg *msg = smsg;
|
||||
+ struct wcrypto_comp_tag *tag = (void *)(uintptr_t)msg->udata;
|
||||
struct wd_queue *q = info->q;
|
||||
__u8 flush_type;
|
||||
__u8 data_fmt;
|
||||
@@ -628,6 +633,9 @@ int qm_fill_zip_sqe_v3(void *smsg, struct qm_queue_info *info, __u16 i)
|
||||
ops[msg->alg_type].fill_sqe_hw_info(sqe, msg);
|
||||
sqe->tag_l = msg->tag;
|
||||
|
||||
+ if (tag && info->sqe_fill_priv)
|
||||
+ info->sqe_fill_priv(sqe, WCRYPTO_COMP, tag->priv);
|
||||
+
|
||||
info->req_cache[i] = msg;
|
||||
|
||||
return WD_SUCCESS;
|
||||
@@ -728,6 +736,9 @@ int qm_parse_zip_sqe_v3(void *hw_msg, const struct qm_queue_info *info,
|
||||
if (tag && tag->priv && !info->sqe_fill_priv)
|
||||
fill_priv_lz77_zstd(sqe, recv_msg);
|
||||
|
||||
+ if (tag && info->sqe_parse_priv)
|
||||
+ info->sqe_parse_priv(sqe, WCRYPTO_COMP, tag->priv);
|
||||
+
|
||||
return 1;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
28
0027-uadk-v1-modify-the-alignment-size-of-sha384.patch
Normal file
28
0027-uadk-v1-modify-the-alignment-size-of-sha384.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 8653c2b447e8b27a18d0fe5e85a94ba97b382aab Mon Sep 17 00:00:00 2001
|
||||
From: Qi Tao <taoqi10@huawei.com>
|
||||
Date: Wed, 20 Sep 2023 15:44:38 +0800
|
||||
Subject: [PATCH 27/38] uadk/v1: modify the alignment size of sha384
|
||||
|
||||
Sha384 alignment size is 128Byte instead of 64Byte.
|
||||
|
||||
Signed-off-by: Qi Tao <taoqi10@huawei.com>
|
||||
---
|
||||
v1/wd_digest.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index cb0d4d8..7965206 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -199,7 +199,7 @@ void *wcrypto_create_digest_ctx(struct wd_queue *q,
|
||||
}
|
||||
}
|
||||
|
||||
- if (setup->alg >= WCRYPTO_SHA512)
|
||||
+ if (setup->alg >= WCRYPTO_SHA384)
|
||||
ctx->align_sz = SEC_SHA512_ALIGN_SZ;
|
||||
else
|
||||
ctx->align_sz = SEC_SHA1_ALIGN_SZ;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
141
0028-uadk-digest-optimize-the-zero-byte-packet-checking-f.patch
Normal file
141
0028-uadk-digest-optimize-the-zero-byte-packet-checking-f.patch
Normal file
@ -0,0 +1,141 @@
|
||||
From 13c256f943f44a65c7d1e8b7b40ce20aa7bd4c51 Mon Sep 17 00:00:00 2001
|
||||
From: Qi Tao <taoqi10@huawei.com>
|
||||
Date: Wed, 20 Sep 2023 15:47:31 +0800
|
||||
Subject: [PATCH 28/38] uadk/digest: optimize the zero byte packet checking for
|
||||
hash
|
||||
|
||||
Optimize the zero byte packet checking in bd2 and
|
||||
add the zero byte packet checking in bd3.
|
||||
|
||||
Hardware v2: long hash mode does not support 0 byte packet in the
|
||||
frist and middle bd. Block hash mode does not support 0 byte packet.
|
||||
|
||||
Hardware v3: long hash mode does not support 0 byte packet in the
|
||||
frist and middle bd. But, block hash mode do support 0 byte packet.
|
||||
|
||||
Signed-off-by: Qi Tao <taoqi10@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 39 +++++++++++++++++++++++----------------
|
||||
v1/drv/hisi_sec_udrv.c | 21 ++++++++++++++++++---
|
||||
2 files changed, 41 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index bc4c248..69529d2 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -1574,31 +1574,38 @@ static int digest_long_bd_align_check(struct wd_digest_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int aes_auth_len_check(struct wd_digest_msg *msg)
|
||||
+static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
- if ((msg->alg == WD_DIGEST_AES_XCBC_MAC_96 ||
|
||||
- msg->alg == WD_DIGEST_AES_XCBC_PRF_128 ||
|
||||
- msg->alg == WD_DIGEST_AES_CMAC) && !msg->in_bytes) {
|
||||
- WD_ERR("digest mode: %u not supports 0 size!\n", msg->alg);
|
||||
+ enum hash_bd_type type = get_hash_bd_type(msg);
|
||||
+
|
||||
+ /* Long hash first and middle bd */
|
||||
+ if (type == HASH_FRIST_BD || type == HASH_MIDDLE_BD) {
|
||||
+ WD_ERR("hardware v2 not supports 0 size in long hash!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ /* Block mode hash bd */
|
||||
+ if (type == HASH_SINGLE_BD) {
|
||||
+ WD_ERR("hardware v2 not supports 0 size in block hash!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg)
|
||||
+static int digest_bd3_zero_packet_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
enum hash_bd_type type = get_hash_bd_type(msg);
|
||||
-
|
||||
/* Long hash first and middle bd */
|
||||
if (type == HASH_FRIST_BD || type == HASH_MIDDLE_BD) {
|
||||
- WD_ERR("hardware v2 not supports 0 size in long hash!\n");
|
||||
+ WD_ERR("invalid: hardware v3 not supports 0 size in long hash!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- /* Block mode hash bd */
|
||||
- if (type == HASH_SINGLE_BD) {
|
||||
- WD_ERR("hardware v2 not supports 0 size in block hash!\n");
|
||||
+ if (msg->alg == WD_DIGEST_AES_XCBC_MAC_96 ||
|
||||
+ msg->alg == WD_DIGEST_AES_XCBC_PRF_128 ||
|
||||
+ msg->alg == WD_DIGEST_AES_CMAC) {
|
||||
+ WD_ERR("invalid: digest mode %u not supports 0 size!\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1610,9 +1617,9 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
int ret;
|
||||
|
||||
/*
|
||||
- * Hardware v2 needs to check the zero byte packet in the block
|
||||
- * and long hash mode. Frist and Middle bd not supports 0 size,
|
||||
- * final bd not need to check it. Hardware v3 has fixed it.
|
||||
+ * Hardware needs to check the zero byte packet in the block
|
||||
+ * and long hash mode. First and middle bd not support 0 size,
|
||||
+ * final bd not need to check it.
|
||||
*/
|
||||
if (type == BD_TYPE2 && !msg->in_bytes) {
|
||||
ret = digest_bd2_zero_packet_check(msg);
|
||||
@@ -1620,8 +1627,8 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- if (type == BD_TYPE3) {
|
||||
- ret = aes_auth_len_check(msg);
|
||||
+ if (type == BD_TYPE3 && !msg->in_bytes) {
|
||||
+ ret = digest_bd3_zero_packet_check(msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 32bded4..1dd9f37 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -992,9 +992,16 @@ static int fill_digest_bd2_alg(struct wcrypto_digest_msg *msg,
|
||||
if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (unlikely(msg->in_bytes == 0)) {
|
||||
- WD_ERR("digest bd2 not supports 0 packet!\n");
|
||||
- return -WD_EINVAL;
|
||||
+ if(unlikely(msg->in_bytes == 0)) {
|
||||
+ if ((msg->has_next && !msg->iv_bytes) || (msg->has_next && msg->iv_bytes)) {
|
||||
+ /* Long hash first and middle BD */
|
||||
+ WD_ERR("invalid: digest bd2 not supports 0 packet in first bd and middle bd!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ } else if (!msg->has_next && !msg->iv_bytes) {
|
||||
+ /* Block hash BD */
|
||||
+ WD_ERR("invalid: digest bd2 not supports 0 packet in block mode!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
}
|
||||
|
||||
sqe->type2.mac_len = msg->out_bytes / WORD_BYTES;
|
||||
@@ -1383,6 +1390,14 @@ static int fill_digest_bd3_alg(struct wcrypto_digest_msg *msg,
|
||||
if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
+ if (unlikely(msg->in_bytes == 0)) {
|
||||
+ if ((msg->has_next && !msg->iv_bytes) || (msg->has_next && msg->iv_bytes)) {
|
||||
+ /* Long hash first and middle BD */
|
||||
+ WD_ERR("invalid: digest bd3 not supports 0 packet in first bd and middle bd!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
sqe->mac_len = msg->out_bytes / WORD_BYTES;
|
||||
if (msg->mode == WCRYPTO_DIGEST_NORMAL)
|
||||
sqe->a_alg = g_digest_a_alg[msg->alg];
|
||||
--
|
||||
2.25.1
|
||||
|
||||
243
0029-uadk-v1-cipher-support-aes-cbc-cts-mode.patch
Normal file
243
0029-uadk-v1-cipher-support-aes-cbc-cts-mode.patch
Normal file
@ -0,0 +1,243 @@
|
||||
From 5d48e854f755213bb145032dfa6b18583a5ced4e Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Tue, 19 Sep 2023 15:49:10 +0800
|
||||
Subject: [PATCH 29/38] uadk/v1/cipher: support aes-cbc cts mode
|
||||
|
||||
Support AES-CBC CTS(ciphertext stealing) mode in v1,
|
||||
including CBC-CS1, CBC-CS2, CBC-CS3.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 100 ++++++++++++++++++++++++++++++++++++++---
|
||||
v1/drv/hisi_sec_udrv.h | 6 +++
|
||||
v1/wd_cipher.c | 3 ++
|
||||
v1/wd_cipher.h | 4 ++
|
||||
4 files changed, 106 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 1dd9f37..832d6a3 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -179,6 +179,18 @@ static int fill_cipher_bd2_mode(struct wcrypto_cipher_msg *msg,
|
||||
case WCRYPTO_CIPHER_XTS:
|
||||
sqe->type2.c_mode = C_MODE_XTS;
|
||||
break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ sqe->type2.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type2.c_width = C_WIDTH_CS1;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ sqe->type2.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type2.c_width = C_WIDTH_CS2;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
+ sqe->type2.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type2.c_width = C_WIDTH_CS3;
|
||||
+ break;
|
||||
default:
|
||||
WD_ERR("Invalid cipher alg type!\n");
|
||||
ret = -WD_EINVAL;
|
||||
@@ -253,6 +265,9 @@ static void update_iv(struct wcrypto_cipher_msg *msg)
|
||||
{
|
||||
switch (msg->mode) {
|
||||
case WCRYPTO_CIPHER_CBC:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
if (msg->op_type == WCRYPTO_CIPHER_ENCRYPTION &&
|
||||
msg->out_bytes >= msg->iv_bytes)
|
||||
update_iv_from_res(msg->iv, msg->out,
|
||||
@@ -360,6 +375,18 @@ static int fill_cipher_bd1_mode(struct wcrypto_cipher_msg *msg,
|
||||
case WCRYPTO_CIPHER_XTS:
|
||||
sqe->type1.c_mode = C_MODE_XTS;
|
||||
break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ sqe->type1.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type1.c_width = C_WIDTH_CS1;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ sqe->type1.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type1.c_width = C_WIDTH_CS2;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
+ sqe->type1.c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->type1.c_width = C_WIDTH_CS3;
|
||||
+ break;
|
||||
default:
|
||||
WD_ERR("Invalid cipher alg type for bd1\n");
|
||||
return -WD_EINVAL;
|
||||
@@ -587,8 +614,32 @@ map_in_error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static int aes_sm4_param_check(struct wcrypto_cipher_msg *msg)
|
||||
+{
|
||||
+ if (msg->alg == WCRYPTO_CIPHER_AES &&
|
||||
+ msg->in_bytes <= CBC_AES_BLOCK_SIZE &&
|
||||
+ (msg->mode == WCRYPTO_CIPHER_CBC_CS1 ||
|
||||
+ msg->mode == WCRYPTO_CIPHER_CBC_CS2 ||
|
||||
+ msg->mode == WCRYPTO_CIPHER_CBC_CS3)) {
|
||||
+ WD_ERR("failed to check input bytes of AES CTS, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if ((msg->in_bytes & (CBC_AES_BLOCK_SIZE - 1)) &&
|
||||
+ (msg->mode == WCRYPTO_CIPHER_CBC ||
|
||||
+ msg->mode == WCRYPTO_CIPHER_ECB)) {
|
||||
+ WD_ERR("input AES or SM4 cipher parameter is error!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ return WD_SUCCESS;
|
||||
+}
|
||||
+
|
||||
static int cipher_param_check(struct wcrypto_cipher_msg *msg)
|
||||
{
|
||||
+ int ret;
|
||||
+
|
||||
if (unlikely(msg->in_bytes > MAX_CIPHER_LENGTH ||
|
||||
!msg->in_bytes)) {
|
||||
WD_ERR("input cipher len is too large!\n");
|
||||
@@ -616,10 +667,9 @@ static int cipher_param_check(struct wcrypto_cipher_msg *msg)
|
||||
}
|
||||
|
||||
if (msg->alg == WCRYPTO_CIPHER_AES || msg->alg == WCRYPTO_CIPHER_SM4) {
|
||||
- if (unlikely(msg->in_bytes & (CBC_AES_BLOCK_SIZE - 1))) {
|
||||
- WD_ERR("input AES or SM4 cipher parameter is error!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
+ ret = aes_sm4_param_check(msg);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
return WD_SUCCESS;
|
||||
@@ -793,6 +843,18 @@ static int fill_cipher_bd3_mode(struct wcrypto_cipher_msg *msg,
|
||||
case WCRYPTO_CIPHER_CFB:
|
||||
sqe->c_mode = C_MODE_CFB;
|
||||
break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ sqe->c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->c_width = C_WIDTH_CS1;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ sqe->c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->c_width = C_WIDTH_CS2;
|
||||
+ break;
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
+ sqe->c_mode = C_MODE_CBC_CS;
|
||||
+ sqe->c_width = C_WIDTH_CS3;
|
||||
+ break;
|
||||
default:
|
||||
WD_ERR("Invalid cipher alg type!\n");
|
||||
ret = -WD_EINVAL;
|
||||
@@ -843,7 +905,7 @@ static int fill_cipher_bd3(struct wd_queue *q, struct hisi_sec_bd3_sqe *sqe,
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static int sm4_aes_mode_check(int mode)
|
||||
+static int sm4_mode_check(int mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case WCRYPTO_CIPHER_ECB:
|
||||
@@ -860,6 +922,26 @@ static int sm4_aes_mode_check(int mode)
|
||||
}
|
||||
}
|
||||
|
||||
+static int aes_mode_check(int mode)
|
||||
+{
|
||||
+ switch (mode) {
|
||||
+ case WCRYPTO_CIPHER_ECB:
|
||||
+ case WCRYPTO_CIPHER_CBC:
|
||||
+ case WCRYPTO_CIPHER_OFB:
|
||||
+ case WCRYPTO_CIPHER_CFB:
|
||||
+ case WCRYPTO_CIPHER_CTR:
|
||||
+ case WCRYPTO_CIPHER_XTS:
|
||||
+ case WCRYPTO_CIPHER_CCM:
|
||||
+ case WCRYPTO_CIPHER_GCM:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
+ return WD_SUCCESS;
|
||||
+ default:
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int triple_des_mode_check(int mode)
|
||||
{
|
||||
switch (mode) {
|
||||
@@ -878,8 +960,10 @@ static int cipher_comb_param_check(struct wcrypto_cipher_msg *msg)
|
||||
|
||||
switch (msg->alg) {
|
||||
case WCRYPTO_CIPHER_SM4:
|
||||
+ ret = sm4_mode_check(msg->mode);
|
||||
+ break;
|
||||
case WCRYPTO_CIPHER_AES:
|
||||
- ret = sm4_aes_mode_check(msg->mode);
|
||||
+ ret = aes_mode_check(msg->mode);
|
||||
break;
|
||||
case WCRYPTO_CIPHER_DES:
|
||||
case WCRYPTO_CIPHER_3DES:
|
||||
@@ -2228,8 +2312,10 @@ static int aead_comb_param_check(struct wcrypto_aead_msg *msg)
|
||||
|
||||
switch (msg->calg) {
|
||||
case WCRYPTO_CIPHER_SM4:
|
||||
+ ret = sm4_mode_check(msg->cmode);
|
||||
+ break;
|
||||
case WCRYPTO_CIPHER_AES:
|
||||
- ret = sm4_aes_mode_check(msg->cmode);
|
||||
+ ret = aes_mode_check(msg->cmode);
|
||||
break;
|
||||
default:
|
||||
return -WD_EINVAL;
|
||||
diff --git a/v1/drv/hisi_sec_udrv.h b/v1/drv/hisi_sec_udrv.h
|
||||
index af96a76..9db4af8 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.h
|
||||
+++ b/v1/drv/hisi_sec_udrv.h
|
||||
@@ -461,6 +461,12 @@ enum C_MODE {
|
||||
C_MODE_CBC_CS = 0x9
|
||||
};
|
||||
|
||||
+enum SEC_C_WIDTH {
|
||||
+ C_WIDTH_CS1 = 0x1,
|
||||
+ C_WIDTH_CS2 = 0x2,
|
||||
+ C_WIDTH_CS3 = 0x3,
|
||||
+};
|
||||
+
|
||||
enum CKEY_LEN {
|
||||
CKEY_LEN_128_BIT = 0x0,
|
||||
CKEY_LEN_192_BIT = 0x1,
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 6c0ef69..1b50089 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -83,6 +83,9 @@ static __u32 get_iv_block_size(int alg, int mode)
|
||||
|
||||
switch (mode) {
|
||||
case WCRYPTO_CIPHER_CBC:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS1:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS2:
|
||||
+ case WCRYPTO_CIPHER_CBC_CS3:
|
||||
case WCRYPTO_CIPHER_OFB:
|
||||
if (alg == WCRYPTO_CIPHER_3DES ||
|
||||
alg == WCRYPTO_CIPHER_DES)
|
||||
diff --git a/v1/wd_cipher.h b/v1/wd_cipher.h
|
||||
index 591a590..dafd8a4 100644
|
||||
--- a/v1/wd_cipher.h
|
||||
+++ b/v1/wd_cipher.h
|
||||
@@ -47,6 +47,10 @@ enum wcrypto_cipher_mode {
|
||||
WCRYPTO_CIPHER_CFB,
|
||||
WCRYPTO_CIPHER_CCM,
|
||||
WCRYPTO_CIPHER_GCM,
|
||||
+ WCRYPTO_CIPHER_CBC_CS1,
|
||||
+ WCRYPTO_CIPHER_CBC_CS2,
|
||||
+ WCRYPTO_CIPHER_CBC_CS3,
|
||||
+ WCRYPTO_CIPHER_MODE_MAX,
|
||||
};
|
||||
|
||||
/**
|
||||
--
|
||||
2.25.1
|
||||
|
||||
326
0030-uadk-v1-cipher-support-user-self-defined-data-functi.patch
Normal file
326
0030-uadk-v1-cipher-support-user-self-defined-data-functi.patch
Normal file
@ -0,0 +1,326 @@
|
||||
From 998b7f678edf910281e07539de2a9f0399ddc2ac Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Sat, 23 Sep 2023 18:32:02 +0800
|
||||
Subject: [PATCH 30/38] uadk/v1/cipher: support user self-defined data
|
||||
functions
|
||||
|
||||
Support user self-defined data for calculation. This means
|
||||
user do not need to use reserved memory provided by uadk-v1
|
||||
driver and make the data to be parsed and processed by the
|
||||
uadk-v1 driver. Through this new feature, users can configure
|
||||
the custom data according to 'struct wd_sec_udata', and pass
|
||||
it to the 'priv' member of 'struct wcrypto_cipher_op_data',
|
||||
enabling hardware deal with the user custom data directly.
|
||||
|
||||
Note that if users want to set key through custom data, the
|
||||
uadk-v1 api wcrypto_set_cipher_key(), which used to set the
|
||||
key, should not be used any more. Users should set the key with
|
||||
'struct wd_sec_udata' type and pass it to 'priv' member.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 153 ++++++++++++++++++++++++++++++++++-------
|
||||
v1/wd_cipher.c | 4 +-
|
||||
2 files changed, 130 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 832d6a3..2931bb4 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -395,7 +395,7 @@ static int fill_cipher_bd1_mode(struct wcrypto_cipher_msg *msg,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void fill_cipher_bd1_udata(struct hisi_sec_sqe *sqe,
|
||||
+static void fill_cipher_bd1_dif(struct hisi_sec_sqe *sqe,
|
||||
struct wd_sec_udata *udata)
|
||||
{
|
||||
sqe->type1.gran_num = udata->gran_num;
|
||||
@@ -418,6 +418,28 @@ static void fill_cipher_bd1_udata(struct hisi_sec_sqe *sqe,
|
||||
sqe->type1.lba_h = udata->dif.lba >> QM_HADDR_SHIFT;
|
||||
}
|
||||
|
||||
+static void fill_cipher_bd1_udata_addr(struct wcrypto_cipher_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
+{
|
||||
+ uintptr_t phy;
|
||||
+
|
||||
+ /* For user self-defined scene, iova = pa */
|
||||
+ phy = (uintptr_t)msg->in;
|
||||
+ sqe->type1.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type1.data_src_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->out;
|
||||
+ sqe->type1.data_dst_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type1.data_dst_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->key;
|
||||
+ sqe->type1.c_key_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type1.c_key_addr_h = HI_U32(phy);
|
||||
+ if (msg->iv_bytes) {
|
||||
+ phy = (uintptr_t)msg->iv;
|
||||
+ sqe->type1.c_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type1.c_ivin_addr_h = HI_U32(phy);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int map_addr(struct wd_queue *q, __u8 *key, __u16 len,
|
||||
__u32 *addr_l, __u32 *addr_h, __u8 data_fmt)
|
||||
{
|
||||
@@ -500,8 +522,8 @@ map_key_error:
|
||||
static int fill_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
struct wcrypto_cipher_msg *msg, struct wcrypto_cipher_tag *tag)
|
||||
{
|
||||
- int ret;
|
||||
struct wd_sec_udata *udata = tag->priv;
|
||||
+ int ret;
|
||||
|
||||
sqe->type = BD_TYPE1;
|
||||
sqe->scene = SCENE_STORAGE;
|
||||
@@ -519,11 +541,16 @@ static int fill_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
if (ret != WD_SUCCESS)
|
||||
return ret;
|
||||
|
||||
- fill_cipher_bd1_udata(sqe, udata);
|
||||
-
|
||||
- ret = fill_cipher_bd1_addr(q, msg, sqe);
|
||||
- if (ret != WD_SUCCESS)
|
||||
- return ret;
|
||||
+ if (udata) {
|
||||
+ /* User self-defined data with DIF scence */
|
||||
+ fill_cipher_bd1_dif(sqe, udata);
|
||||
+ fill_cipher_bd1_udata_addr(msg, sqe);
|
||||
+ } else {
|
||||
+ /* Reserved for non user self-defined data scence */
|
||||
+ ret = fill_cipher_bd1_addr(q, msg, sqe);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
sqe->type1.tag = tag->wcrypto_tag.ctx_id;
|
||||
|
||||
@@ -636,6 +663,27 @@ static int aes_sm4_param_check(struct wcrypto_cipher_msg *msg)
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
+static void fill_cipher_bd2_udata_addr(struct wcrypto_cipher_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
+{
|
||||
+ uintptr_t phy;
|
||||
+
|
||||
+ phy = (uintptr_t)msg->in;
|
||||
+ sqe->type2.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.data_src_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->out;
|
||||
+ sqe->type2.data_dst_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.data_dst_addr_h = HI_U32(phy);
|
||||
+ phy = (uintptr_t)msg->key;
|
||||
+ sqe->type2.c_key_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.c_key_addr_h = HI_U32(phy);
|
||||
+ if (msg->iv_bytes) {
|
||||
+ phy = (uintptr_t)msg->iv;
|
||||
+ sqe->type2.c_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK);
|
||||
+ sqe->type2.c_ivin_addr_h = HI_U32(phy);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int cipher_param_check(struct wcrypto_cipher_msg *msg)
|
||||
{
|
||||
int ret;
|
||||
@@ -705,9 +753,14 @@ static int fill_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
return ret;
|
||||
}
|
||||
|
||||
- ret = fill_cipher_bd2_addr(q, msg, sqe);
|
||||
- if (ret != WD_SUCCESS)
|
||||
- return ret;
|
||||
+ if (tag->priv) {
|
||||
+ /* User self-defined data process */
|
||||
+ fill_cipher_bd2_udata_addr(msg, sqe);
|
||||
+ } else {
|
||||
+ ret = fill_cipher_bd2_addr(q, msg, sqe);
|
||||
+ if (ret != WD_SUCCESS)
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
if (tag)
|
||||
sqe->type2.tag = tag->wcrypto_tag.ctx_id;
|
||||
@@ -978,10 +1031,11 @@ static int cipher_comb_param_check(struct wcrypto_cipher_msg *msg)
|
||||
|
||||
int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
- struct hisi_sec_sqe *sqe;
|
||||
struct wcrypto_cipher_msg *msg = message;
|
||||
- struct wd_queue *q = info->q;
|
||||
struct wcrypto_cipher_tag *tag = (void *)(uintptr_t)msg->usr_data;
|
||||
+ struct wd_sec_udata *udata = tag->priv;
|
||||
+ struct wd_queue *q = info->q;
|
||||
+ struct hisi_sec_sqe *sqe;
|
||||
uintptr_t temp;
|
||||
int ret;
|
||||
|
||||
@@ -994,10 +1048,13 @@ int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
|
||||
temp = (uintptr_t)info->sq_base + i * info->sqe_size;
|
||||
sqe = (struct hisi_sec_sqe *)temp;
|
||||
-
|
||||
memset(sqe, 0, sizeof(struct hisi_sec_sqe));
|
||||
|
||||
- if (tag->priv)
|
||||
+ /**
|
||||
+ * For user self-defined data with DIF scence, will fill BD1.
|
||||
+ * Other scences will fill BD2 by default, including no DIF scence.
|
||||
+ */
|
||||
+ if (udata && udata->gran_num != 0)
|
||||
ret = fill_cipher_bd1(q, sqe, msg, tag);
|
||||
else
|
||||
ret = fill_cipher_bd2(q, sqe, msg, tag);
|
||||
@@ -1015,10 +1072,12 @@ int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
|
||||
int qm_fill_cipher_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
{
|
||||
- struct hisi_sec_bd3_sqe *sqe3;
|
||||
struct wcrypto_cipher_msg *msg = message;
|
||||
- struct wd_queue *q = info->q;
|
||||
struct wcrypto_cipher_tag *tag = (void *)(uintptr_t)msg->usr_data;
|
||||
+ struct wd_sec_udata *udata = tag->priv;
|
||||
+ struct wd_queue *q = info->q;
|
||||
+ struct hisi_sec_bd3_sqe *sqe3;
|
||||
+ struct hisi_sec_sqe *sqe;
|
||||
uintptr_t temp;
|
||||
int ret;
|
||||
|
||||
@@ -1030,18 +1089,35 @@ int qm_fill_cipher_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
}
|
||||
|
||||
temp = (uintptr_t)info->sq_base + i * info->sqe_size;
|
||||
- sqe3 = (struct hisi_sec_bd3_sqe *)temp;
|
||||
|
||||
- memset(sqe3, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
+ /*
|
||||
+ * For user self-defined data with DIF scence, will fill BD1.
|
||||
+ * For user self-defined data without DIF scence, will fill BD2.
|
||||
+ * For non user self-defined data scence, will fill BD3.
|
||||
+ */
|
||||
+ if (udata) {
|
||||
+ sqe = (struct hisi_sec_sqe *)temp;
|
||||
+ memset(sqe, 0, sizeof(struct hisi_sec_sqe));
|
||||
+ if (udata->gran_num != 0)
|
||||
+ ret = fill_cipher_bd1(q, sqe, msg, tag);
|
||||
+ else
|
||||
+ ret = fill_cipher_bd2(q, sqe, msg, tag);
|
||||
+ } else {
|
||||
+ sqe3 = (struct hisi_sec_bd3_sqe *)temp;
|
||||
+ memset(sqe3, 0, sizeof(struct hisi_sec_bd3_sqe));
|
||||
+ ret = fill_cipher_bd3(q, sqe3, msg, tag);
|
||||
+ }
|
||||
|
||||
- ret = fill_cipher_bd3(q, sqe3, msg, tag);
|
||||
if (ret != WD_SUCCESS)
|
||||
return ret;
|
||||
|
||||
info->req_cache[i] = msg;
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
- sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS);
|
||||
+ if (udata)
|
||||
+ sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
+ else
|
||||
+ sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
@@ -1686,6 +1762,7 @@ static void cipher_ofb_data_handle(struct wcrypto_cipher_msg *msg)
|
||||
static void parse_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
struct wcrypto_cipher_msg *cipher_msg)
|
||||
{
|
||||
+ struct wcrypto_cipher_tag *tag;
|
||||
__u64 dma_addr;
|
||||
|
||||
if (sqe->type2.done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
|
||||
@@ -1695,6 +1772,11 @@ static void parse_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
} else
|
||||
cipher_msg->result = WD_SUCCESS;
|
||||
|
||||
+ /* In user self-define data case, may not need addr map, just return */
|
||||
+ tag = (void *)(uintptr_t)cipher_msg->usr_data;
|
||||
+ if (tag->priv)
|
||||
+ return;
|
||||
+
|
||||
dma_addr = DMA_ADDR(sqe->type2.data_src_addr_h,
|
||||
sqe->type2.data_src_addr_l);
|
||||
drv_iova_unmap(q, cipher_msg->in, (void *)(uintptr_t)dma_addr,
|
||||
@@ -1790,25 +1872,44 @@ int qm_parse_cipher_bd3_sqe(void *msg, const struct qm_queue_info *info,
|
||||
__u16 i, __u16 usr)
|
||||
{
|
||||
struct wcrypto_cipher_msg *cipher_msg = info->req_cache[i];
|
||||
- struct hisi_sec_bd3_sqe *sqe = msg;
|
||||
+ struct hisi_sec_bd3_sqe *sqe3 = msg;
|
||||
struct wd_queue *q = info->q;
|
||||
+ struct hisi_sec_sqe *sqe;
|
||||
|
||||
if (unlikely(!cipher_msg)) {
|
||||
WD_ERR("info->req_cache is null at index:%hu\n", i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
- if (likely(sqe->type == BD_TYPE3)) {
|
||||
- if (unlikely(usr && sqe->tag_l != usr))
|
||||
+ switch (sqe3->type) {
|
||||
+ case BD_TYPE3:
|
||||
+ if (unlikely(usr && sqe3->tag_l != usr))
|
||||
return 0;
|
||||
- parse_cipher_bd3(q, sqe, cipher_msg);
|
||||
- } else {
|
||||
+ parse_cipher_bd3(q, sqe3, cipher_msg);
|
||||
+ break;
|
||||
+ case BD_TYPE2:
|
||||
+ sqe = (struct hisi_sec_sqe *)sqe3;
|
||||
+ if (usr && sqe->type2.tag != usr)
|
||||
+ return 0;
|
||||
+ parse_cipher_bd2(q, sqe, cipher_msg);
|
||||
+ break;
|
||||
+ case BD_TYPE1:
|
||||
+ sqe = (struct hisi_sec_sqe *)sqe3;
|
||||
+ if (usr && sqe->type1.tag != usr)
|
||||
+ return 0;
|
||||
+ parse_cipher_bd1(q, sqe, cipher_msg);
|
||||
+ break;
|
||||
+ default:
|
||||
WD_ERR("SEC BD Type error\n");
|
||||
cipher_msg->result = WD_IN_EPARA;
|
||||
+ break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
- sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
+ if (sqe3->type == BD_TYPE3)
|
||||
+ sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS);
|
||||
+ else
|
||||
+ sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 1b50089..624adb0 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -69,7 +69,7 @@ static void del_ctx_key(struct wcrypto_cipher_ctx *ctx)
|
||||
if (ctx->key) {
|
||||
if (ctx->setup.data_fmt == WD_FLAT_BUF)
|
||||
memset(ctx->key, 0, MAX_CIPHER_KEY_SIZE);
|
||||
- else if (ctx->setup.data_fmt == WD_SGL_BUF)
|
||||
+ else if (ctx->setup.data_fmt == WD_SGL_BUF && ctx->key_bytes)
|
||||
wd_sgl_cp_from_pbuf(ctx->key, 0, tmp, MAX_CIPHER_KEY_SIZE);
|
||||
}
|
||||
|
||||
@@ -361,6 +361,8 @@ static int cipher_requests_init(struct wcrypto_cipher_msg **req,
|
||||
req[i]->in_bytes = op[i]->in_bytes;
|
||||
req[i]->out = op[i]->out;
|
||||
req[i]->out_bytes = op[i]->out_bytes;
|
||||
+
|
||||
+ /* In user self-define data case, need update key from udata */
|
||||
udata = op[i]->priv;
|
||||
if (udata && udata->key) {
|
||||
req[i]->key = udata->key;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
45
0031-uadk-cipher-cleaup-judgement-sequence.patch
Normal file
45
0031-uadk-cipher-cleaup-judgement-sequence.patch
Normal file
@ -0,0 +1,45 @@
|
||||
From 03bd2bcd7980b4dad4b453dfdaa120dc93c0c6df Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Sun, 24 Sep 2023 23:14:16 +0800
|
||||
Subject: [PATCH 31/38] uadk/cipher: cleaup judgement sequence
|
||||
|
||||
Modify the jugement sequence in aes_sm4_len_check(),
|
||||
prioritize the conditions that must be met.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 12 ++++++------
|
||||
1 file changed, 6 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 69529d2..2c71090 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -891,18 +891,18 @@ static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
|
||||
|
||||
static int aes_sm4_len_check(struct wd_cipher_msg *msg)
|
||||
{
|
||||
- if ((msg->mode == WD_CIPHER_CBC_CS1 ||
|
||||
+ if (msg->alg == WD_CIPHER_AES &&
|
||||
+ msg->in_bytes <= AES_BLOCK_SIZE &&
|
||||
+ (msg->mode == WD_CIPHER_CBC_CS1 ||
|
||||
msg->mode == WD_CIPHER_CBC_CS2 ||
|
||||
- msg->mode == WD_CIPHER_CBC_CS3) &&
|
||||
- msg->alg == WD_CIPHER_AES &&
|
||||
- msg->in_bytes <= AES_BLOCK_SIZE) {
|
||||
+ msg->mode == WD_CIPHER_CBC_CS3)) {
|
||||
WD_ERR("failed to check input bytes of AES_CBC_CS_X, size = %u\n",
|
||||
msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if ((msg->mode == WD_CIPHER_CBC || msg->mode == WD_CIPHER_ECB) &&
|
||||
- msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
|
||||
+ if ((msg->in_bytes & (AES_BLOCK_SIZE - 1)) &&
|
||||
+ (msg->mode == WD_CIPHER_CBC || msg->mode == WD_CIPHER_ECB)) {
|
||||
WD_ERR("failed to check input bytes of AES or SM4, size = %u\n",
|
||||
msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
From bd5884e9f0b04e1c09f1c19eb5a28d21138c6aac Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 11:42:32 +0800
|
||||
Subject: [PATCH 32/38] uadk: fix for wd_memset_zero occupies high cpu usage
|
||||
|
||||
When key bytes is 0, it should not clean session key,
|
||||
CPU usage is occupied by wd_memset_zero now,
|
||||
which will causing performance deterioration.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_aead.c | 4 ++--
|
||||
wd_cipher.c | 2 +-
|
||||
wd_digest.c | 2 +-
|
||||
3 files changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index ed7b987..e5e1b19 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -342,8 +342,8 @@ void wd_aead_free_sess(handle_t h_sess)
|
||||
return;
|
||||
}
|
||||
|
||||
- wd_memset_zero(sess->ckey, MAX_CIPHER_KEY_SIZE);
|
||||
- wd_memset_zero(sess->akey, MAX_HMAC_KEY_SIZE);
|
||||
+ wd_memset_zero(sess->ckey, sess->ckey_bytes);
|
||||
+ wd_memset_zero(sess->akey, sess->akey_bytes);
|
||||
|
||||
if (sess->sched_key)
|
||||
free(sess->sched_key);
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 6f57e17..2eaa77b 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -284,7 +284,7 @@ void wd_cipher_free_sess(handle_t h_sess)
|
||||
return;
|
||||
}
|
||||
|
||||
- wd_memset_zero(sess->key, MAX_CIPHER_KEY_SIZE);
|
||||
+ wd_memset_zero(sess->key, sess->key_bytes);
|
||||
|
||||
if (sess->sched_key)
|
||||
free(sess->sched_key);
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index c8ccc8d..0847fe3 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -211,7 +211,7 @@ void wd_digest_free_sess(handle_t h_sess)
|
||||
return;
|
||||
}
|
||||
|
||||
- wd_memset_zero(sess->key, MAX_HMAC_KEY_SIZE);
|
||||
+ wd_memset_zero(sess->key, sess->key_bytes);
|
||||
if (sess->sched_key)
|
||||
free(sess->sched_key);
|
||||
free(sess);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
103
0033-uadk-optimize-session-update-for-long-hash-mode.patch
Normal file
103
0033-uadk-optimize-session-update-for-long-hash-mode.patch
Normal file
@ -0,0 +1,103 @@
|
||||
From ae66995a2eb2af4163e1e88b5141fd2e15ab0d3d Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 11:51:27 +0800
|
||||
Subject: [PATCH 33/38] uadk: optimize session update for long hash mode
|
||||
|
||||
The session should be updated after job is done successfully.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_digest.h | 2 +-
|
||||
wd_digest.c | 44 +++++++++++++++++++++++---------------------
|
||||
2 files changed, 24 insertions(+), 22 deletions(-)
|
||||
|
||||
diff --git a/include/wd_digest.h b/include/wd_digest.h
|
||||
index 874e9c1..9abbe16 100644
|
||||
--- a/include/wd_digest.h
|
||||
+++ b/include/wd_digest.h
|
||||
@@ -180,7 +180,7 @@ void wd_digest_uninit2(void);
|
||||
handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup);
|
||||
|
||||
/**
|
||||
- * wd_alg_digest_free_sess() - Free digest session.
|
||||
+ * wd_digest_free_sess() - Free digest session.
|
||||
* @h_sess: session handler which will be free
|
||||
*/
|
||||
void wd_digest_free_sess(handle_t h_sess);
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 0847fe3..fd26cc8 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -63,12 +63,13 @@ struct wd_digest_sess {
|
||||
__u32 key_bytes;
|
||||
void *sched_key;
|
||||
/*
|
||||
- * Notify the BD state, zero is frist BD, non-zero
|
||||
- * is middle or final BD.
|
||||
+ * Notify the stream message state, zero is frist message,
|
||||
+ * non-zero is middle or final message.
|
||||
*/
|
||||
- int bd_state;
|
||||
- /* Total of data for stream mode */
|
||||
- __u64 long_data_len;
|
||||
+ int msg_state;
|
||||
+
|
||||
+ /* Total data length for stream mode */
|
||||
+ __u64 long_data_len;
|
||||
};
|
||||
|
||||
struct wd_env_config wd_digest_env_config;
|
||||
@@ -542,15 +543,10 @@ static void fill_request_msg(struct wd_digest_msg *msg,
|
||||
msg->out_bytes = req->out_bytes;
|
||||
msg->data_fmt = req->data_fmt;
|
||||
msg->has_next = req->has_next;
|
||||
- sess->long_data_len += req->in_bytes;
|
||||
- msg->long_data_len = sess->long_data_len;
|
||||
+ msg->long_data_len = sess->long_data_len + req->in_bytes;
|
||||
|
||||
- /* To store the stream BD state, iv_bytes also means BD state */
|
||||
- msg->iv_bytes = sess->bd_state;
|
||||
- if (req->has_next == 0) {
|
||||
- sess->long_data_len = 0;
|
||||
- sess->bd_state = 0;
|
||||
- }
|
||||
+ /* Use iv_bytes to store the stream message state */
|
||||
+ msg->iv_bytes = sess->msg_state;
|
||||
}
|
||||
|
||||
static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *dsess,
|
||||
@@ -565,17 +561,23 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
|
||||
msg, NULL, wd_digest_setting.config.epoll_en);
|
||||
+ pthread_spin_unlock(&ctx->lock);
|
||||
if (unlikely(ret))
|
||||
- goto out;
|
||||
+ return ret;
|
||||
|
||||
- /*
|
||||
- * non-zero is final BD or middle BD as stream mode.
|
||||
- */
|
||||
- dsess->bd_state = msg->has_next;
|
||||
+ /* After a stream mode job was done, update session long_data_len */
|
||||
+ if (msg->has_next) {
|
||||
+ /* Long hash(first and middle message) */
|
||||
+ dsess->long_data_len += msg->in_bytes;
|
||||
+ } else if (msg->iv_bytes) {
|
||||
+ /* Long hash(final message) */
|
||||
+ dsess->long_data_len = 0;
|
||||
+ }
|
||||
|
||||
-out:
|
||||
- pthread_spin_unlock(&ctx->lock);
|
||||
- return ret;
|
||||
+ /* Update session message state */
|
||||
+ dsess->msg_state = msg->has_next;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
From b9e157a5c0283668b1abcd15af6c455dc08d1ab3 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 13:53:15 +0800
|
||||
Subject: [PATCH 34/38] uadk: support digest message carrying long data
|
||||
information
|
||||
|
||||
Currently, we use 0 and 1 to fill the has_next filed of digest request,
|
||||
0 indicates that there is no next packet, 1 indicates there are next packets,
|
||||
we use WD_DIGEST_END and WD_DIGEST_DOING to mark those messages.
|
||||
|
||||
In another scenario, when user calculates on data flow A, after partial data is calculated,
|
||||
the result may be copied to data flow B so that flow B can calculate different data.
|
||||
However, flow B uses a new session, there's no information required for continuing calculation.
|
||||
Therefore, messages with this information need to be delivered to uadk, so we use
|
||||
WD_DIGEST_STREAM_END and WD_DIGEST_STREAM_DOING to mark those messages,
|
||||
long_data_len is also added to messages to store the length of the processed data.
|
||||
|
||||
After uadk set long data length and msg_state for the session,
|
||||
it will also change the status of has_next, change WD_DIGEST_STREAM_END
|
||||
to WD_DIGEST_END, WD_DIGEST_STREAM_DOING to WD_DIGEST_DOING.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_digest.h | 19 ++++++++++++++++++-
|
||||
wd_digest.c | 10 ++++++++++
|
||||
2 files changed, 28 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/wd_digest.h b/include/wd_digest.h
|
||||
index 9abbe16..7539866 100644
|
||||
--- a/include/wd_digest.h
|
||||
+++ b/include/wd_digest.h
|
||||
@@ -78,6 +78,20 @@ enum wd_digest_mode {
|
||||
WD_DIGEST_MODE_MAX,
|
||||
};
|
||||
|
||||
+/**
|
||||
+ * wd_digest_msg_state - Message state of digest
|
||||
+ * @WD_DIGEST_END: Final message or single block message
|
||||
+ * @WD_DIGEST_DOING: First message or middle message
|
||||
+ * @WD_DIGEST_STREAM_END: Final message carrying long data information
|
||||
+ * @WD_DIGEST_STREAM_DOING: Middle message carrying long data information
|
||||
+ */
|
||||
+enum wd_digest_msg_state {
|
||||
+ WD_DIGEST_END = 0x0,
|
||||
+ WD_DIGEST_DOING,
|
||||
+ WD_DIGEST_STREAM_END,
|
||||
+ WD_DIGEST_STREAM_DOING,
|
||||
+};
|
||||
+
|
||||
/**
|
||||
* wd_digest_sess_setup - Parameters which is used to allocate a digest session
|
||||
* @alg: digest algorithm type, denoted by enum wd_digest_type
|
||||
@@ -100,9 +114,11 @@ typedef void *wd_digest_cb_t(void *cb_param);
|
||||
* @out_buf_bytes: actual output buffer size
|
||||
* @iv: input iv data addrss for AES_GMAC
|
||||
* @iv_bytes: input iv data size
|
||||
- * @has_next: is there next data block
|
||||
+ * @has_next: message state, all types are defined in enum wd_digest_msg_state.
|
||||
* @cb: callback function for async mode
|
||||
* @cb_param: pointer of callback parameter
|
||||
+ * @long_data_len: total length of data has been processed, it is only needed by
|
||||
+ * the data flow switched to another session for processing.
|
||||
*
|
||||
* Note: If there is a alg selected in session, alg below will be ignore
|
||||
* otherwise, alg here will be used. Same as mode below.
|
||||
@@ -125,6 +141,7 @@ struct wd_digest_req {
|
||||
__u8 data_fmt;
|
||||
wd_digest_cb_t *cb;
|
||||
void *cb_param;
|
||||
+ __u64 long_data_len;
|
||||
};
|
||||
|
||||
struct wd_cb_tag {
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index fd26cc8..69c4b28 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -531,6 +531,16 @@ static void fill_request_msg(struct wd_digest_msg *msg,
|
||||
{
|
||||
memcpy(&msg->req, req, sizeof(struct wd_digest_req));
|
||||
|
||||
+ if (unlikely(req->has_next == WD_DIGEST_STREAM_END)) {
|
||||
+ sess->long_data_len = req->long_data_len;
|
||||
+ sess->msg_state = WD_DIGEST_DOING;
|
||||
+ req->has_next = WD_DIGEST_END;
|
||||
+ } else if (unlikely(req->has_next == WD_DIGEST_STREAM_DOING)) {
|
||||
+ sess->long_data_len = req->long_data_len;
|
||||
+ sess->msg_state = WD_DIGEST_DOING;
|
||||
+ req->has_next = WD_DIGEST_DOING;
|
||||
+ }
|
||||
+
|
||||
msg->alg_type = WD_DIGEST;
|
||||
msg->alg = sess->alg;
|
||||
msg->mode = sess->mode;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
134
0035-uadk-add-out_bytes-check-for-long-hash-scene.patch
Normal file
134
0035-uadk-add-out_bytes-check-for-long-hash-scene.patch
Normal file
@ -0,0 +1,134 @@
|
||||
From 875549731f40bd2ee4ca7921b0d18f1e37a2f77b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 13:58:00 +0800
|
||||
Subject: [PATCH 35/38] uadk: add out_bytes check for long hash scene
|
||||
|
||||
In long hash scene, the first and middle hash task should ensure
|
||||
full mac len out buffer, so we add out_bytes check here. But
|
||||
out_bytes of the last hash task should be actual length.
|
||||
|
||||
mac length should also be set for hardware mac check.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 4 ++++
|
||||
v1/wd_digest.c | 34 ++++++++++++++++++++++++++--------
|
||||
v1/wd_digest.h | 12 ++++++++++++
|
||||
3 files changed, 42 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 2931bb4..1249cb6 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -1185,11 +1185,13 @@ static void qm_fill_digest_long_bd(struct wcrypto_digest_msg *msg,
|
||||
|
||||
if (msg->has_next && (msg->iv_bytes == 0)) {
|
||||
/* LONG BD FIRST */
|
||||
+ sqe->type2.mac_len = 0x1;
|
||||
sqe->type2.ai_gen = AI_GEN_INNER;
|
||||
sqe->type2.a_pad = AUTHPAD_NOPAD;
|
||||
msg->iv_bytes = msg->out_bytes;
|
||||
} else if (msg->has_next && (msg->iv_bytes != 0)) {
|
||||
/* LONG BD MIDDLE */
|
||||
+ sqe->type2.mac_len = 0x1;
|
||||
sqe->type2.ai_gen = AI_GEN_IVIN_ADDR;
|
||||
sqe->type2.a_pad = AUTHPAD_NOPAD;
|
||||
sqe->type2.a_ivin_addr_h = sqe->type2.mac_addr_h;
|
||||
@@ -1515,11 +1517,13 @@ static void qm_fill_digest_long_bd3(struct wcrypto_digest_msg *msg,
|
||||
/* iv_bytes is multiplexed as a flag bit to determine whether it is LOGN BD FIRST */
|
||||
if (msg->has_next && msg->iv_bytes == 0) {
|
||||
/* LONG BD FIRST */
|
||||
+ sqe->mac_len = 0x1;
|
||||
sqe->ai_gen = AI_GEN_INNER;
|
||||
sqe->stream_scene.auth_pad = AUTHPAD_NOPAD;
|
||||
msg->iv_bytes = msg->out_bytes;
|
||||
} else if (msg->has_next && msg->iv_bytes != 0) {
|
||||
/* LONG BD MIDDLE */
|
||||
+ sqe->mac_len = 0x1;
|
||||
sqe->ai_gen = AI_GEN_IVIN_ADDR;
|
||||
sqe->stream_scene.auth_pad = AUTHPAD_NOPAD;
|
||||
sqe->auth_key_iv.a_ivin_addr_h = sqe->mac_addr_h;
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index 7965206..be43c73 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -54,6 +54,14 @@ static __u32 g_digest_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = {
|
||||
WCRYPTO_DIGEST_SHA512_224_LEN, WCRYPTO_DIGEST_SHA512_256_LEN
|
||||
};
|
||||
|
||||
+static __u32 g_digest_mac_full_len[WCRYPTO_MAX_DIGEST_TYPE] = {
|
||||
+ WCRYPTO_DIGEST_SM3_FULL_LEN, WCRYPTO_DIGEST_MD5_FULL_LEN,
|
||||
+ WCRYPTO_DIGEST_SHA1_FULL_LEN, WCRYPTO_DIGEST_SHA256_FULL_LEN,
|
||||
+ WCRYPTO_DIGEST_SHA224_FULL_LEN, WCRYPTO_DIGEST_SHA384_FULL_LEN,
|
||||
+ WCRYPTO_DIGEST_SHA512_FULL_LEN, WCRYPTO_DIGEST_SHA512_224_FULL_LEN,
|
||||
+ WCRYPTO_DIGEST_SHA512_256_FULL_LEN
|
||||
+};
|
||||
+
|
||||
static void del_ctx_key(struct wcrypto_digest_ctx *ctx)
|
||||
{
|
||||
struct wd_mm_br *br = &(ctx->setup.br);
|
||||
@@ -330,20 +338,30 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(num != 1 && d_opdata[i]->has_next)) {
|
||||
- WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n");
|
||||
+ if (unlikely(!d_opdata[i]->out_bytes)) {
|
||||
+ WD_ERR("invalid: digest mac length is 0.\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(d_opdata[0]->has_next && d_opdata[0]->in_bytes % d_ctx->align_sz)) {
|
||||
- WD_ERR("digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
- if (d_opdata[i]->out_bytes == 0 ||
|
||||
- d_opdata[i]->out_bytes > g_digest_mac_len[alg]) {
|
||||
+ if (d_opdata[i]->has_next) {
|
||||
+ if (unlikely(num != 1)) {
|
||||
+ WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ if (unlikely(d_opdata[i]->in_bytes % d_ctx->align_sz)) {
|
||||
+ WD_ERR("digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ if (unlikely(d_opdata[i]->out_bytes < g_digest_mac_full_len[alg])) {
|
||||
+ WD_ERR("digest stream mode out buffer space is not enough!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (unlikely(d_opdata[i]->out_bytes > g_digest_mac_len[alg])) {
|
||||
WD_ERR("failed to check digest mac length!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
+ }
|
||||
|
||||
if (unlikely(tag && !tag[i])) {
|
||||
WD_ERR("tag[%u] is NULL!\n", i);
|
||||
diff --git a/v1/wd_digest.h b/v1/wd_digest.h
|
||||
index 6ad4c85..8f7ac2e 100644
|
||||
--- a/v1/wd_digest.h
|
||||
+++ b/v1/wd_digest.h
|
||||
@@ -51,6 +51,18 @@ enum wd_digest_mac_len {
|
||||
WCRYPTO_DIGEST_SHA512_256_LEN = 32
|
||||
};
|
||||
|
||||
+enum wcrypto_digest_mac_full_len {
|
||||
+ WCRYPTO_DIGEST_SM3_FULL_LEN = 32,
|
||||
+ WCRYPTO_DIGEST_MD5_FULL_LEN = 16,
|
||||
+ WCRYPTO_DIGEST_SHA1_FULL_LEN = 20,
|
||||
+ WCRYPTO_DIGEST_SHA256_FULL_LEN = 32,
|
||||
+ WCRYPTO_DIGEST_SHA224_FULL_LEN = 32,
|
||||
+ WCRYPTO_DIGEST_SHA384_FULL_LEN = 64,
|
||||
+ WCRYPTO_DIGEST_SHA512_FULL_LEN = 64,
|
||||
+ WCRYPTO_DIGEST_SHA512_224_FULL_LEN = 64,
|
||||
+ WCRYPTO_DIGEST_SHA512_256_FULL_LEN = 64,
|
||||
+};
|
||||
+
|
||||
enum wcrypto_digest_mode {
|
||||
WCRYPTO_DIGEST_NORMAL,
|
||||
WCRYPTO_DIGEST_HMAC,
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
From b20d26a878066c2697ab060ea2bb6f6053434a2c Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 14:00:36 +0800
|
||||
Subject: [PATCH 36/38] uadk: bugfix for aead set decrypt mac for stream mode
|
||||
|
||||
For the aead stream mode, packets are sent in three phases:
|
||||
first, middle and final, user may deliver the decrypt mac through
|
||||
the first or final message.
|
||||
|
||||
Currently uadk stores the first message's mac to the session,
|
||||
then restore it when process the final message, it can't work
|
||||
when the first message does not carry a valid decrypt mac.
|
||||
|
||||
Now uadk can cache the mac calculated based on the first message
|
||||
and the middle message to the session and use the decrypt mac
|
||||
until the final message is processed.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_sec.c | 4 ++--
|
||||
include/drv/wd_aead_drv.h | 2 +-
|
||||
wd_aead.c | 14 +++++++++-----
|
||||
3 files changed, 12 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 2c71090..0ea1870 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -2271,7 +2271,7 @@ static void gcm_auth_ivin(struct wd_aead_msg *msg)
|
||||
|
||||
/* Use the user's origin mac for decrypt icv check */
|
||||
if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- memcpy(msg->mac, msg->mac_bak, msg->auth_bytes);
|
||||
+ memcpy(msg->mac, msg->dec_mac, msg->auth_bytes);
|
||||
}
|
||||
|
||||
static void fill_gcm_first_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
|
||||
@@ -2364,7 +2364,7 @@ static int gcm_do_soft_mac(struct wd_aead_msg *msg)
|
||||
msg->mac[i] = g[i] ^ ctr_r[i];
|
||||
|
||||
if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST) {
|
||||
- ret = memcmp(msg->mac, msg->mac_bak, msg->auth_bytes);
|
||||
+ ret = memcmp(msg->mac, msg->dec_mac, msg->auth_bytes);
|
||||
if (ret) {
|
||||
msg->result = WD_IN_EPARA;
|
||||
WD_ERR("failed to do the gcm authentication!\n");
|
||||
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
|
||||
index 5e4f73a..a9c0e7c 100644
|
||||
--- a/include/drv/wd_aead_drv.h
|
||||
+++ b/include/drv/wd_aead_drv.h
|
||||
@@ -64,7 +64,7 @@ struct wd_aead_msg {
|
||||
/* mac */
|
||||
__u8 *mac;
|
||||
/* mac data pointer for decrypto as stream mode */
|
||||
- __u8 mac_bak[AES_BLOCK_SIZE];
|
||||
+ __u8 *dec_mac;
|
||||
/* total of data for stream mode */
|
||||
__u64 long_data_len;
|
||||
enum wd_aead_msg_state msg_state;
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index e5e1b19..87d61c3 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -635,20 +635,24 @@ static void fill_stream_msg(struct wd_aead_msg *msg, struct wd_aead_req *req,
|
||||
memset(sess->iv, 0, MAX_IV_SIZE);
|
||||
memcpy(sess->iv, req->iv, GCM_IV_SIZE);
|
||||
|
||||
- /* Store the original mac of first message to session */
|
||||
if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- memcpy(sess->mac_bak, req->mac, sess->auth_bytes);
|
||||
+ msg->mac = sess->mac_bak;
|
||||
break;
|
||||
case AEAD_MSG_MIDDLE:
|
||||
/* Middle messages need to store the stream's total length to session */
|
||||
sess->long_data_len += req->in_bytes;
|
||||
|
||||
msg->long_data_len = sess->long_data_len;
|
||||
+
|
||||
+ if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
+ msg->mac = sess->mac_bak;
|
||||
break;
|
||||
case AEAD_MSG_END:
|
||||
- /* Sets the original mac for final message */
|
||||
- if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- memcpy(msg->mac_bak, sess->mac_bak, sess->auth_bytes);
|
||||
+ if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST) {
|
||||
+ /* Sets the original mac for final message */
|
||||
+ msg->dec_mac = req->mac;
|
||||
+ msg->mac = sess->mac_bak;
|
||||
+ }
|
||||
|
||||
msg->long_data_len = sess->long_data_len + req->in_bytes;
|
||||
/* Reset the session's long_data_len */
|
||||
--
|
||||
2.25.1
|
||||
|
||||
74
0037-uadk-fix-for-digest-mac-full-length-check.patch
Normal file
74
0037-uadk-fix-for-digest-mac-full-length-check.patch
Normal file
@ -0,0 +1,74 @@
|
||||
From 1ef7825f5ae4ad052fb95b626c04dcf6857c48bf Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Fri, 22 Sep 2023 14:02:21 +0800
|
||||
Subject: [PATCH 37/38] uadk: fix for digest mac full length check
|
||||
|
||||
An uadk check error caused because digest mac full length check
|
||||
does not consider the new added request message type,
|
||||
so mac full length needs to be checked based on all message types.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_digest.h | 1 +
|
||||
wd_digest.c | 33 ++++++++++++++++++++-------------
|
||||
2 files changed, 21 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/include/wd_digest.h b/include/wd_digest.h
|
||||
index 7539866..ad4d579 100644
|
||||
--- a/include/wd_digest.h
|
||||
+++ b/include/wd_digest.h
|
||||
@@ -90,6 +90,7 @@ enum wd_digest_msg_state {
|
||||
WD_DIGEST_DOING,
|
||||
WD_DIGEST_STREAM_END,
|
||||
WD_DIGEST_STREAM_DOING,
|
||||
+ WD_DIGEST_MSG_STATE_MAX,
|
||||
};
|
||||
|
||||
/**
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 69c4b28..2307bf1 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -463,19 +463,26 @@ static int wd_mac_length_check(struct wd_digest_sess *sess,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(!req->has_next &&
|
||||
- req->out_bytes > g_digest_mac_len[sess->alg])) {
|
||||
- WD_ERR("invalid: digest mac length, alg = %d, out_bytes = %u\n",
|
||||
- sess->alg, req->out_bytes);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
- /* User need to input full mac buffer in first and middle hash */
|
||||
- if (unlikely(req->has_next &&
|
||||
- req->out_bytes != g_digest_mac_full_len[sess->alg])) {
|
||||
- WD_ERR("invalid: digest mac full length is error, alg = %d, out_bytes = %u\n",
|
||||
- sess->alg, req->out_bytes);
|
||||
- return -WD_EINVAL;
|
||||
+ switch (req->has_next) {
|
||||
+ case WD_DIGEST_END:
|
||||
+ case WD_DIGEST_STREAM_END:
|
||||
+ if (unlikely(req->out_bytes > g_digest_mac_len[sess->alg])) {
|
||||
+ WD_ERR("invalid: digest mac length, alg = %d, out_bytes = %u\n",
|
||||
+ sess->alg, req->out_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ break;
|
||||
+ case WD_DIGEST_DOING:
|
||||
+ case WD_DIGEST_STREAM_DOING:
|
||||
+ /* User need to input full mac buffer in first and middle hash */
|
||||
+ if (unlikely(req->out_bytes != g_digest_mac_full_len[sess->alg])) {
|
||||
+ WD_ERR("invalid: digest mac full length, alg = %d, out_bytes = %u\n",
|
||||
+ sess->alg, req->out_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ break;
|
||||
+ default:
|
||||
+ break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
From 58af9f26c14b8afcfa928bec9d811efa86cccfbf Mon Sep 17 00:00:00 2001
|
||||
From: Qi Tao <taoqi10@huawei.com>
|
||||
Date: Wed, 27 Sep 2023 14:57:11 +0800
|
||||
Subject: [PATCH 38/38] uadk/sec: optimize the function name and implement for
|
||||
digest
|
||||
|
||||
digest_bd2_zero_packet_check() and digest_bd3_zero_packet_check()
|
||||
do not check whether the packet length is 0. Therefor, the
|
||||
function name does not match the function semantics.
|
||||
|
||||
Signed-off-by: Qi Tao <taoqi10@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 25 ++++++++++---------------
|
||||
1 file changed, 10 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 0ea1870..507f48b 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -1574,7 +1574,7 @@ static int digest_long_bd_align_check(struct wd_digest_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg)
|
||||
+static int digest_bd2_type_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
enum hash_bd_type type = get_hash_bd_type(msg);
|
||||
|
||||
@@ -1593,7 +1593,7 @@ static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int digest_bd3_zero_packet_check(struct wd_digest_msg *msg)
|
||||
+static int digest_bd3_type_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
enum hash_bd_type type = get_hash_bd_type(msg);
|
||||
/* Long hash first and middle bd */
|
||||
@@ -1614,28 +1614,23 @@ static int digest_bd3_zero_packet_check(struct wd_digest_msg *msg)
|
||||
|
||||
static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
{
|
||||
- int ret;
|
||||
+ int ret = 0;
|
||||
|
||||
/*
|
||||
* Hardware needs to check the zero byte packet in the block
|
||||
* and long hash mode. First and middle bd not support 0 size,
|
||||
* final bd not need to check it.
|
||||
*/
|
||||
- if (type == BD_TYPE2 && !msg->in_bytes) {
|
||||
- ret = digest_bd2_zero_packet_check(msg);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
- }
|
||||
+ if (unlikely(!msg->in_bytes)) {
|
||||
+ if (type == BD_TYPE2)
|
||||
+ ret = digest_bd2_type_check(msg);
|
||||
+ else if (type == BD_TYPE3)
|
||||
+ ret = digest_bd3_type_check(msg);
|
||||
|
||||
- if (type == BD_TYPE3 && !msg->in_bytes) {
|
||||
- ret = digest_bd3_zero_packet_check(msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
- }
|
||||
-
|
||||
- if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
- WD_ERR("digest input length is too long, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ } else if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
+ WD_ERR("digest input length is too long, size = %u\n", msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
Name: libwd
|
||||
Summary: User Space Accelerator Development Kit
|
||||
Version: 2.5.0
|
||||
Release: 2
|
||||
Release: 4
|
||||
License: Apache-2.0
|
||||
Source: %{name}-%{version}.tar.gz
|
||||
Vendor: Huawei Corporation
|
||||
@ -11,10 +11,49 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-root
|
||||
Conflicts: %{name} < %{version}-%{release}
|
||||
Provides: %{name} = %{version}-%{release}
|
||||
BuildRequires: numactl-devel, openssl-devel, zlib-devel
|
||||
BuildRequires: automake, autoconf, libtool
|
||||
BuildRequires: automake, autoconf, libtool, chrpath
|
||||
BuildRequires: gcc, make
|
||||
ExclusiveArch: aarch64
|
||||
|
||||
Patch0001: 0001-uadk-comp-fix-duplicate-release-of-comp.patch
|
||||
Patch0002: 0002-uadk_tool-use-DT_RUNPATH-instead-of-DT_RPATH.patch
|
||||
Patch0003: 0003-uadk-cipher-fix-wd_cipher_init2-typo.patch
|
||||
Patch0004: 0004-uadk-v1-fix-local-variable-type.patch
|
||||
Patch0005: 0005-drv-qm-fix-memory-leak-in-hisi_qm_create_sglpool.patch
|
||||
Patch0006: 0006-uadk-v1-fix-memory-leak-in-wd_sgl.c.patch
|
||||
Patch0007: 0007-uadk-hisi_comp-free-sgl-when-send-request-error.patch
|
||||
Patch0008: 0008-uadk-hisi_comp-add-output-length-check-for-lz77_zstd.patch
|
||||
Patch0009: 0009-drivers-alloc-and-free-resources-by-themself.patch
|
||||
Patch0010: 0010-uadk-fix-for-get_str_attr.patch
|
||||
Patch0011: 0011-uadk-remove-unused-information.patch
|
||||
Patch0012: 0012-uadk-support-digest-to-parse-private-data.patch
|
||||
Patch0013: 0013-uadk-support-aead-to-parse-user-private-data.patch
|
||||
Patch0014: 0014-uadk-fix-sec-test.patch
|
||||
Patch0015: 0015-sanity_test-fix-to-show-messages-from-testcase.patch
|
||||
Patch0016: 0016-sanity_test-append-run_cmd-for-zip.patch
|
||||
Patch0017: 0017-uadk-fix-hpre-test.patch
|
||||
Patch0018: 0018-uadk-add-the-msg-pool-depth-configuration.patch
|
||||
Patch0019: 0019-uadk-v1-add-the-cookie-depth-configuration.patch
|
||||
Patch0020: 0020-uadk_tool-initialize-cparams-to-0.patch
|
||||
Patch0021: 0021-uadk-add-init-wait-timeout.patch
|
||||
Patch0022: 0022-uadk-fix-key-length-check-error-in-xts-mode.patch
|
||||
Patch0023: 0023-uadk-v1-fix-key-length-check-error-in-xts-mode.patch
|
||||
Patch0024: 0024-uadk-support-loading-alg-lib-from-specified-director.patch
|
||||
Patch0025: 0025-uadk-zlibwrapper-fix-failed-to-create-multiple-z_str.patch
|
||||
Patch0026: 0026-uadk-v1-hisilicon-zip-add-sqe_fill_priv-and-sqe_pars.patch
|
||||
Patch0027: 0027-uadk-v1-modify-the-alignment-size-of-sha384.patch
|
||||
Patch0028: 0028-uadk-digest-optimize-the-zero-byte-packet-checking-f.patch
|
||||
Patch0029: 0029-uadk-v1-cipher-support-aes-cbc-cts-mode.patch
|
||||
Patch0030: 0030-uadk-v1-cipher-support-user-self-defined-data-functi.patch
|
||||
Patch0031: 0031-uadk-cipher-cleaup-judgement-sequence.patch
|
||||
Patch0032: 0032-uadk-fix-for-wd_memset_zero-occupies-high-cpu-usage.patch
|
||||
Patch0033: 0033-uadk-optimize-session-update-for-long-hash-mode.patch
|
||||
Patch0034: 0034-uadk-support-digest-message-carrying-long-data-infor.patch
|
||||
Patch0035: 0035-uadk-add-out_bytes-check-for-long-hash-scene.patch
|
||||
Patch0036: 0036-uadk-bugfix-for-aead-set-decrypt-mac-for-stream-mode.patch
|
||||
Patch0037: 0037-uadk-fix-for-digest-mac-full-length-check.patch
|
||||
Patch0038: 0038-uadk-sec-optimize-the-function-name-and-implement-fo.patch
|
||||
|
||||
%description
|
||||
This package contains the User Space Accelerator Library
|
||||
for hardware accelerator, compress, symmetric encryption
|
||||
@ -33,9 +72,17 @@ mkdir -p ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libwd.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libwd_crypto.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libwd_comp.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libhisi_sec.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libhisi_hpre.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
install -b -m755 .libs/libhisi_zip.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
|
||||
mkdir -p ${RPM_BUILD_ROOT}/usr/lib64/uadk
|
||||
install -b -m755 .libs/libhisi_sec.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64/uadk
|
||||
install -b -m755 .libs/libhisi_hpre.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64/uadk
|
||||
install -b -m755 .libs/libhisi_zip.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64/uadk
|
||||
|
||||
chrpath -d ${RPM_BUILD_ROOT}/usr/lib64/libwd_crypto.so.%{version}
|
||||
chrpath -d ${RPM_BUILD_ROOT}/usr/lib64/libwd_comp.so.%{version}
|
||||
chrpath -d ${RPM_BUILD_ROOT}/usr/lib64/uadk/libhisi_sec.so.%{version}
|
||||
chrpath -d ${RPM_BUILD_ROOT}/usr/lib64/uadk/libhisi_hpre.so.%{version}
|
||||
chrpath -d ${RPM_BUILD_ROOT}/usr/lib64/uadk/libhisi_zip.so.%{version}
|
||||
|
||||
mkdir -p ${RPM_BUILD_ROOT}/usr/include/warpdrive/include
|
||||
cp v1/uacce.h ${RPM_BUILD_ROOT}/usr/include/warpdrive/include
|
||||
cp v1/wd.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
|
||||
@ -82,9 +129,9 @@ rm -rf ${RPM_BUILD_ROOT}
|
||||
/usr/lib64/libwd.so.%{version}
|
||||
/usr/lib64/libwd_crypto.so.%{version}
|
||||
/usr/lib64/libwd_comp.so.%{version}
|
||||
/usr/lib64/libhisi_sec.so.%{version}
|
||||
/usr/lib64/libhisi_hpre.so.%{version}
|
||||
/usr/lib64/libhisi_zip.so.%{version}
|
||||
/usr/lib64/uadk/libhisi_sec.so.%{version}
|
||||
/usr/lib64/uadk/libhisi_hpre.so.%{version}
|
||||
/usr/lib64/uadk/libhisi_zip.so.%{version}
|
||||
%defattr(644,root,root)
|
||||
/usr/include/warpdrive/include/uacce.h
|
||||
/usr/include/warpdrive/wd.h
|
||||
@ -119,9 +166,6 @@ rm -rf ${RPM_BUILD_ROOT}
|
||||
%exclude /usr/lib64/libwd.so.2
|
||||
%exclude /usr/lib64/libwd_crypto.so.2
|
||||
%exclude /usr/lib64/libwd_comp.so.2
|
||||
%exclude /usr/lib64/libhisi_sec.so.2
|
||||
%exclude /usr/lib64/libhisi_hpre.so.2
|
||||
%exclude /usr/lib64/libhisi_zip.so.2
|
||||
/usr/lib64/pkgconfig/libwd.pc
|
||||
/usr/lib64/pkgconfig/libwd_crypto.pc
|
||||
/usr/lib64/pkgconfig/libwd_comp.pc
|
||||
@ -134,12 +178,12 @@ if [ "$1" = "2" ] ; then #2: update
|
||||
rm -rf /usr/lib64/libwd_crypto.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libwd_comp.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libwd_comp.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_sec.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_sec.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_hpre.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_hpre.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_zip.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_zip.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_sec.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_sec.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_hpre.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_hpre.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_zip.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_zip.so.2 > /dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
%post
|
||||
@ -151,6 +195,7 @@ if [[ "$1" = "1" || "$1" = "2" ]] ; then #1: install 2: update
|
||||
ln -sf libwd_crypto.so.%{version} libwd_crypto.so.2
|
||||
ln -sf libwd_comp.so.%{version} libwd_comp.so
|
||||
ln -sf libwd_comp.so.%{version} libwd_comp.so.2
|
||||
cd /usr/lib64/uadk
|
||||
ln -sf libhisi_sec.so.%{version} libhisi_sec.so
|
||||
ln -sf libhisi_sec.so.%{version} libhisi_sec.so.2
|
||||
ln -sf libhisi_hpre.so.%{version} libhisi_hpre.so
|
||||
@ -168,20 +213,26 @@ if [ "$1" = "0" ] ; then #0: uninstall
|
||||
rm -rf /usr/lib64/libwd_crypto.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libwd_comp.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libwd_comp.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_sec.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_sec.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_hpre.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_hpre.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_zip.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/libhisi_zip.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_sec.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_sec.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_hpre.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_hpre.so.2 > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_zip.so > /dev/null 2>&1 || true
|
||||
rm -rf /usr/lib64/uadk/libhisi_zip.so.2 > /dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
%postun
|
||||
/sbin/ldconfig
|
||||
|
||||
%changelog
|
||||
* Thu Sep 28 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-4
|
||||
- libwd: update the source code
|
||||
|
||||
* Mon Sep 4 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-3
|
||||
- libwd: Deleting rpath information from the dynamic library
|
||||
|
||||
* Mon Aug 7 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-2
|
||||
- libwd: update the source code to 2.5.0
|
||||
- libwd: Adding and packing the pkgconfig file
|
||||
|
||||
* Mon Aug 7 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-1
|
||||
- libwd: update the source code to 2.5.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user