!81 libwd: update the source code

From: @xiao_jiang_shui 
Reviewed-by: @hao-fang 
Signed-off-by: @hao-fang
This commit is contained in:
openeuler-ci-bot 2023-12-08 06:57:33 +00:00 committed by Gitee
commit 0bf46982b4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
73 changed files with 13997 additions and 1 deletions

View File

@ -0,0 +1,38 @@
From d05210ffd7720e93758a940079c230692ef976ee Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:12 +0800
Subject: [PATCH 43/85] uadk_tool: delete redundant memset zero
wd_rsa_del_kg_out() clears the data before freeing the memory.
Therefore, no additional memset zero is required before
calling wd_rsa_del_kg_out().
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index e722c36..eaa8408 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1316,16 +1316,6 @@ static void *rsa_uadk_async_run(void *arg)
/* clean output buffer remainings in the last time operation */
if (req.op_type == WD_RSA_GENKEY) {
- char *data;
- int len;
-
- len = wd_rsa_kg_out_data((void *)req.dst, &data);
- if (len < 0) {
- HPRE_TST_PRT("failed to wd rsa get key gen out data!\n");
- goto tag_release;
- }
- memset(data, 0, len);
-
wd_rsa_del_kg_in(h_sess, req.src);
req.src = NULL;
wd_rsa_del_kg_out(h_sess, req.dst);
--
2.25.1

View File

@ -0,0 +1,162 @@
From ddb0ffc17b5fffb4db3e36b12fe60a694eeafb5c Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:13 +0800
Subject: [PATCH 44/85] uadk_tool: fix possible memory leak in
<alg>_uadk_async_run
After a session is applied for, if subsequent
operations fail, the session should be released.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 45 +++++++++++------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index eaa8408..9d89f7e 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1238,7 +1238,7 @@ static void *rsa_uadk_async_run(void *arg)
key_info = malloc(key_size * 16);
if (!key_info) {
HPRE_TST_PRT("failed to alloc RSA key info!\n");
- return NULL;
+ goto h_sess_release;
}
memset(key_info, 0, key_size * 16);
@@ -1251,13 +1251,20 @@ static void *rsa_uadk_async_run(void *arg)
rsa_key_in->p = rsa_key_in->e + key_size;
rsa_key_in->q = rsa_key_in->p + (key_size >> 1);
- ret = get_rsa_key_from_sample(h_sess, key_info, key_info,
+ ret = get_rsa_key_from_sample(h_sess, key_info, key_info,
pdata->keybits, pdata->kmode);
if (ret) {
HPRE_TST_PRT("failed to get sample key data!\n");
- goto sample_release;
+ goto key_in_release;
}
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ if (!tag) {
+ HPRE_TST_PRT("failed to malloc rsa tag!\n");
+ goto key_in_release;
+ }
+
+ req.cb = rsa_async_cb;
req.src_bytes = key_size;
req.dst_bytes = key_size;
req.op_type = pdata->optype;
@@ -1265,13 +1272,13 @@ static void *rsa_uadk_async_run(void *arg)
ret = get_hpre_keygen_opdata(h_sess, &req);
if (ret){
HPRE_TST_PRT("failed to fill rsa key gen req!\n");
- goto sample_release;
+ goto tag_release;
}
} else {
req.src = malloc(key_size);
if (!req.src) {
HPRE_TST_PRT("failed to alloc rsa in buffer!\n");
- goto sample_release;
+ goto tag_release;
}
memset(req.src, 0, req.src_bytes);
memcpy(req.src + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m));
@@ -1282,13 +1289,6 @@ static void *rsa_uadk_async_run(void *arg)
}
}
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
- if (!tag) {
- HPRE_TST_PRT("failed to malloc rsa tag!\n");
- goto dst_release;
- }
- req.cb = rsa_async_cb;
-
do {
if (get_run_state() == 0)
break;
@@ -1309,7 +1309,7 @@ static void *rsa_uadk_async_run(void *arg)
continue;
} else if (ret) {
HPRE_TST_PRT("failed to do rsa async task!\n");
- goto tag_release;
+ break;
}
count++;
} while(true);
@@ -1322,19 +1322,18 @@ static void *rsa_uadk_async_run(void *arg)
req.dst = NULL;
}
-tag_release:
- free(tag);
-dst_release:
if (req.dst)
free(req.dst);
src_release:
if (req.src)
free(req.src);
-sample_release:
+tag_release:
+ free(tag);
+key_in_release:
free(rsa_key_in);
key_release:
free(key_info);
-
+h_sess_release:
wd_rsa_free_sess(h_sess);
add_send_complete();
@@ -1542,7 +1541,7 @@ static void *dh_uadk_async_run(void *arg)
ret = get_dh_opdata_param(h_sess, &req, &param, key_size);
if (ret){
HPRE_TST_PRT("failed to fill dh key gen req!\n");
- goto param_release;
+ goto sess_release;
}
tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
@@ -1572,12 +1571,11 @@ static void *dh_uadk_async_run(void *arg)
continue;
} else if (ret) {
HPRE_TST_PRT("failed to do DH async task!\n");
- goto tag_release;
+ break;
}
count++;
} while(true);
-tag_release:
free(tag);
param_release:
free(req.x_p);
@@ -2200,7 +2198,7 @@ static void *ecc_uadk_async_run(void *arg)
tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
if (!tag) {
HPRE_TST_PRT("failed to malloc rsa tag!\n");
- goto src_release;
+ goto src_release;
}
req.cb = ecc_async_cb;
@@ -2224,12 +2222,11 @@ static void *ecc_uadk_async_run(void *arg)
continue;
} else if (ret) {
HPRE_TST_PRT("failed to do ECC async task!\n");
- goto tag_release;
+ break;
}
count++;
} while(true);
-tag_release:
free(tag);
src_release:
if (req.src)
--
2.25.1

View File

@ -0,0 +1,29 @@
From b36986f417bfbcfe37c822b4c9a9c7168b12554d Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:14 +0800
Subject: [PATCH 45/85] uadk_tool: fix the called function interface
In asynchronous scenarios, call wd_do_rsa_async()
instead of wd_do_rsa_sync().
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 9d89f7e..653232f 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -2211,7 +2211,7 @@ static void *ecc_uadk_async_run(void *arg)
tag[i].sess = h_sess;
req.cb_param = &tag[i];
- ret = wd_do_ecc_sync(h_sess, &req);
+ ret = wd_do_ecc_async(h_sess, &req);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
try_cnt++;
--
2.25.1

View File

@ -0,0 +1,91 @@
From 36363fb48e8653a6efbacc32a1374e76a86592a4 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:15 +0800
Subject: [PATCH 46/85] uadk_tool: release memory after all tasks are complete
In asynchronous scenarios, memory is released after all tasks are complete.
This prevents segmentation errors caused by the polling thread uses the
memory after the memory is freed.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 49 ++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 653232f..5e84d61 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1314,7 +1314,22 @@ static void *rsa_uadk_async_run(void *arg)
count++;
} while(true);
- /* clean output buffer remainings in the last time operation */
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
if (req.op_type == WD_RSA_GENKEY) {
wd_rsa_del_kg_in(h_sess, req.src);
req.src = NULL;
@@ -1576,6 +1591,22 @@ static void *dh_uadk_async_run(void *arg)
count++;
} while(true);
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
free(tag);
param_release:
free(req.x_p);
@@ -2227,6 +2258,22 @@ static void *ecc_uadk_async_run(void *arg)
count++;
} while(true);
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
free(tag);
src_release:
if (req.src)
--
2.25.1

View File

@ -0,0 +1,905 @@
From 44077a50fb4f259c59f86331e9ccd4a386e4b81f Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:16 +0800
Subject: [PATCH 47/85] uadk_tool: Optimize sec's sva benchmark code
Update the performance test code of sec's sva mode, and optimize the
performance test code of sec's sva mode by splitting sub-functions.
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 705 ++++++++++++++---------
1 file changed, 443 insertions(+), 262 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 09cd8f4..1ea57ee 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -27,6 +27,7 @@ struct thread_pool {
u8 *iv;
u8 *key;
u8 *mac;
+ u8 *hash;
} g_uadk_pool;
typedef struct uadk_thread_res {
@@ -37,6 +38,9 @@ typedef struct uadk_thread_res {
u32 ivsize;
u32 optype;
u32 td_id;
+ bool is_union;
+ u32 dalg;
+ u32 dmode;
} thread_data;
static struct wd_ctx_config g_ctx_cfg;
@@ -66,8 +70,11 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
{
u32 algtype = options->algtype;
u32 optype = options->optype;
+ bool is_union = false;
u8 keysize = 0;
u8 ivsize = 0;
+ u8 dmode;
+ u8 dalg;
u8 mode;
u8 alg;
@@ -270,6 +277,33 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
mode = WD_CIPHER_GCM;
alg = WD_CIPHER_AES;
break;
+ case AES_128_CBC_SHA256_HMAC:
+ keysize = 16;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC;
+ alg = WD_CIPHER_AES;
+ is_union = true;
+ dalg = WD_DIGEST_SHA256;
+ dmode = WD_DIGEST_HMAC;
+ break;
+ case AES_192_CBC_SHA256_HMAC:
+ keysize = 24;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC;
+ alg = WD_CIPHER_AES;
+ is_union = true;
+ dalg = WD_DIGEST_SHA256;
+ dmode = WD_DIGEST_HMAC;
+ break;
+ case AES_256_CBC_SHA256_HMAC:
+ keysize = 32;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC;
+ alg = WD_CIPHER_AES;
+ is_union = true;
+ dalg = WD_DIGEST_SHA256;
+ dmode = WD_DIGEST_HMAC;
+ break;
case SM4_128_CCM:
keysize = 16;
ivsize = 16;
@@ -334,8 +368,11 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
tddata->alg = alg;
tddata->mode = mode;
+ tddata->dalg = dalg;
+ tddata->dmode = dmode;
tddata->ivsize = ivsize;
tddata->keysize = keysize;
+ tddata->is_union = is_union;
tddata->optype = options->optype;
tddata->subtype = options->subtype;
@@ -382,7 +419,7 @@ static int init_ctx_config(char *alg, int subtype, int mode)
break;
default:
SEC_TST_PRT("Fail to parse alg subtype!\n");
- goto out;
+ return -EINVAL;
}
if (!g_sched) {
SEC_TST_PRT("Fail to alloc sched!\n");
@@ -416,8 +453,6 @@ static int init_ctx_config(char *alg, int subtype, int mode)
case DIGEST_TYPE:
ret = wd_digest_init(&g_ctx_cfg, g_sched);
break;
- default:
- goto out;
}
if (ret) {
SEC_TST_PRT("Fail to cipher ctx!\n");
@@ -471,6 +506,7 @@ static int init_uadk_bd_pool(void)
g_uadk_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
g_uadk_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
g_uadk_pool.mac = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+ g_uadk_pool.hash = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
g_uadk_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
if (!g_uadk_pool.pool) {
@@ -523,6 +559,7 @@ malloc_error1:
free(g_uadk_pool.iv);
free(g_uadk_pool.key);
free(g_uadk_pool.mac);
+ free(g_uadk_pool.hash);
SEC_TST_PRT("init uadk bd pool alloc failed!\n");
return -ENOMEM;
@@ -601,20 +638,15 @@ recv_error:
return NULL;
}
-static void *sec_uadk_async_run(void *arg)
+static void *sec_uadk_cipher_async(void *arg)
{
thread_data *pdata = (thread_data *)arg;
struct wd_cipher_sess_setup cipher_setup = {0};
- struct wd_aead_sess_setup aead_setup = {0};
- struct wd_digest_sess_setup digest_setup = {0};
struct wd_cipher_req creq;
- struct wd_aead_req areq;
- struct wd_digest_req dreq;
struct bd_pool *uadk_pool;
- u8 *priv_iv, *priv_key, *priv_mac;
+ u8 *priv_iv, *priv_key;
int try_cnt = 0;
handle_t h_sess;
- u32 auth_size = 16;
u32 count = 0;
int ret, i = 0;
@@ -624,176 +656,296 @@ static void *sec_uadk_async_run(void *arg)
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
priv_iv = &g_uadk_pool.iv[pdata->td_id];
priv_key = &g_uadk_pool.key[pdata->td_id];
- priv_mac = &g_uadk_pool.mac[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) {
- case CIPHER_TYPE:
- cipher_setup.alg = pdata->alg;
- cipher_setup.mode = pdata->mode;
- h_sess = wd_cipher_alloc_sess(&cipher_setup);
- if (!h_sess)
- return NULL;
- ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize);
- if (ret) {
- SEC_TST_PRT("test sec cipher set key is failed!\n");
- wd_cipher_free_sess(h_sess);
- return NULL;
- }
+ cipher_setup.alg = pdata->alg;
+ cipher_setup.mode = pdata->mode;
+ h_sess = wd_cipher_alloc_sess(&cipher_setup);
+ if (!h_sess)
+ return NULL;
+ ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize);
+ if (ret) {
+ SEC_TST_PRT("test sec cipher set key is failed!\n");
+ wd_cipher_free_sess(h_sess);
+ return NULL;
+ }
- creq.op_type = pdata->optype;
- creq.iv = priv_iv;
- creq.iv_bytes = pdata->ivsize;
- creq.in_bytes = g_pktlen;
- creq.out_bytes = g_pktlen;
- creq.out_buf_bytes = g_pktlen;
- creq.data_fmt = 0;
- creq.state = 0;
- creq.cb = cipher_async_cb;
-
- while(1) {
- if (get_run_state() == 0)
- break;
- try_cnt = 0;
- i = count % MAX_POOL_LENTH;
- creq.src = uadk_pool->bds[i].src;
- creq.dst = uadk_pool->bds[i].dst;
-
- ret = wd_do_cipher_async(h_sess, &creq);
- if (ret < 0) {
- usleep(SEND_USLEEP * try_cnt);
- try_cnt++;
- if (try_cnt > MAX_TRY_CNT) {
- SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT);
- try_cnt = 0;
- }
- continue;
+ creq.op_type = pdata->optype;
+ creq.iv = priv_iv;
+ creq.iv_bytes = pdata->ivsize;
+ creq.in_bytes = g_pktlen;
+ creq.out_bytes = g_pktlen;
+ creq.out_buf_bytes = g_pktlen;
+ creq.data_fmt = 0;
+ creq.state = 0;
+ creq.cb = cipher_async_cb;
+
+ while(1) {
+ if (get_run_state() == 0)
+ break;
+ try_cnt = 0;
+ i = count % MAX_POOL_LENTH;
+ creq.src = uadk_pool->bds[i].src;
+ creq.dst = uadk_pool->bds[i].dst;
+
+ ret = wd_do_cipher_async(h_sess, &creq);
+ if (ret < 0) {
+ usleep(SEND_USLEEP * try_cnt);
+ try_cnt++;
+ if (try_cnt > MAX_TRY_CNT) {
+ SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT);
+ try_cnt = 0;
}
- count++;
+ continue;
}
- wd_cipher_free_sess(h_sess);
- break;
- case AEAD_TYPE: // just ccm and gcm
- aead_setup.calg = pdata->alg;
- aead_setup.cmode = pdata->mode;
- h_sess = wd_aead_alloc_sess(&aead_setup);
- if (!h_sess)
- return NULL;
- ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize);
- if (ret) {
- SEC_TST_PRT("test sec cipher set key is failed!\n");
- wd_aead_free_sess(h_sess);
- return NULL;
- }
- ret = wd_aead_set_authsize(h_sess, auth_size);
+ count++;
+ }
+ wd_cipher_free_sess(h_sess);
+
+ add_send_complete();
+
+ return NULL;
+}
+
+static void *sec_uadk_aead_async(void *arg)
+{
+ thread_data *pdata = (thread_data *)arg;
+ struct wd_aead_sess_setup aead_setup = {0};
+ u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
+ struct wd_aead_req areq;
+ struct bd_pool *uadk_pool;
+ int try_cnt = 0;
+ handle_t h_sess;
+ u32 auth_size = 16;
+ u32 count = 0;
+ int ret, i = 0;
+
+ if (pdata->td_id > g_thread_num)
+ return NULL;
+
+ uadk_pool = &g_uadk_pool.pool[pdata->td_id];
+ priv_iv = &g_uadk_pool.iv[pdata->td_id];
+ priv_key = &g_uadk_pool.key[pdata->td_id];
+ priv_mac = &g_uadk_pool.mac[pdata->td_id];
+ priv_hash = &g_uadk_pool.hash[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ aead_setup.calg = pdata->alg;
+ aead_setup.cmode = pdata->mode;
+ if (pdata->is_union) {
+ aead_setup.dalg = pdata->dalg;
+ aead_setup.dmode = pdata->dmode;
+ }
+ h_sess = wd_aead_alloc_sess(&aead_setup);
+ if (!h_sess)
+ return NULL;
+ ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize);
+ if (ret) {
+ SEC_TST_PRT("test sec cipher set key is failed!\n");
+ wd_aead_free_sess(h_sess);
+ return NULL;
+ }
+ if (pdata->is_union) {
+ ret = wd_aead_set_akey(h_sess, (const __u8*)priv_hash, HASH_ZISE);
if (ret) {
- SEC_TST_PRT("set auth size fail, authsize: 16\n");
+ SEC_TST_PRT("test sec aead set akey is failed!\n");
wd_aead_free_sess(h_sess);
return NULL;
}
+ }
+ ret = wd_aead_set_authsize(h_sess, auth_size);
+ if (ret) {
+ SEC_TST_PRT("set auth size fail, authsize: 16\n");
+ wd_aead_free_sess(h_sess);
+ return NULL;
+ }
+
+ areq.op_type = pdata->optype;
+ areq.iv = priv_iv; // aead IV need update with param
+ areq.mac = priv_mac;
+ areq.iv_bytes = pdata->ivsize;
+ areq.mac_bytes = auth_size;
+ areq.assoc_bytes = 16;
+ areq.in_bytes = g_pktlen;
+ if (pdata->is_union)
+ areq.mac_bytes = 32;
+ if (areq.op_type) // decrypto
+ areq.out_bytes = g_pktlen + 16; // aadsize = 16;
+ else
+ areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
+
+ areq.data_fmt = 0;
+ areq.state = 0;
+ areq.cb = aead_async_cb;
- areq.op_type = pdata->optype;
- areq.iv = priv_iv; // aead IV need update with param
- areq.mac = priv_mac;
- areq.iv_bytes = pdata->ivsize;
- areq.mac_bytes = auth_size;
- areq.assoc_bytes = 16;
- areq.in_bytes = g_pktlen;
- if (areq.op_type)// decrypto
- areq.out_bytes = g_pktlen + 16; // aadsize = 16;
- else
- areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
-
- areq.data_fmt = 0;
- areq.state = 0;
- areq.cb = aead_async_cb;
-
- while(1) {
- if (get_run_state() == 0)
- break;
- try_cnt = 0;
- i = count % MAX_POOL_LENTH;
- areq.src = uadk_pool->bds[i].src;
- areq.dst = uadk_pool->bds[i].dst;
-
- ret = wd_do_aead_async(h_sess, &areq);
- if (ret < 0) {
- usleep(SEND_USLEEP * try_cnt);
- try_cnt++;
- if (try_cnt > MAX_TRY_CNT) {
- SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT);
- try_cnt = 0;
- }
- continue;
+ while(1) {
+ if (get_run_state() == 0)
+ break;
+ try_cnt = 0;
+ i = count % MAX_POOL_LENTH;
+ areq.src = uadk_pool->bds[i].src;
+ areq.dst = uadk_pool->bds[i].dst;
+
+ ret = wd_do_aead_async(h_sess, &areq);
+ if (ret < 0) {
+ usleep(SEND_USLEEP * try_cnt);
+ try_cnt++;
+ if (try_cnt > MAX_TRY_CNT) {
+ SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT);
+ try_cnt = 0;
}
- count++;
+ continue;
}
- wd_aead_free_sess(h_sess);
- break;
- case DIGEST_TYPE:
- digest_setup.alg = pdata->alg;
- digest_setup.mode = pdata->mode; // digest mode is optype
- h_sess = wd_digest_alloc_sess(&digest_setup);
- if (!h_sess)
+ count++;
+ }
+ wd_aead_free_sess(h_sess);
+
+ add_send_complete();
+
+ return NULL;
+}
+
+static void *sec_uadk_digest_async(void *arg)
+{
+ thread_data *pdata = (thread_data *)arg;
+ struct wd_digest_sess_setup digest_setup = {0};
+ struct wd_digest_req dreq;
+ struct bd_pool *uadk_pool;
+ u8 *priv_iv, *priv_key;
+ int try_cnt = 0;
+ handle_t h_sess;
+ u32 count = 0;
+ int ret, i = 0;
+
+ if (pdata->td_id > g_thread_num)
+ return NULL;
+
+ uadk_pool = &g_uadk_pool.pool[pdata->td_id];
+ priv_iv = &g_uadk_pool.iv[pdata->td_id];
+ priv_key = &g_uadk_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ digest_setup.alg = pdata->alg;
+ digest_setup.mode = pdata->mode; // digest mode is optype
+ h_sess = wd_digest_alloc_sess(&digest_setup);
+ if (!h_sess)
+ return NULL;
+ if (digest_setup.mode == WD_DIGEST_HMAC) {
+ ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4);
+ if (ret) {
+ SEC_TST_PRT("test sec digest set key is failed!\n");
+ wd_digest_free_sess(h_sess);
return NULL;
- if (digest_setup.mode == WD_DIGEST_HMAC) {
- ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4);
- if (ret) {
- SEC_TST_PRT("test sec digest set key is failed!\n");
- wd_digest_free_sess(h_sess);
- return NULL;
- }
}
- dreq.in_bytes = g_pktlen;
- dreq.out_bytes = 16;
- dreq.out_buf_bytes = 16;
- dreq.data_fmt = 0;
- dreq.state = 0;
- dreq.has_next = 0;
- dreq.cb = digest_async_cb;
-
- while(1) {
- if (get_run_state() == 0)
- break;
- try_cnt = 0;
- i = count % MAX_POOL_LENTH;
- dreq.in = uadk_pool->bds[i].src;
- dreq.out = uadk_pool->bds[i].dst;
-
- ret = wd_do_digest_async(h_sess, &dreq);
- if (ret < 0) {
- usleep(SEND_USLEEP * try_cnt);
- try_cnt++;
- if (try_cnt > MAX_TRY_CNT) {
- SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT);
- try_cnt = 0;
- }
- continue;
+ }
+ dreq.in_bytes = g_pktlen;
+ dreq.out_bytes = 16;
+ dreq.out_buf_bytes = 16;
+ dreq.data_fmt = 0;
+ dreq.state = 0;
+ dreq.has_next = 0;
+ dreq.cb = digest_async_cb;
+
+ while(1) {
+ if (get_run_state() == 0)
+ break;
+ try_cnt = 0;
+ i = count % MAX_POOL_LENTH;
+ dreq.in = uadk_pool->bds[i].src;
+ dreq.out = uadk_pool->bds[i].dst;
+
+ ret = wd_do_digest_async(h_sess, &dreq);
+ if (ret < 0) {
+ usleep(SEND_USLEEP * try_cnt);
+ try_cnt++;
+ if (try_cnt > MAX_TRY_CNT) {
+ SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT);
+ try_cnt = 0;
}
- count++;
+ continue;
}
- wd_digest_free_sess(h_sess);
- break;
+ count++;
}
+ wd_digest_free_sess(h_sess);
add_send_complete();
return NULL;
}
-static void *sec_uadk_sync_run(void *arg)
+static void *sec_uadk_cipher_sync(void *arg)
{
thread_data *pdata = (thread_data *)arg;
struct wd_cipher_sess_setup cipher_setup = {0};
- struct wd_aead_sess_setup aead_setup = {0};
- struct wd_digest_sess_setup digest_setup = {0};
struct wd_cipher_req creq;
+ struct bd_pool *uadk_pool;
+ u8 *priv_iv, *priv_key;
+ handle_t h_sess;
+ u32 count = 0;
+ int ret, i = 0;
+
+ if (pdata->td_id > g_thread_num)
+ return NULL;
+
+ uadk_pool = &g_uadk_pool.pool[pdata->td_id];
+ priv_iv = &g_uadk_pool.iv[pdata->td_id];
+ priv_key = &g_uadk_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ cipher_setup.alg = pdata->alg;
+ cipher_setup.mode = pdata->mode;
+ h_sess = wd_cipher_alloc_sess(&cipher_setup);
+ if (!h_sess)
+ return NULL;
+ ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize);
+ if (ret) {
+ SEC_TST_PRT("test sec cipher set key is failed!\n");
+ wd_cipher_free_sess(h_sess);
+ return NULL;
+ }
+
+ creq.op_type = pdata->optype;
+ creq.iv = priv_iv;
+ creq.iv_bytes = pdata->ivsize;
+ creq.in_bytes = g_pktlen;
+ creq.out_bytes = g_pktlen;
+ creq.out_buf_bytes = g_pktlen;
+ creq.data_fmt = 0;
+ creq.state = 0;
+
+ while(1) {
+ i = count % MAX_POOL_LENTH;
+ creq.src = uadk_pool->bds[i].src;
+ creq.dst = uadk_pool->bds[i].dst;
+ ret = wd_do_cipher_sync(h_sess, &creq);
+ if ((ret < 0 && ret != -WD_EBUSY) || creq.state)
+ break;
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+ wd_cipher_free_sess(h_sess);
+
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_uadk_aead_sync(void *arg)
+{
+ thread_data *pdata = (thread_data *)arg;
+ struct wd_aead_sess_setup aead_setup = {0};
+ u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
struct wd_aead_req areq;
- struct wd_digest_req dreq;
struct bd_pool *uadk_pool;
- u8 *priv_iv, *priv_key, *priv_mac;
handle_t h_sess;
u32 auth_size = 16;
u32 count = 0;
@@ -806,129 +958,130 @@ static void *sec_uadk_sync_run(void *arg)
priv_iv = &g_uadk_pool.iv[pdata->td_id];
priv_key = &g_uadk_pool.key[pdata->td_id];
priv_mac = &g_uadk_pool.mac[pdata->td_id];
+ priv_hash = &g_uadk_pool.hash[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) {
- case CIPHER_TYPE:
- cipher_setup.alg = pdata->alg;
- cipher_setup.mode = pdata->mode;
- h_sess = wd_cipher_alloc_sess(&cipher_setup);
- if (!h_sess)
- return NULL;
- ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize);
- if (ret) {
- SEC_TST_PRT("test sec cipher set key is failed!\n");
- wd_cipher_free_sess(h_sess);
- return NULL;
- }
-
- creq.op_type = pdata->optype;
- creq.iv = priv_iv;
- creq.iv_bytes = pdata->ivsize;
- creq.in_bytes = g_pktlen;
- creq.out_bytes = g_pktlen;
- creq.out_buf_bytes = g_pktlen;
- creq.data_fmt = 0;
- creq.state = 0;
-
- while(1) {
- i = count % MAX_POOL_LENTH;
- creq.src = uadk_pool->bds[i].src;
- creq.dst = uadk_pool->bds[i].dst;
- ret = wd_do_cipher_sync(h_sess, &creq);
- if ((ret < 0 && ret != -WD_EBUSY) || creq.state)
- break;
- count++;
- if (get_run_state() == 0)
- break;
- }
- wd_cipher_free_sess(h_sess);
- break;
- case AEAD_TYPE: // just ccm and gcm
- aead_setup.calg = pdata->alg;
- aead_setup.cmode = pdata->mode;
- h_sess = wd_aead_alloc_sess(&aead_setup);
- if (!h_sess)
- return NULL;
- ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize);
- if (ret) {
- SEC_TST_PRT("test sec cipher set key is failed!\n");
- wd_aead_free_sess(h_sess);
- return NULL;
- }
- ret = wd_aead_set_authsize(h_sess, auth_size);
+ aead_setup.calg = pdata->alg;
+ aead_setup.cmode = pdata->mode;
+ if (pdata->is_union) {
+ aead_setup.dalg = WD_DIGEST_SHA256;
+ aead_setup.dmode = WD_DIGEST_HMAC;
+ }
+ h_sess = wd_aead_alloc_sess(&aead_setup);
+ if (!h_sess)
+ return NULL;
+ ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize);
+ if (ret) {
+ SEC_TST_PRT("test sec cipher set key is failed!\n");
+ wd_aead_free_sess(h_sess);
+ return NULL;
+ }
+ if (pdata->is_union) {
+ ret = wd_aead_set_akey(h_sess, (const __u8*)priv_hash, HASH_ZISE);
if (ret) {
- SEC_TST_PRT("set auth size fail, authsize: 16\n");
+ SEC_TST_PRT("test sec aead set akey is failed!\n");
wd_aead_free_sess(h_sess);
return NULL;
}
-
- areq.op_type = pdata->optype;
- areq.iv = priv_iv; // aead IV need update with param
- areq.mac = priv_mac;
- areq.mac_bytes = 16;
- areq.iv_bytes = pdata->ivsize;
- areq.assoc_bytes = 16;
- areq.in_bytes = g_pktlen;
- areq.mac_bytes = auth_size;
- if (areq.op_type)// decrypto
- areq.out_bytes = g_pktlen + 16; // aadsize = 16;
- else
- areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
-
- areq.data_fmt = 0;
- areq.state = 0;
-
- while(1) {
- i = count % MAX_POOL_LENTH;
- areq.src = uadk_pool->bds[i].src;
- areq.dst = uadk_pool->bds[i].dst;
- count++;
- ret = wd_do_aead_sync(h_sess, &areq);
- if (ret || areq.state)
- break;
- if (get_run_state() == 0)
- break;
- }
+ }
+ ret = wd_aead_set_authsize(h_sess, auth_size);
+ if (ret) {
+ SEC_TST_PRT("set auth size fail, authsize: 16\n");
wd_aead_free_sess(h_sess);
- break;
- case DIGEST_TYPE:
- digest_setup.alg = pdata->alg;
- digest_setup.mode = pdata->mode; // digest mode is optype
- h_sess = wd_digest_alloc_sess(&digest_setup);
- if (!h_sess)
+ return NULL;
+ }
+
+ areq.op_type = pdata->optype;
+ areq.iv = priv_iv; // aead IV need update with param
+ areq.mac = priv_mac;
+ areq.mac_bytes = 16;
+ areq.iv_bytes = pdata->ivsize;
+ areq.assoc_bytes = 16;
+ areq.in_bytes = g_pktlen;
+ areq.mac_bytes = auth_size;
+ if (pdata->is_union)
+ areq.mac_bytes = 32;
+ if (areq.op_type) // decrypto
+ areq.out_bytes = g_pktlen + 16; // aadsize = 16;
+ else
+ areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
+
+ areq.data_fmt = 0;
+ areq.state = 0;
+
+ while(1) {
+ i = count % MAX_POOL_LENTH;
+ areq.src = uadk_pool->bds[i].src;
+ areq.dst = uadk_pool->bds[i].dst;
+ count++;
+ ret = wd_do_aead_sync(h_sess, &areq);
+ if (ret || areq.state)
+ break;
+ if (get_run_state() == 0)
+ break;
+ }
+ wd_aead_free_sess(h_sess);
+
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_uadk_digest_sync(void *arg)
+{
+ thread_data *pdata = (thread_data *)arg;
+ struct wd_digest_sess_setup digest_setup = {0};
+ struct wd_digest_req dreq;
+ struct bd_pool *uadk_pool;
+ u8 *priv_iv, *priv_key;
+ handle_t h_sess;
+ u32 count = 0;
+ int ret, i = 0;
+
+ if (pdata->td_id > g_thread_num)
+ return NULL;
+
+ uadk_pool = &g_uadk_pool.pool[pdata->td_id];
+ priv_iv = &g_uadk_pool.iv[pdata->td_id];
+ priv_key = &g_uadk_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ digest_setup.alg = pdata->alg;
+ digest_setup.mode = pdata->mode; // digest mode is optype
+ h_sess = wd_digest_alloc_sess(&digest_setup);
+ if (!h_sess)
+ return NULL;
+ if (digest_setup.mode == WD_DIGEST_HMAC) {
+ ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4);
+ if (ret) {
+ SEC_TST_PRT("test sec digest set key is failed!\n");
+ wd_digest_free_sess(h_sess);
return NULL;
- if (digest_setup.mode == WD_DIGEST_HMAC) {
- ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4);
- if (ret) {
- SEC_TST_PRT("test sec digest set key is failed!\n");
- wd_digest_free_sess(h_sess);
- return NULL;
- }
}
- dreq.in_bytes = g_pktlen;
- dreq.out_bytes = 16;
- dreq.out_buf_bytes = 16;
- dreq.data_fmt = 0;
- dreq.state = 0;
- dreq.has_next = 0;
-
- while(1) {
- i = count % MAX_POOL_LENTH;
- dreq.in = uadk_pool->bds[i].src;
- dreq.out = uadk_pool->bds[i].dst;
- ret = wd_do_digest_sync(h_sess, &dreq);
- if (ret || dreq.state)
- break;
- count++;
- if (get_run_state() == 0)
- break;
- }
- wd_digest_free_sess(h_sess);
- break;
}
+ dreq.in_bytes = g_pktlen;
+ dreq.out_bytes = 16;
+ dreq.out_buf_bytes = 16;
+ dreq.data_fmt = 0;
+ dreq.state = 0;
+ dreq.has_next = 0;
+
+ while(1) {
+ i = count % MAX_POOL_LENTH;
+ dreq.in = uadk_pool->bds[i].src;
+ dreq.out = uadk_pool->bds[i].dst;
+ ret = wd_do_digest_sync(h_sess, &dreq);
+ if (ret || dreq.state)
+ break;
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+ wd_digest_free_sess(h_sess);
add_recv_data(count, g_pktlen);
@@ -937,6 +1090,8 @@ static void *sec_uadk_sync_run(void *arg)
int sec_uadk_sync_threads(struct acc_option *options)
{
+ typedef void *(*sec_sync_run)(void *arg);
+ sec_sync_run uadk_sec_sync_run = NULL;
thread_data threads_args[THREADS_NUM];
thread_data threads_option;
pthread_t tdid[THREADS_NUM];
@@ -947,6 +1102,18 @@ int sec_uadk_sync_threads(struct acc_option *options)
if (ret)
return ret;
+ switch (options->subtype) {
+ case CIPHER_TYPE:
+ uadk_sec_sync_run = sec_uadk_cipher_sync;
+ break;
+ case AEAD_TYPE:
+ uadk_sec_sync_run = sec_uadk_aead_sync;
+ break;
+ case DIGEST_TYPE:
+ uadk_sec_sync_run = sec_uadk_digest_sync;
+ break;
+ }
+
for (i = 0; i < g_thread_num; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].alg = threads_option.alg;
@@ -955,7 +1122,7 @@ int sec_uadk_sync_threads(struct acc_option *options)
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, sec_uadk_sync_run, &threads_args[i]);
+ ret = pthread_create(&tdid[i], NULL, uadk_sec_sync_run, &threads_args[i]);
if (ret) {
SEC_TST_PRT("Create sync thread fail!\n");
goto sync_error;
@@ -977,6 +1144,8 @@ sync_error:
int sec_uadk_async_threads(struct acc_option *options)
{
+ typedef void *(*sec_async_run)(void *arg);
+ sec_async_run uadk_sec_async_run = NULL;
thread_data threads_args[THREADS_NUM];
thread_data threads_option;
pthread_t tdid[THREADS_NUM];
@@ -988,6 +1157,18 @@ int sec_uadk_async_threads(struct acc_option *options)
if (ret)
return ret;
+ switch (options->subtype) {
+ case CIPHER_TYPE:
+ uadk_sec_async_run = sec_uadk_cipher_async;
+ break;
+ case AEAD_TYPE:
+ uadk_sec_async_run = sec_uadk_aead_async;
+ break;
+ case DIGEST_TYPE:
+ uadk_sec_async_run = sec_uadk_digest_async;
+ break;
+ }
+
for (i = 0; i < g_ctxnum; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].td_id = i;
@@ -1007,7 +1188,7 @@ int sec_uadk_async_threads(struct acc_option *options)
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, sec_uadk_async_run, &threads_args[i]);
+ ret = pthread_create(&tdid[i], NULL, uadk_sec_async_run, &threads_args[i]);
if (ret) {
SEC_TST_PRT("Create async thread fail!\n");
goto async_error;
--
2.25.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,531 @@
From ca646cd14b69137795a90d8ec527743c43d0f897 Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:19 +0800
Subject: [PATCH 50/85] uadk_tool: add latency test function for uadk_tools
Add latency test function for symmetric algorithm, asymmetric
algorithm and compression algorithm in uadk_tools, and add this
function for SVA mode and No-SVA mode at the same time.
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 3 +
uadk_tool/benchmark/hpre_wd_benchmark.c | 3 +
uadk_tool/benchmark/sec_soft_benchmark.c | 3 +
uadk_tool/benchmark/sec_uadk_benchmark.c | 3 +
uadk_tool/benchmark/sec_wd_benchmark.c | 3 +
uadk_tool/benchmark/uadk_benchmark.c | 105 ++++++++++++++--------
uadk_tool/benchmark/uadk_benchmark.h | 15 +++-
uadk_tool/benchmark/zip_uadk_benchmark.c | 12 +--
uadk_tool/benchmark/zip_wd_benchmark.c | 12 +--
9 files changed, 102 insertions(+), 57 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 5e84d61..13e24ca 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1198,6 +1198,7 @@ key_release:
free(key_info);
wd_rsa_free_sess(h_sess);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
@@ -1670,6 +1671,7 @@ param_release:
free(req.pri);
sess_release:
wd_dh_free_sess(h_sess);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
@@ -2102,6 +2104,7 @@ msg_release:
if (subtype == SM2_TYPE)
free(setup.msg);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c
index 354e0e1..231b569 100644
--- a/uadk_tool/benchmark/hpre_wd_benchmark.c
+++ b/uadk_tool/benchmark/hpre_wd_benchmark.c
@@ -928,6 +928,7 @@ key_release:
free(key_info);
wcrypto_del_rsa_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
@@ -1324,6 +1325,7 @@ param_release:
wd_free_blk(pool, opdata.pri);
ctx_release:
wcrypto_del_dh_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
@@ -2193,6 +2195,7 @@ sess_release:
msg_release:
if (subtype == SM2_TYPE)
free(setup.msg);
+ cal_avg_latency(count);
add_recv_data(count, key_size);
return NULL;
diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c
index ea84393..f3510b1 100644
--- a/uadk_tool/benchmark/sec_soft_benchmark.c
+++ b/uadk_tool/benchmark/sec_soft_benchmark.c
@@ -882,6 +882,7 @@ static void *sec_soft_cipher_sync(void *arg)
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -986,6 +987,7 @@ static void *sec_soft_aead_sync(void *arg)
}
EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1056,6 +1058,7 @@ static void *sec_soft_digest_sync(void *arg)
HMAC_CTX_free(hm_ctx);
}
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 1ea57ee..ff83769 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -934,6 +934,7 @@ static void *sec_uadk_cipher_sync(void *arg)
}
wd_cipher_free_sess(h_sess);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1024,6 +1025,7 @@ static void *sec_uadk_aead_sync(void *arg)
}
wd_aead_free_sess(h_sess);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1083,6 +1085,7 @@ static void *sec_uadk_digest_sync(void *arg)
}
wd_digest_free_sess(h_sess);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index 038d3ab..5dd1501 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -1032,6 +1032,7 @@ static void *sec_wd_cipher_sync(void *arg)
}
wcrypto_del_cipher_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1156,6 +1157,7 @@ static void *sec_wd_aead_sync(void *arg)
}
wcrypto_del_aead_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1245,6 +1247,7 @@ static void *sec_wd_digest_sync(void *arg)
}
wcrypto_del_digest_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index 752553d..2791f84 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -18,6 +18,7 @@
/*----------------------------------------head struct--------------------------------------------------------*/
static unsigned int g_run_state = 1;
+static struct acc_option *g_run_options;
static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct _recv_data {
double pkg_len;
@@ -116,6 +117,9 @@ static struct acc_alg_item alg_options[] = {
{"aes-128-gcm", AES_128_GCM},
{"aes-192-gcm", AES_192_GCM},
{"aes-256-gcm", AES_256_GCM},
+ {"aes-128-cbc-sha256-hmac", AES_128_CBC_SHA256_HMAC},
+ {"aes-192-cbc-sha256-hmac", AES_192_CBC_SHA256_HMAC},
+ {"aes-256-cbc-sha256-hmac", AES_256_CBC_SHA256_HMAC},
{"sm4-128-ccm", SM4_128_CCM},
{"sm4-128-gcm", SM4_128_GCM},
{"sm3", SM3_ALG},
@@ -290,6 +294,18 @@ void get_rand_data(u8 *addr, u32 size)
#endif
}
+
+void cal_avg_latency(u32 count)
+{
+ double latency;
+
+ if (!g_run_options || !g_run_options->latency)
+ return;
+
+ latency = (double)g_run_options->times * SEC_2_USEC / count;
+ ACC_TST_PRT("thread<%lu> avg latency: %.1fus\n", gettid(), latency);
+}
+
/*-------------------------------------main code------------------------------------------------------*/
static void parse_alg_param(struct acc_option *option)
@@ -382,7 +398,7 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime)
if (get_recv_time() == option->threads)
break;
} else { // ASYNC_MODE
- if (get_recv_time() == 1)
+ if (get_recv_time() == 1) // poll complete
break;
}
usleep(1000);
@@ -471,9 +487,9 @@ int acc_benchmark_run(struct acc_option *option)
int i, ret = 0;
int status;
- ACC_TST_PRT("start UADK benchmark test.\n");
parse_alg_param(option);
dump_param(option);
+ g_run_options = option;
pthread_mutex_init(&acc_mutex, NULL);
if (option->multis <= 1) {
@@ -549,12 +565,12 @@ int acc_default_case(struct acc_option *option)
static void print_help(void)
{
ACC_TST_PRT("NAME\n");
- ACC_TST_PRT(" uadk_tool benchmark: test UADK acc performance,etc\n");
+ ACC_TST_PRT(" benchmark: test UADK acc performance,etc\n");
ACC_TST_PRT("USAGE\n");
- ACC_TST_PRT(" uadk_tool benchmark [--alg aes-128-cbc] [--alg rsa-2048]\n");
- ACC_TST_PRT(" uadk_tool benchmark [--mode] [--pktlen] [--keylen] [--seconds]\n");
- ACC_TST_PRT(" uadk_tool benchmark [--multi] [--sync] [--async] [--help]\n");
- ACC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./uadk_tool benchmark xxxx\n");
+ ACC_TST_PRT(" benchmark [--alg aes-128-cbc] [--alg rsa-2048]\n");
+ ACC_TST_PRT(" benchmark [--mode] [--pktlen] [--keylen] [--seconds]\n");
+ ACC_TST_PRT(" benchmark [--multi] [--sync] [--async] [--help]\n");
+ ACC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./uadk_benchmark xxxx\n");
ACC_TST_PRT(" specify numa nodes for cpu and memory\n");
ACC_TST_PRT("DESCRIPTION\n");
ACC_TST_PRT(" [--alg aes-128-cbc ]:\n");
@@ -569,7 +585,7 @@ static void print_help(void)
ACC_TST_PRT(" [--seconds]:\n");
ACC_TST_PRT(" set the test times\n");
ACC_TST_PRT(" [--multi]:\n");
- ACC_TST_PRT(" set the number of process\n");
+ ACC_TST_PRT(" set the number of threads\n");
ACC_TST_PRT(" [--thread]:\n");
ACC_TST_PRT(" set the number of threads\n");
ACC_TST_PRT(" [--ctxnum]:\n");
@@ -580,11 +596,13 @@ static void print_help(void)
ACC_TST_PRT(" set the test openssl engine\n");
ACC_TST_PRT(" [--alglist]:\n");
ACC_TST_PRT(" list the all support alg\n");
+ ACC_TST_PRT(" [--latency]:\n");
+ ACC_TST_PRT(" test the running time of packets\n");
ACC_TST_PRT(" [--help] = usage\n");
ACC_TST_PRT("Example\n");
ACC_TST_PRT(" ./uadk_tool benchmark --alg aes-128-cbc --mode sva --opt 0 --sync\n");
- ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 4\n");
- ACC_TST_PRT("UPDATE:2022-7-18\n");
+ ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 2\n");
+ ACC_TST_PRT("UPDATE:2022-3-28\n");
}
static void print_support_alg(void)
@@ -603,20 +621,21 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
int c;
static struct option long_options[] = {
- {"alg", required_argument, 0, 2},
- {"mode", required_argument, 0, 3},
- {"opt", required_argument, 0, 4},
- {"sync", no_argument, 0, 5},
- {"async", no_argument, 0, 6},
- {"pktlen", required_argument, 0, 7},
- {"seconds", required_argument, 0, 8},
- {"thread", required_argument, 0, 9},
- {"multi", required_argument, 0, 10},
- {"ctxnum", required_argument, 0, 11},
- {"prefetch", no_argument, 0, 12},
- {"engine", required_argument, 0, 13},
- {"alglist", no_argument, 0, 14},
- {"help", no_argument, 0, 15},
+ {"alg", required_argument, 0, 1},
+ {"mode", required_argument, 0, 2},
+ {"opt", required_argument, 0, 3},
+ {"sync", no_argument, 0,4},
+ {"async", no_argument, 0,5},
+ {"pktlen", required_argument, 0, 6},
+ {"seconds", required_argument, 0, 7},
+ {"thread", required_argument, 0, 8},
+ {"multi", required_argument, 0, 9},
+ {"ctxnum", required_argument, 0, 10},
+ {"prefetch", no_argument, 0,11},
+ {"engine", required_argument, 0,12},
+ {"alglist", no_argument, 0, 13},
+ {"latency", no_argument, 0, 14},
+ {"help", no_argument, 0, 15},
{0, 0, 0, 0}
};
@@ -626,46 +645,49 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
break;
switch (c) {
- case 2:
+ case 1:
option->algtype = get_alg_type(optarg);
strcpy(option->algname, optarg);
break;
- case 3:
+ case 2:
option->modetype = get_mode_type(optarg);
break;
- case 4:
+ case 3:
option->optype = strtol(optarg, NULL, 0);
break;
- case 5:
+ case 4:
option->syncmode = SYNC_MODE;
break;
- case 6:
+ case 5:
option->syncmode = ASYNC_MODE;
break;
- case 7:
+ case 6:
option->pktlen = strtol(optarg, NULL, 0);
break;
- case 8:
+ case 7:
option->times = strtol(optarg, NULL, 0);
break;
- case 9:
+ case 8:
option->threads = strtol(optarg, NULL, 0);
break;
- case 10:
+ case 9:
option->multis = strtol(optarg, NULL, 0);
break;
- case 11:
+ case 10:
option->ctxnums = strtol(optarg, NULL, 0);
break;
- case 12:
+ case 11:
option->prefetch = 1;
break;
- case 13:
+ case 12:
strcpy(option->engine, optarg);
break;
- case 14:
+ case 13:
print_support_alg();
goto to_exit;
+ case 14:
+ option->latency = true;
+ break;
case 15:
print_help();
goto to_exit;
@@ -729,9 +751,14 @@ int acc_option_convert(struct acc_option *option)
if (!strlen(option->engine)) {
option->engine_flag = false;
return 0;
- } else if (strcmp(option->engine, "uadk")) {
+ } else if (strcmp(option->engine, "uadk_engine")) {
option->engine_flag = false;
- ACC_TST_PRT("uadk benchmark just support engine: uadk\n");
+ ACC_TST_PRT("uadk benchmark just support engine: uadk_engine\n");
+ goto param_err;
+ }
+
+ if (option->syncmode == ASYNC_MODE && option->latency) {
+ ACC_TST_PRT("uadk benchmark async mode can't test latency\n");
goto param_err;
}
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index a344fac..2c8de11 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -32,12 +32,17 @@
#define MAX_POOL_LENTH 4096
#define MAX_TRY_CNT 5000
#define SEND_USLEEP 100
+#define SEC_2_USEC 1000000
+#define HASH_ZISE 16
-typedef unsigned char u8;
+typedef unsigned long long u64;
typedef unsigned int u32;
-typedef unsigned long long u64;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
#define SCHED_SINGLE "sched_single"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define gettid() syscall(__NR_gettid)
/**
* struct acc_option - Define the test acc app option list.
@@ -47,6 +52,7 @@ typedef unsigned long long u64;
* @modetype: sva, no-sva, soft mode
* @optype: enc/dec, comp/decomp
* @prefetch: write allocated memory to prevent page faults
+ * @latency: test packet running time
*/
struct acc_option {
char algname[64];
@@ -65,6 +71,7 @@ struct acc_option {
char engine[64];
u32 engine_flag;
u32 prefetch;
+ bool latency;
};
enum acc_type {
@@ -153,6 +160,9 @@ enum test_alg {
AES_128_GCM,
AES_192_GCM,
AES_256_GCM,
+ AES_128_CBC_SHA256_HMAC,
+ AES_192_CBC_SHA256_HMAC,
+ AES_256_CBC_SHA256_HMAC,
SM4_128_CCM,
SM4_128_GCM,
SM3_ALG, // digest
@@ -177,6 +187,7 @@ extern void get_rand_data(u8 *addr, u32 size);
extern void add_recv_data(u32 cnt, u32 pkglen);
extern void add_send_complete(void);
extern u32 get_recv_time(void);
+extern void cal_avg_latency(u32 count);
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option);
int acc_default_case(struct acc_option *option);
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index ba18e6d..ffffa9b 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -603,8 +603,7 @@ fse_err:
free(ftuple);
wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.dst_len);
+ cal_avg_latency(count);
if (pdata->optype == WD_DIR_COMPRESS)
add_recv_data(count, creq.src_len);
else
@@ -700,8 +699,7 @@ fse_err:
free(ftuple);
wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.dst_len);
+ cal_avg_latency(count);
if (pdata->optype == WD_DIR_COMPRESS)
add_recv_data(count, creq.src_len);
else
@@ -872,8 +870,7 @@ static void *zip_uadk_blk_sync_run(void *arg)
}
wd_comp_free_sess(h_sess);
- //ZIP_TST_PRT("valid pool len: %u, send count BD: %u, input len: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.src_len, g_pktlen);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -936,8 +933,7 @@ static void *zip_uadk_stm_sync_run(void *arg)
}
wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.dst_len);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index 0df78cd..8d013c5 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -591,8 +591,7 @@ fse_err:
free(ftuple);
wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
+ cal_avg_latency(count);
if (pdata->optype == WCRYPTO_DEFLATE)
add_recv_data(count, opdata.in_len);
else
@@ -703,8 +702,7 @@ fse_err:
free(ftuple);
wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
+ cal_avg_latency(count);
if (pdata->optype == WCRYPTO_DEFLATE)
add_recv_data(count, opdata.in_len);
else
@@ -906,8 +904,7 @@ static void *zip_wd_blk_sync_run(void *arg)
}
wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -983,8 +980,7 @@ static void *zip_wd_stm_sync_run(void *arg)
}
wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
--
2.25.1

View File

@ -0,0 +1,551 @@
From c0466b8e9855bcb3eacd4b005a077b3c97c38e7b Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:20 +0800
Subject: [PATCH 51/85] uadk_tool: modify the clean code issue
1. update the code editing method for random number acquisition.
2. remove some remaining asset operations
3. fix a memory leak issue
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 15 ----------
uadk_tool/benchmark/hpre_wd_benchmark.c | 15 ----------
uadk_tool/benchmark/sec_soft_benchmark.c | 16 ++++++----
uadk_tool/benchmark/sec_uadk_benchmark.c | 13 ++++----
uadk_tool/benchmark/sec_wd_benchmark.c | 36 ++++++++++++++---------
uadk_tool/benchmark/uadk_benchmark.c | 19 ++++++------
uadk_tool/benchmark/zip_uadk_benchmark.c | 12 ++++----
uadk_tool/benchmark/zip_wd_benchmark.c | 12 ++++----
8 files changed, 59 insertions(+), 79 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 13e24ca..e3372fb 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1206,11 +1206,6 @@ key_release:
static void rsa_async_cb(void *req_t)
{
- //struct wd_rsa_req *req = req_t;
- //struct rsa_async_tag *tag = req->cb_param;
- //enum wd_rsa_op_type op_type = req->op_type;
- //handle_t h_sess = tag->sess;
-
return;
}
@@ -1517,11 +1512,6 @@ ag_error:
static void dh_async_cb(void *req_t)
{
- //struct wd_dh_req *req = req_t;
- //struct rsa_async_tag *tag = req->cb_param;
- //enum wd_rsa_op_type op_type = req->op_type;
- //handle_t h_sess = tag->sess;
-
return;
}
@@ -2112,11 +2102,6 @@ msg_release:
static void ecc_async_cb(void *req_t)
{
- //struct wd_ecc_req *req = req_t;
- //struct rsa_async_tag *tag = req->cb_param;
- //enum wd_rsa_op_type op_type = req->op_type;
- //handle_t h_sess = tag->sess;
-
return;
}
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c
index 231b569..2e23c95 100644
--- a/uadk_tool/benchmark/hpre_wd_benchmark.c
+++ b/uadk_tool/benchmark/hpre_wd_benchmark.c
@@ -936,11 +936,6 @@ key_release:
static void rsa_async_cb(const void *msg, void *tag)
{
- //struct wcrypto_rsa_msg *massage = msg;
- //struct rsa_async_tag *ptag = tag;
- //u32 op_type = tag->op_type;
- //void *ctx = tag->ctx;
-
return;
}
@@ -1333,11 +1328,6 @@ ctx_release:
static void dh_async_cb(const void *msg, void *tag)
{
- //struct wcrypto_dh_msg *massage = msg;
- //struct rsa_async_tag *ptag = tag;
- //u32 op_type = tag->op_type;
- //void *ctx = tag->ctx;
-
return;
}
@@ -2203,11 +2193,6 @@ msg_release:
static void ecc_async_cb(const void *msg, void *tag)
{
- //struct wcrypto_ecc_msg *massage = msg;
- //struct rsa_async_tag *ptag = tag;
- //u32 op_type = tag->op_type;
- //void *ctx = tag->ctx;
-
return;
}
diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c
index f3510b1..3a38cbd 100644
--- a/uadk_tool/benchmark/sec_soft_benchmark.c
+++ b/uadk_tool/benchmark/sec_soft_benchmark.c
@@ -428,7 +428,7 @@ static int sec_soft_cipher_jobfunc(void *args)
u32 jid = jdata->jobid;
struct bd_pool *soft_pool;
u8 *priv_iv, *priv_key;
- int ret, outl, i = 0;
+ int ret, outl, i;
EVP_CIPHER_CTX *ctx;
ASYNC_JOB *currjob;
u32 count = 0;
@@ -509,9 +509,13 @@ static int sec_soft_aead_jobfunc(void *args)
u32 jid = jdata->jobid;
struct bd_pool *soft_pool;
u8 *priv_iv, *priv_key;
- int ret, outl, i = 0;
+ int ret, outl, i;
EVP_CIPHER_CTX *ctx;
ASYNC_JOB *currjob;
+ /*
+ * these length parameters specify the default
+ * length according to the GCM/CCM algorithm
+ */
u8 faketag[16] = {0xcc};
u8 aad[13] = {0xcc};
u8 tag[12] = {0};
@@ -615,7 +619,7 @@ static int sec_soft_digest_jobfunc(void *args)
u32 ssl_size = 0;
u8 *priv_key, *src;
u32 count = 0;
- int i = 0;
+ int i;
currjob = ASYNC_get_current_job();
if (!currjob) {
@@ -821,7 +825,7 @@ static void *sec_soft_cipher_sync(void *arg)
EVP_CIPHER_CTX *ctx = NULL;
u32 count = 0;
u8 *src, *dst;
- int ret, i = 0;
+ int ret, i;
int outl = 0;
if (!evp_cipher) {
@@ -901,7 +905,7 @@ static void *sec_soft_aead_sync(void *arg)
u8 tag[12] = {0};
u32 count = 0;
u8 *src, *dst;
- int ret, i = 0;
+ int ret, i;
int outl = 0;
if (!evp_cipher) {
@@ -1006,7 +1010,7 @@ static void *sec_soft_digest_sync(void *arg)
u8 *priv_key, *src;
u32 ssl_size = 0;
u32 count = 0;
- int i = 0;
+ int i;
if (!evp_cipher && !evp_md) {
SSL_TST_PRT("Error: openssl not support!\n");
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index ff83769..16f96a2 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -62,7 +62,6 @@ static void *aead_async_cb(struct wd_aead_req *req, void *data)
static void *digest_async_cb(void *data)
{
- // struct wd_digest_req *req = (struct wd_digest_req *)data;
return NULL;
}
@@ -648,7 +647,7 @@ static void *sec_uadk_cipher_async(void *arg)
int try_cnt = 0;
handle_t h_sess;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -720,7 +719,7 @@ static void *sec_uadk_aead_async(void *arg)
handle_t h_sess;
u32 auth_size = 16;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -819,7 +818,7 @@ static void *sec_uadk_digest_async(void *arg)
int try_cnt = 0;
handle_t h_sess;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -888,7 +887,7 @@ static void *sec_uadk_cipher_sync(void *arg)
u8 *priv_iv, *priv_key;
handle_t h_sess;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -950,7 +949,7 @@ static void *sec_uadk_aead_sync(void *arg)
handle_t h_sess;
u32 auth_size = 16;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -1040,7 +1039,7 @@ static void *sec_uadk_digest_sync(void *arg)
u8 *priv_iv, *priv_key;
handle_t h_sess;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index 5dd1501..739c49e 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -62,7 +62,6 @@ static void *aead_async_cb(void *message, void *cipher_tag)
static void *digest_async_cb(void *message, void *digest_tag)
{
- // struct WCRYPTO_req *req = (struct WCRYPTO_req *)data;
return NULL;
}
@@ -598,7 +597,7 @@ static void *sec_wd_cipher_async(void *arg)
void **res_iv;
u32 count = 0;
int try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
@@ -632,7 +631,7 @@ static void *sec_wd_cipher_async(void *arg)
ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup);
if (!ctx) {
SEC_TST_PRT("wd create cipher ctx fail!\n");
- return NULL;
+ goto tag_err;
}
tag->ctx = ctx;
@@ -640,7 +639,7 @@ static void *sec_wd_cipher_async(void *arg)
if (ret) {
SEC_TST_PRT("wd cipher set key fail!\n");
wcrypto_del_cipher_ctx(ctx);
- return NULL;
+ goto tag_err;
}
if (queue->capa.priv.direction == 0)
@@ -692,6 +691,9 @@ static void *sec_wd_cipher_async(void *arg)
wcrypto_del_cipher_ctx(ctx);
+tag_err:
+ free(tag);
+
return NULL;
}
@@ -712,7 +714,7 @@ static void *sec_wd_aead_async(void *arg)
u32 count = 0;
int try_cnt = 0;
u32 authsize;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
@@ -759,7 +761,7 @@ static void *sec_wd_aead_async(void *arg)
if (ret) {
SEC_TST_PRT("wd aead set key fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto tag_err;
}
if (pdata->is_union) {
@@ -767,7 +769,7 @@ static void *sec_wd_aead_async(void *arg)
if (ret) {
SEC_TST_PRT("set akey fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto tag_err;
}
}
@@ -776,7 +778,7 @@ static void *sec_wd_aead_async(void *arg)
if (ret) {
SEC_TST_PRT("set authsize fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto tag_err;
}
if (queue->capa.priv.direction == 0) {
@@ -833,6 +835,9 @@ static void *sec_wd_aead_async(void *arg)
wcrypto_del_aead_ctx(ctx);
+tag_err:
+ free(tag);
+
return NULL;
}
@@ -850,7 +855,7 @@ static void *sec_wd_digest_async(void *arg)
void **res_out;
u32 count = 0;
int try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
@@ -883,7 +888,7 @@ static void *sec_wd_digest_async(void *arg)
ctx = wcrypto_create_digest_ctx(queue, &digest_setup);
if (!ctx) {
SEC_TST_PRT("wd create digest ctx fail!\n");
- return NULL;
+ goto tag_err;
}
tag->ctx = ctx;
@@ -893,7 +898,7 @@ static void *sec_wd_digest_async(void *arg)
if (ret) {
SEC_TST_PRT("wd digest set key fail!\n");
wcrypto_del_digest_ctx(ctx);
- return NULL;
+ goto tag_err;
}
}
@@ -939,6 +944,9 @@ static void *sec_wd_digest_async(void *arg)
wcrypto_del_digest_ctx(ctx);
+tag_err:
+ free(tag);
+
return NULL;
}
@@ -957,7 +965,7 @@ static void *sec_wd_cipher_sync(void *arg)
void **res_iv;
u32 count = 0;
int try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
@@ -1055,7 +1063,7 @@ static void *sec_wd_aead_sync(void *arg)
u32 count = 0;
int try_cnt = 0;
u32 authsize;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
@@ -1177,7 +1185,7 @@ static void *sec_wd_digest_sync(void *arg)
void **res_out;
u32 count = 0;
int try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
void *pool;
if (pdata->td_id > g_thread_num)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index 2791f84..f36cc4b 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -281,20 +281,20 @@ void get_rand_data(u8 *addr, u32 size)
{
unsigned short rand_state[3] = {
(0xae >> 16) & 0xffff, 0xae & 0xffff, 0x330e};
+ static __thread u64 rand_seed = 0x330eabcd;
+ u64 rand48 = 0;
int i;
-#if 1
// only 32bit valid, other 32bit is zero
- for (i = 0; i < size >> 3; i++)
- *((u64 *)addr + i) = nrand48(rand_state);
-#else
- // full 64bit valid
- for (i = 0; i < size >> 2; i++)
- *((u32 *)addr + i) = nrand48(rand_state);
-#endif
+ for (i = 0; i < size >> 3; i++) {
+ rand_state[0] = (u16)rand_seed;
+ rand_state[1] = (u16)(rand_seed >> 16);
+ rand48 = nrand48(rand_state);
+ *((u64 *)addr + i) = rand48;
+ rand_seed = rand48;
+ }
}
-
void cal_avg_latency(u32 count)
{
double latency;
@@ -307,7 +307,6 @@ void cal_avg_latency(u32 count)
}
/*-------------------------------------main code------------------------------------------------------*/
-
static void parse_alg_param(struct acc_option *option)
{
switch(option->algtype) {
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index ffffa9b..d74d3fb 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -535,7 +535,7 @@ static void *zip_uadk_blk_lz77_sync_run(void *arg)
u32 first_len = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -628,7 +628,7 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
u32 first_len = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -722,7 +722,7 @@ static void *zip_uadk_blk_lz77_async_run(void *arg)
u32 out_len = 0;
u32 count = 0;
u32 try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -826,7 +826,7 @@ static void *zip_uadk_blk_sync_run(void *arg)
handle_t h_sess;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -885,7 +885,7 @@ static void *zip_uadk_stm_sync_run(void *arg)
handle_t h_sess;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -950,7 +950,7 @@ static void *zip_uadk_blk_async_run(void *arg)
int try_cnt = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index 8d013c5..cbbbb5d 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -509,7 +509,7 @@ static void *zip_wd_blk_lz77_sync_run(void *arg)
u32 first_len = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -617,7 +617,7 @@ static void *zip_wd_stm_lz77_sync_run(void *arg)
u32 first_len = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -726,7 +726,7 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
u32 out_len = 0;
u32 count = 0;
u32 try_cnt = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -847,7 +847,7 @@ static void *zip_wd_blk_sync_run(void *arg)
struct wd_bd *bd_pool;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -920,7 +920,7 @@ static void *zip_wd_stm_sync_run(void *arg)
struct wd_bd *bd_pool;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
@@ -999,7 +999,7 @@ static void *zip_wd_blk_async_run(void *arg)
int try_cnt = 0;
u32 out_len = 0;
u32 count = 0;
- int ret, i = 0;
+ int ret, i;
if (pdata->td_id > g_thread_num)
return NULL;
--
2.25.1

View File

@ -0,0 +1,598 @@
From a146fb0a7d68ceb327a45bcc1f74c79084c38fbd Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Fri, 10 Nov 2023 11:52:21 +0800
Subject: [PATCH 52/85] uadk_tool - support aead algorithm decrypto perf
testing
The ciphertext and mac result are saved by a file. Can be reloaded
it as decrypto. So the AEAD ecryption passes the hard icv checking.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 354 +++++++++++++++++++----
1 file changed, 304 insertions(+), 50 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 16f96a2..36c7381 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -12,6 +12,18 @@
#define SEC_TST_PRT printf
#define MAX_IVK_LENTH 64
#define DEF_IVK_DATA 0xAA
+#define SEC_AEAD_LEN 16
+#define SEC_PERF_KEY_LEN 16
+#define SEC_MAX_MAC_LEN 64
+#define SEC_SAVE_FILE_LEN 64
+#define SEC_PERF_AUTH_SIZE 16
+
+char aead_key[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
+ "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf";
+
+char aead_aad[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
+ "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf";
+char g_save_mac[SEC_MAX_MAC_LEN];
struct uadk_bd {
u8 *src;
@@ -24,10 +36,10 @@ struct bd_pool {
struct thread_pool {
struct bd_pool *pool;
- u8 *iv;
- u8 *key;
- u8 *mac;
- u8 *hash;
+ u8 **iv;
+ u8 **key;
+ u8 **mac;
+ u8 **hash;
} g_uadk_pool;
typedef struct uadk_thread_res {
@@ -49,6 +61,70 @@ static unsigned int g_thread_num;
static unsigned int g_ctxnum;
static unsigned int g_prefetch;
static unsigned int g_pktlen;
+static unsigned int g_alg;
+static unsigned int g_algtype;
+static unsigned int g_optype;
+static unsigned int g_maclen;
+
+struct aead_alg_info {
+ int index;
+ char *name;
+ unsigned int mac_len;
+};
+
+struct aead_alg_info aead_info[] = {
+ {
+ .index = AES_128_CCM,
+ .name = "AES_128_CCM",
+ .mac_len = 16,
+ }, {
+ .index = AES_128_GCM,
+ .name = "AES_128_GCM",
+ .mac_len = 16,
+ }, {
+ .index = AES_128_CBC_SHA256_HMAC,
+ .name = "AES_128_CBC_SHA256_HMAC",
+ .mac_len = 32,
+ }, {
+ .index = SM4_128_GCM,
+ .name = "SM4_128_GCM",
+ .mac_len = 16,
+ }, {
+ .index = SM4_128_CCM,
+ .name = "SM4_128_CCM",
+ .mac_len = 16,
+ },
+};
+
+static u32 get_aead_mac_len(int algtype)
+{
+ int table_size = sizeof(aead_info) / sizeof(aead_info[0]);
+ int i;
+
+ for (i = 0; i < table_size; i++) {
+ if (algtype == aead_info[i].index)
+ return aead_info[i].mac_len;
+ }
+
+ SEC_TST_PRT("failed to get the aead mac len\n");
+
+ return -1;
+}
+
+static char *get_aead_alg_name(int algtype)
+{
+ int table_size = sizeof(aead_info) / sizeof(aead_info[0]);
+ int i;
+
+ for (i = 0; i < table_size; i++) {
+ if (algtype == aead_info[i].index)
+ return aead_info[i].name;
+ }
+
+ SEC_TST_PRT("failed to get the aead alg name\n");
+
+ return NULL;
+}
static void *cipher_async_cb(struct wd_cipher_req *req, void *data)
{
@@ -361,7 +437,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
alg = WD_DIGEST_SHA512_256;
break;
default:
- SEC_TST_PRT("Fail to set sec alg\n");
+ SEC_TST_PRT("failed to set sec alg\n");
return -EINVAL;
}
@@ -391,7 +467,7 @@ static int init_ctx_config(char *alg, int subtype, int mode)
list = wd_get_accel_list(alg);
if (!list) {
- SEC_TST_PRT("Fail to get %s device\n", alg);
+ SEC_TST_PRT("failed to get %s device\n", alg);
return -ENODEV;
}
memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
@@ -417,11 +493,11 @@ static int init_ctx_config(char *alg, int subtype, int mode)
g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_digest_poll_ctx);
break;
default:
- SEC_TST_PRT("Fail to parse alg subtype!\n");
+ SEC_TST_PRT("failed to parse alg subtype!\n");
return -EINVAL;
}
if (!g_sched) {
- SEC_TST_PRT("Fail to alloc sched!\n");
+ SEC_TST_PRT("failed to alloc sched!\n");
goto out;
}
@@ -437,7 +513,7 @@ static int init_ctx_config(char *alg, int subtype, int mode)
param.end = g_ctxnum - 1;
ret = wd_sched_rr_instance(g_sched, &param);
if (ret) {
- SEC_TST_PRT("Fail to fill sched data!\n");
+ SEC_TST_PRT("failed to fill sched data!\n");
goto out;
}
@@ -454,7 +530,7 @@ static int init_ctx_config(char *alg, int subtype, int mode)
break;
}
if (ret) {
- SEC_TST_PRT("Fail to cipher ctx!\n");
+ SEC_TST_PRT("failed to cipher ctx!\n");
goto out;
}
@@ -484,7 +560,7 @@ static void uninit_ctx_config(int subtype)
wd_digest_uninit();
break;
default:
- SEC_TST_PRT("Fail to parse alg subtype on uninit!\n");
+ SEC_TST_PRT("failed to parse alg subtype on uninit!\n");
return;
}
@@ -494,23 +570,172 @@ static void uninit_ctx_config(int subtype)
wd_sched_rr_release(g_sched);
}
+static void get_aead_data(u8 *addr, u32 size)
+{
+ memset(addr, 0, size);
+ memcpy(addr, aead_aad, SEC_AEAD_LEN);
+}
+
+static void save_aead_dst_data(u8 *addr, u32 size)
+{
+ char file_name[SEC_SAVE_FILE_LEN] = {0};
+ char *alg_name;
+ FILE *fp;
+
+ alg_name = get_aead_alg_name(g_algtype);
+ if (!alg_name) {
+ SEC_TST_PRT("failed to get the aead alg name!\n");
+ return;
+ }
+
+ snprintf(file_name, SEC_SAVE_FILE_LEN, "ctext_%s_%u", alg_name, g_pktlen);
+
+ fp = fopen(file_name, "w");
+ if (!fp) {
+ SEC_TST_PRT("failed to open the ctext file!\n");
+ return;
+ }
+
+ memcpy(addr + size, g_uadk_pool.mac[0], SEC_PERF_AUTH_SIZE);
+
+ for (int i = 0; i < size + SEC_PERF_AUTH_SIZE; i++)
+ fputc((char)addr[i], fp);
+
+ fclose(fp);
+}
+
+static void read_aead_dst_data(u8 *addr, u32 len)
+{
+ char file_name[SEC_SAVE_FILE_LEN] = {0};
+ char *alg_name;
+ FILE *fp;
+ int size;
+
+ alg_name = get_aead_alg_name(g_algtype);
+ if (!alg_name) {
+ SEC_TST_PRT("failed to get the aead alg name!\n");
+ return;
+ }
+
+ snprintf(file_name, SEC_SAVE_FILE_LEN, "ctext_%s_%u", alg_name, g_pktlen);
+
+ fp = fopen(file_name, "r");
+ if (!fp) {
+ SEC_TST_PRT("failed to open the ctext file!\n");
+ return;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ size = ftell(fp);
+
+ rewind(fp);
+ size = fread(addr, 1, size, fp);
+ addr[size] = '\0';
+
+ memcpy(g_save_mac, (char *)addr + len, SEC_MAX_MAC_LEN);
+
+ fclose(fp);
+}
+
+static int init_ivkey_source(void)
+{
+ int i, j, k, m, idx;
+
+ g_uadk_pool.iv = malloc(sizeof(char *) * g_thread_num);
+ for (i = 0; i < g_thread_num; i++) {
+ g_uadk_pool.iv[i] = calloc(MAX_IVK_LENTH, sizeof(char));
+ if (!g_uadk_pool.iv[i])
+ goto free_iv;
+ }
+
+ g_uadk_pool.key = malloc(sizeof(char *) * g_thread_num);
+ for (j = 0; j < g_thread_num; j++) {
+ g_uadk_pool.key[j] = calloc(MAX_IVK_LENTH, sizeof(char));
+ if (!g_uadk_pool.key[j])
+ goto free_key;
+
+ memcpy(g_uadk_pool.key[j], aead_key, SEC_PERF_KEY_LEN);
+ }
+
+ g_uadk_pool.mac = malloc(sizeof(char *) * g_thread_num);
+ for (k = 0; k < g_thread_num; k++) {
+ g_uadk_pool.mac[k] = calloc(MAX_IVK_LENTH, sizeof(char));
+ if (!g_uadk_pool.mac[k])
+ goto free_mac;
+ }
+
+ g_uadk_pool.hash = malloc(sizeof(char *) * g_thread_num);
+ for (m = 0; m < g_thread_num; m++) {
+ g_uadk_pool.hash[m] = calloc(MAX_IVK_LENTH, sizeof(char));
+ if (!g_uadk_pool.hash[m])
+ goto free_hash;
+
+ memcpy(g_uadk_pool.hash[m], aead_key, SEC_PERF_KEY_LEN);
+ }
+
+ return 0;
+
+free_hash:
+ for (idx = m - 1; idx >= 0; idx--)
+ free(g_uadk_pool.hash[idx]);
+ free(g_uadk_pool.hash);
+
+free_mac:
+ for (idx = k - 1; idx >= 0; idx--)
+ free(g_uadk_pool.mac[idx]);
+
+ free(g_uadk_pool.mac);
+
+free_key:
+ for (idx = j - 1; idx >= 0; idx--)
+ free(g_uadk_pool.key[idx]);
+
+ free(g_uadk_pool.key);
+free_iv:
+ for (idx = i - 1; idx >= 0; idx--)
+ free(g_uadk_pool.iv[idx]);
+
+ free(g_uadk_pool.iv);
+
+ return -1;
+}
+
+static void free_ivkey_source(void)
+{
+ int i;
+
+ for (i = 0; i < g_thread_num; i++) {
+ free(g_uadk_pool.hash[i]);
+ free(g_uadk_pool.mac[i]);
+ free(g_uadk_pool.key[i]);
+ free(g_uadk_pool.iv[i]);
+ }
+
+ free(g_uadk_pool.hash);
+ free(g_uadk_pool.mac);
+ free(g_uadk_pool.key);
+ free(g_uadk_pool.iv);
+}
+
static int init_uadk_bd_pool(void)
{
unsigned long step;
int i, j;
+ int ret;
// make the block not align to 4K
step = sizeof(char) * g_pktlen * 2;
- g_uadk_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
- g_uadk_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
- g_uadk_pool.mac = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
- g_uadk_pool.hash = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+ ret = init_ivkey_source();
+ if (ret) {
+ SEC_TST_PRT("init uadk ivkey resource failed!\n");
+ return -ENOMEM;
+ }
g_uadk_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
if (!g_uadk_pool.pool) {
SEC_TST_PRT("init uadk pool alloc thread failed!\n");
- return -ENOMEM;
+ goto free_ivkey;
} else {
for (i = 0; i < g_thread_num; i++) {
g_uadk_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
@@ -527,10 +752,23 @@ static int init_uadk_bd_pool(void)
if (!g_uadk_pool.pool[i].bds[j].dst)
goto malloc_error3;
- get_rand_data(g_uadk_pool.pool[i].bds[j].src, g_pktlen);
- if (g_prefetch)
- get_rand_data(g_uadk_pool.pool[i].bds[j].dst, g_pktlen);
+ if (g_alg != AEAD_TYPE) {
+ get_rand_data(g_uadk_pool.pool[i].bds[j].src, g_pktlen);
+ if (g_prefetch)
+ get_rand_data(g_uadk_pool.pool[i].bds[j].dst,
+ g_pktlen);
+ } else {
+ if (!g_optype)
+ get_aead_data(g_uadk_pool.pool[i].bds[j].src,
+ g_pktlen + SEC_AEAD_LEN);
+ else
+ read_aead_dst_data(g_uadk_pool.pool[i].bds[j].src,
+ g_pktlen + SEC_AEAD_LEN);
+ }
}
+
+ if (g_alg == AEAD_TYPE && g_optype)
+ memcpy(g_uadk_pool.mac[i], g_save_mac, SEC_MAX_MAC_LEN);
}
}
@@ -555,10 +793,8 @@ malloc_error1:
free(g_uadk_pool.pool);
g_uadk_pool.pool = NULL;
- free(g_uadk_pool.iv);
- free(g_uadk_pool.key);
- free(g_uadk_pool.mac);
- free(g_uadk_pool.hash);
+free_ivkey:
+ free_ivkey_source();
SEC_TST_PRT("init uadk bd pool alloc failed!\n");
return -ENOMEM;
@@ -568,6 +804,11 @@ static void free_uadk_bd_pool(void)
{
int i, j;
+ /* save aad + ctext + mac */
+ if (g_alg == AEAD_TYPE && !g_optype)
+ save_aead_dst_data(g_uadk_pool.pool[0].bds[0].dst,
+ g_pktlen + SEC_AEAD_LEN);
+
for (i = 0; i < g_thread_num; i++) {
if (g_uadk_pool.pool[i].bds) {
for (j = 0; j < MAX_POOL_LENTH; j++) {
@@ -581,9 +822,7 @@ static void free_uadk_bd_pool(void)
free(g_uadk_pool.pool);
g_uadk_pool.pool = NULL;
- free(g_uadk_pool.iv);
- free(g_uadk_pool.key);
- free(g_uadk_pool.mac);
+ free_ivkey_source();
}
/*-------------------------------uadk benchmark main code-------------------------------------*/
@@ -653,8 +892,8 @@ static void *sec_uadk_cipher_async(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -713,11 +952,11 @@ static void *sec_uadk_aead_async(void *arg)
thread_data *pdata = (thread_data *)arg;
struct wd_aead_sess_setup aead_setup = {0};
u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
+ u32 auth_size = SEC_PERF_AUTH_SIZE;
struct wd_aead_req areq;
struct bd_pool *uadk_pool;
int try_cnt = 0;
handle_t h_sess;
- u32 auth_size = 16;
u32 count = 0;
int ret, i;
@@ -725,10 +964,10 @@ static void *sec_uadk_aead_async(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
- priv_mac = &g_uadk_pool.mac[pdata->td_id];
- priv_hash = &g_uadk_pool.hash[pdata->td_id];
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
+ priv_mac = g_uadk_pool.mac[pdata->td_id];
+ priv_hash = g_uadk_pool.hash[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -768,7 +1007,7 @@ static void *sec_uadk_aead_async(void *arg)
areq.mac = priv_mac;
areq.iv_bytes = pdata->ivsize;
areq.mac_bytes = auth_size;
- areq.assoc_bytes = 16;
+ areq.assoc_bytes = SEC_AEAD_LEN;
areq.in_bytes = g_pktlen;
if (pdata->is_union)
areq.mac_bytes = 32;
@@ -824,8 +1063,8 @@ static void *sec_uadk_digest_async(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -893,8 +1132,8 @@ static void *sec_uadk_cipher_sync(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -944,10 +1183,10 @@ static void *sec_uadk_aead_sync(void *arg)
thread_data *pdata = (thread_data *)arg;
struct wd_aead_sess_setup aead_setup = {0};
u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
+ u32 auth_size = SEC_PERF_AUTH_SIZE;
struct wd_aead_req areq;
struct bd_pool *uadk_pool;
handle_t h_sess;
- u32 auth_size = 16;
u32 count = 0;
int ret, i;
@@ -955,10 +1194,11 @@ static void *sec_uadk_aead_sync(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
- priv_mac = &g_uadk_pool.mac[pdata->td_id];
- priv_hash = &g_uadk_pool.hash[pdata->td_id];
+
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
+ priv_mac = g_uadk_pool.mac[pdata->td_id];
+ priv_hash = g_uadk_pool.hash[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -996,13 +1236,10 @@ static void *sec_uadk_aead_sync(void *arg)
areq.op_type = pdata->optype;
areq.iv = priv_iv; // aead IV need update with param
areq.mac = priv_mac;
- areq.mac_bytes = 16;
areq.iv_bytes = pdata->ivsize;
- areq.assoc_bytes = 16;
+ areq.assoc_bytes = SEC_AEAD_LEN;
areq.in_bytes = g_pktlen;
- areq.mac_bytes = auth_size;
- if (pdata->is_union)
- areq.mac_bytes = 32;
+ areq.mac_bytes = g_maclen;
if (areq.op_type) // decrypto
areq.out_bytes = g_pktlen + 16; // aadsize = 16;
else
@@ -1016,6 +1253,7 @@ static void *sec_uadk_aead_sync(void *arg)
areq.src = uadk_pool->bds[i].src;
areq.dst = uadk_pool->bds[i].dst;
count++;
+
ret = wd_do_aead_sync(h_sess, &areq);
if (ret || areq.state)
break;
@@ -1045,8 +1283,8 @@ static void *sec_uadk_digest_sync(void *arg)
return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
- priv_iv = &g_uadk_pool.iv[pdata->td_id];
- priv_key = &g_uadk_pool.key[pdata->td_id];
+ priv_iv = g_uadk_pool.iv[pdata->td_id];
+ priv_key = g_uadk_pool.key[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -1119,7 +1357,9 @@ int sec_uadk_sync_threads(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].alg = threads_option.alg;
+ threads_args[i].dalg = threads_option.dalg;
threads_args[i].mode = threads_option.mode;
+ threads_args[i].is_union = threads_option.is_union;
threads_args[i].keysize = threads_option.keysize;
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
@@ -1185,7 +1425,9 @@ int sec_uadk_async_threads(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].alg = threads_option.alg;
+ threads_args[i].dalg = threads_option.dalg;
threads_args[i].mode = threads_option.mode;
+ threads_args[i].is_union = threads_option.is_union;
threads_args[i].keysize = threads_option.keysize;
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
@@ -1227,6 +1469,18 @@ int sec_uadk_benchmark(struct acc_option *options)
g_pktlen = options->pktlen;
g_ctxnum = options->ctxnums;
g_prefetch = options->prefetch;
+ g_alg = options->subtype;
+ g_optype = options->optype;
+ g_algtype = options->algtype;
+
+ if (g_alg == AEAD_TYPE) {
+ g_maclen = get_aead_mac_len(g_algtype);
+ if (g_maclen < 0) {
+ SEC_TST_PRT("SEC algtype error: %u\n", g_algtype);
+ return -EINVAL;
+ }
+ }
+
if (options->optype > WD_CIPHER_DECRYPTION) {
SEC_TST_PRT("SEC optype error: %u\n", options->optype);
return -EINVAL;
--
2.25.1

View File

@ -0,0 +1,452 @@
From 9a0b4eba99f8390bcfe6d594afb159dac4c53355 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:22 +0800
Subject: [PATCH 53/85] uadk_tool: fix hpre test code issues
1.Change the ECC_CURVE_ID to 2 for secp256k1 test.
2.Increase the block size for the nosva test.
3.Modify the sample data of ecdsa 256 verify.
4.Queues on multiple devices can be obtained.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_protocol_data.h | 77 ++++++++++++++--
uadk_tool/benchmark/hpre_uadk_benchmark.c | 107 ++++++++++++++++++----
uadk_tool/benchmark/hpre_wd_benchmark.c | 80 ++++++++++------
3 files changed, 210 insertions(+), 54 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_protocol_data.h b/uadk_tool/benchmark/hpre_protocol_data.h
index 9c92138..7bdb942 100644
--- a/uadk_tool/benchmark/hpre_protocol_data.h
+++ b/uadk_tool/benchmark/hpre_protocol_data.h
@@ -1292,8 +1292,9 @@ static unsigned char ecc_except_kinv_secp256k1[] = {
};
static unsigned char ecc_except_e_secp256k1[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04
+ 0x3a, 0x10, 0x3a, 0x4e, 0x57, 0x29, 0xad, 0x68, 0xc0, 0x2a, 0x67, 0x8a,
+ 0xe3, 0x9a, 0xcc, 0xfb, 0xc0, 0xae, 0x20, 0x80, 0x96, 0x43, 0x74, 0x01,
+ 0xb7, 0xce, 0xab, 0x63, 0xcc, 0xa0, 0x62, 0x2f
};
static unsigned char ecc_cp_sign_secp256k1[] = {
@@ -1649,19 +1650,75 @@ static unsigned char sm2_ciphertext_l[609] = {
static unsigned char sm2_pubkey[] = {
0x04,
- 0x09, 0xf9, 0xdf, 0x31, 0x1e, 0x54, 0x21, 0xa1, 0x50, 0xdd, 0x7d, 0x16, 0x1e, 0x4b, 0xc5, 0xc6,
- 0x72, 0x17, 0x9f, 0xad, 0x18, 0x33, 0xfc, 0x07, 0x6b, 0xb0, 0x8f, 0xf3, 0x56, 0xf3, 0x50, 0x20,
- 0xcc, 0xea, 0x49, 0x0c, 0xe2, 0x67, 0x75, 0xa5, 0x2d, 0xc6, 0xea, 0x71, 0x8c, 0xc1, 0xaa, 0x60,
- 0x0a, 0xed, 0x05, 0xfb, 0xf3, 0x5e, 0x08, 0x4a, 0x66, 0x32, 0xf6, 0x07, 0x2d, 0xa9, 0xad, 0x13
+ 0x09, 0xf9, 0xdf, 0x31, 0x1e, 0x54, 0x21, 0xa1, 0x50, 0xdd, 0x7d, 0x16,
+ 0x1e, 0x4b, 0xc5, 0xc6, 0x72, 0x17, 0x9f, 0xad, 0x18, 0x33, 0xfc, 0x07,
+ 0x6b, 0xb0, 0x8f, 0xf3, 0x56, 0xf3, 0x50, 0x20,
+ 0xcc, 0xea, 0x49, 0x0c, 0xe2, 0x67, 0x75, 0xa5, 0x2d, 0xc6, 0xea, 0x71,
+ 0x8c, 0xc1, 0xaa, 0x60, 0x0a, 0xed, 0x05, 0xfb, 0xf3, 0x5e, 0x08, 0x4a,
+ 0x66, 0x32, 0xf6, 0x07, 0x2d, 0xa9, 0xad, 0x13
};
static unsigned char sm2_priv[] = {
- 0x39, 0x45, 0x20, 0x8f, 0x7b, 0x21, 0x44, 0xb1, 0x3f, 0x36, 0xe3, 0x8a, 0xc6, 0xd3, 0x9f, 0x95,
- 0x88, 0x93, 0x93, 0x69, 0x28, 0x60, 0xb5, 0x1a, 0x42, 0xfb, 0x81, 0xef, 0x4d, 0xf7, 0xc5, 0xb8
+ 0x39, 0x45, 0x20, 0x8f, 0x7b, 0x21, 0x44, 0xb1, 0x3f, 0x36, 0xe3, 0x8a,
+ 0xc6, 0xd3, 0x9f, 0x95, 0x88, 0x93, 0x93, 0x69, 0x28, 0x60, 0xb5, 0x1a,
+ 0x42, 0xfb, 0x81, 0xef, 0x4d, 0xf7, 0xc5, 0xb8
};
static unsigned char sm2_digest[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
+ 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74
+};
+
+static char ecdsa_verf_p_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+};
+
+static char ecdsa_verf_a_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC
+};
+
+static char ecdsa_verf_b_secp256k1[] = {
+ 0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55,
+ 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
+ 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B
+};
+
+static char ecdsa_verf_g_secp256k1[] = {
+ 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5,
+ 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
+ 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
+ 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, 0x4A,
+ 0x7C, 0x0F, 0x9E, 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
+ 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5
+};
+
+static char ecdsa_verf_n_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
+ 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
+};
+
+static char ecdsa_verf_sign_secp256k1[] = {
+ 0x31, 0x28, 0x18, 0x0d, 0x19, 0x7c, 0xd1, 0xa5, 0xcb, 0x32, 0x95, 0x98,
+ 0xb6, 0x5f, 0x8c, 0xb8, 0xdf, 0x0b, 0x4e, 0xf3, 0xef, 0x5e, 0x22, 0x79,
+ 0x7f, 0xe0, 0xdb, 0xf0, 0x33, 0x59, 0x67, 0x01,
+ 0xeb, 0xd1, 0xca, 0x09, 0x55, 0x6a, 0xbe, 0xd5, 0x32, 0x34, 0xfb, 0xb2,
+ 0x4f, 0xfc, 0x7d, 0xa3, 0xd1, 0x6d, 0xc9, 0x65, 0x30, 0xca, 0x76, 0x3b,
+ 0x09, 0xd5, 0xef, 0x6a, 0x65, 0x05, 0x0d, 0x23
+};
+
+static char ecdh_verf_pubkey_secp256k1[] = {
+ 0x04,
+ 0xab, 0xd2, 0xd9, 0xec, 0x43, 0x60, 0xcc, 0x5b, 0x23, 0x5a, 0x80, 0x74,
+ 0x2e, 0xbc, 0xb8, 0x36, 0x27, 0xe7, 0xb5, 0x4f, 0x72, 0xc3, 0x4a, 0x05,
+ 0xe9, 0x70, 0x5a, 0x12, 0x8f, 0xab, 0x95, 0x7c,
+ 0x6b, 0xf1, 0x84, 0x92, 0x46, 0x7b, 0x81, 0x4e, 0x28, 0x83, 0x25, 0xfb,
+ 0x1f, 0x60, 0xe9, 0x98, 0xb6, 0x9f, 0xa0, 0xf4, 0x50, 0x3f, 0xa4, 0x1d,
+ 0x4a, 0x4d, 0x87, 0xb8, 0xe6, 0xe4, 0x81, 0xd4
};
#endif
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index e3372fb..ffa1a85 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -346,30 +346,40 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options
static int init_hpre_ctx_config(char *alg, int subtype, int mode)
{
- struct uacce_dev_list *list;
struct sched_params param;
- int i, max_node;
+ struct uacce_dev *dev;
+ int max_node;
int ret = 0;
+ int i = 0;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -EINVAL;
- list = wd_get_accel_list(alg);
- if (!list) {
- HPRE_TST_PRT("failed to get %s device\n", alg);
- return -ENODEV;
- }
memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
g_ctx_cfg.ctx_num = g_ctxnum;
g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
if (!g_ctx_cfg.ctxs)
return -ENOMEM;
- for (i = 0; i < g_ctxnum; i++) {
- g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev);
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
- g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ HPRE_TST_PRT("failed to get %s device\n", alg);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
}
switch(subtype) {
@@ -395,12 +405,8 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- /* If there is no numa, we defualt config to zero */
- if (list->dev->numa_id < 0)
- list->dev->numa_id = 0;
-
g_sched->name = SCHED_SINGLE;
- param.numa_id = list->dev->numa_id;
+ param.numa_id = 0;
param.type = 0;
param.mode = mode;
param.begin = 0;
@@ -434,10 +440,11 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- wd_free_list_accels(list);
-
return 0;
out:
+ for (i = i - 1; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
free(g_ctx_cfg.ctxs);
wd_sched_rr_release(g_sched);
@@ -1964,6 +1971,38 @@ del_ecc_out:
return ret;
}
+static void fill_ecc_param_data(struct wd_ecc_curve *ecc_pa,
+ struct hpre_ecc_setup *ecc_set,
+ u32 key_bits)
+{
+ u32 key_size = (key_bits + 7) / 8;
+
+ ecc_pa->a.data = ecdsa_verf_a_secp256k1;
+ ecc_pa->b.data = ecdsa_verf_b_secp256k1;
+ ecc_pa->p.data = ecdsa_verf_p_secp256k1;
+ ecc_pa->n.data = ecdsa_verf_n_secp256k1;
+ ecc_pa->g.x.data = ecdsa_verf_g_secp256k1;
+ ecc_pa->g.y.data = ecdsa_verf_g_secp256k1 + key_size;
+
+ ecc_set->sign = ecdsa_verf_sign_secp256k1;
+ ecc_set->sign_size = sizeof(ecdsa_verf_sign_secp256k1);
+ ecc_set->pub_key = ecdh_verf_pubkey_secp256k1;
+ ecc_set->pub_key_size = sizeof(ecdh_verf_pubkey_secp256k1);
+
+ ecc_pa->a.bsize = key_size;
+ ecc_pa->a.dsize = key_size;
+ ecc_pa->b.bsize = key_size;
+ ecc_pa->b.dsize = key_size;
+ ecc_pa->p.bsize = key_size;
+ ecc_pa->p.dsize = key_size;
+ ecc_pa->n.bsize = key_size;
+ ecc_pa->n.dsize = key_size;
+ ecc_pa->g.x.bsize = key_size;
+ ecc_pa->g.x.dsize = key_size;
+ ecc_pa->g.y.bsize = key_size;
+ ecc_pa->g.y.dsize = key_size;
+}
+
static void *ecc_uadk_sync_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
@@ -1971,6 +2010,8 @@ static void *ecc_uadk_sync_run(void *arg)
u32 subtype = pdata->subtype;
struct wd_ecc_sess_setup sess_setup;
struct hpre_ecc_setup setup;
+ struct wd_ecc_curve_cfg cfg;
+ struct wd_ecc_curve cv;
struct wd_ecc_curve param;
struct wd_ecc_key *ecc_key;
struct wd_ecc_point pbk;
@@ -2015,6 +2056,12 @@ static void *ecc_uadk_sync_run(void *arg)
case ECDSA_TYPE:
sess_setup.alg = "ecdsa";
break;
+ case X448_TYPE:
+ sess_setup.alg = "x448";
+ break;
+ case X25519_TYPE:
+ sess_setup.alg = "x25519";
+ break;
}
// set def setting;
@@ -2025,6 +2072,14 @@ static void *ecc_uadk_sync_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_param_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WD_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ sess_setup.cv = cfg;
+ }
+
h_sess = wd_ecc_alloc_sess(&sess_setup);
if (!h_sess)
goto msg_release;
@@ -2113,6 +2168,8 @@ static void *ecc_uadk_async_run(void *arg)
struct wd_ecc_sess_setup sess_setup;
struct rsa_async_tag *tag;
struct hpre_ecc_setup setup;
+ struct wd_ecc_curve_cfg cfg;
+ struct wd_ecc_curve cv;
struct wd_ecc_curve param;
struct wd_ecc_key *ecc_key;
struct wd_ecc_point pbk;
@@ -2158,6 +2215,12 @@ static void *ecc_uadk_async_run(void *arg)
case ECDSA_TYPE:
sess_setup.alg = "ecdsa";
break;
+ case X448_TYPE:
+ sess_setup.alg = "x448";
+ break;
+ case X25519_TYPE:
+ sess_setup.alg = "x25519";
+ break;
}
// set def setting;
@@ -2168,6 +2231,14 @@ static void *ecc_uadk_async_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_param_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WD_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ sess_setup.cv = cfg;
+ }
+
h_sess = wd_ecc_alloc_sess(&sess_setup);
if (!h_sess)
goto msg_release;
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c
index 2e23c95..67d57c6 100644
--- a/uadk_tool/benchmark/hpre_wd_benchmark.c
+++ b/uadk_tool/benchmark/hpre_wd_benchmark.c
@@ -12,7 +12,7 @@
#include "v1/wd_bmm.h"
#include "v1/wd_util.h"
-#define ECC_CURVE_ID 0x3 /* def set secp256k1 */
+#define ECC_CURVE_ID 0x2 /* def set secp256k1 */
#define HPRE_TST_PRT printf
#define ERR_OPTYPE 0xFF
#define SM2_DG_SZ 1024
@@ -403,33 +403,9 @@ static int hpre_wd_get_block(u32 algtype)
case DH_4096:
block_size = 8192;
break;
- case ECDH_256:
- block_size = 256;
- break;
- case ECDH_384:
- block_size = 384;
- break;
- case ECDH_521:
- block_size = 576;
- break;
- case ECDSA_256:
- block_size = 256;
- break;
- case ECDSA_384:
- block_size = 384;
- break;
- case ECDSA_521:
+ default:
block_size = 576;
break;
- case SM2_ALG:
- block_size = 4352;
- break;
- case X25519_ALG:
- block_size = 256;
- break;
- case X448_ALG:
- block_size = 384;
- break;
}
return block_size;
@@ -1759,6 +1735,38 @@ static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup,
return 0;
}
+static void fill_ecc_cv_data(struct wcrypto_ecc_curve *cv,
+ struct hpre_ecc_setup *ecc_setup,
+ u32 key_bits)
+{
+ u32 key_size = (key_bits + 7) / 8;
+
+ cv->a.data = ecdsa_verf_a_secp256k1;
+ cv->b.data = ecdsa_verf_b_secp256k1;
+ cv->p.data = ecdsa_verf_p_secp256k1;
+ cv->n.data = ecdsa_verf_n_secp256k1;
+ cv->g.x.data = ecdsa_verf_g_secp256k1;
+ cv->g.y.data = ecdsa_verf_g_secp256k1 + key_size;
+
+ ecc_setup->sign = ecdsa_verf_sign_secp256k1;
+ ecc_setup->sign_size = sizeof(ecdsa_verf_sign_secp256k1);
+ ecc_setup->pub_key = ecdh_verf_pubkey_secp256k1;
+ ecc_setup->pub_key_size = sizeof(ecdh_verf_pubkey_secp256k1);
+
+ cv->a.bsize = key_size;
+ cv->a.dsize = key_size;
+ cv->b.bsize = key_size;
+ cv->b.dsize = key_size;
+ cv->p.bsize = key_size;
+ cv->p.dsize = key_size;
+ cv->n.bsize = key_size;
+ cv->n.dsize = key_size;
+ cv->g.x.bsize = key_size;
+ cv->g.x.dsize = key_size;
+ cv->g.y.bsize = key_size;
+ cv->g.y.dsize = key_size;
+}
+
static int ecdsa_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata,
struct wcrypto_ecc_key *ecc_key, struct hpre_ecc_setup *setup,
thread_data *pdata)
@@ -2060,6 +2068,8 @@ static void *ecc_wd_sync_run(void *arg)
struct wcrypto_ecc_ctx_setup ctx_setup;
struct wcrypto_ecc_op_data opdata;
struct wcrypto_ecc_curve param;
+ struct wcrypto_ecc_curve_cfg cfg;
+ struct wcrypto_ecc_curve cv;
struct hpre_ecc_setup setup;
struct wcrypto_ecc_key *ecc_key;
struct wcrypto_ecc_point pbk;
@@ -2114,6 +2124,14 @@ static void *ecc_wd_sync_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_cv_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WCRYPTO_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ ctx_setup.cv = cfg;
+ }
+
ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup);
if (!ctx)
goto msg_release;
@@ -2208,6 +2226,8 @@ static void *ecc_wd_async_run(void *arg)
struct wcrypto_ecc_ctx_setup ctx_setup;
struct wcrypto_ecc_op_data opdata;
struct wcrypto_ecc_curve param;
+ struct wcrypto_ecc_curve_cfg cfg;
+ struct wcrypto_ecc_curve cv;
struct hpre_ecc_setup setup;
struct wcrypto_ecc_key *ecc_key;
struct wcrypto_ecc_point pbk;
@@ -2263,6 +2283,14 @@ static void *ecc_wd_async_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_cv_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WCRYPTO_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ ctx_setup.cv = cfg;
+ }
+
ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup);
if (!ctx)
goto msg_release;
--
2.25.1

View File

@ -0,0 +1,101 @@
From d15cd3c19573154337cd5ab974ebc1e6891d6fee Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Fri, 10 Nov 2023 11:52:23 +0800
Subject: [PATCH 54/85] uadk_tool - support dual sec engine device testing
Support dual sec engine device perfmance testing. Users
can configure half of the number of queues for each device.
one thread configures one queue.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 44 ++++++++++++++----------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 36c7381..aed1b26 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -456,30 +456,38 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
static int init_ctx_config(char *alg, int subtype, int mode)
{
- struct uacce_dev_list *list;
struct sched_params param;
- int i, max_node;
- int ret = 0;
+ struct uacce_dev *dev = NULL;
+ int ret, max_node, i;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -EINVAL;
- list = wd_get_accel_list(alg);
- if (!list) {
- SEC_TST_PRT("failed to get %s device\n", alg);
- return -ENODEV;
- }
memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
g_ctx_cfg.ctx_num = g_ctxnum;
g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
if (!g_ctx_cfg.ctxs)
return -ENOMEM;
- for (i = 0; i < g_ctxnum; i++) {
- g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev);
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
- g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ i = 0;
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ SEC_TST_PRT("failed to get %s device\n", alg);
+ goto out;
+ }
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
}
switch(subtype) {
@@ -501,12 +509,8 @@ static int init_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- /* If there is no numa, we defualt config to zero */
- if (list->dev->numa_id < 0)
- list->dev->numa_id = 0;
-
g_sched->name = SCHED_SINGLE;
- param.numa_id = list->dev->numa_id;
+ param.numa_id = 0;
param.type = 0;
param.mode = mode;
param.begin = 0;
@@ -534,10 +538,12 @@ static int init_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- wd_free_list_accels(list);
-
return 0;
+
out:
+ for (i--; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
free(g_ctx_cfg.ctxs);
wd_sched_rr_release(g_sched);
--
2.25.1

View File

@ -0,0 +1,442 @@
From e018308c64d35b73779298ffb361031a30a9426e Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:24 +0800
Subject: [PATCH 55/85] uadk_tool: Support performance test for TRNG.
Support performance test for TRNG.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/Makefile.am | 1 +
uadk_tool/benchmark/trng_wd_benchmark.c | 324 ++++++++++++++++++++++++
uadk_tool/benchmark/trng_wd_benchmark.h | 7 +
uadk_tool/benchmark/uadk_benchmark.c | 14 +
uadk_tool/benchmark/uadk_benchmark.h | 2 +
5 files changed, 348 insertions(+)
create mode 100644 uadk_tool/benchmark/trng_wd_benchmark.c
create mode 100644 uadk_tool/benchmark/trng_wd_benchmark.h
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 62372d8..6b787f9 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -15,6 +15,7 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \
benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \
benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \
benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \
+ benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \
test/uadk_test.c test/uadk_test.h \
test/test_sec.c test/test_sec.h test/sec_template_tv.h
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c
new file mode 100644
index 0000000..64942f0
--- /dev/null
+++ b/uadk_tool/benchmark/trng_wd_benchmark.c
@@ -0,0 +1,324 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#include <numa.h>
+#include "uadk_benchmark.h"
+
+#include "trng_wd_benchmark.h"
+#include "v1/wd.h"
+#include "v1/wd_rng.h"
+
+struct thread_bd_res {
+ struct wd_queue *queue;
+ void *out;
+ __u32 in_bytes;
+};
+
+struct thread_queue_res {
+ struct thread_bd_res *bd_res;
+};
+
+struct wd_thread_res {
+ u32 td_id;
+ u32 pollid;
+};
+
+struct trng_async_tag {
+ void *ctx;
+ int optype;
+};
+
+static unsigned int g_thread_num;
+static struct thread_queue_res g_thread_queue;
+
+static int init_trng_wd_queue(struct acc_option *options)
+{
+ int i, ret;
+
+ g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res));
+ if (!g_thread_queue.bd_res) {
+ printf("failed to malloc thread res memory!\n");
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < g_thread_num; i++) {
+ g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
+ if (!g_thread_queue.bd_res[i].queue) {
+ ret = -ENOMEM;
+ goto free_mem;
+ }
+
+ g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
+ /* nodemask need to be clean */
+ g_thread_queue.bd_res[i].queue->node_mask = 0x0;
+ memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE);
+
+ g_thread_queue.bd_res[i].in_bytes = options->pktlen;
+ g_thread_queue.bd_res[i].out = malloc(options->pktlen);
+ if (!g_thread_queue.bd_res[i].queue) {
+ free(g_thread_queue.bd_res[i].queue);
+ ret = -ENOMEM;
+ goto free_mem;
+ }
+
+ ret = wd_request_queue(g_thread_queue.bd_res[i].queue);
+ if (ret) {
+ printf("failed to request queue %d, ret = %d!\n", i, ret);
+ free(g_thread_queue.bd_res[i].out);
+ free(g_thread_queue.bd_res[i].queue);
+ goto free_mem;
+ }
+ }
+
+ return 0;
+
+free_mem:
+ for (i = i - 1; i >= 0; i--) {
+ wd_release_queue(g_thread_queue.bd_res[i].queue);
+ free(g_thread_queue.bd_res[i].out);
+ free(g_thread_queue.bd_res[i].queue);
+ }
+
+ free(g_thread_queue.bd_res);
+ return ret;
+}
+
+static void uninit_trng_wd_queue(void)
+{
+ int j;
+
+ for (j = 0; j < g_thread_num; j++) {
+ wd_release_queue(g_thread_queue.bd_res[j].queue);
+ free(g_thread_queue.bd_res[j].out);
+ free(g_thread_queue.bd_res[j].queue);
+ }
+
+ free(g_thread_queue.bd_res);
+}
+
+static void *trng_wd_sync_run(void *arg)
+{
+ struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
+ struct wcrypto_rng_ctx_setup trng_setup;
+ struct wcrypto_rng_op_data opdata;
+ struct wd_queue *queue;
+ void *ctx = NULL;
+ u32 count = 0;
+ int ret;
+
+ queue = g_thread_queue.bd_res[pdata->td_id].queue;
+ ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
+ if (!ctx)
+ return NULL;
+
+ memset(&opdata, 0, sizeof(opdata));
+ opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
+ opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
+ opdata.op_type = WCRYPTO_TRNG_GEN;
+
+ do {
+ ret = wcrypto_do_rng(ctx, &opdata, NULL);
+ if (ret) {
+ printf("failed to do rng task, ret: %d\n", ret);
+ goto ctx_release;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ } while (true);
+
+ctx_release:
+ wcrypto_del_rng_ctx(ctx);
+ add_recv_data(count, opdata.in_bytes);
+
+ return NULL;
+}
+
+static void trng_wd_sync_threads(void)
+{
+ struct wd_thread_res threads_args[THREADS_NUM];
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].td_id = i;
+ ret = pthread_create(&tdid[i], NULL, trng_wd_sync_run, &threads_args[i]);
+ if (ret) {
+ printf("failed to create sync thread!\n");
+ return;
+ }
+ }
+
+ /* join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ printf("failed to join sync thread!\n");
+ return;
+ }
+ }
+}
+
+void *wd_trng_poll(void *data)
+{
+ struct wd_thread_res *pdata = (struct wd_thread_res *)data;
+ struct wd_queue *queue;
+ u32 last_time = 2; // poll need one more recv time
+ u32 count = 0;
+ u32 in_bytes;
+ int recv;
+
+ in_bytes = g_thread_queue.bd_res[pdata->pollid].in_bytes;
+ queue = g_thread_queue.bd_res[pdata->pollid].queue;
+
+ while (last_time) {
+ recv = wcrypto_rng_poll(queue, ACC_QUEUE_SIZE);
+ if (recv < 0) {
+ printf("failed to recv bd, ret: %d!\n", recv);
+ goto recv_error;
+ }
+ count += recv;
+
+ if (get_run_state() == 0)
+ last_time--;
+ }
+
+recv_error:
+ add_recv_data(count, in_bytes);
+
+ return NULL;
+}
+
+static void *trng_async_cb(const void *msg, void *tag)
+{
+ return NULL;
+}
+
+static void *wd_trng_async_run(void *arg)
+{
+ struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
+ struct wcrypto_rng_ctx_setup trng_setup;
+ struct wcrypto_rng_op_data opdata;
+ struct trng_async_tag *tag = NULL;
+ struct wd_queue *queue;
+ void *ctx = NULL;
+ int ret, i;
+
+ memset(&opdata, 0, sizeof(opdata));
+
+ queue = g_thread_queue.bd_res[pdata->td_id].queue;
+ trng_setup.cb = (void *)trng_async_cb;
+
+ ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
+ if (!ctx)
+ return NULL;
+
+ opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
+ opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
+ opdata.op_type = WCRYPTO_TRNG_GEN;
+
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ if (!tag) {
+ printf("failed to malloc dh tag!\n");
+ goto free_ctx;
+ }
+ tag->ctx = ctx;
+
+ do {
+ ret = wcrypto_do_rng(ctx, &opdata, tag);
+ if (ret && ret != -WD_EBUSY) {
+ printf("failed to send trng task, ret = %d!\n", ret);
+ break;
+ }
+
+ if (get_run_state() == 0)
+ break;
+ } while (true);
+
+ /* Release memory after all tasks are complete. */
+ i = 0;
+ while (get_recv_time() != g_thread_num) {
+ if (i++ >= MAX_TRY_CNT) {
+ printf("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ if (tag)
+ free(tag);
+free_ctx:
+ wcrypto_del_rng_ctx(ctx);
+ add_send_complete();
+
+ return NULL;
+}
+
+static void trng_wd_async_threads(void)
+{
+ struct wd_thread_res threads_args[THREADS_NUM];
+ pthread_t tdid[THREADS_NUM];
+ pthread_t pollid[THREADS_NUM];
+ int i, ret;
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].pollid = i;
+ /* poll thread */
+ ret = pthread_create(&pollid[i], NULL, wd_trng_poll, &threads_args[i]);
+ if (ret) {
+ printf("failed to create poll thread!\n");
+ return;
+ }
+ }
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].td_id = i;
+ ret = pthread_create(&tdid[i], NULL, wd_trng_async_run, &threads_args[i]);
+ if (ret) {
+ printf("failed to create async thread!\n");
+ return;
+ }
+ }
+
+ /* join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ printf("failed to join async thread!\n");
+ return;
+ }
+ }
+
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(pollid[i], NULL);
+ if (ret) {
+ printf("failed to join poll thread!\n");
+ return;
+ }
+ }
+}
+
+int trng_wd_benchmark(struct acc_option *options)
+{
+ u32 ptime;
+ int ret;
+
+ g_thread_num = options->threads;
+
+ ret = init_trng_wd_queue(options);
+ if (ret)
+ return ret;
+
+ get_pid_cpu_time(&ptime);
+ time_start(options->times);
+ if (options->syncmode)
+ trng_wd_async_threads();
+ else
+ trng_wd_sync_threads();
+ cal_perfermance_data(options, ptime);
+
+ uninit_trng_wd_queue();
+
+ return 0;
+}
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.h b/uadk_tool/benchmark/trng_wd_benchmark.h
new file mode 100644
index 0000000..49453c8
--- /dev/null
+++ b/uadk_tool/benchmark/trng_wd_benchmark.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#ifndef TRNG_WD_BENCHMARK_H
+#define TRNG_WD_BENCHMARK_H
+
+extern int trng_wd_benchmark(struct acc_option *options);
+#endif /* TRNG_WD_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index f36cc4b..f903829 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -14,6 +14,8 @@
#include "zip_uadk_benchmark.h"
#include "zip_wd_benchmark.h"
+#include "trng_wd_benchmark.h"
+
#define TABLE_SPACE_SIZE 8
/*----------------------------------------head struct--------------------------------------------------------*/
@@ -131,6 +133,7 @@ static struct acc_alg_item alg_options[] = {
{"sha512", SHA512_ALG},
{"sha512-224", SHA512_224},
{"sha512-256", SHA512_256},
+ {"trng", TRNG},
{"", ALG_MAX}
};
@@ -345,6 +348,11 @@ static void parse_alg_param(struct acc_option *option)
option->acctype = HPRE_TYPE;
option->subtype = X448_TYPE;
break;
+ case TRNG:
+ snprintf(option->algclass, MAX_ALG_NAME, "%s", "trng");
+ option->acctype = TRNG_TYPE;
+ option->subtype = DEFAULT_TYPE;
+ break;
default:
if (option->algtype <= RSA_4096_CRT) {
snprintf(option->algclass, MAX_ALG_NAME, "%s", "rsa");
@@ -456,6 +464,12 @@ static int benchmark_run(struct acc_option *option)
} else if (option->modetype & NOSVA_MODE) {
ret = zip_wd_benchmark(option);
}
+ case TRNG_TYPE:
+ if (option->modetype & SVA_MODE)
+ ACC_TST_PRT("TRNG not support sva mode..\n");
+ else if (option->modetype & NOSVA_MODE)
+ ret = trng_wd_benchmark(option);
+
break;
}
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 2c8de11..44e2dd9 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -78,6 +78,7 @@ enum acc_type {
SEC_TYPE,
HPRE_TYPE,
ZIP_TYPE,
+ TRNG_TYPE,
};
enum alg_type {
@@ -174,6 +175,7 @@ enum test_alg {
SHA512_ALG,
SHA512_224,
SHA512_256, // digest key all set 4 Bytes
+ TRNG,
ALG_MAX,
};
--
2.25.1

View File

@ -0,0 +1,427 @@
From 8591a69ee1ce5a796390bde817813aaa61f40cf8 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 10 Nov 2023 11:52:25 +0800
Subject: [PATCH 56/85] uadk/tools - support new parameters for compression
Support the new configure parameters for uadk compression.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
uadk_tool/benchmark/uadk_benchmark.c | 46 ++++++++++--------
uadk_tool/benchmark/uadk_benchmark.h | 8 ++--
uadk_tool/benchmark/zip_uadk_benchmark.c | 61 +++++++++++++++---------
uadk_tool/benchmark/zip_wd_benchmark.c | 34 ++++++++-----
4 files changed, 91 insertions(+), 58 deletions(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index f903829..d869688 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -429,7 +429,7 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime)
ops = perfops / option->times;
cpu_rate = (double)ptime / option->times;
ACC_TST_PRT("algname: length: perf: iops: CPU_rate:\n"
- "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n",
+ "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n",
palgname, option->pktlen, perfermance, ops, cpu_rate);
}
@@ -572,7 +572,7 @@ int acc_default_case(struct acc_option *option)
option->multis = 1;
option->ctxnums = 2;
- return acc_benchmark_run(option);
+ return acc_benchmark_run(option);
}
static void print_help(void)
@@ -634,21 +634,23 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
int c;
static struct option long_options[] = {
- {"alg", required_argument, 0, 1},
- {"mode", required_argument, 0, 2},
- {"opt", required_argument, 0, 3},
- {"sync", no_argument, 0,4},
- {"async", no_argument, 0,5},
- {"pktlen", required_argument, 0, 6},
- {"seconds", required_argument, 0, 7},
- {"thread", required_argument, 0, 8},
- {"multi", required_argument, 0, 9},
- {"ctxnum", required_argument, 0, 10},
- {"prefetch", no_argument, 0,11},
- {"engine", required_argument, 0,12},
- {"alglist", no_argument, 0, 13},
- {"latency", no_argument, 0, 14},
- {"help", no_argument, 0, 15},
+ {"help", no_argument, 0, 0},
+ {"alg", required_argument, 0, 1},
+ {"mode", required_argument, 0, 2},
+ {"opt", required_argument, 0, 3},
+ {"sync", no_argument, 0, 4},
+ {"async", no_argument, 0, 5},
+ {"pktlen", required_argument, 0, 6},
+ {"seconds", required_argument, 0, 7},
+ {"thread", required_argument, 0, 8},
+ {"multi", required_argument, 0, 9},
+ {"ctxnum", required_argument, 0, 10},
+ {"prefetch", no_argument, 0, 11},
+ {"engine", required_argument, 0, 12},
+ {"alglist", no_argument, 0, 13},
+ {"latency", no_argument, 0, 14},
+ {"winsize", required_argument, 0, 15},
+ {"complevel", required_argument, 0, 16},
{0, 0, 0, 0}
};
@@ -658,6 +660,9 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
break;
switch (c) {
+ case 0:
+ print_help();
+ goto to_exit;
case 1:
option->algtype = get_alg_type(optarg);
strcpy(option->algname, optarg);
@@ -702,8 +707,11 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
option->latency = true;
break;
case 15:
- print_help();
- goto to_exit;
+ option->winsize = strtol(optarg, NULL, 0);
+ break;
+ case 16:
+ option->complevel = strtol(optarg, NULL, 0);
+ break;
default:
ACC_TST_PRT("bad input test parameter!\n");
print_help();
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 44e2dd9..71fe2dc 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -55,7 +55,9 @@ typedef unsigned char u8;
* @latency: test packet running time
*/
struct acc_option {
- char algname[64];
+ char algname[64];
+ char algclass[64];
+ char engine[64];
u32 algtype;
u32 modetype;
u32 optype;
@@ -65,12 +67,12 @@ struct acc_option {
u32 threads;
u32 multis;
u32 ctxnums;
- char algclass[64];
u32 acctype;
u32 subtype;
- char engine[64];
u32 engine_flag;
u32 prefetch;
+ u32 winsize;
+ u32 complevel;
bool latency;
};
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index d74d3fb..747172a 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -8,11 +8,11 @@
#include "include/wd_sched.h"
#include "include/fse.h"
-#define ZIP_TST_PRT printf
-#define PATH_SIZE 64
-#define ZIP_FILE "./zip"
-#define COMP_LEN_RATE 2
-#define DECOMP_LEN_RATE 2
+#define ZIP_TST_PRT printf
+#define PATH_SIZE 64
+#define ZIP_FILE "./zip"
+#define COMP_LEN_RATE 2
+#define DECOMP_LEN_RATE 2
struct uadk_bd {
u8 *src;
@@ -44,9 +44,11 @@ struct zip_async_tag {
typedef struct uadk_thread_res {
u32 alg;
- u32 mode; // block/stream
+ u32 mode;
u32 optype;
u32 td_id;
+ u32 win_sz;
+ u32 comp_lv;
} thread_data;
struct zip_file_head {
@@ -240,10 +242,10 @@ static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options)
return -EINVAL;
} else if (optype >= WD_DIR_MAX) {
mode = STREAM_MODE;
+ optype = optype % WD_DIR_MAX;
+ options->optype = optype;
}
- optype = optype % WD_DIR_MAX;
-
switch(algtype) {
case ZLIB:
alg = WD_ZLIB;
@@ -268,17 +270,20 @@ static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options)
tddata->alg = alg;
tddata->mode = mode;
tddata->optype = optype;
+ tddata->win_sz = options->winsize;
+ tddata->comp_lv = options->complevel;
return 0;
}
+static struct sched_params param;
static int init_ctx_config(char *alg, int mode, int optype)
{
struct uacce_dev_list *list;
- struct sched_params param;
int i, max_node;
int ret = 0;
+ optype = optype % WD_DIR_MAX;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -EINVAL;
@@ -306,7 +311,7 @@ static int init_ctx_config(char *alg, int mode, int optype)
for (i = 0; i < g_ctxnum; i++) {
g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev);
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
+ g_ctx_cfg.ctxs[i].op_type = optype; // default op_type
g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
}
g_sched->name = SCHED_SINGLE;
@@ -315,7 +320,6 @@ static int init_ctx_config(char *alg, int mode, int optype)
* All contexts for 2 modes & 2 types.
* The test only uses one kind of contexts at the same time.
*/
- optype = optype % WD_DIR_MAX;
param.numa_id = list->dev->numa_id;
param.type = optype;
param.mode = mode;
@@ -546,8 +550,9 @@ static void *zip_uadk_blk_lz77_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -639,8 +644,9 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -733,8 +739,9 @@ static void *zip_uadk_blk_lz77_async_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -837,8 +844,9 @@ static void *zip_uadk_blk_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -896,8 +904,9 @@ static void *zip_uadk_stm_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -961,8 +970,9 @@ static void *zip_uadk_blk_async_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WD_COMP_L8;
- comp_setup.win_sz = WD_COMP_WS_8K;
+ comp_setup.win_sz = pdata->win_sz;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.sched_param = &param;
h_sess = wd_comp_alloc_sess(&comp_setup);
if (!h_sess)
return NULL;
@@ -1044,6 +1054,7 @@ static int zip_uadk_sync_threads(struct acc_option *options)
if (ret)
return ret;
+ threads_option.optype = options->optype;
if (threads_option.mode == 1) {// stream mode
if (threads_option.alg == LZ77_ZSTD)
uadk_zip_sync_run = zip_uadk_stm_lz77_sync_run;
@@ -1059,6 +1070,8 @@ static int zip_uadk_sync_threads(struct acc_option *options)
threads_args[i].alg = threads_option.alg;
threads_args[i].mode = threads_option.mode;
threads_args[i].optype = threads_option.optype;
+ threads_args[i].win_sz = threads_option.win_sz;
+ threads_args[i].comp_lv = threads_option.comp_lv;
threads_args[i].td_id = i;
ret = pthread_create(&tdid[i], NULL, uadk_zip_sync_run, &threads_args[i]);
if (ret) {
@@ -1119,6 +1132,8 @@ static int zip_uadk_async_threads(struct acc_option *options)
threads_args[i].alg = threads_option.alg;
threads_args[i].mode = threads_option.mode;
threads_args[i].optype = threads_option.optype;
+ threads_args[i].win_sz = threads_option.win_sz;
+ threads_args[i].comp_lv = threads_option.comp_lv;
threads_args[i].td_id = i;
ret = pthread_create(&tdid[i], NULL, uadk_zip_async_run, &threads_args[i]);
if (ret) {
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index cbbbb5d..dc00631 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -57,9 +57,11 @@ struct zip_async_tag {
typedef struct uadk_thread_res {
u32 alg;
- u32 mode; // block/stream
+ u32 mode;
u32 optype;
u32 td_id;
+ u32 comp_lv;
+ u32 win_size;
} thread_data;
struct zip_file_head {
@@ -277,6 +279,8 @@ static int zip_wd_param_parse(thread_data *tddata, struct acc_option *options)
tddata->alg = alg;
tddata->mode = mode;
tddata->optype = optype;
+ tddata->win_size = options->winsize;
+ tddata->comp_lv = options->complevel;
return 0;
}
@@ -528,8 +532,8 @@ static void *zip_wd_blk_lz77_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATELESS;
ctx = wcrypto_create_comp_ctx(queue, &comp_setup);
@@ -636,8 +640,8 @@ static void *zip_wd_stm_lz77_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL;
ctx = wcrypto_create_comp_ctx(queue, &comp_setup);
@@ -745,8 +749,8 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATELESS;
comp_setup.cb = zip_lz77_async_cb;
@@ -866,8 +870,8 @@ static void *zip_wd_blk_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATELESS;
ctx = wcrypto_create_comp_ctx(queue, &comp_setup);
@@ -939,8 +943,8 @@ static void *zip_wd_stm_sync_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL;
ctx = wcrypto_create_comp_ctx(queue, &comp_setup);
@@ -1018,8 +1022,8 @@ static void *zip_wd_blk_async_run(void *arg)
comp_setup.alg_type = pdata->alg;
comp_setup.op_type = pdata->optype;
- comp_setup.comp_lv = WCRYPTO_COMP_L8;
- comp_setup.win_size = WCRYPTO_COMP_WS_8K;
+ comp_setup.comp_lv = pdata->comp_lv;
+ comp_setup.win_size = pdata->win_size;
comp_setup.stream_mode = WCRYPTO_COMP_STATELESS;
comp_setup.cb = zip_async_cb;
@@ -1123,6 +1127,8 @@ static int zip_wd_sync_threads(struct acc_option *options)
threads_args[i].alg = threads_option.alg;
threads_args[i].mode = threads_option.mode;
threads_args[i].optype = threads_option.optype;
+ threads_args[i].comp_lv = threads_option.comp_lv;
+ threads_args[i].win_size = threads_option.win_size;
threads_args[i].td_id = i;
ret = pthread_create(&tdid[i], NULL, wd_zip_sync_run, &threads_args[i]);
if (ret) {
@@ -1183,6 +1189,8 @@ static int zip_wd_async_threads(struct acc_option *options)
threads_args[i].alg = threads_option.alg;
threads_args[i].mode = threads_option.mode;
threads_args[i].optype = threads_option.optype;
+ threads_args[i].comp_lv = threads_option.comp_lv;
+ threads_args[i].win_size = threads_option.win_size;
threads_args[i].td_id = i;
ret = pthread_create(&tdid[i], NULL, wd_zip_async_run, &threads_args[i]);
if (ret) {
--
2.25.1

View File

@ -0,0 +1,317 @@
From 7701b69c844f49cfeeb68446d599da9699ca8b6d Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Fri, 10 Nov 2023 11:52:26 +0800
Subject: [PATCH 57/85] uadk_tool/v1 - support aead algorithm decrypto perf
testing
The structure of the nosva aead input and output are as follows :
AEAD encryption input: assoc data || plaintext
AEAD encryption output: assoc data || ciphertext || auth tag
AEAD decryption input: assoc data || ciphertext || auth tag
AEAD decryption output: assoc data || plaintext
First, we store the encrypted result in a file,
and then use the encrypted result as input for decryption.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
uadk_tool/benchmark/sec_wd_benchmark.c | 165 +++++++++++++++++++++++--
1 file changed, 157 insertions(+), 8 deletions(-)
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index 739c49e..95222c5 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -14,6 +14,10 @@
#define MAX_IVK_LENTH 64
#define DEF_IVK_DATA 0xAA
#define SQE_SIZE 128
+#define SEC_AAD_LEN 16
+#define SEC_PERF_KEY_LEN 16
+#define SEC_SAVE_FILE_LEN 64
+#define SEC_MAC_LEN 16
typedef struct wd_thread_res {
u32 subtype;
@@ -46,10 +50,134 @@ struct wcrypto_async_tag {
int cnt;
};
+struct aead_alg_info {
+ int index;
+ char *name;
+ unsigned int mac_len;
+};
+
static struct thread_queue_res g_thread_queue;
static unsigned int g_thread_num;
static unsigned int g_pktlen;
+static unsigned int g_alg;
+static unsigned int g_algtype;
+static unsigned int g_optype;
+
+static char wd_aead_key[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
+ "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf";
+
+static char wd_aead_aad[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
+ "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf";
+
+static struct aead_alg_info wd_aead_info[] = {
+ {
+ .index = AES_128_CCM,
+ .name = "AES_128_CCM",
+ .mac_len = 16,
+ }, {
+ .index = AES_128_GCM,
+ .name = "AES_128_GCM",
+ .mac_len = 16,
+ }, {
+ .index = AES_128_CBC_SHA256_HMAC,
+ .name = "AES_128_CBC_SHA256_HMAC",
+ .mac_len = 32,
+ }, {
+ .index = SM4_128_GCM,
+ .name = "SM4_128_GCM",
+ .mac_len = 16,
+ }, {
+ .index = SM4_128_CCM,
+ .name = "SM4_128_CCM",
+ .mac_len = 16,
+ },
+};
+
+static char *get_aead_alg_name(int algtype)
+{
+ int table_size = ARRAY_SIZE(wd_aead_info);
+ int i;
+
+ for (i = 0; i < table_size; i++) {
+ if (algtype == wd_aead_info[i].index)
+ return wd_aead_info[i].name;
+ }
+
+ SEC_TST_PRT("failed to get the aead alg name\n");
+
+ return NULL;
+}
+
+static void init_aead_enc_input(u8 *addr, u32 size)
+{
+ memset(addr, 0, size);
+ memcpy(addr, wd_aead_aad, SEC_AAD_LEN);
+}
+
+static void save_aead_enc_output(u8 *addr, u32 size)
+{
+ char file_name[SEC_SAVE_FILE_LEN] = {0};
+ char *alg_name;
+ FILE *fp;
+
+ alg_name = get_aead_alg_name(g_algtype);
+ if (!alg_name) {
+ SEC_TST_PRT("failed to get the aead alg name!\n");
+ return;
+ }
+
+ snprintf(file_name, SEC_SAVE_FILE_LEN, "ctext_%s_%u_WD", alg_name, g_pktlen);
+
+ fp = fopen(file_name, "w");
+ if (!fp) {
+ SEC_TST_PRT("failed to open the ctext file!\n");
+ return;
+ }
+
+ for (int i = 0; i < size; i++)
+ fputc((char)addr[i], fp);
+
+ fclose(fp);
+}
+
+static void init_aead_dec_input(u8 *addr, u32 size)
+{
+ char file_name[SEC_SAVE_FILE_LEN] = {0};
+ char *alg_name;
+ FILE *fp;
+ int read_size;
+
+ alg_name = get_aead_alg_name(g_algtype);
+ if (!alg_name) {
+ SEC_TST_PRT("failed to get the aead alg name!\n");
+ return;
+ }
+
+ snprintf(file_name, SEC_SAVE_FILE_LEN, "ctext_%s_%u_WD", alg_name, g_pktlen);
+
+ fp = fopen(file_name, "r");
+ if (!fp) {
+ SEC_TST_PRT("failed to open the ctext file!\n");
+ return;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ size = ftell(fp);
+
+ rewind(fp);
+ read_size = fread(addr, 1, size, fp);
+ if (read_size != size) {
+ SEC_TST_PRT("failed to read enough data from ctext!\n");
+ fclose(fp);
+ return;
+ }
+
+ addr[size] = '\0';
+
+ fclose(fp);
+}
+
static void *cipher_async_cb(void *message, void *cipher_tag)
{
return NULL;
@@ -434,6 +562,15 @@ static int init_wd_queue(struct acc_option *options)
ret = -ENOMEM;
goto in_err;
}
+ if (g_alg == AEAD_TYPE) {
+ if (!g_optype) {
+ init_aead_enc_input(g_thread_queue.bd_res[m].in[idx],
+ g_pktlen + SEC_AAD_LEN);
+ } else {
+ init_aead_dec_input(g_thread_queue.bd_res[m].in[idx],
+ g_pktlen + SEC_AAD_LEN + SEC_MAC_LEN);
+ }
+ }
}
}
@@ -509,6 +646,11 @@ static void uninit_wd_queue(void)
{
int i, j, idx;
+ // save aad + ciphertxt + mac to file.
+ if (g_alg == AEAD_TYPE && !g_optype)
+ save_aead_enc_output(g_thread_queue.bd_res[0].out[0],
+ g_pktlen + SEC_AAD_LEN + SEC_MAC_LEN);
+
for (i = 0; i < g_thread_num; i++) {
for (idx = 0; idx < MAX_POOL_LENTH; idx++) {
wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].iv[idx]);
@@ -642,7 +784,7 @@ static void *sec_wd_cipher_async(void *arg)
goto tag_err;
}
- if (queue->capa.priv.direction == 0)
+ if (!g_optype)
copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION;
else
copdata.op_type = WCRYPTO_CIPHER_DECRYPTION;
@@ -728,7 +870,7 @@ static void *sec_wd_aead_async(void *arg)
res_iv = bd_res->iv;
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- memset(priv_hash, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memcpy(priv_hash, wd_aead_key, SEC_PERF_KEY_LEN);
tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag
if (!tag) {
SEC_TST_PRT("wcrypto async alloc tag fail!\n");
@@ -781,7 +923,7 @@ static void *sec_wd_aead_async(void *arg)
goto tag_err;
}
- if (queue->capa.priv.direction == 0) {
+ if (!g_optype) {
aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST;
aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize;
} else {
@@ -791,7 +933,6 @@ static void *sec_wd_aead_async(void *arg)
aopdata.assoc_size = 16;
aopdata.in_bytes = g_pktlen;
- aopdata.out_bytes = g_pktlen;
aopdata.iv_bytes = pdata->ivsize;
aopdata.priv = NULL;
aopdata.out_buf_bytes = g_pktlen * 2;
@@ -800,6 +941,7 @@ static void *sec_wd_aead_async(void *arg)
aopdata.in = res_in[0];
aopdata.out = res_out[0];
aopdata.iv = res_iv[0];
+ memset(aopdata.iv, DEF_IVK_DATA, MAX_IVK_LENTH);
usleep(SEND_USLEEP);
while(1) {
if (get_run_state() == 0)
@@ -1002,7 +1144,7 @@ static void *sec_wd_cipher_sync(void *arg)
return NULL;
}
- if (queue->capa.priv.direction == 0)
+ if (!g_optype)
copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION;
else
copdata.op_type = WCRYPTO_CIPHER_DECRYPTION;
@@ -1077,7 +1219,7 @@ static void *sec_wd_aead_sync(void *arg)
res_iv = bd_res->iv;
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- memset(priv_hash, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memcpy(priv_hash, wd_aead_key, SEC_PERF_KEY_LEN);
aead_setup.calg = pdata->alg;
aead_setup.cmode = pdata->mode;
@@ -1122,7 +1264,7 @@ static void *sec_wd_aead_sync(void *arg)
return NULL;
}
- if (queue->capa.priv.direction == 0) {
+ if (!g_optype) {
aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST;
aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize;
} else {
@@ -1132,7 +1274,6 @@ static void *sec_wd_aead_sync(void *arg)
aopdata.assoc_size = 16;
aopdata.in_bytes = g_pktlen;
- aopdata.out_bytes = g_pktlen;
aopdata.iv_bytes = pdata->ivsize;
aopdata.priv = NULL;
aopdata.out_buf_bytes = g_pktlen * 2;
@@ -1140,6 +1281,7 @@ static void *sec_wd_aead_sync(void *arg)
aopdata.in = res_in[0];
aopdata.out = res_out[0];
aopdata.iv = res_iv[0];
+ memset(aopdata.iv, DEF_IVK_DATA, MAX_IVK_LENTH);
usleep(SEND_USLEEP);
while(1) {
if (get_run_state() == 0)
@@ -1290,7 +1432,9 @@ int sec_wd_sync_threads(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].alg = threads_option.alg;
+ threads_args[i].dalg = threads_option.dalg;
threads_args[i].mode = threads_option.mode;
+ threads_args[i].is_union = threads_option.is_union;
threads_args[i].keysize = threads_option.keysize;
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
@@ -1357,7 +1501,9 @@ int sec_wd_async_threads(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) {
threads_args[i].subtype = threads_option.subtype;
threads_args[i].alg = threads_option.alg;
+ threads_args[i].dalg = threads_option.dalg;
threads_args[i].mode = threads_option.mode;
+ threads_args[i].is_union = threads_option.is_union;
threads_args[i].keysize = threads_option.keysize;
threads_args[i].ivsize = threads_option.ivsize;
threads_args[i].optype = threads_option.optype;
@@ -1395,6 +1541,9 @@ int sec_wd_benchmark(struct acc_option *options)
u32 ptime;
int ret;
+ g_alg = options->subtype;
+ g_algtype = options->algtype;
+ g_optype = options->optype;
g_thread_num = options->threads;
g_pktlen = options->pktlen;
if (options->optype > WCRYPTO_CIPHER_DECRYPTION) {
--
2.25.1

View File

@ -0,0 +1,106 @@
From dada1bc4138629d622c18bbd5d04924af16db5a6 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Fri, 10 Nov 2023 11:52:27 +0800
Subject: [PATCH 58/85] uadk_tool/v1: fix sec benchmark problem
1.do not free ctxs until tasks are complete.
2.wait for aead tasks, it need to free aiv in callback function.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
uadk_tool/benchmark/sec_wd_benchmark.c | 43 +++++++++++++-------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index 95222c5..3791792 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -94,6 +94,20 @@ static struct aead_alg_info wd_aead_info[] = {
},
};
+static void wait_recv_complete(void)
+{
+ int i = 0;
+
+ while (get_recv_time() != g_thread_num) {
+ if (i++ >= MAX_TRY_CNT) {
+ SEC_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+}
+
static char *get_aead_alg_name(int algtype)
{
int table_size = ARRAY_SIZE(wd_aead_info);
@@ -705,17 +719,19 @@ void *sec_wd_poll(void *data)
recv = wd_poll_ctx(g_thread_queue.bd_res[id].queue, expt);
/*
* warpdrive async mode poll easy to 100% with small package.
- * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv);
+ * SEC_TST_PRT("warpdrive poll %d recv: %d!\n", i, recv);
*/
if (unlikely(recv < 0)) {
- SEC_TST_PRT("poll ret: %u!\n", recv);
+ SEC_TST_PRT("poll ret: %d!\n", recv);
goto recv_error;
}
count += recv;
recv = 0;
- if (get_run_state() == 0)
+ if (get_run_state() == 0) {
last_time--;
+ usleep(SEND_USLEEP);
+ }
}
recv_error:
@@ -824,12 +840,7 @@ static void *sec_wd_cipher_async(void *arg)
}
add_send_complete();
-
- while (1) {
- if (get_recv_time() > 0) // wait Async mode finish recv
- break;
- usleep(SEND_USLEEP);
- }
+ wait_recv_complete();
wcrypto_del_cipher_ctx(ctx);
@@ -968,12 +979,7 @@ static void *sec_wd_aead_async(void *arg)
}
add_send_complete();
-
- while (1) {
- if (get_recv_time() > 0) // wait Async mode finish recv
- break;
- usleep(SEND_USLEEP);
- }
+ wait_recv_complete();
wcrypto_del_aead_ctx(ctx);
@@ -1077,12 +1083,7 @@ static void *sec_wd_digest_async(void *arg)
}
add_send_complete();
-
- while (1) {
- if (get_recv_time() > 0) // wait async mode finish recv
- break;
- usleep(SEND_USLEEP);
- }
+ wait_recv_complete();
wcrypto_del_digest_ctx(ctx);
--
2.25.1

View File

@ -0,0 +1,591 @@
From a5e9a9cfaadfe594358efde05e14f8c8d095bf16 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 10 Nov 2023 11:52:28 +0800
Subject: [PATCH 59/85] uadk/tools - misc fixes for uadk compress performance
1.The decompression performance is depends on the compression ratio,
usually based on 50%. So adjust the compression source data to make
the compression ratio near 50%.
2.The per-thread data pool depth determines the size of memory. 4096
is too big for EVB environment. So limit to 512 for compression.
3.The req.src_len will be override after do compression. So need to
use 'g_pktlen' to calculate length.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
uadk_tool/benchmark/uadk_benchmark.c | 2 +-
uadk_tool/benchmark/zip_uadk_benchmark.c | 75 +++++++++++------------
uadk_tool/benchmark/zip_wd_benchmark.c | 76 +++++++++++-------------
3 files changed, 71 insertions(+), 82 deletions(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index d869688..aa884bc 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -429,7 +429,7 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime)
ops = perfops / option->times;
cpu_rate = (double)ptime / option->times;
ACC_TST_PRT("algname: length: perf: iops: CPU_rate:\n"
- "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n",
+ "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n",
palgname, option->pktlen, perfermance, ops, cpu_rate);
}
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 747172a..44746f6 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -13,6 +13,8 @@
#define ZIP_FILE "./zip"
#define COMP_LEN_RATE 2
#define DECOMP_LEN_RATE 2
+#define MAX_POOL_LENTH_COMP 512
+#define COMPRESSION_RATIO_FACTOR 0.7
struct uadk_bd {
u8 *src;
@@ -54,7 +56,7 @@ typedef struct uadk_thread_res {
struct zip_file_head {
u32 file_size;
u32 block_num;
- u32 blk_sz[MAX_POOL_LENTH];
+ u32 blk_sz[MAX_POOL_LENTH_COMP];
};
static struct wd_ctx_config g_ctx_cfg;
@@ -115,11 +117,11 @@ static int save_file_data(const char *alg, u32 pkg_len, u32 optype)
}
// init file head informations
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
fhead->blk_sz[j] = g_zip_pool.pool[0].bds[j].dst_len;
total_file_size += fhead->blk_sz[j];
}
- fhead->block_num = MAX_POOL_LENTH;
+ fhead->block_num = MAX_POOL_LENTH_COMP;
fhead->file_size = total_file_size;
size = write(fd, fhead, sizeof(*fhead));
if (size < 0) {
@@ -129,7 +131,7 @@ static int save_file_data(const char *alg, u32 pkg_len, u32 optype)
}
// write data for one buffer one buffer to file line.
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
size = write(fd, g_zip_pool.pool[0].bds[j].dst,
fhead->blk_sz[j]);
if (size < 0) {
@@ -144,7 +146,7 @@ write_error:
fd_error:
close(fd);
- full_size = g_pktlen * MAX_POOL_LENTH;
+ full_size = g_pktlen * MAX_POOL_LENTH_COMP;
comp_rate = (double) total_file_size / full_size;
ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100);
@@ -187,14 +189,14 @@ static int load_file_data(const char *alg, u32 pkg_len, u32 optype)
goto fd_err;
}
size = read(fd, fhead, sizeof(*fhead));
- if (size < 0 || fhead->block_num != MAX_POOL_LENTH) {
+ if (size < 0 || fhead->block_num != MAX_POOL_LENTH_COMP) {
ZIP_TST_PRT("failed to read file head\n");
ret = -EINVAL;
goto read_err;
}
// read data for one buffer one buffer from file line
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
memset(g_zip_pool.pool[0].bds[j].src, 0x0,
g_zip_pool.pool[0].bds[j].src_len);
if (size != 0) { // zero size buffer no need to read;
@@ -212,7 +214,7 @@ static int load_file_data(const char *alg, u32 pkg_len, u32 optype)
}
for (i = 1; i < g_thread_num; i++) {
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
if (g_zip_pool.pool[0].bds[j].src_len)
memcpy(g_zip_pool.pool[i].bds[j].src,
g_zip_pool.pool[0].bds[j].src,
@@ -383,14 +385,14 @@ static int init_uadk_bd_pool(u32 optype)
return -ENOMEM;
} else {
for (i = 0; i < g_thread_num; i++) {
- g_zip_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
+ g_zip_pool.pool[i].bds = malloc(MAX_POOL_LENTH_COMP *
sizeof(struct uadk_bd));
if (!g_zip_pool.pool[i].bds) {
ZIP_TST_PRT("init uadk bds alloc failed!\n");
goto malloc_error1;
}
- for (j = 0; j < MAX_POOL_LENTH; j++) {
- g_zip_pool.pool[i].bds[j].src = malloc(insize);
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
+ g_zip_pool.pool[i].bds[j].src = calloc(1, insize);
if (!g_zip_pool.pool[i].bds[j].src)
goto malloc_error2;
g_zip_pool.pool[i].bds[j].src_len = insize;
@@ -400,7 +402,7 @@ static int init_uadk_bd_pool(u32 optype)
goto malloc_error3;
g_zip_pool.pool[i].bds[j].dst_len = outsize;
- get_rand_data(g_zip_pool.pool[i].bds[j].src, insize);
+ get_rand_data(g_zip_pool.pool[i].bds[j].src, insize * COMPRESSION_RATIO_FACTOR);
if (g_prefetch)
get_rand_data(g_zip_pool.pool[i].bds[j].dst, outsize);
}
@@ -418,7 +420,7 @@ malloc_error2:
}
malloc_error1:
for (i--; i >= 0; i--) {
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
free(g_zip_pool.pool[i].bds[j].src);
free(g_zip_pool.pool[i].bds[j].dst);
}
@@ -438,7 +440,7 @@ static void free_uadk_bd_pool(void)
for (i = 0; i < g_thread_num; i++) {
if (g_zip_pool.pool[i].bds) {
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
free(g_zip_pool.pool[i].bds[j].src);
free(g_zip_pool.pool[i].bds[j].dst);
}
@@ -565,17 +567,17 @@ static void *zip_uadk_blk_lz77_sync_run(void *arg)
creq.data_fmt = 0;
creq.status = 0;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = &hw_buff_out[i]; //temp out
creq.src_len = uadk_pool->bds[i].src_len;
@@ -610,7 +612,7 @@ fse_err:
cal_avg_latency(count);
if (pdata->optype == WD_DIR_COMPRESS)
- add_recv_data(count, creq.src_len);
+ add_recv_data(count, g_pktlen);
else
add_recv_data(count, first_len);
@@ -659,17 +661,17 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
creq.data_fmt = 0;
creq.status = 0;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = &hw_buff_out[i]; //temp out
creq.src_len = uadk_pool->bds[i].src_len;
@@ -707,7 +709,7 @@ fse_err:
cal_avg_latency(count);
if (pdata->optype == WD_DIR_COMPRESS)
- add_recv_data(count, creq.src_len);
+ add_recv_data(count, g_pktlen);
else
add_recv_data(count, first_len);
@@ -754,16 +756,16 @@ static void *zip_uadk_blk_lz77_async_run(void *arg)
creq.data_fmt = 0;
creq.status = 0;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP);
if (!tag) {
ZIP_TST_PRT("failed to malloc zip tag!\n");
goto tag_err;
@@ -774,7 +776,7 @@ static void *zip_uadk_blk_lz77_async_run(void *arg)
break;
try_cnt = 0;
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = &hw_buff_out[i]; //temp out
creq.src_len = uadk_pool->bds[i].src_len;
@@ -815,10 +817,6 @@ hw_buff_err:
fse_err:
free(ftuple);
wd_comp_free_sess(h_sess);
-
- // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.dst_len);
-
add_send_complete();
return NULL;
@@ -861,7 +859,7 @@ static void *zip_uadk_blk_sync_run(void *arg)
creq.status = 0;
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = uadk_pool->bds[i].dst;
creq.src_len = uadk_pool->bds[i].src_len;
@@ -921,7 +919,7 @@ static void *zip_uadk_stm_sync_run(void *arg)
creq.status = 0;
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = uadk_pool->bds[i].dst;
creq.src_len = uadk_pool->bds[i].src_len;
@@ -986,7 +984,7 @@ static void *zip_uadk_blk_async_run(void *arg)
creq.priv = 0;
creq.status = 0;
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP);
if (!tag) {
ZIP_TST_PRT("failed to malloc zip tag!\n");
wd_comp_free_sess(h_sess);
@@ -998,7 +996,7 @@ static void *zip_uadk_blk_async_run(void *arg)
break;
try_cnt = 0;
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
creq.src = uadk_pool->bds[i].src;
creq.dst = uadk_pool->bds[i].dst;
creq.src_len = uadk_pool->bds[i].src_len;
@@ -1032,9 +1030,6 @@ static void *zip_uadk_blk_async_run(void *arg)
free(tag);
wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, creq.dst_len);
-
add_send_complete();
return NULL;
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index dc00631..61f6c69 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -18,6 +18,8 @@
#define COMP_LEN_RATE 2
#define DECOMP_LEN_RATE 2
+#define COMPRESSION_RATIO_FACTOR 0.7
+#define MAX_POOL_LENTH_COMP 512
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
@@ -67,7 +69,7 @@ typedef struct uadk_thread_res {
struct zip_file_head {
u32 file_size;
u32 block_num;
- u32 blk_sz[MAX_POOL_LENTH];
+ u32 blk_sz[MAX_POOL_LENTH_COMP];
};
static unsigned int g_thread_num;
@@ -124,11 +126,11 @@ static int save_file_data(const char *alg, u32 pkg_len, u32 optype)
}
// init file head informations
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
fhead->blk_sz[j] = g_thread_queue.bd_res[0].bds[j].dst_len;
total_file_size += fhead->blk_sz[j];
}
- fhead->block_num = MAX_POOL_LENTH;
+ fhead->block_num = MAX_POOL_LENTH_COMP;
fhead->file_size = total_file_size;
size = write(fd, fhead, sizeof(*fhead));
if (size < 0) {
@@ -138,7 +140,7 @@ static int save_file_data(const char *alg, u32 pkg_len, u32 optype)
}
// write data for one buffer one buffer to file line.
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
size = write(fd, g_thread_queue.bd_res[0].bds[j].dst,
fhead->blk_sz[j]);
if (size < 0) {
@@ -153,7 +155,7 @@ write_error:
fd_error:
close(fd);
- full_size = g_pktlen * MAX_POOL_LENTH;
+ full_size = g_pktlen * MAX_POOL_LENTH_COMP;
comp_rate = (double) total_file_size / full_size;
ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100);
@@ -196,14 +198,14 @@ static int load_file_data(const char *alg, u32 pkg_len, u32 optype)
goto fd_err;
}
size = read(fd, fhead, sizeof(*fhead));
- if (size < 0 || fhead->block_num != MAX_POOL_LENTH) {
+ if (size < 0 || fhead->block_num != MAX_POOL_LENTH_COMP) {
ZIP_TST_PRT("failed to read file head\n");
ret = -EINVAL;
goto read_err;
}
// read data for one buffer one buffer from file line
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
memset(g_thread_queue.bd_res[0].bds[j].src, 0x0,
g_thread_queue.bd_res[0].bds[j].src_len);
if (size != 0) { // zero size buffer no need to read;
@@ -221,7 +223,7 @@ static int load_file_data(const char *alg, u32 pkg_len, u32 optype)
}
for (i = 1; i < g_thread_num; i++) {
- for (j = 0; j < MAX_POOL_LENTH; j++) {
+ for (j = 0; j < MAX_POOL_LENTH_COMP; j++) {
if (g_thread_queue.bd_res[0].bds[j].src_len)
memcpy(g_thread_queue.bd_res[i].bds[j].src,
g_thread_queue.bd_res[0].bds[j].src,
@@ -328,7 +330,7 @@ static int init_zip_wd_queue(struct acc_option *options)
}
}
- // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of MAX_POOL_LENTH
+ // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of MAX_POOL_LENTH_COMP
memset(&blksetup, 0, sizeof(blksetup));
outsize = ALIGN(outsize, ALIGN_SIZE);
blksetup.block_size = outsize;
@@ -345,12 +347,12 @@ static int init_zip_wd_queue(struct acc_option *options)
}
pool = g_thread_queue.bd_res[j].pool;
- g_thread_queue.bd_res[j].bds = malloc(sizeof(struct wd_bd) * MAX_POOL_LENTH);
+ g_thread_queue.bd_res[j].bds = malloc(sizeof(struct wd_bd) * MAX_POOL_LENTH_COMP);
if (!g_thread_queue.bd_res[j].bds)
goto bds_error;
bds = g_thread_queue.bd_res[j].bds;
- for (i = 0; i < MAX_POOL_LENTH; i++) {
+ for (i = 0; i < MAX_POOL_LENTH_COMP; i++) {
bds[i].src = wd_alloc_blk(pool);
if (!bds[i].src) {
ret = -ENOMEM;
@@ -365,7 +367,7 @@ static int init_zip_wd_queue(struct acc_option *options)
}
bds[i].dst_len = outsize;
- get_rand_data(bds[i].src, insize);
+ get_rand_data(bds[i].src, insize * COMPRESSION_RATIO_FACTOR);
}
}
@@ -385,7 +387,7 @@ pool_err:
for (j--; j >= 0; j--) {
pool = g_thread_queue.bd_res[j].pool;
bds = g_thread_queue.bd_res[j].bds;
- for (i = 0; i < MAX_POOL_LENTH; i++) {
+ for (i = 0; i < MAX_POOL_LENTH_COMP; i++) {
wd_free_blk(pool, bds[i].src);
wd_free_blk(pool, bds[i].dst);
}
@@ -410,7 +412,7 @@ static void uninit_zip_wd_queue(void)
for (j = 0; j < g_thread_num; j++) {
pool = g_thread_queue.bd_res[j].pool;
bds = g_thread_queue.bd_res[j].bds;
- for (i = 0; i < MAX_POOL_LENTH; i++) {
+ for (i = 0; i < MAX_POOL_LENTH_COMP; i++) {
wd_free_blk(pool, bds[i].src);
wd_free_blk(pool, bds[i].dst);
}
@@ -551,17 +553,17 @@ static void *zip_wd_blk_lz77_sync_run(void *arg)
out_len = bd_pool[0].dst_len;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = &hw_buff_out[i]; //temp out
opdata.in_len = bd_pool[i].src_len;
@@ -597,7 +599,7 @@ fse_err:
cal_avg_latency(count);
if (pdata->optype == WCRYPTO_DEFLATE)
- add_recv_data(count, opdata.in_len);
+ add_recv_data(count, g_pktlen);
else
add_recv_data(count, first_len);
@@ -659,17 +661,17 @@ static void *zip_wd_stm_lz77_sync_run(void *arg)
out_len = bd_pool[0].dst_len;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = &hw_buff_out[i]; //temp out
opdata.in_len = bd_pool[i].src_len;
@@ -708,7 +710,7 @@ fse_err:
cal_avg_latency(count);
if (pdata->optype == WCRYPTO_DEFLATE)
- add_recv_data(count, opdata.in_len);
+ add_recv_data(count, g_pktlen);
else
add_recv_data(count, first_len);
@@ -769,16 +771,16 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
out_len = bd_pool[0].dst_len;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH);
+ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH);
+ hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
if (!hw_buff_out)
goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH);
+ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP);
if (!tag) {
ZIP_TST_PRT("failed to malloc zip tag!\n");
goto tag_err;
@@ -789,7 +791,7 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
break;
try_cnt = 0;
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = &hw_buff_out[i]; //temp out
opdata.in_len = bd_pool[i].src_len;
@@ -832,10 +834,6 @@ hw_buff_err:
fse_err:
free(ftuple);
wcrypto_del_comp_ctx(ctx);
-
- // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
-
add_send_complete();
return NULL;
@@ -890,7 +888,7 @@ static void *zip_wd_blk_sync_run(void *arg)
out_len = bd_pool[0].dst_len;
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = bd_pool[i].dst;
opdata.in_len = bd_pool[i].src_len;
@@ -963,7 +961,7 @@ static void *zip_wd_stm_sync_run(void *arg)
out_len = bd_pool[0].dst_len;
while(1) {
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = bd_pool[i].dst;
opdata.in_len = bd_pool[i].src_len;
@@ -1041,7 +1039,7 @@ static void *zip_wd_blk_async_run(void *arg)
opdata.flush = WCRYPTO_FINISH;
out_len = bd_pool[0].dst_len;
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
+ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP);
if (!tag) {
ZIP_TST_PRT("failed to malloc zip tag!\n");
goto tag_release;
@@ -1051,7 +1049,7 @@ static void *zip_wd_blk_async_run(void *arg)
if (get_run_state() == 0)
break;
- i = count % MAX_POOL_LENTH;
+ i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
opdata.out = bd_pool[i].dst;
opdata.in_len = bd_pool[i].src_len;
@@ -1088,10 +1086,6 @@ static void *zip_wd_blk_async_run(void *arg)
tag_release:
free(tag);
wcrypto_del_comp_ctx(ctx);
-
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n",
- // MAX_POOL_LENTH, count, opdata.produced);
-
add_send_complete();
return NULL;
--
2.25.1

View File

@ -0,0 +1,456 @@
From 2b8826c6582ddaa48a1f6be3487d5de7e9bd42be Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 10 Nov 2023 11:52:29 +0800
Subject: [PATCH 60/85] uadk/tools - fix lz77_zstd performance test for nosva
mode
1.lz77_zstd need a large buffer to output literals and sequences.
2.For nosva mode, the output buffer need to be alloced by wd_alloc_blk
from block memory pool.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
uadk_tool/benchmark/zip_uadk_benchmark.c | 67 ++++------
uadk_tool/benchmark/zip_wd_benchmark.c | 160 ++++++-----------------
2 files changed, 66 insertions(+), 161 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 44746f6..7c96edf 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -15,7 +15,7 @@
#define DECOMP_LEN_RATE 2
#define MAX_POOL_LENTH_COMP 512
#define COMPRESSION_RATIO_FACTOR 0.7
-
+#define CHUNK_SIZE (128 * 1024)
struct uadk_bd {
u8 *src;
u8 *dst;
@@ -623,16 +623,12 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
struct wd_comp_sess_setup comp_setup = {0};
- ZSTD_CCtx *cctx = zstd_soft_fse_init(15);
- ZSTD_inBuffer zstd_input = {0};
- ZSTD_outBuffer zstd_output = {0};
COMP_TUPLE_TAG *ftuple = NULL;
struct bd_pool *uadk_pool;
struct wd_comp_req creq;
- char *hw_buff_out = NULL;
- size_t fse_size;
handle_t h_sess;
- u32 first_len = 0;
+ void *src, *dst;
+ u32 in_len = 0;
u32 out_len = 0;
u32 count = 0;
int ret, i;
@@ -654,7 +650,6 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
return NULL;
creq.op_type = pdata->optype;
- creq.src_len = g_pktlen;
out_len = uadk_pool->bds[0].dst_len;
creq.cb = NULL;
@@ -665,53 +660,45 @@ static void *zip_uadk_stm_lz77_sync_run(void *arg)
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
- if (!hw_buff_out)
- goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
-
while(1) {
i = count % MAX_POOL_LENTH_COMP;
- creq.src = uadk_pool->bds[i].src;
- creq.dst = &hw_buff_out[i]; //temp out
- creq.src_len = uadk_pool->bds[i].src_len;
- creq.dst_len = out_len;
- creq.priv = &ftuple[i];
+ src = uadk_pool->bds[i].src;
+ dst = uadk_pool->bds[i].dst;
+ in_len = uadk_pool->bds[0].src_len;
+ out_len = uadk_pool->bds[0].dst_len;
+
+ while (in_len > 0) {
+ creq.src_len = in_len > CHUNK_SIZE ? CHUNK_SIZE : in_len;
+ creq.dst_len = out_len > 2 * CHUNK_SIZE ? 2 * CHUNK_SIZE : out_len;
+ creq.src = src;
+ creq.dst = dst;
+ creq.priv = &ftuple[i];
+
+ ret = wd_do_comp_strm(h_sess, &creq);
+ if (ret < 0 || creq.status == WD_IN_EPARA) {
+ ZIP_TST_PRT("wd comp, invalid or incomplete data! "
+ "ret(%d), req.status(%u)\n", ret, creq.status);
+ break;
+ }
- ret = wd_do_comp_strm(h_sess, &creq);
- if (ret < 0 || creq.status == WD_IN_EPARA) {
- ZIP_TST_PRT("wd comp, invalid or incomplete data! "
- "ret(%d), req.status(%u)\n", ret, creq.status);
- break;
+ src += CHUNK_SIZE;
+ in_len -= CHUNK_SIZE;
+ dst += 2 * CHUNK_SIZE;
+ out_len -= 2 * CHUNK_SIZE;
}
count++;
- zstd_input.src = creq.src;
- zstd_input.size = creq.src_len;
- zstd_input.pos = 0;
- zstd_output.dst = uadk_pool->bds[i].dst;
- zstd_output.size = out_len;
- zstd_output.pos = 0;
- fse_size = zstd_soft_fse(creq.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end);
- uadk_pool->bds[i].dst_len = fse_size;
- if (unlikely(i == 0))
- first_len = fse_size;
if (get_run_state() == 0)
break;
}
-hw_buff_err:
- free(hw_buff_out);
-fse_err:
free(ftuple);
+fse_err:
wd_comp_free_sess(h_sess);
cal_avg_latency(count);
- if (pdata->optype == WD_DIR_COMPRESS)
- add_recv_data(count, g_pktlen);
- else
- add_recv_data(count, first_len);
+ add_recv_data(count, g_pktlen);
return NULL;
}
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index 61f6c69..b25f1fb 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -20,6 +20,7 @@
#define DECOMP_LEN_RATE 2
#define COMPRESSION_RATIO_FACTOR 0.7
#define MAX_POOL_LENTH_COMP 512
+#define CHUNK_SIZE (128 * 1024)
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
@@ -75,18 +76,6 @@ struct zip_file_head {
static unsigned int g_thread_num;
static unsigned int g_pktlen;
-#ifndef ZLIB_FSE
-static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level)
-{
- return NULL;
-}
-
-static int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode)
-{
- return input->size;
-}
-#endif
-
static int save_file_data(const char *alg, u32 pkg_len, u32 optype)
{
struct zip_file_head *fhead = NULL;
@@ -430,26 +419,12 @@ static void zip_lz77_async_cb(const void *message, void *data)
{
const struct wcrypto_comp_msg *cbmsg = message;
struct zip_async_tag *tag = data;
- ZSTD_CCtx *cctx = tag->cctx;
- ZSTD_inBuffer zstd_input;
- ZSTD_outBuffer zstd_output;
- struct wd_bd *bd_pool;
int td_id = tag->td_id;
+ struct wd_bd *bd_pool;
int idx = tag->bd_idx;
- size_t fse_size;
bd_pool = g_thread_queue.bd_res[td_id].bds;
bd_pool[idx].dst_len = cbmsg->produced;
-
- zstd_input.src = cbmsg->src;
- zstd_input.size = cbmsg->in_size;
- zstd_input.pos = 0;
- zstd_output.dst = bd_pool[idx].dst;
- zstd_output.size = tag->cm_len;
- zstd_output.pos = 0;
- fse_size = zstd_soft_fse(tag->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end);
-
- bd_pool[idx].dst_len = fse_size;
}
static void zip_async_cb(const void *message, void *data)
@@ -501,18 +476,12 @@ recv_error:
static void *zip_wd_blk_lz77_sync_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
- ZSTD_CCtx *cctx = zstd_soft_fse_init(15);
- ZSTD_inBuffer zstd_input = {0};
- ZSTD_outBuffer zstd_output = {0};
COMP_TUPLE_TAG *ftuple = NULL;
struct wcrypto_comp_ctx_setup comp_setup;
struct wcrypto_comp_op_data opdata;
struct wcrypto_comp_ctx *ctx;
struct wd_queue *queue;
struct wd_bd *bd_pool;
- u8 *hw_buff_out = NULL;
- size_t fse_size;
- u32 first_len = 0;
u32 out_len = 0;
u32 count = 0;
int ret, i;
@@ -557,15 +526,10 @@ static void *zip_wd_blk_lz77_sync_run(void *arg)
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
- if (!hw_buff_out)
- goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
-
while(1) {
i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
- opdata.out = &hw_buff_out[i]; //temp out
+ opdata.out = bd_pool[i].dst;
opdata.in_len = bd_pool[i].src_len;
opdata.avail_out = out_len;
opdata.priv = &ftuple[i];
@@ -576,32 +540,17 @@ static void *zip_wd_blk_lz77_sync_run(void *arg)
break;
count++;
- zstd_input.src = opdata.in;
- zstd_input.size = opdata.in_len;
- zstd_input.pos = 0;
- zstd_output.dst = bd_pool[i].dst;
- zstd_output.size = out_len;
- zstd_output.pos = 0;
- fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end);
-
- bd_pool[i].dst_len = fse_size;
- if (unlikely(i == 0))
- first_len = fse_size;
+
if (get_run_state() == 0)
break;
}
-hw_buff_err:
- free(hw_buff_out);
-fse_err:
free(ftuple);
+fse_err:
wcrypto_del_comp_ctx(ctx);
cal_avg_latency(count);
- if (pdata->optype == WCRYPTO_DEFLATE)
- add_recv_data(count, g_pktlen);
- else
- add_recv_data(count, first_len);
+ add_recv_data(count, g_pktlen);
return NULL;
}
@@ -609,18 +558,14 @@ fse_err:
static void *zip_wd_stm_lz77_sync_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
- ZSTD_CCtx *cctx = zstd_soft_fse_init(15);
- ZSTD_inBuffer zstd_input = {0};
- ZSTD_outBuffer zstd_output = {0};
COMP_TUPLE_TAG *ftuple = NULL;
struct wcrypto_comp_ctx_setup comp_setup;
struct wcrypto_comp_op_data opdata;
struct wcrypto_comp_ctx *ctx;
struct wd_queue *queue;
struct wd_bd *bd_pool;
- u8 *hw_buff_out = NULL;
- size_t fse_size;
- u32 first_len = 0;
+ void *src, *dst;
+ u32 in_len = 0;
u32 out_len = 0;
u32 count = 0;
int ret, i;
@@ -659,60 +604,48 @@ static void *zip_wd_stm_lz77_sync_run(void *arg)
else
opdata.flush = WCRYPTO_FINISH;
- out_len = bd_pool[0].dst_len;
-
ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP);
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
- if (!hw_buff_out)
- goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
-
while(1) {
i = count % MAX_POOL_LENTH_COMP;
- opdata.in = bd_pool[i].src;
- opdata.out = &hw_buff_out[i]; //temp out
- opdata.in_len = bd_pool[i].src_len;
- opdata.avail_out = out_len;
- opdata.priv = &ftuple[i];
-
- ret = wcrypto_do_comp(ctx, &opdata, NULL);
- if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE ||
- opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) {
- ZIP_TST_PRT("wd comp, invalid or incomplete data! "
- "ret(%d), req.status(%u)\n", ret, opdata.status);
- break;
+ src = bd_pool[i].src;
+ dst = bd_pool[i].dst;
+ in_len = bd_pool[i].src_len;
+ out_len = bd_pool[i].dst_len;
+
+ while (in_len > 0) {
+ opdata.in_len = in_len > CHUNK_SIZE ? CHUNK_SIZE : in_len;
+ opdata.avail_out = out_len > 2 * CHUNK_SIZE ? 2 * CHUNK_SIZE : out_len;
+ opdata.in = src;
+ opdata.out = dst;
+ opdata.priv = &ftuple[i];
+
+ ret = wcrypto_do_comp(ctx, &opdata, NULL);
+ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE ||
+ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) {
+ ZIP_TST_PRT("wd comp, invalid or incomplete data! "
+ "ret(%d), req.status(%u)\n", ret, opdata.status);
+ break;
+ }
+ src += CHUNK_SIZE;
+ in_len -= CHUNK_SIZE;
+ dst += 2 * CHUNK_SIZE;
+ out_len -= 2 * CHUNK_SIZE;
}
-
count++;
- zstd_input.src = opdata.in;
- zstd_input.size = opdata.in_len;
- zstd_input.pos = 0;
- zstd_output.dst = opdata.out;
- zstd_output.size = out_len;
- zstd_output.pos = 0;
- fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end);
-
- bd_pool[i].dst_len = fse_size;
- if (unlikely(i == 0))
- first_len = fse_size;
+
if (get_run_state() == 0)
break;
}
-hw_buff_err:
- free(hw_buff_out);
-fse_err:
free(ftuple);
+fse_err:
wcrypto_del_comp_ctx(ctx);
cal_avg_latency(count);
- if (pdata->optype == WCRYPTO_DEFLATE)
- add_recv_data(count, g_pktlen);
- else
- add_recv_data(count, first_len);
+ add_recv_data(count, g_pktlen);
return NULL;
}
@@ -720,18 +653,16 @@ fse_err:
static void *zip_wd_blk_lz77_async_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
- ZSTD_CCtx *cctx = zstd_soft_fse_init(15);
- COMP_TUPLE_TAG *ftuple = NULL;
struct wcrypto_comp_ctx_setup comp_setup;
struct wcrypto_comp_op_data opdata;
+ COMP_TUPLE_TAG *ftuple = NULL;
struct wcrypto_comp_ctx *ctx;
struct zip_async_tag *tag;
- u8 *hw_buff_out = NULL;
struct wd_queue *queue;
struct wd_bd *bd_pool;
u32 out_len = 0;
- u32 count = 0;
u32 try_cnt = 0;
+ u32 count = 0;
int ret, i;
if (pdata->td_id > g_thread_num)
@@ -760,14 +691,9 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
if (!ctx)
return NULL;
- opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW;
opdata.alg_type = pdata->alg;
opdata.priv = NULL;
opdata.status = 0;
- if (pdata->optype == WCRYPTO_INFLATE)
- opdata.flush = WCRYPTO_SYNC_FLUSH;
- else
- opdata.flush = WCRYPTO_FINISH;
out_len = bd_pool[0].dst_len;
@@ -775,11 +701,6 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
if (!ftuple)
goto fse_err;
- hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP);
- if (!hw_buff_out)
- goto hw_buff_err;
- memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP);
-
tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP);
if (!tag) {
ZIP_TST_PRT("failed to malloc zip tag!\n");
@@ -793,7 +714,7 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
try_cnt = 0;
i = count % MAX_POOL_LENTH_COMP;
opdata.in = bd_pool[i].src;
- opdata.out = &hw_buff_out[i]; //temp out
+ opdata.out = bd_pool[i].dst; //temp out
opdata.in_len = bd_pool[i].src_len;
opdata.avail_out = out_len;
opdata.priv = &ftuple[i];
@@ -802,7 +723,6 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
tag[i].ctx = ctx;
tag[i].td_id = pdata->td_id;
tag[i].cm_len = out_len;
- tag[i].cctx = cctx;
tag[i].priv = opdata.priv;
ret = wcrypto_do_comp(ctx, &opdata, &tag[i]);
@@ -827,12 +747,10 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
usleep(SEND_USLEEP);
}
-tag_err:
free(tag);
-hw_buff_err:
- free(hw_buff_out);
-fse_err:
+tag_err:
free(ftuple);
+fse_err:
wcrypto_del_comp_ctx(ctx);
add_send_complete();
--
2.25.1

View File

@ -0,0 +1,138 @@
From 9c3a48205372045097d4bf835d772aeffd4e5f8d Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 10 Nov 2023 11:52:30 +0800
Subject: [PATCH 61/85] uadk/tools - fix for uadk compression stream
performance
The compression stream mode test case should devide the input package
into 128KiB block.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
uadk_tool/benchmark/zip_uadk_benchmark.c | 4 +-
uadk_tool/benchmark/zip_wd_benchmark.c | 57 ++++++++++++++----------
2 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 7c96edf..6bf1749 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -13,7 +13,7 @@
#define ZIP_FILE "./zip"
#define COMP_LEN_RATE 2
#define DECOMP_LEN_RATE 2
-#define MAX_POOL_LENTH_COMP 512
+#define MAX_POOL_LENTH_COMP 1
#define COMPRESSION_RATIO_FACTOR 0.7
#define CHUNK_SIZE (128 * 1024)
struct uadk_bd {
@@ -912,7 +912,7 @@ static void *zip_uadk_stm_sync_run(void *arg)
creq.src_len = uadk_pool->bds[i].src_len;
creq.dst_len = out_len;
- ret = wd_do_comp_strm(h_sess, &creq);
+ ret = wd_do_comp_sync2(h_sess, &creq);
if (ret < 0 || creq.status == WD_IN_EPARA) {
ZIP_TST_PRT("wd comp, invalid or incomplete data! "
"ret(%d), req.status(%u)\n", ret, creq.status);
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index b25f1fb..d2340e0 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -323,9 +323,8 @@ static int init_zip_wd_queue(struct acc_option *options)
memset(&blksetup, 0, sizeof(blksetup));
outsize = ALIGN(outsize, ALIGN_SIZE);
blksetup.block_size = outsize;
- blksetup.block_num = MAX_BLOCK_NM;
+ blksetup.block_num = MAX_POOL_LENTH_COMP * 3;
blksetup.align_size = ALIGN_SIZE;
- // ZIP_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10);
for (j = 0; j < g_thread_num; j++) {
g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup);
@@ -832,14 +831,14 @@ static void *zip_wd_blk_sync_run(void *arg)
static void *zip_wd_stm_sync_run(void *arg)
{
+ u32 in_len, out_len, total_out, count = 0;
thread_data *pdata = (thread_data *)arg;
struct wcrypto_comp_ctx_setup comp_setup;
struct wcrypto_comp_op_data opdata;
struct wcrypto_comp_ctx *ctx;
struct wd_queue *queue;
struct wd_bd *bd_pool;
- u32 out_len = 0;
- u32 count = 0;
+ void *src, *dst;
int ret, i;
if (pdata->td_id > g_thread_num)
@@ -867,34 +866,46 @@ static void *zip_wd_stm_sync_run(void *arg)
if (!ctx)
return NULL;
- opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW;
opdata.alg_type = pdata->alg;
opdata.priv = NULL;
opdata.status = 0;
- if (pdata->optype == WCRYPTO_INFLATE)
- opdata.flush = WCRYPTO_SYNC_FLUSH;
- else
- opdata.flush = WCRYPTO_FINISH;
-
- out_len = bd_pool[0].dst_len;
while(1) {
i = count % MAX_POOL_LENTH_COMP;
- opdata.in = bd_pool[i].src;
- opdata.out = bd_pool[i].dst;
- opdata.in_len = bd_pool[i].src_len;
- opdata.avail_out = out_len;
+ src = bd_pool[i].src;
+ dst = bd_pool[i].dst;
+ in_len = bd_pool[i].src_len;
+ out_len = g_pktlen * DECOMP_LEN_RATE;
+ total_out = 0;
+ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW;
- ret = wcrypto_do_comp(ctx, &opdata, NULL);
- if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE ||
- opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) {
- ZIP_TST_PRT("wd comp, invalid or incomplete data! "
- "ret(%d), req.status(%u)\n", ret, opdata.status);
- break;
- }
+ do {
+ opdata.in_len = in_len > CHUNK_SIZE ? CHUNK_SIZE : in_len;
+ opdata.avail_out = out_len > 2 * CHUNK_SIZE ? 2 * CHUNK_SIZE : out_len;
+ opdata.in = src;
+ opdata.out = dst;
+ opdata.flush = in_len ? WCRYPTO_SYNC_FLUSH : WCRYPTO_FINISH;
+
+ ret = wcrypto_do_comp(ctx, &opdata, NULL);
+ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE ||
+ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) {
+ ZIP_TST_PRT("wd comp, invalid or incomplete data! "
+ "ret(%d), req.status(%u)\n", ret, opdata.status);
+ break;
+ }
+
+ opdata.stream_pos = WCRYPTO_COMP_STREAM_OLD;
+
+ src += opdata.consumed;
+ in_len -= opdata.consumed;
+ dst += opdata.produced;
+ out_len -= opdata.produced;
+ total_out += opdata.produced;
+ } while (in_len > 0);
count++;
- bd_pool[i].dst_len = opdata.produced;
+ bd_pool[i].dst_len = total_out;
+
if (get_run_state() == 0)
break;
}
--
2.25.1

View File

@ -0,0 +1,185 @@
From f4adc9ff84c39def8c82a6976e7c62d2c79c5363 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Fri, 10 Nov 2023 11:52:31 +0800
Subject: [PATCH 62/85] uadk/tools: fix for uadk tool sec aead async mode
In asynchronous mode, each BD of each thread requires an
independent MAC address. Otherwise, hardware write-back
overwrites each other.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 43 +++++++-----------------
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index aed1b26..d0bf871 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -28,6 +28,7 @@ char g_save_mac[SEC_MAX_MAC_LEN];
struct uadk_bd {
u8 *src;
u8 *dst;
+ u8 mac[SEC_MAX_MAC_LEN];
};
struct bd_pool {
@@ -38,7 +39,6 @@ struct thread_pool {
struct bd_pool *pool;
u8 **iv;
u8 **key;
- u8 **mac;
u8 **hash;
} g_uadk_pool;
@@ -602,7 +602,7 @@ static void save_aead_dst_data(u8 *addr, u32 size)
return;
}
- memcpy(addr + size, g_uadk_pool.mac[0], SEC_PERF_AUTH_SIZE);
+ memcpy(addr + size, g_uadk_pool.pool[0].bds[0].mac, SEC_PERF_AUTH_SIZE);
for (int i = 0; i < size + SEC_PERF_AUTH_SIZE; i++)
fputc((char)addr[i], fp);
@@ -645,7 +645,7 @@ static void read_aead_dst_data(u8 *addr, u32 len)
static int init_ivkey_source(void)
{
- int i, j, k, m, idx;
+ int i, j, m, idx;
g_uadk_pool.iv = malloc(sizeof(char *) * g_thread_num);
for (i = 0; i < g_thread_num; i++) {
@@ -663,13 +663,6 @@ static int init_ivkey_source(void)
memcpy(g_uadk_pool.key[j], aead_key, SEC_PERF_KEY_LEN);
}
- g_uadk_pool.mac = malloc(sizeof(char *) * g_thread_num);
- for (k = 0; k < g_thread_num; k++) {
- g_uadk_pool.mac[k] = calloc(MAX_IVK_LENTH, sizeof(char));
- if (!g_uadk_pool.mac[k])
- goto free_mac;
- }
-
g_uadk_pool.hash = malloc(sizeof(char *) * g_thread_num);
for (m = 0; m < g_thread_num; m++) {
g_uadk_pool.hash[m] = calloc(MAX_IVK_LENTH, sizeof(char));
@@ -686,12 +679,6 @@ free_hash:
free(g_uadk_pool.hash[idx]);
free(g_uadk_pool.hash);
-free_mac:
- for (idx = k - 1; idx >= 0; idx--)
- free(g_uadk_pool.mac[idx]);
-
- free(g_uadk_pool.mac);
-
free_key:
for (idx = j - 1; idx >= 0; idx--)
free(g_uadk_pool.key[idx]);
@@ -712,13 +699,11 @@ static void free_ivkey_source(void)
for (i = 0; i < g_thread_num; i++) {
free(g_uadk_pool.hash[i]);
- free(g_uadk_pool.mac[i]);
free(g_uadk_pool.key[i]);
free(g_uadk_pool.iv[i]);
}
free(g_uadk_pool.hash);
- free(g_uadk_pool.mac);
free(g_uadk_pool.key);
free(g_uadk_pool.iv);
}
@@ -767,14 +752,13 @@ static int init_uadk_bd_pool(void)
if (!g_optype)
get_aead_data(g_uadk_pool.pool[i].bds[j].src,
g_pktlen + SEC_AEAD_LEN);
- else
+ else {
read_aead_dst_data(g_uadk_pool.pool[i].bds[j].src,
g_pktlen + SEC_AEAD_LEN);
+ memcpy(g_uadk_pool.pool[i].bds[j].mac, g_save_mac, SEC_MAX_MAC_LEN);
+ }
}
}
-
- if (g_alg == AEAD_TYPE && g_optype)
- memcpy(g_uadk_pool.mac[i], g_save_mac, SEC_MAX_MAC_LEN);
}
}
@@ -957,7 +941,7 @@ static void *sec_uadk_aead_async(void *arg)
{
thread_data *pdata = (thread_data *)arg;
struct wd_aead_sess_setup aead_setup = {0};
- u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
+ u8 *priv_iv, *priv_key, *priv_hash;
u32 auth_size = SEC_PERF_AUTH_SIZE;
struct wd_aead_req areq;
struct bd_pool *uadk_pool;
@@ -972,7 +956,6 @@ static void *sec_uadk_aead_async(void *arg)
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
priv_iv = g_uadk_pool.iv[pdata->td_id];
priv_key = g_uadk_pool.key[pdata->td_id];
- priv_mac = g_uadk_pool.mac[pdata->td_id];
priv_hash = g_uadk_pool.hash[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -1010,7 +993,7 @@ static void *sec_uadk_aead_async(void *arg)
areq.op_type = pdata->optype;
areq.iv = priv_iv; // aead IV need update with param
- areq.mac = priv_mac;
+ areq.mac = uadk_pool->bds[0].mac;
areq.iv_bytes = pdata->ivsize;
areq.mac_bytes = auth_size;
areq.assoc_bytes = SEC_AEAD_LEN;
@@ -1033,6 +1016,7 @@ static void *sec_uadk_aead_async(void *arg)
i = count % MAX_POOL_LENTH;
areq.src = uadk_pool->bds[i].src;
areq.dst = uadk_pool->bds[i].dst;
+ areq.mac = uadk_pool->bds[i].mac;
ret = wd_do_aead_async(h_sess, &areq);
if (ret < 0) {
@@ -1188,7 +1172,7 @@ static void *sec_uadk_aead_sync(void *arg)
{
thread_data *pdata = (thread_data *)arg;
struct wd_aead_sess_setup aead_setup = {0};
- u8 *priv_iv, *priv_key, *priv_mac, *priv_hash;
+ u8 *priv_iv, *priv_key, *priv_hash;
u32 auth_size = SEC_PERF_AUTH_SIZE;
struct wd_aead_req areq;
struct bd_pool *uadk_pool;
@@ -1203,7 +1187,6 @@ static void *sec_uadk_aead_sync(void *arg)
priv_iv = g_uadk_pool.iv[pdata->td_id];
priv_key = g_uadk_pool.key[pdata->td_id];
- priv_mac = g_uadk_pool.mac[pdata->td_id];
priv_hash = g_uadk_pool.hash[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
@@ -1212,8 +1195,8 @@ static void *sec_uadk_aead_sync(void *arg)
aead_setup.calg = pdata->alg;
aead_setup.cmode = pdata->mode;
if (pdata->is_union) {
- aead_setup.dalg = WD_DIGEST_SHA256;
- aead_setup.dmode = WD_DIGEST_HMAC;
+ aead_setup.dalg = pdata->dalg;
+ aead_setup.dmode = pdata->dmode;
}
h_sess = wd_aead_alloc_sess(&aead_setup);
if (!h_sess)
@@ -1241,7 +1224,7 @@ static void *sec_uadk_aead_sync(void *arg)
areq.op_type = pdata->optype;
areq.iv = priv_iv; // aead IV need update with param
- areq.mac = priv_mac;
+ areq.mac = uadk_pool->bds[0].mac;
areq.iv_bytes = pdata->ivsize;
areq.assoc_bytes = SEC_AEAD_LEN;
areq.in_bytes = g_pktlen;
--
2.25.1

View File

@ -0,0 +1,217 @@
From ab37cec169fc17a7aa2e661db55ea9892e8ec78d Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:32 +0800
Subject: [PATCH 63/85] uadk/tools: Update test function for init2
Added support for init2 performance test function for uadk_tools
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/uadk_benchmark.c | 108 +++++++++++++++++++++++++++
uadk_tool/benchmark/uadk_benchmark.h | 8 ++
2 files changed, 116 insertions(+)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index aa884bc..26b381e 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -137,6 +137,86 @@ static struct acc_alg_item alg_options[] = {
{"", ALG_MAX}
};
+static struct acc_alg_item alg_name_options[] = {
+ {"zlib", ZLIB},
+ {"gzip", GZIP},
+ {"deflate", DEFLATE},
+ {"lz77_zstd", LZ77_ZSTD},
+ {"rsa", RSA_1024},
+ {"rsa", RSA_2048},
+ {"rsa", RSA_3072},
+ {"rsa", RSA_4096},
+ {"rsa", RSA_1024_CRT},
+ {"rsa", RSA_2048_CRT},
+ {"rsa", RSA_3072_CRT},
+ {"rsa", RSA_4096_CRT},
+ {"dh", DH_768},
+ {"dh", DH_1024},
+ {"dh", DH_1536},
+ {"dh", DH_2048},
+ {"dh", DH_3072},
+ {"dh", DH_4096},
+ {"ecdh", ECDH_256},
+ {"ecdh", ECDH_384},
+ {"ecdh", ECDH_521},
+ {"ecdsa", ECDSA_256},
+ {"ecdsa", ECDSA_384},
+ {"ecdsa", ECDSA_521},
+ {"sm2", SM2_ALG},
+ {"x25519", X25519_ALG},
+ {"x448", X448_ALG},
+ {"ecb(aes)", AES_128_ECB},
+ {"ecb(aes)", AES_192_ECB},
+ {"ecb(aes)", AES_256_ECB},
+ {"cbc(aes)", AES_128_CBC},
+ {"cbc(aes)", AES_192_CBC},
+ {"cbc(aes)", AES_256_CBC},
+ {"ctr(aes)", AES_128_CTR},
+ {"ctr(aes)", AES_192_CTR},
+ {"ctr(aes)", AES_256_CTR},
+ {"ofb(aes)", AES_128_OFB},
+ {"ofb(aes)", AES_192_OFB},
+ {"ofb(aes)", AES_256_OFB},
+ {"cfb(aes)", AES_128_CFB},
+ {"cfb(aes)", AES_192_CFB},
+ {"cfb(aes)", AES_256_CFB},
+ {"xts(aes)", AES_256_XTS},
+ {"xts(aes)", AES_512_XTS},
+ {"ecb(des3_ede)", DES3_128_ECB},
+ {"ecb(des3_ede)", DES3_192_ECB},
+ {"cbc(des3_ede)", DES3_128_CBC},
+ {"cbc(des3_ede)", DES3_192_CBC},
+ {"ecb(sm4)", SM4_128_ECB},
+ {"cbc(sm4)", SM4_128_CBC},
+ {"ctr(sm4)", SM4_128_CTR},
+ {"ofb(sm4)", SM4_128_OFB},
+ {"cfb(sm4)", SM4_128_CFB},
+ {"xts(sm4)", SM4_128_XTS},
+ {"ccm(aes)", AES_128_CCM},
+ {"ccm(aes)", AES_192_CCM},
+ {"ccm(aes)", AES_256_CCM},
+ {"gcm(aes)", AES_128_GCM},
+ {"gcm(aes)", AES_192_GCM},
+ {"gcm(aes)", AES_256_GCM},
+ {"authenc(hmac(sha256),cbc(aes))", AES_128_CBC_SHA256_HMAC},
+ {"authenc(hmac(sha256),cbc(aes))", AES_192_CBC_SHA256_HMAC},
+ {"authenc(hmac(sha256),cbc(aes))", AES_256_CBC_SHA256_HMAC},
+ {"ccm(sm4)", SM4_128_CCM},
+ {"gcm(sm4)", SM4_128_GCM},
+ {"sm3", SM3_ALG},
+ {"md5", MD5_ALG},
+ {"sha1", SHA1_ALG},
+ {"sha256", SHA256_ALG},
+ {"sha224", SHA224_ALG},
+ {"sha384", SHA384_ALG},
+ {"sha512", SHA512_ALG},
+ {"sha512-224", SHA512_224},
+ {"sha512-256", SHA512_256},
+ {"trng", TRNG},
+ {"", ALG_MAX}
+};
+
+
/*-------------------------------------tool code------------------------------------------------------*/
void add_send_complete(void)
{
@@ -194,6 +274,20 @@ static int get_alg_type(const char *alg_name)
return alg;
}
+int get_alg_name(int alg, char *alg_name)
+{
+ int i;
+
+ for (i = 0; i < ALG_MAX; i++) {
+ if (alg == alg_name_options[i].alg) {
+ strcpy(alg_name, alg_name_options[i].name);
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
static int get_mode_type(const char *mode_name)
{
u32 modetype = INVALID_MODE;
@@ -491,6 +585,8 @@ static void dump_param(struct acc_option *option)
ACC_TST_PRT(" [--acctype]: %u\n", option->acctype);
ACC_TST_PRT(" [--prefetch]:%u\n", option->prefetch);
ACC_TST_PRT(" [--engine]: %s\n", option->engine);
+ ACC_TST_PRT(" [--latency]: %u\n", option->latency);
+ ACC_TST_PRT(" [--init2]: %u\n", option->inittype);
}
int acc_benchmark_run(struct acc_option *option)
@@ -571,6 +667,7 @@ int acc_default_case(struct acc_option *option)
option->threads = 1;
option->multis = 1;
option->ctxnums = 2;
+ option->inittype = INIT_TYPE;
return acc_benchmark_run(option);
}
@@ -611,6 +708,8 @@ static void print_help(void)
ACC_TST_PRT(" list the all support alg\n");
ACC_TST_PRT(" [--latency]:\n");
ACC_TST_PRT(" test the running time of packets\n");
+ ACC_TST_PRT(" [--init2]:\n");
+ ACC_TST_PRT(" select init2 mode in the init interface of UADK SVA\n");
ACC_TST_PRT(" [--help] = usage\n");
ACC_TST_PRT("Example\n");
ACC_TST_PRT(" ./uadk_tool benchmark --alg aes-128-cbc --mode sva --opt 0 --sync\n");
@@ -651,6 +750,7 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
{"latency", no_argument, 0, 14},
{"winsize", required_argument, 0, 15},
{"complevel", required_argument, 0, 16},
+ {"init2", no_argument, 0, 17},
{0, 0, 0, 0}
};
@@ -712,6 +812,9 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
case 16:
option->complevel = strtol(optarg, NULL, 0);
break;
+ case 17:
+ option->inittype = INIT2_TYPE;
+ break;
default:
ACC_TST_PRT("bad input test parameter!\n");
print_help();
@@ -783,6 +886,11 @@ int acc_option_convert(struct acc_option *option)
goto param_err;
}
+ if (option->inittype == INIT2_TYPE && option->modetype != SVA_MODE) {
+ ACC_TST_PRT("uadk benchmark No-SVA mode can't use init2\n");
+ goto param_err;
+ }
+
return 0;
param_err:
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 71fe2dc..3a33fd8 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -73,6 +73,7 @@ struct acc_option {
u32 prefetch;
u32 winsize;
u32 complevel;
+ u32 inittype;
bool latency;
};
@@ -83,6 +84,12 @@ enum acc_type {
TRNG_TYPE,
};
+enum acc_init_type {
+ INIT_TYPE = 0,
+ INIT2_TYPE,
+ MAX_TYPE,
+};
+
enum alg_type {
DEFAULT_TYPE,
CIPHER_TYPE,
@@ -192,6 +199,7 @@ extern void add_recv_data(u32 cnt, u32 pkglen);
extern void add_send_complete(void);
extern u32 get_recv_time(void);
extern void cal_avg_latency(u32 count);
+extern int get_alg_name(int alg, char *alg_name);
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option);
int acc_default_case(struct acc_option *option);
--
2.25.1

View File

@ -0,0 +1,531 @@
From d06338f09aa0e36078c789b6203d2a1801fddbd5 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Fri, 10 Nov 2023 11:52:33 +0800
Subject: [PATCH 64/85] uadk: support some uadk dfx stronger feature
add some dfx dumping interface as task error.
Signed-off-by: Kai Ye <yekai13@huawei.com>
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/test/test_sec.c | 140 +++++++++++++++++---------------------
1 file changed, 64 insertions(+), 76 deletions(-)
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c
index 9594e61..c8bfdf4 100644
--- a/uadk_tool/test/test_sec.c
+++ b/uadk_tool/test/test_sec.c
@@ -126,8 +126,8 @@ struct sva_bd_pool {
};
typedef struct _thread_data_t {
- int tid;
- int flag;
+ int tid;
+ int flag;
int mode;
int cpu_id;
struct sva_bd_pool *bd_pool;
@@ -172,7 +172,6 @@ struct test_sec_option {
__u32 init;
};
-//static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t test_sec_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t system_test_thrds[THREADS_NUM];
static thread_data_t thr_data[THREADS_NUM];
@@ -304,7 +303,7 @@ static inline void copy_mem(int dst_sgl, void *dst, int src_sgl, void *src,
SEC_TST_PRT("Not supported memory type for copy.\n");
}
-static void dump_mem(int sgl, unsigned char *buf, size_t len)
+static void dump_mem(const char *str, int sgl, unsigned char *buf, size_t len)
{
struct wd_datalist *p;
size_t i, tmp;
@@ -314,6 +313,8 @@ static void dump_mem(int sgl, unsigned char *buf, size_t len)
return;
}
+ SEC_TST_PRT("%s\n", str);
+
if (sgl == WD_FLAT_BUF) {
for (i = 0; i < len; i++) {
SEC_TST_PRT("\\0x%02x", buf[i]);
@@ -693,7 +694,7 @@ static int test_sec_cipher_sync_once(void)
float speed, time_used;
int pid = getpid();
int cnt = g_times;
- size_t unit_sz;
+ size_t unit_sz, len;
int ret;
/* config setup */
@@ -713,9 +714,10 @@ static int test_sec_cipher_sync_once(void)
req.op_type = WD_CIPHER_DECRYPTION;
/* get resource */
- ret = get_cipher_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
+ (void)get_cipher_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
- req.in_bytes = tv->len;
+ len = g_pktlen < tv->len ? g_pktlen : tv->len;
+ req.in_bytes = len;
unit_sz = cal_unit_sz(req.in_bytes, g_sgl_num);
req.src = create_buf(g_data_fmt, req.in_bytes, unit_sz);
if (!req.src) {
@@ -723,17 +725,18 @@ static int test_sec_cipher_sync_once(void)
goto out;
}
- SEC_TST_PRT("req src--------->:\n");
if (g_direction == 0)
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF,
(void *)tv->ptext, (size_t)tv->len);
else
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF,
(void *)tv->ctext, (size_t)tv->len);
- dump_mem(g_data_fmt, req.src, req.in_bytes);
- req.out_bytes = tv->len;
- req.out_buf_bytes = g_pktlen;
+ dump_mem("req src--->:", g_data_fmt, req.src, req.in_bytes);
+ SEC_TST_PRT("input_len: %u, ready to dump sgl ? fmt:%d\n", req.in_bytes, g_data_fmt);
+
+ req.out_bytes = len;
+ req.out_buf_bytes = len;
req.data_fmt = g_data_fmt;
req.dst = create_buf(g_data_fmt, req.out_buf_bytes, unit_sz);
if (!req.dst) {
@@ -753,8 +756,7 @@ static int test_sec_cipher_sync_once(void)
memset(req.iv, 0, req.iv_bytes);
if (tv->iv)
memcpy(req.iv, tv->iv, strlen(tv->iv));
- SEC_TST_PRT("cipher req iv--------->:\n");
- dump_mem(WD_FLAT_BUF, req.iv, req.iv_bytes);
+ dump_mem("cipher req iv--->:", WD_FLAT_BUF, req.iv, req.iv_bytes);
}
h_sess = wd_cipher_alloc_sess(&setup);
@@ -768,7 +770,6 @@ static int test_sec_cipher_sync_once(void)
SEC_TST_PRT("req set key failed!\n");
goto out_key;
}
- SEC_TST_PRT("cipher req key--------->:\n");
gettimeofday(&bg_tval, NULL);
while (cnt) {
@@ -784,8 +785,7 @@ static int test_sec_cipher_sync_once(void)
SEC_TST_PRT("Pro-%d, thread_id-%d, speed:%0.3f ops, Perf: %ld KB/s\n", pid,
thread_id, speed, Perf);
- SEC_TST_PRT("Test cipher sync function: output dst-->\n");
- dump_mem(g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("Test cipher sync function: output dst-->", g_data_fmt, req.dst, req.out_bytes);
out_key:
wd_cipher_free_sess(h_sess);
@@ -849,7 +849,7 @@ static int test_sec_cipher_async_once(void)
}
/* get resource */
- ret = get_cipher_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
+ (void)get_cipher_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
req.data_fmt = g_data_fmt;
req.in_bytes = g_pktlen;
@@ -860,14 +860,13 @@ static int test_sec_cipher_async_once(void)
goto out;
}
- SEC_TST_PRT("req src--------->:\n");
if (g_direction == 0)
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF,
(void *)tv->ptext, (size_t)tv->len);
else
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF,
(void *)tv->ctext, (size_t)tv->len);
- dump_mem(g_data_fmt, req.src, req.in_bytes);
+ dump_mem("req src--->:", g_data_fmt, req.src, req.in_bytes);
req.out_bytes = tv->len;
req.out_buf_bytes = BUFF_SIZE;
@@ -877,6 +876,7 @@ static int test_sec_cipher_async_once(void)
goto out_dst;
}
+
req.iv = malloc(IV_SIZE);
if (!req.iv) {
ret = -ENOMEM;
@@ -889,8 +889,7 @@ static int test_sec_cipher_async_once(void)
memset(req.iv, 0, req.iv_bytes);
if (tv->iv)
memcpy(req.iv, tv->iv, strlen(tv->iv));
- SEC_TST_PRT("cipher req iv--------->:\n");
- dump_mem(WD_FLAT_BUF, req.iv, req.iv_bytes);
+ dump_mem("cipher req iv--->:", WD_FLAT_BUF, req.iv, req.iv_bytes);
}
h_sess = wd_cipher_alloc_sess(&setup);
if (!h_sess) {
@@ -903,7 +902,7 @@ static int test_sec_cipher_async_once(void)
SEC_TST_PRT("req set key failed!\n");
goto out_key;
}
- SEC_TST_PRT("cipher req key--------->:\n");
+
gettimeofday(&bg_tval, NULL);
while (cnt) {
req.cb = async_cb;
@@ -971,7 +970,7 @@ static int test_sec_cipher_sync(void *arg)
int ret;
/* get resource */
- ret = get_cipher_resource(&tv, (int *)&setup->alg, (int *)&setup->mode);
+ (void)get_cipher_resource(&tv, (int *)&setup->alg, (int *)&setup->mode);
h_sess = wd_cipher_alloc_sess(setup);
if (!h_sess) {
@@ -980,11 +979,10 @@ static int test_sec_cipher_sync(void *arg)
}
pktlen = req->in_bytes;
- SEC_TST_PRT("cipher req src--------->:\n");
- dump_mem(g_data_fmt, req->src, req->in_bytes);
+ dump_mem("cipher req src--->:", g_data_fmt, req->src, req->in_bytes);
- SEC_TST_PRT("ivlen = %d, cipher req iv--------->:\n", req->iv_bytes);
- dump_mem(WD_FLAT_BUF, req->iv, req->iv_bytes);
+ SEC_TST_PRT("ivlen = %d\n", req->iv_bytes);
+ dump_mem("cipher req iv--->:", WD_FLAT_BUF, req->iv, req->iv_bytes);
ret = wd_cipher_set_key(h_sess, (const __u8*)tv->key, tv->klen);
if (ret) {
@@ -992,8 +990,6 @@ static int test_sec_cipher_sync(void *arg)
goto out;;
}
- SEC_TST_PRT("cipher req key--------->:\n");
-
pthread_mutex_lock(&test_sec_mutex);
/* run task */
while (cnt) {
@@ -1080,7 +1076,7 @@ static int sec_cipher_sync_test(void)
memset(setup, 0, sizeof(struct wd_cipher_sess_setup) * THREADS_NUM);
/* get resource */
- ret = get_cipher_resource(&tv, &test_alg, &test_mode);
+ (void)get_cipher_resource(&tv, &test_alg, &test_mode);
iv = calloc(1, IV_SIZE * THREADS_NUM);
if (!iv) {
@@ -1088,7 +1084,6 @@ static int sec_cipher_sync_test(void)
goto out_iv;
}
-
len = g_pktlen < tv->len ? g_pktlen : tv->len;
unit_sz = cal_unit_sz(len, g_sgl_num);
for (i = 0; i < parallel; i++) {
@@ -1131,7 +1126,7 @@ static int sec_cipher_sync_test(void)
ret = init_ctx_config(CTX_TYPE_ENCRYPT, CTX_MODE_SYNC);
if (ret) {
- SEC_TST_PRT("fail to init sigle ctx config!\n");
+ SEC_TST_PRT("failed to init sigle ctx config!\n");
goto out_cfg;
}
@@ -1172,7 +1167,7 @@ static int test_sec_cipher_async(void *arg)
int ret;
/* get resource */
- ret = get_cipher_resource(&tv, (int *)&setup->alg, (int *)&setup->mode);
+ (void)get_cipher_resource(&tv, (int *)&setup->alg, (int *)&setup->mode);
h_sess = wd_cipher_alloc_sess(setup);
if (!h_sess) {
@@ -1187,7 +1182,6 @@ static int test_sec_cipher_async(void *arg)
}
pthread_mutex_lock(&test_sec_mutex);
- // pthread_cond_wait(&cond, &test_sec_mutex);
/* run task */
do {
try_do_again:
@@ -1469,8 +1463,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)
@@ -1847,10 +1841,9 @@ static int sec_digest_sync_once(void)
req.in_bytes = tv->psize;
- SEC_TST_PRT("req src in--------->:\n");
copy_mem(g_data_fmt, req.in, WD_FLAT_BUF,
(void *)tv->plaintext, tv->psize);
- dump_mem(g_data_fmt, req.in, req.in_bytes);
+ dump_mem("req src in--->:", g_data_fmt, req.in, req.in_bytes);
req.out = create_buf(WD_FLAT_BUF, BUFF_SIZE, unit_sz);
if (!req.out) {
@@ -1905,7 +1898,7 @@ static int sec_digest_sync_once(void)
SEC_TST_PRT("time_used:%0.0f us, send task num:%lld\n", time_used, g_times);
SEC_TST_PRT("Pro-%d, thread_id-%d, speed:%0.3f ops, Perf: %ld KB/s\n", getpid(),
(int)syscall(__NR_gettid), speed, Perf);
- dump_mem(WD_FLAT_BUF, req.out, req.out_bytes);
+ dump_mem("req's out--->", WD_FLAT_BUF, req.out, req.out_bytes);
out_key:
wd_digest_free_sess(h_sess);
@@ -1981,8 +1974,8 @@ static int sec_digest_sync_stream_cmp(void)
cnt--;
}
- SEC_TST_PRT("one hash BD dump the out memory, cmp the stream mode:\n");
- dump_mem(WD_FLAT_BUF, req.out, 16);
+ char digest_str[] = "one hash BD dump the out memory, cmp the stream mode:";
+ dump_mem(digest_str, WD_FLAT_BUF, req.out, 16);
out_key:
wd_digest_free_sess(h_sess);
@@ -2080,8 +2073,8 @@ static int sec_digest_sync_stream_mode(void)
memcpy(req.in, tv->plaintext, tv->psize);
cnt--;
}
- SEC_TST_PRT("long hash BD dump the out memory:--------->:\n");
- dump_mem(g_data_fmt, req.out, 16);
+ char digest_str[] = "long hash BD dump the out memory:--->:";
+ dump_mem(digest_str, g_data_fmt, req.out, 16);
out:
free(req.out);
@@ -2174,8 +2167,8 @@ void *digest_sync_stream_mode_send_td(void *data)
memcpy(req.in, tv->plaintext, tv->psize);
cnt--;
}
- SEC_TST_PRT("Pid - %d, thread-id - %d, long hash BD dump the out memory:\n", getpid(), thread_id);
- dump_mem(g_data_fmt, req.out, 16);
+ SEC_TST_PRT("Pid - %d, thread-id - %d\n", getpid(), thread_id);
+ dump_mem("long hash BD dump the out memory:", g_data_fmt, req.out, 16);
out_key:
wd_digest_free_sess(h_sess);
out:
@@ -2370,10 +2363,9 @@ static int sec_digest_async_once(void)
req.in_bytes = tv->psize;
- SEC_TST_PRT("req src in--------->:\n");
copy_mem(g_data_fmt, req.in, WD_FLAT_BUF,
(void *)tv->plaintext, (size_t)tv->psize);
- dump_mem(g_data_fmt, req.in, req.in_bytes);
+ dump_mem("req src in--->:", g_data_fmt, req.in, req.in_bytes);
req.out = create_buf(WD_FLAT_BUF, BUFF_SIZE, unit_sz);
if (!req.out) {
@@ -2430,7 +2422,7 @@ static int sec_digest_async_once(void)
SEC_TST_PRT("pthread_join fail at %s", __func__);
goto out_thr;
}
- dump_mem(WD_FLAT_BUF, req.out, req.out_bytes);
+ dump_mem("req src out--->:", WD_FLAT_BUF, req.out, req.out_bytes);
out_thr:
out_key:
@@ -2477,8 +2469,7 @@ static int sec_digest_sync_multi(void)
memcpy(req.in, tv->plaintext, tv->psize);
req.in_bytes = tv->psize;
- SEC_TST_PRT("req src in--------->:\n");
- dump_mem(g_data_fmt, req.in, req.in_bytes);
+ dump_mem("req src in--->:", g_data_fmt, req.in, req.in_bytes);
req.out = create_buf(g_data_fmt, BUFF_SIZE, unit_sz);
if (!req.out) {
@@ -2532,7 +2523,7 @@ static int sec_digest_sync_multi(void)
g_thread_num, td_data.sum_perf,
(td_data.sum_perf >> 10) * req.in_bytes);
- dump_mem(g_data_fmt, req.out, req.out_bytes);
+ dump_mem("req src out--->:", g_data_fmt, req.out, req.out_bytes);
out_thr:
out_key:
wd_digest_free_sess(h_sess);
@@ -2580,8 +2571,7 @@ static int sec_digest_async_multi(void)
}
memcpy(req.in, tv->plaintext, tv->psize);
req.in_bytes = tv->psize;
- SEC_TST_PRT("req src in--------->:\n");
- dump_mem(WD_FLAT_BUF, req.in, tv->psize);
+ dump_mem("req src in--->:", WD_FLAT_BUF, req.in, tv->psize);
req.out = malloc(BUFF_SIZE);
if (!req.out) {
SEC_TST_PRT("req dst out mem malloc failed!\n");
@@ -2644,7 +2634,7 @@ static int sec_digest_async_multi(void)
return ret;
}
- dump_mem(WD_FLAT_BUF, req.out, req.out_bytes);
+ dump_mem("req src out--->:", WD_FLAT_BUF, req.out, req.out_bytes);
out:
if (req.in)
free(req.in);
@@ -2721,8 +2711,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)
@@ -2931,7 +2921,7 @@ static int sec_aead_sync_once(void)
}
/* should set key */
- dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
+ dump_mem("req src key--->:", WD_FLAT_BUF, (void *)tv->key, tv->klen);
if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
if (ret) {
@@ -3023,8 +3013,7 @@ static int sec_aead_sync_once(void)
memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
}
- SEC_TST_PRT("mac addr src is:\n");
- dump_mem(0, req.mac, auth_size);
+ dump_mem("mac addr src is:", 0, req.mac, auth_size);
req.src = create_buf(g_data_fmt, in_size, unit_sz);
if (!req.src) {
@@ -3034,8 +3023,8 @@ static int sec_aead_sync_once(void)
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
(size_t)(req.in_bytes + tv->alen));
free(src);
- SEC_TST_PRT("aead req src in--------->: %u\n", tv->alen + req.in_bytes);
- dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
+ SEC_TST_PRT("aead req src len: %u\n", tv->alen + req.in_bytes);
+ dump_mem("aead req src in--->", g_data_fmt, req.src, tv->alen + req.in_bytes);
if (g_direction == 0) {
req.out_bytes = req.assoc_bytes + tv->clen - auth_size;
@@ -3081,10 +3070,8 @@ static int sec_aead_sync_once(void)
SEC_TST_PRT("Pro-%d, thread_id-%d, speed:%0.3f ops, Perf: %ld KB/s\n", getpid(),
(int)syscall(__NR_gettid), speed, Perf);
- SEC_TST_PRT("aead dump out addr is:\n");
- dump_mem(g_data_fmt, req.dst, req.out_bytes);
- SEC_TST_PRT("aead dump mac addr is:\n");
- dump_mem(0, req.mac, auth_size);
+ dump_mem("aead dump out addr is:", g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("aead dump mac addr is:", 0, req.mac, auth_size);
free(req.iv);
out_iv:
@@ -3169,7 +3156,7 @@ void *aead_poll_thread(void *data)
time_used = (float)((cur_tval.tv_sec - td_data->start_tval.tv_sec) * 1000000 +
cur_tval.tv_usec - td_data->start_tval.tv_usec);
speed = cnt / time_used * 1000000;
- Perf = speed * req->in_bytes / 1024; //B->KB
+ Perf = speed * req->in_bytes / 1024;
pthread_mutex_unlock(&test_sec_mutex);
SEC_TST_PRT("time_used:%0.0f us, send task num:%ld\n", time_used, cnt);
SEC_TST_PRT("Pro-%d, thread_id-%d, speed:%0.3f ops, Perf: %ld KB/s\n", getpid(),
@@ -3255,7 +3242,7 @@ static int sec_aead_async_once(void)
}
/* should set key */
- dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
+ dump_mem("aead dump aead key is:", WD_FLAT_BUF, (void *)tv->key, tv->klen);
if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
if (ret) {
@@ -3349,8 +3336,8 @@ static int sec_aead_async_once(void)
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
(size_t)(req.in_bytes + tv->alen));
free(src);
- SEC_TST_PRT("aead req alen---->: %u. in_bytes--->:%u\n", tv->alen, req.in_bytes);
- dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
+ SEC_TST_PRT("aead req alen--->: %u. in_bytes--->:%u\n", tv->alen, req.in_bytes);
+ dump_mem("aead dump req in is:", g_data_fmt, req.src, tv->alen + req.in_bytes);
// alloc out buffer memory
req.dst = create_buf(g_data_fmt, BUFF_SIZE, unit_sz);
@@ -3411,7 +3398,8 @@ static int sec_aead_async_once(void)
goto out_thr;
}
- dump_mem(g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("dump aead dst data", g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("dump aead dst mac", g_data_fmt, req.mac, 8);
out_thr:
free(req.iv);
out_iv:
@@ -3467,7 +3455,7 @@ static int sec_aead_sync_multi(void)
}
/* should set key */
- dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
+ dump_mem("dump aead key", WD_FLAT_BUF, (void *)tv->key, tv->klen);
if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
if (ret) {
@@ -3562,8 +3550,8 @@ static int sec_aead_sync_multi(void)
(size_t)(req.in_bytes + tv->alen));
free(src);
- SEC_TST_PRT("aead req src in>: alen:%u, input len:%d\n", tv->alen, req.in_bytes);
- dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
+ SEC_TST_PRT(" alen:%u, input len:%d\n", tv->alen, req.in_bytes);
+ dump_mem("aead req src in--->:", g_data_fmt, req.src, tv->alen + req.in_bytes);
// alloc out buffer memory
req.dst = create_buf(g_data_fmt, BUFF_SIZE, unit_sz);
@@ -3617,7 +3605,7 @@ static int sec_aead_sync_multi(void)
}
}
- dump_mem(g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("aead req src out--->:", g_data_fmt, req.dst, req.out_bytes);
out_thr:
free(req.iv);
out_iv:
@@ -3674,7 +3662,7 @@ static int sec_aead_async_multi(void)
}
/* should set key */
- dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
+ dump_mem("aead set key--->:", WD_FLAT_BUF, (void *)tv->key, tv->klen);
if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
if (ret) {
@@ -3766,8 +3754,8 @@ static int sec_aead_async_multi(void)
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
(size_t)(req.in_bytes + tv->alen));
free(src);
- SEC_TST_PRT("aead req src in--------->: %u\n", tv->alen + req.in_bytes);
- dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
+ SEC_TST_PRT("src len: %u\n", tv->alen + req.in_bytes);
+ dump_mem("aead req src in--->", g_data_fmt, req.src, tv->alen + req.in_bytes);
// alloc out buffer memory
req.dst = create_buf(g_data_fmt, BUFF_SIZE, unit_sz);
@@ -3831,7 +3819,7 @@ static int sec_aead_async_multi(void)
goto out;
}
- dump_mem(g_data_fmt, req.dst, req.out_bytes);
+ dump_mem("aead req src out--->", g_data_fmt, req.dst, req.out_bytes);
out:
if (req.mac)
free(req.mac);
--
2.25.1

View File

@ -0,0 +1,191 @@
From 73307d9181922b4291025d757617a027cfdce94c Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:34 +0800
Subject: [PATCH 65/85] uadk/sec: added init2 performance test
Added init2 performance test function for uadk_tools of
SEC module.
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 119 ++++++++++++++++++++++-
1 file changed, 114 insertions(+), 5 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index d0bf871..9f1f903 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -454,10 +454,13 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
return 0;
}
-static int init_ctx_config(char *alg, int subtype, int mode)
+static int init_ctx_config(struct acc_option *options)
{
struct sched_params param;
struct uacce_dev *dev = NULL;
+ char *alg = options->algclass;
+ int subtype = options->subtype;
+ int mode = options->syncmode;
int ret, max_node, i;
max_node = numa_max_node() + 1;
@@ -576,6 +579,57 @@ static void uninit_ctx_config(int subtype)
wd_sched_rr_release(g_sched);
}
+static void uninit_ctx_config2(int subtype)
+{
+ /* uninit2 */
+ switch(subtype) {
+ case CIPHER_TYPE:
+ wd_cipher_uninit2();
+ break;
+ case AEAD_TYPE:
+ wd_aead_uninit2();
+ break;
+ case DIGEST_TYPE:
+ wd_digest_uninit2();
+ break;
+ default:
+ SEC_TST_PRT("failed to parse alg subtype on uninit2!\n");
+ return;
+ }
+}
+
+static int init_ctx_config2(struct acc_option *options)
+{
+ char alg_name[64];
+ int subtype = options->subtype;
+ int ret;
+
+ ret = get_alg_name(options->algtype, alg_name);
+ if (ret) {
+ SEC_TST_PRT("failed to get valid alg name!\n");
+ return -EINVAL;
+ }
+
+ /* init */
+ switch(subtype) {
+ case CIPHER_TYPE:
+ ret = wd_cipher_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ break;
+ case AEAD_TYPE:
+ ret = wd_aead_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ break;
+ case DIGEST_TYPE:
+ ret = wd_digest_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ break;
+ }
+ if (ret) {
+ SEC_TST_PRT("failed to do cipher init2!\n");
+ return ret;
+ }
+
+ return 0;
+}
+
static void get_aead_data(u8 *addr, u32 size)
{
memset(addr, 0, size);
@@ -852,7 +906,52 @@ static void *sec_uadk_poll(void *data)
count += recv;
recv = 0;
if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
- SEC_TST_PRT("poll ret: %u!\n", ret);
+ SEC_TST_PRT("poll ret: %d!\n", ret);
+ goto recv_error;
+ }
+
+ if (get_run_state() == 0)
+ last_time--;
+ }
+
+recv_error:
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_uadk_poll2(void *data)
+{
+ typedef int (*poll_ctx)(__u32 expt, __u32 *count);
+ poll_ctx uadk_poll_policy = NULL;
+ thread_data *pdata = (thread_data *)data;
+ u32 expt = ACC_QUEUE_SIZE * g_thread_num;
+ u32 last_time = 2; // poll need one more recv time
+ u32 count = 0;
+ u32 recv = 0;
+ int ret;
+
+ switch(pdata->subtype) {
+ case CIPHER_TYPE:
+ uadk_poll_policy = wd_cipher_poll;
+ break;
+ case AEAD_TYPE:
+ uadk_poll_policy = wd_aead_poll;
+ break;
+ case DIGEST_TYPE:
+ uadk_poll_policy = wd_digest_poll;
+ break;
+ default:
+ SEC_TST_PRT("<<<<<<async poll interface is NULL!\n");
+ return NULL;
+ }
+
+ while (last_time) {
+ ret = uadk_poll_policy(expt, &recv);
+ count += recv;
+ recv = 0;
+ if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
+ SEC_TST_PRT("poll ret: %d!\n", ret);
goto recv_error;
}
@@ -866,6 +965,7 @@ recv_error:
return NULL;
}
+
static void *sec_uadk_cipher_async(void *arg)
{
thread_data *pdata = (thread_data *)arg;
@@ -1404,7 +1504,10 @@ int sec_uadk_async_threads(struct acc_option *options)
threads_args[i].subtype = threads_option.subtype;
threads_args[i].td_id = i;
/* poll thread */
- ret = pthread_create(&pollid[i], NULL, sec_uadk_poll, &threads_args[i]);
+ if (options->inittype == INIT2_TYPE)
+ ret = pthread_create(&pollid[i], NULL, sec_uadk_poll2, &threads_args[i]);
+ else
+ ret = pthread_create(&pollid[i], NULL, sec_uadk_poll, &threads_args[i]);
if (ret) {
SEC_TST_PRT("Create poll thread fail!\n");
goto async_error;
@@ -1475,7 +1578,10 @@ int sec_uadk_benchmark(struct acc_option *options)
return -EINVAL;
}
- ret = init_ctx_config(options->algclass, options->subtype, options->syncmode);
+ if (options->inittype == INIT2_TYPE)
+ ret = init_ctx_config2(options);
+ else
+ ret = init_ctx_config(options);
if (ret)
return ret;
@@ -1494,7 +1600,10 @@ int sec_uadk_benchmark(struct acc_option *options)
return ret;
free_uadk_bd_pool();
- uninit_ctx_config(options->subtype);
+ if (options->inittype == INIT2_TYPE)
+ uninit_ctx_config2(options->subtype);
+ else
+ uninit_ctx_config(options->subtype);
return 0;
}
--
2.25.1

View File

@ -0,0 +1,134 @@
From c650bdadb5c4dd767268411349f7109be33fefe4 Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:35 +0800
Subject: [PATCH 66/85] uadk/comp: added init2 test function for comp
Added support for init2 performance test function for uadk_tools
of comp module.
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
uadk_tool/benchmark/zip_uadk_benchmark.c | 76 ++++++++++++++++++++++--
1 file changed, 71 insertions(+), 5 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 6bf1749..7b02df8 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -278,10 +278,40 @@ static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options)
return 0;
}
+static void uninit_ctx_config2(void)
+{
+ /* uninit2 */
+ wd_comp_uninit2();
+}
+
+static int init_ctx_config2(struct acc_option *options)
+{
+ char alg_name[64];
+ int ret = 0;
+
+ ret = get_alg_name(options->algtype, alg_name);
+ if (ret) {
+ ZIP_TST_PRT("failed to get valid alg name!\n");
+ return -EINVAL;
+ }
+
+ /* init */
+ ret = wd_comp_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ if (ret) {
+ ZIP_TST_PRT("Fail to do comp init2!\n");
+ return ret;
+ }
+
+ return 0;
+}
+
static struct sched_params param;
-static int init_ctx_config(char *alg, int mode, int optype)
+static int init_ctx_config(struct acc_option *options)
{
struct uacce_dev_list *list;
+ char *alg = options->algclass;
+ int optype = options->optype;
+ int mode = options->syncmode;
int i, max_node;
int ret = 0;
@@ -511,7 +541,34 @@ static void *zip_uadk_poll(void *data)
count += recv;
recv = 0;
if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
- ZIP_TST_PRT("poll ret: %u!\n", ret);
+ ZIP_TST_PRT("poll ret: %d!\n", ret);
+ goto recv_error;
+ }
+
+ if (get_run_state() == 0)
+ last_time--;
+ }
+
+recv_error:
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *zip_uadk_poll2(void *data)
+{
+ u32 expt = ACC_QUEUE_SIZE * g_thread_num;
+ u32 last_time = 2; // poll need one more recv time
+ u32 count = 0;
+ u32 recv = 0;
+ int ret;
+
+ while (last_time) {
+ ret = wd_comp_poll(expt, &recv);
+ count += recv;
+ recv = 0;
+ if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
+ ZIP_TST_PRT("poll ret: %d!\n", ret);
goto recv_error;
}
@@ -1103,7 +1160,10 @@ static int zip_uadk_async_threads(struct acc_option *options)
for (i = 0; i < g_ctxnum; i++) {
threads_args[i].td_id = i;
/* poll thread */
- ret = pthread_create(&pollid[i], NULL, zip_uadk_poll, &threads_args[i]);
+ if (options->inittype == INIT2_TYPE)
+ ret = pthread_create(&pollid[i], NULL, zip_uadk_poll2, &threads_args[i]);
+ else
+ ret = pthread_create(&pollid[i], NULL, zip_uadk_poll, &threads_args[i]);
if (ret) {
ZIP_TST_PRT("Create poll thread fail!\n");
goto async_error;
@@ -1160,7 +1220,10 @@ int zip_uadk_benchmark(struct acc_option *options)
return -EINVAL;
}
- ret = init_ctx_config(options->algclass, options->syncmode, options->optype);
+ if (options->inittype == INIT2_TYPE)
+ ret = init_ctx_config2(options);
+ else
+ ret = init_ctx_config(options);
if (ret)
return ret;
@@ -1187,7 +1250,10 @@ int zip_uadk_benchmark(struct acc_option *options)
return ret;
free_uadk_bd_pool();
- uninit_ctx_config();
+ if (options->inittype == INIT2_TYPE)
+ uninit_ctx_config2();
+ else
+ uninit_ctx_config();
return 0;
}
--
2.25.1

View File

@ -0,0 +1,230 @@
From 782a3a9954b9a7ae4243fc3cc6c25c296c36b34b Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:36 +0800
Subject: [PATCH 67/85] uadk_tool: added init2 test function for hpre
Added support for init2 performance test function for uadk_tools
of hpre module.
And fix some code style issues.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 137 ++++++++++++++++++++--
1 file changed, 125 insertions(+), 12 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index ffa1a85..028e102 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -344,8 +344,11 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options
return 0;
}
-static int init_hpre_ctx_config(char *alg, int subtype, int mode)
+static int init_hpre_ctx_config(struct acc_option *options)
{
+ int subtype = options->subtype;
+ char *alg = options->algclass;
+ int mode = options->syncmode;
struct sched_params param;
struct uacce_dev *dev;
int max_node;
@@ -398,7 +401,7 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
break;
default:
HPRE_TST_PRT("failed to parse alg subtype!\n");
- g_sched = NULL;
+ return -EINVAL;
}
if (!g_sched) {
HPRE_TST_PRT("failed to alloc sched!\n");
@@ -432,8 +435,6 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
case X448_TYPE:
ret = wd_ecc_init(&g_ctx_cfg, g_sched);
break;
- default:
- ret = -EINVAL;
}
if (ret) {
HPRE_TST_PRT("failed to get hpre ctx!\n");
@@ -456,7 +457,7 @@ static void uninit_hpre_ctx_config(int subtype)
int i;
/* uninit */
- switch(subtype) {
+ switch (subtype) {
case RSA_TYPE:
wd_rsa_uninit();
break;
@@ -481,6 +482,59 @@ static void uninit_hpre_ctx_config(int subtype)
wd_sched_rr_release(g_sched);
}
+static void uninit_hpre_ctx_config2(int subtype)
+{
+ /* uninit2 */
+ switch (subtype) {
+ case RSA_TYPE:
+ wd_rsa_uninit2();
+ break;
+ case DH_TYPE:
+ wd_dh_uninit2();
+ break;
+ case ECDH_TYPE:
+ case ECDSA_TYPE:
+ case SM2_TYPE:
+ case X25519_TYPE:
+ case X448_TYPE:
+ wd_ecc_uninit2();
+ break;
+ default:
+ HPRE_TST_PRT("failed to parse alg subtype on uninit2!\n");
+ return;
+ }
+}
+
+static int init_hpre_ctx_config2(struct acc_option *options)
+{
+ int subtype = options->subtype;
+ char alg_name[MAX_ALG_NAME];
+ int ret;
+
+ ret = get_alg_name(options->algtype, alg_name);
+ if (ret) {
+ HPRE_TST_PRT("failed to get valid alg name!\n");
+ return -EINVAL;
+ }
+
+ /* init2 */
+ switch (subtype) {
+ case RSA_TYPE:
+ return wd_rsa_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ case DH_TYPE:
+ return wd_dh_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ case ECDH_TYPE:
+ case ECDSA_TYPE:
+ case SM2_TYPE:
+ case X25519_TYPE:
+ case X448_TYPE:
+ return wd_ecc_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
+ default:
+ HPRE_TST_PRT("failed to parse alg subtype on uninit2!\n");
+ return -EINVAL;
+ }
+}
+
/*-------------------------------uadk benchmark main code-------------------------------------*/
void *hpre_uadk_poll(void *data)
@@ -498,7 +552,7 @@ void *hpre_uadk_poll(void *data)
if (id > g_ctxnum)
return NULL;
- switch(pdata->subtype) {
+ switch (pdata->subtype) {
case RSA_TYPE:
uadk_poll_ctx = wd_rsa_poll_ctx;
break;
@@ -522,7 +576,56 @@ void *hpre_uadk_poll(void *data)
count += recv;
recv = 0;
if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
- HPRE_TST_PRT("poll ret: %u!\n", ret);
+ HPRE_TST_PRT("poll ret: %d!\n", ret);
+ goto recv_error;
+ }
+
+ if (get_run_state() == 0)
+ last_time--;
+ }
+
+recv_error:
+ add_recv_data(count, pdata->keybits >> 3);
+
+ return NULL;
+}
+
+void *hpre_uadk_poll2(void *data)
+{
+ typedef int (*poll_ctx)(__u32 expt, __u32 *count);
+ thread_data *pdata = (thread_data *)data;
+ u32 expt = ACC_QUEUE_SIZE * g_thread_num;
+ poll_ctx uadk_poll = NULL;
+ u32 last_time = 2; // poll need one more recv time
+ u32 count = 0;
+ u32 recv = 0;
+ int ret;
+
+ switch (pdata->subtype) {
+ case RSA_TYPE:
+ uadk_poll = wd_rsa_poll;
+ break;
+ case DH_TYPE:
+ uadk_poll = wd_dh_poll;
+ break;
+ case ECDH_TYPE:
+ case ECDSA_TYPE:
+ case SM2_TYPE:
+ case X25519_TYPE:
+ case X448_TYPE:
+ uadk_poll = wd_ecc_poll;
+ break;
+ default:
+ HPRE_TST_PRT("<<<<<<async poll interface is NULL!\n");
+ return NULL;
+ }
+
+ while (last_time) {
+ ret = uadk_poll(expt, &recv);
+ count += recv;
+ recv = 0;
+ if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
+ HPRE_TST_PRT("poll ret: %d!\n", ret);
goto recv_error;
}
@@ -2451,7 +2554,10 @@ static int hpre_uadk_async_threads(struct acc_option *options)
threads_args[i].subtype = threads_option.subtype;
threads_args[i].td_id = i;
/* poll thread */
- ret = pthread_create(&pollid[i], NULL, hpre_uadk_poll, &threads_args[i]);
+ if (options->inittype == INIT2_TYPE)
+ ret = pthread_create(&pollid[i], NULL, hpre_uadk_poll2, &threads_args[i]);
+ else
+ ret = pthread_create(&pollid[i], NULL, hpre_uadk_poll, &threads_args[i]);
if (ret) {
HPRE_TST_PRT("Create poll thread fail!\n");
goto async_error;
@@ -2505,10 +2611,14 @@ int hpre_uadk_benchmark(struct acc_option *options)
return -EINVAL;
}
- ret = init_hpre_ctx_config(options->algclass, options->subtype,
- options->syncmode);
- if (ret)
+ if (options->inittype == INIT2_TYPE)
+ ret = init_hpre_ctx_config2(options);
+ else
+ ret = init_hpre_ctx_config(options);
+ if (ret) {
+ HPRE_TST_PRT("failed to init %s ctx, ret = %d!\n", options->algclass, ret);
return ret;
+ }
get_pid_cpu_time(&ptime);
time_start(options->times);
@@ -2520,7 +2630,10 @@ int hpre_uadk_benchmark(struct acc_option *options)
if (ret)
return ret;
- uninit_hpre_ctx_config(options->subtype);
+ if (options->inittype == INIT2_TYPE)
+ uninit_hpre_ctx_config2(options->subtype);
+ else
+ uninit_hpre_ctx_config(options->subtype);
return 0;
}
--
2.25.1

View File

@ -0,0 +1,43 @@
From 3fb56fddd367e6bcace4cc56a732002385c4be41 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:37 +0800
Subject: [PATCH 68/85] uadk_tool: use marco to replace numbers
Use marco to replace incomprehensible numbers.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 2 +-
uadk_tool/benchmark/zip_uadk_benchmark.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 9f1f903..88806ca 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -600,8 +600,8 @@ static void uninit_ctx_config2(int subtype)
static int init_ctx_config2(struct acc_option *options)
{
- char alg_name[64];
int subtype = options->subtype;
+ char alg_name[MAX_ALG_NAME];
int ret;
ret = get_alg_name(options->algtype, alg_name);
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 7b02df8..435c0b4 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -286,7 +286,7 @@ static void uninit_ctx_config2(void)
static int init_ctx_config2(struct acc_option *options)
{
- char alg_name[64];
+ char alg_name[MAX_ALG_NAME];
int ret = 0;
ret = get_alg_name(options->algtype, alg_name);
--
2.25.1

View File

@ -0,0 +1,211 @@
From 3881092b8832687b78498ecc8d509edd96c9d568 Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Fri, 10 Nov 2023 11:52:38 +0800
Subject: [PATCH 69/85] uadk_tool: support test case for aes cbc cts mode
Add test case for AES-CBC CTS mode, CS1/2/3, for both
uadk v1 and uadk v2 in uadk_tool benchmark tool.
Use param such as '--alg aes-128-cbc-cs1' to enable
cs1 mode test.
Use 'uadk_tool benchmark --alglist' to find the name
of other modes.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 54 ++++++++++++++++++++++++
uadk_tool/benchmark/sec_wd_benchmark.c | 54 ++++++++++++++++++++++++
uadk_tool/benchmark/uadk_benchmark.c | 18 ++++++++
uadk_tool/benchmark/uadk_benchmark.h | 9 ++++
4 files changed, 135 insertions(+)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 88806ca..1994ad0 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -190,6 +190,60 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
mode = WD_CIPHER_CBC;
alg = WD_CIPHER_AES;
break;
+ case AES_128_CBC_CS1:
+ keysize = 16;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS1;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_128_CBC_CS2:
+ keysize = 16;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS2;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_128_CBC_CS3:
+ keysize = 16;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS3;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS1:
+ keysize = 24;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS1;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS2:
+ keysize = 24;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS2;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS3:
+ keysize = 24;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS3;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS1:
+ keysize = 32;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS1;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS2:
+ keysize = 32;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS2;
+ alg = WD_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS3:
+ keysize = 32;
+ ivsize = 16;
+ mode = WD_CIPHER_CBC_CS3;
+ alg = WD_CIPHER_AES;
+ break;
case AES_128_CTR:
keysize = 16;
ivsize = 16;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index 3791792..aa36c22 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -256,6 +256,60 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options)
mode = WCRYPTO_CIPHER_CBC;
alg = WCRYPTO_CIPHER_AES;
break;
+ case AES_128_CBC_CS1:
+ keysize = 16;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS1;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_128_CBC_CS2:
+ keysize = 16;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS2;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_128_CBC_CS3:
+ keysize = 16;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS3;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS1:
+ keysize = 24;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS1;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS2:
+ keysize = 24;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS2;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_192_CBC_CS3:
+ keysize = 24;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS3;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS1:
+ keysize = 32;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS1;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS2:
+ keysize = 32;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS2;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
+ case AES_256_CBC_CS3:
+ keysize = 32;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_CBC_CS3;
+ alg = WCRYPTO_CIPHER_AES;
+ break;
case AES_128_CTR:
keysize = 16;
ivsize = 16;
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index 26b381e..ff95bea 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -92,6 +92,15 @@ static struct acc_alg_item alg_options[] = {
{"aes-128-cbc", AES_128_CBC},
{"aes-192-cbc", AES_192_CBC},
{"aes-256-cbc", AES_256_CBC},
+ {"aes-128-cbc-cs1", AES_128_CBC_CS1},
+ {"aes-128-cbc-cs2", AES_128_CBC_CS2},
+ {"aes-128-cbc-cs3", AES_128_CBC_CS3},
+ {"aes-192-cbc-cs1", AES_192_CBC_CS1},
+ {"aes-192-cbc-cs2", AES_192_CBC_CS2},
+ {"aes-192-cbc-cs3", AES_192_CBC_CS3},
+ {"aes-256-cbc-cs1", AES_256_CBC_CS1},
+ {"aes-256-cbc-cs2", AES_256_CBC_CS2},
+ {"aes-256-cbc-cs3", AES_256_CBC_CS3},
{"aes-128-ctr", AES_128_CTR},
{"aes-192-ctr", AES_192_CTR},
{"aes-256-ctr", AES_256_CTR},
@@ -171,6 +180,15 @@ static struct acc_alg_item alg_name_options[] = {
{"cbc(aes)", AES_128_CBC},
{"cbc(aes)", AES_192_CBC},
{"cbc(aes)", AES_256_CBC},
+ {"cbc-cs1(aes)", AES_128_CBC_CS1},
+ {"cbc-cs2(aes)", AES_128_CBC_CS2},
+ {"cbc-cs3(aes)", AES_128_CBC_CS3},
+ {"cbc-cs1(aes)", AES_192_CBC_CS1},
+ {"cbc-cs2(aes)", AES_192_CBC_CS2},
+ {"cbc-cs3(aes)", AES_192_CBC_CS3},
+ {"cbc-cs1(aes)", AES_256_CBC_CS1},
+ {"cbc-cs2(aes)", AES_256_CBC_CS2},
+ {"cbc-cs3(aes)", AES_256_CBC_CS3},
{"ctr(aes)", AES_128_CTR},
{"ctr(aes)", AES_192_CTR},
{"ctr(aes)", AES_256_CTR},
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 3a33fd8..c2ba9bc 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -143,6 +143,15 @@ enum test_alg {
AES_128_CBC,
AES_192_CBC,
AES_256_CBC,
+ AES_128_CBC_CS1,
+ AES_128_CBC_CS2,
+ AES_128_CBC_CS3,
+ AES_192_CBC_CS1,
+ AES_192_CBC_CS2,
+ AES_192_CBC_CS3,
+ AES_256_CBC_CS1,
+ AES_256_CBC_CS2,
+ AES_256_CBC_CS3,
AES_128_CTR,
AES_192_CTR,
AES_256_CTR,
--
2.25.1

View File

@ -0,0 +1,39 @@
From 7ee9dd2c72a1402b967c9be23d5773dbc3054071 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:39 +0800
Subject: [PATCH 70/85] uadk/tool: initialize cparams to zero
Initialize cparams to zero.
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 c8bfdf4..b00a933 100644
--- a/uadk_tool/test/test_sec.c
+++ b/uadk_tool/test/test_sec.c
@@ -1463,8 +1463,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)
@@ -2711,8 +2711,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

View File

@ -0,0 +1,28 @@
From 70d792b664ce9e5374f803335056643826985f47 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 10 Nov 2023 11:52:40 +0800
Subject: [PATCH 71/85] uadk_tool: fix the memory leak problem
After calling the wd_release_queue (*q),
call free(*q) to release the memory pointed to by q.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
uadk_tool/benchmark/sec_wd_benchmark.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index aa36c22..f34051e 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -733,6 +733,7 @@ static void uninit_wd_queue(void)
for (j = 0; j < g_thread_num; j++) {
wd_blkpool_destroy(g_thread_queue.bd_res[j].pool);
wd_release_queue(g_thread_queue.bd_res[j].queue);
+ free(g_thread_queue.bd_res[j].queue);
}
free(g_thread_queue.bd_res);
--
2.25.1

View File

@ -0,0 +1,104 @@
From baa660f648148440bc95a4c563d0f83e31afd380 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 10 Nov 2023 11:52:41 +0800
Subject: [PATCH 72/85] uadk_tool: fix error writing data to uninitialized
memory
After the memory is applied for, the memory
must be initialized before being written.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 14 ++++++++++----
uadk_tool/benchmark/sec_wd_benchmark.c | 1 +
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 1994ad0..7ccdb7e 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -756,6 +756,7 @@ static int init_ivkey_source(void)
int i, j, m, idx;
g_uadk_pool.iv = malloc(sizeof(char *) * g_thread_num);
+ memset(g_uadk_pool.iv, 0, sizeof(char *) * g_thread_num);
for (i = 0; i < g_thread_num; i++) {
g_uadk_pool.iv[i] = calloc(MAX_IVK_LENTH, sizeof(char));
if (!g_uadk_pool.iv[i])
@@ -763,6 +764,7 @@ static int init_ivkey_source(void)
}
g_uadk_pool.key = malloc(sizeof(char *) * g_thread_num);
+ memset(g_uadk_pool.key, 0, sizeof(char *) * g_thread_num);
for (j = 0; j < g_thread_num; j++) {
g_uadk_pool.key[j] = calloc(MAX_IVK_LENTH, sizeof(char));
if (!g_uadk_pool.key[j])
@@ -772,6 +774,7 @@ static int init_ivkey_source(void)
}
g_uadk_pool.hash = malloc(sizeof(char *) * g_thread_num);
+ memset(g_uadk_pool.hash, 0, sizeof(char *) * g_thread_num);
for (m = 0; m < g_thread_num; m++) {
g_uadk_pool.hash[m] = calloc(MAX_IVK_LENTH, sizeof(char));
if (!g_uadk_pool.hash[m])
@@ -832,22 +835,25 @@ static int init_uadk_bd_pool(void)
}
g_uadk_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
+ memset(g_uadk_pool.pool, 0, g_thread_num * sizeof(struct bd_pool));
if (!g_uadk_pool.pool) {
SEC_TST_PRT("init uadk pool alloc thread failed!\n");
goto free_ivkey;
} else {
for (i = 0; i < g_thread_num; i++) {
- g_uadk_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
- sizeof(struct uadk_bd));
+ g_uadk_pool.pool[i].bds = malloc(MAX_POOL_LENTH *sizeof(struct uadk_bd));
+ memset(g_uadk_pool.pool[i].bds, 0, MAX_POOL_LENTH *sizeof(struct uadk_bd));
if (!g_uadk_pool.pool[i].bds) {
SEC_TST_PRT("init uadk bds alloc failed!\n");
goto malloc_error1;
}
for (j = 0; j < MAX_POOL_LENTH; j++) {
g_uadk_pool.pool[i].bds[j].src = malloc(step);
+ memset(g_uadk_pool.pool[i].bds[j].src, 0, step);
if (!g_uadk_pool.pool[i].bds[j].src)
goto malloc_error2;
g_uadk_pool.pool[i].bds[j].dst = malloc(step);
+ memset(g_uadk_pool.pool[i].bds[j].dst, 0, step);
if (!g_uadk_pool.pool[i].bds[j].dst)
goto malloc_error3;
@@ -1097,7 +1103,7 @@ static void *sec_uadk_aead_async(void *arg)
struct wd_aead_sess_setup aead_setup = {0};
u8 *priv_iv, *priv_key, *priv_hash;
u32 auth_size = SEC_PERF_AUTH_SIZE;
- struct wd_aead_req areq;
+ struct wd_aead_req areq = {0};
struct bd_pool *uadk_pool;
int try_cnt = 0;
handle_t h_sess;
@@ -1328,7 +1334,7 @@ static void *sec_uadk_aead_sync(void *arg)
struct wd_aead_sess_setup aead_setup = {0};
u8 *priv_iv, *priv_key, *priv_hash;
u32 auth_size = SEC_PERF_AUTH_SIZE;
- struct wd_aead_req areq;
+ struct wd_aead_req areq = {0};
struct bd_pool *uadk_pool;
handle_t h_sess;
u32 count = 0;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index f34051e..e620c3c 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -587,6 +587,7 @@ static int init_wd_queue(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) {
g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
+ memset(g_thread_queue.bd_res[i].queue, 0, sizeof(struct wd_queue));
g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
// 0 is ENC, 1 is DEC
g_thread_queue.bd_res[i].queue->capa.priv.direction = options->optype;
--
2.25.1

View File

@ -0,0 +1,93 @@
From 12c7632bc6dbf9043c8c1e24177bd3b36aed8b57 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:42 +0800
Subject: [PATCH 73/85] uadk_tool: added sm4-xts GB test
Add testcase cmd sm4-128-xts-gb for sm4-xts GB.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 6 ++++++
uadk_tool/benchmark/sec_wd_benchmark.c | 6 ++++++
uadk_tool/benchmark/uadk_benchmark.c | 4 +++-
uadk_tool/benchmark/uadk_benchmark.h | 1 +
4 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 7ccdb7e..d6effe5 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -370,6 +370,12 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
mode = WD_CIPHER_XTS;
alg = WD_CIPHER_SM4;
break;
+ case SM4_128_XTS_GB:
+ keysize = 32;
+ ivsize = 16;
+ mode = WD_CIPHER_XTS_GB;
+ alg = WD_CIPHER_SM4;
+ break;
case AES_128_CCM:
keysize = 16;
ivsize = 16;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index e620c3c..6e5c8a0 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -436,6 +436,12 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options)
mode = WCRYPTO_CIPHER_XTS;
alg = WCRYPTO_CIPHER_SM4;
break;
+ case SM4_128_XTS_GB:
+ keysize = 32;
+ ivsize = 16;
+ mode = WCRYPTO_CIPHER_XTS_GB;
+ alg = WCRYPTO_CIPHER_SM4;
+ break;
case AES_128_CCM:
keysize = 16;
ivsize = 16;
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index ff95bea..6d5d009 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -122,6 +122,7 @@ static struct acc_alg_item alg_options[] = {
{"sm4-128-ofb", SM4_128_OFB},
{"sm4-128-cfb", SM4_128_CFB},
{"sm4-128-xts", SM4_128_XTS},
+ {"sm4-128-xts-gb", SM4_128_XTS_GB},
{"aes-128-ccm", AES_128_CCM},
{"aes-192-ccm", AES_192_CCM},
{"aes-256-ccm", AES_256_CCM},
@@ -210,6 +211,7 @@ static struct acc_alg_item alg_name_options[] = {
{"ofb(sm4)", SM4_128_OFB},
{"cfb(sm4)", SM4_128_CFB},
{"xts(sm4)", SM4_128_XTS},
+ {"xts(sm4)", SM4_128_XTS_GB},
{"ccm(aes)", AES_128_CCM},
{"ccm(aes)", AES_192_CCM},
{"ccm(aes)", AES_256_CCM},
@@ -482,7 +484,7 @@ static void parse_alg_param(struct acc_option *option)
snprintf(option->algclass, MAX_ALG_NAME, "%s", "ecdsa");
option->acctype = HPRE_TYPE;
option->subtype = ECDSA_TYPE;
- } else if (option->algtype <= SM4_128_XTS) {
+ } else if (option->algtype <= SM4_128_XTS_GB) {
snprintf(option->algclass, MAX_ALG_NAME, "%s", "cipher");
option->acctype = SEC_TYPE;
option->subtype = CIPHER_TYPE;
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index c2ba9bc..1cce63d 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -173,6 +173,7 @@ enum test_alg {
SM4_128_OFB,
SM4_128_CFB,
SM4_128_XTS,
+ SM4_128_XTS_GB,
AES_128_CCM, // aead
AES_192_CCM,
AES_256_CCM,
--
2.25.1

View File

@ -0,0 +1,45 @@
From 1628e0964d25ff490bb98d5de31338603420ce56 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 10 Nov 2023 11:52:43 +0800
Subject: [PATCH 74/85] uadk_tool: initialize the return value 'ret' of the
function
'ret' was used uninitialized in function init_ctx_config().
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
uadk_tool/benchmark/sec_uadk_benchmark.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index d6effe5..f1ae18b 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -516,12 +516,14 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
static int init_ctx_config(struct acc_option *options)
{
- struct sched_params param;
+ struct sched_params param = {0};
struct uacce_dev *dev = NULL;
char *alg = options->algclass;
int subtype = options->subtype;
int mode = options->syncmode;
- int ret, max_node, i;
+ int max_node = 0;
+ int ret = 0;
+ int i = 0;
max_node = numa_max_node() + 1;
if (max_node <= 0)
@@ -533,7 +535,6 @@ static int init_ctx_config(struct acc_option *options)
if (!g_ctx_cfg.ctxs)
return -ENOMEM;
- i = 0;
while (i < g_ctxnum) {
dev = wd_get_accel_dev(alg);
if (!dev) {
--
2.25.1

View File

@ -0,0 +1,43 @@
From 6ad3084be58e00c97d56e1dcf2507bd6519599fd Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 10 Nov 2023 11:52:44 +0800
Subject: [PATCH 75/85] add secure compilation option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add PIE、PIC、BIND_NOW、SP、NO Rpath/RunPath、FS、Ftrapv and Strip
to UADK compilation.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
uadk_tool/Makefile.am | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6b787f9..7f00087 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
-AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
+AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
-pthread
+AM_CFLAGS += -fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
+-O2 -ftrapv -Wl,-z,now -Wl,-s
#AUTOMAKE_OPTIONS = subdir-objects
@@ -33,8 +35,6 @@ 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',--enable-new-dtags
-
if WITH_ZLIB_FSE_DIR
AM_CFLAGS += -DZLIB_FSE
uadk_tool_LDADD+= $(with_zlib_fse_dir)/libfse.a
--
2.25.1

View File

@ -0,0 +1,36 @@
From 35d1a4ff23a7ed21d48e98e2264af61281323532 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:52 +0800
Subject: [PATCH 76/85] uadk/v1/drv: hisi_zip_udrv - fix unmap buffer for
lz77_zstd stream mode
In uadk v1, the library will alloc a ctx_buffer used for storing
stream information. On hisilicon platform, the hardware will output
some data to this buffer. So the ctx_buffer should be map to PA/IOVA.
But here the lz77_zstd forgot to unmap this buffer on error branch.
What's more, if the user use the wd_bmm ops, the unmap is a void
function.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
v1/drv/hisi_zip_udrv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c
index f820b7f..470acb9 100644
--- a/v1/drv/hisi_zip_udrv.c
+++ b/v1/drv/hisi_zip_udrv.c
@@ -512,6 +512,9 @@ static int fill_zip_addr_lz77_zstd(void *ssqe,
unmap_phy_seq:
drv_iova_unmap(q, zstd_out->literal, (void *)phy_lit, zstd_out->lit_sz);
unmap_phy_lit:
+ if (msg->stream_mode == WCRYPTO_COMP_STATEFUL)
+ drv_iova_unmap(q, msg->ctx_buf, (void *)addr.ctxbuf_addr - CTX_BUFFER_OFFSET,
+ MAX_CTX_RSV_SIZE);
drv_iova_unmap(q, msg->src, (void *)addr.source_addr, msg->in_size);
return -WD_ENOMEM;
}
--
2.25.1

View File

@ -0,0 +1,53 @@
From 51d9d531c5944e66d62f28f738f2f1b5aaf8373b Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:53 +0800
Subject: [PATCH 77/85] uadk/v1/drv: hisi_zip_udrv - fix the wrong unmapped
address
Some region is reserved for driver data in ctx_buf. So there is
a offset between the hardware ctx_buf and the original ctx_buf.
The unmapped address should be the original ctx_buf rather than
hardware ctx_buf.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
v1/drv/hisi_zip_udrv.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c
index 470acb9..dfd1fb3 100644
--- a/v1/drv/hisi_zip_udrv.c
+++ b/v1/drv/hisi_zip_udrv.c
@@ -126,6 +126,7 @@ static int qm_fill_zip_sqe_get_phy_addr(struct hisi_zip_sqe_addr *addr,
WD_ERR("Get zip in buf dma address fail!\n");
return -WD_ENOMEM;
}
+
if (!(is_lz77 && msg->data_fmt == WD_SGL_BUF)) {
phy_out = (uintptr_t)drv_iova_map(q, msg->dst, msg->avail_out);
if (!phy_out) {
@@ -296,8 +297,8 @@ int qm_parse_zip_sqe(void *hw_msg, const struct qm_queue_info *info,
phy_out = DMA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
drv_iova_unmap(q, recv_msg->dst, (void *)phy_out, recv_msg->avail_out);
if (recv_msg->ctx_buf) {
- phy_ctxbuf = DMA_ADDR(sqe->stream_ctx_addr_h,
- sqe->stream_ctx_addr_l);
+ phy_ctxbuf = DMA_ADDR(sqe->stream_ctx_addr_h, sqe->stream_ctx_addr_l) -
+ CTX_BUFFER_OFFSET;
drv_iova_unmap(q, recv_msg->ctx_buf, (void *)phy_ctxbuf,
MAX_CTX_RSV_SIZE);
}
@@ -727,8 +728,8 @@ int qm_parse_zip_sqe_v3(void *hw_msg, const struct qm_queue_info *info,
phy_out = DMA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
drv_iova_unmap(q, recv_msg->dst, (void *)phy_out, recv_msg->avail_out);
if (recv_msg->ctx_buf) {
- phy_ctxbuf = DMA_ADDR(sqe->stream_ctx_addr_h,
- sqe->stream_ctx_addr_l);
+ phy_ctxbuf = DMA_ADDR(sqe->stream_ctx_addr_h, sqe->stream_ctx_addr_l) -
+ CTX_BUFFER_OFFSET;
drv_iova_unmap(q, recv_msg->ctx_buf, (void *)phy_ctxbuf,
MAX_CTX_RSV_SIZE);
}
--
2.25.1

View File

@ -0,0 +1,29 @@
From 22869c48d92b607d6c4f13a282af3800244f975c Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:54 +0800
Subject: [PATCH 78/85] uadk/v1: wd_comp - fix unlocked queue resource change
Move the resource release into lock.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
v1/wd_comp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index f898c1d..fb9e413 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -192,8 +192,8 @@ free_ctx_buf:
free(ctx);
free_ctx_id:
wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM);
- wd_spinlock(&qinfo->qlock);
qinfo->ctx_num--;
+ wd_spinlock(&qinfo->qlock);
unlock:
wd_unspinlock(&qinfo->qlock);
return NULL;
--
2.25.1

View File

@ -0,0 +1,32 @@
From f84772417e6f7ec71539bf3ef8512055d9a659be Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:55 +0800
Subject: [PATCH 79/85] uadk/wd_alg - add registering driver parameters check
Add checks for some necessary parameters of dynamically registered
drivers.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
wd_alg.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/wd_alg.c b/wd_alg.c
index 8d88316..3b111c8 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -139,6 +139,11 @@ int wd_alg_driver_register(struct wd_alg_driver *drv)
return -WD_EINVAL;
}
+ if (!drv->init || !drv->exit || !drv->send || !drv->recv) {
+ WD_ERR("invalid: driver's parameter is NULL!\n");
+ return -WD_EINVAL;
+ }
+
new_alg = calloc(1, sizeof(struct wd_alg_list));
if (!new_alg) {
WD_ERR("failed to alloc alg driver memory!\n");
--
2.25.1

View File

@ -0,0 +1,75 @@
From 1dee88d833b6b6186cc63680efe452fd6621de9c Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:56 +0800
Subject: [PATCH 80/85] uadk: wd_comp - fix some comments
Update some comments.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
include/wd_comp.h | 20 ++++++++++----------
wd_comp.c | 3 +--
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 45b0d0b..45994ff 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -39,12 +39,12 @@ enum wd_comp_level {
WD_COMP_L7, /* Compression level 7 */
WD_COMP_L8, /* Compression level 8 */
WD_COMP_L9, /* Compression level 9 */
- WD_COMP_L10, /* Compression level 10 */
- WD_COMP_L11, /* Compression level 11 */
- WD_COMP_L12, /* Compression level 12 */
- WD_COMP_L13, /* Compression level 13 */
- WD_COMP_L14, /* Compression level 14 */
- WD_COMP_L15, /* Compression level 15 */
+ WD_COMP_L10, /* Compression level 10 */
+ WD_COMP_L11, /* Compression level 11 */
+ WD_COMP_L12, /* Compression level 12 */
+ WD_COMP_L13, /* Compression level 13 */
+ WD_COMP_L14, /* Compression level 14 */
+ WD_COMP_L15, /* Compression level 15 */
};
enum wd_comp_winsz_type {
@@ -72,10 +72,10 @@ struct wd_comp_req {
__u32 dst_len;
wd_alg_comp_cb_t *cb;
void *cb_param;
- enum wd_comp_op_type op_type; /* Denoted by wd_comp_op_type */
- enum wd_buff_type data_fmt; /* Denoted by wd_buff_type */
- __u32 last;
- __u32 status;
+ enum wd_comp_op_type op_type; /* denoted by wd_comp_op_type */
+ enum wd_buff_type data_fmt; /* denoted by wd_buff_type */
+ __u32 last; /* flag of last block for stream mode */
+ __u32 status; /* request error code */
void *priv;
};
diff --git a/wd_comp.c b/wd_comp.c
index 21c9928..6e71d35 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -494,7 +494,6 @@ static void fill_comp_msg(struct wd_comp_sess *sess, struct wd_comp_msg *msg,
msg->win_sz = sess->win_sz;
msg->avail_out = req->dst_len;
- /* if is last 1: flush end; other: sync flush */
msg->req.last = 1;
}
@@ -722,7 +721,7 @@ static int append_store_block(struct wd_comp_sess *sess,
memcpy(req->dst, store_block, blocksize);
req->dst_len = blocksize;
checksum = (__u32) cpu_to_be32(checksum);
- /* if zlib, ADLER32 */
+ /* if zlib, ADLER32 */
memcpy(req->dst + blocksize, &checksum, sizeof(checksum));
req->dst_len += sizeof(checksum);
} else if (sess->alg_type == WD_GZIP) {
--
2.25.1

View File

@ -0,0 +1,52 @@
From c1c93a8bf7694a5e73933e6434bcd2c6924f8a00 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Mon, 20 Nov 2023 15:21:57 +0800
Subject: [PATCH 81/85] uadk: fix the process when ctx request fails
When request ctx busy, the ctx needs to be applied again instead of
performing subsequent operations. In addition, add ctx checks,
if ctx is 0, return -WD_ENOMEM.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_util.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c
index a9640c3..8af0261 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -2418,6 +2418,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
struct wd_ctx_nums ctx_nums = attrs->ctx_params->ctx_set_num[op_type];
__u32 ctx_set_num = ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num;
struct wd_ctx_config *ctx_config = attrs->ctx_config;
+ __u32 count = idx + ctx_set_num;
struct uacce_dev *dev;
__u32 i;
@@ -2429,13 +2430,21 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
if (WD_IS_ERR(dev))
return WD_PTR_ERR(dev);
- for (i = idx; i < idx + ctx_set_num; i++) {
+ for (i = idx; i < count; i++) {
ctx_config->ctxs[i].ctx = wd_request_ctx(dev);
if (errno == WD_EBUSY) {
dev = wd_find_dev_by_numa(list, numa_id);
if (WD_IS_ERR(dev))
return WD_PTR_ERR(dev);
+
i--;
+ continue;
+ } else if (!ctx_config->ctxs[i].ctx) {
+ /*
+ * wd_release_ctx_set will release ctx in
+ * caller wd_init_ctx_and_sched.
+ */
+ return -WD_ENOMEM;
}
ctx_config->ctxs[i].op_type = op_type;
ctx_config->ctxs[i].ctx_mode =
--
2.25.1

View File

@ -0,0 +1,47 @@
From 29ee35cd6e2fd592730ce4374acce84f9c4b5c3f Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:58 +0800
Subject: [PATCH 82/85] uadk: wd_util - fix a theoretically infinite loop
In wd_init_ctx_set, it will try to get the ctx from the most
idle device. But requesting ctx from devices is an exclusive
behavior. And there is no lock to protect against multi-process
contention. In the worst situation, a process will always get
'EBUSY' from wd_request_ctx.
So here add a retry count to avoid a infinite loop.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
wd_util.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c
index 8af0261..bfa3af0 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -2420,7 +2420,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
struct wd_ctx_config *ctx_config = attrs->ctx_config;
__u32 count = idx + ctx_set_num;
struct uacce_dev *dev;
- __u32 i;
+ __u32 i, cnt = 0;
/* If the ctx set number is 0, the initialization is skipped. */
if (!ctx_set_num)
@@ -2437,6 +2437,12 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
if (WD_IS_ERR(dev))
return WD_PTR_ERR(dev);
+ if (cnt++ > WD_INIT_RETRY_TIMES) {
+ WD_ERR("failed to request enough ctx due to timeout!\n");
+ return -WD_ETIMEDOUT;
+ }
+
+ /* self-decrease i to eliminate self-increase on next loop */
i--;
continue;
} else if (!ctx_config->ctxs[i].ctx) {
--
2.25.1

View File

@ -0,0 +1,37 @@
From 99bc5eb28297945c496e8fb0d282e108978c22e7 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:21:59 +0800
Subject: [PATCH 83/85] uadk: wd - fix fscanf infinite loop
UADK supports registration of log to the rsyslog service.
So it will read the rsyslog.conf to user's log level.
Here use '%[^\n ] ' to divided the lines in file into
words to analysis.
But there is a problem if the first line in the file is
'\n'. The fscanf will return 0 and always read the first
line, which makes a infinite loop.
Add a whitespace before '%[^\n ] ' to filter the unintended '\n'.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
wd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd.c b/wd.c
index ddde38d..e88c993 100644
--- a/wd.c
+++ b/wd.c
@@ -79,7 +79,7 @@ static void wd_parse_log_level(void)
goto close_file;
}
- while (fscanf(in_file, "%[^\n ] ", file_contents) != EOF) {
+ while (fscanf(in_file, " %[^\n ] ", file_contents) != EOF) {
if (!strcmp("local5.debug", file_contents))
log_debug = true;
else if (!strcmp("local5.info", file_contents))
--
2.25.1

View File

@ -0,0 +1,30 @@
From 28af7936c6eebb6b18492cc128b905158fec56d9 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:22:00 +0800
Subject: [PATCH 84/85] uadk: zlibwrapper - fix wrong request check
Add the check on req.status to show users invalid requests.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
wd_zlibwrapper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index 7189b7f..afa8ee7 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -236,8 +236,8 @@ static int wd_zlib_do_request(z_streamp strm, int flush, enum wd_comp_op_type ty
req.last = (flush == Z_FINISH) ? 1 : 0;
ret = wd_do_comp_strm(h_sess, &req);
- if (unlikely(ret)) {
- WD_ERR("failed to do compress(%d)!\n", ret);
+ if (unlikely(ret || req.status == WD_IN_EPARA)) {
+ WD_ERR("failed to do compress, ret = %d, req.status = %u!\n", ret, req.status);
return Z_STREAM_ERROR;
}
--
2.25.1

View File

@ -0,0 +1,51 @@
From dafb286fe6ca5ba2a4ddf2381db1750b87dd3e1b Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 20 Nov 2023 15:22:01 +0800
Subject: [PATCH 85/85] uadk: drv/hisi - fix sgl copy offset error
The HiSilicon drivers support copy data between the pbuffer and sgl.
And it supports copying data from the specified domain of sgl.
There is a bug when the driver calculate the sgl address. It adds the
next sgl node length rather than the origin one. So if the sgl lengths
are not equal, the target node will be wrong.
Therefore, the driver should add the origin sgl length and then fetch
the next node.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
drv/hisi_qm_udrv.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index d86a692..13db3f0 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -972,20 +972,19 @@ void hisi_qm_sgl_copy(void *pbuff, void *hw_sgl, __u32 offset, __u32 size,
__u8 direct)
{
struct hisi_sgl *tmp = hw_sgl;
+ int begin_sge = 0, i;
__u32 sge_offset = 0;
__u32 len = 0;
- int begin_sge = 0;
- int i;
if (!pbuff || !size || !tmp)
return;
while (len + tmp->entry_size_in_sgl <= offset) {
+ len += tmp->entry_size_in_sgl;
+
tmp = (struct hisi_sgl *)tmp->next_dma;
if (!tmp)
return;
-
- len += tmp->entry_size_in_sgl;
}
/* find the start sge position and start offset */
--
2.25.1

View File

@ -0,0 +1,120 @@
From 4c08e19a760e2095a441e4f4e54449be090323c5 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 24 Nov 2023 11:53:49 +0800
Subject: [PATCH 086/114] uadk/v1/comp: add comp ctx parameters check
Add the check of ctx parameters before create ctx pool.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
v1/wd_comp.c | 75 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 58 insertions(+), 17 deletions(-)
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index f898c1d..154db19 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -56,6 +56,62 @@ static void fill_comp_msg(struct wcrypto_comp_ctx *ctx,
msg->status = 0;
}
+static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *setup)
+{
+ struct q_info *qinfo;
+
+ if (!q || !setup) {
+ WD_ERR("err: q or setup is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (strcmp(q->capa.alg, "zlib") &&
+ strcmp(q->capa.alg, "gzip") &&
+ strcmp(q->capa.alg, "deflate") &&
+ strcmp(q->capa.alg, "lz77_zstd")) {
+ WD_ERR("err: algorithm is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ qinfo = q->qinfo;
+ if (qinfo->ctx_num >= WD_MAX_CTX_NUM) {
+ WD_ERR("err: create too many compress ctx!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->alg_type >= WCRYPTO_COMP_MAX_ALG) {
+ WD_ERR("err: alg_type is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->comp_lv > WCRYPTO_COMP_L9) {
+ WD_ERR("err: comp_lv is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->op_type > WCRYPTO_INFLATE) {
+ WD_ERR("err: op_type is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->stream_mode > WCRYPTO_FINISH) {
+ WD_ERR("err: stream_mode is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->win_size > WCRYPTO_COMP_WS_32K) {
+ WD_ERR("err: win_size is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ if (setup->data_fmt > WD_SGL_BUF) {
+ WD_ERR("err: data_fmt is invalid!\n");
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
static int set_comp_ctx_br(struct q_info *qinfo, struct wd_mm_br *br)
{
if (!br->alloc || !br->free ||
@@ -126,18 +182,9 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q,
__u32 ctx_id = 0;
int ret;
- if (!q || !setup) {
- WD_ERR("err, input parameter invalid!\n");
- return NULL;
- }
-
- if (strcmp(q->capa.alg, "zlib") &&
- strcmp(q->capa.alg, "gzip") &&
- strcmp(q->capa.alg, "deflate") &&
- strcmp(q->capa.alg, "lz77_zstd")) {
- WD_ERR("algorithm mismatch!\n");
+ ret = ctx_params_check(q, setup);
+ if (ret)
return NULL;
- }
qinfo = q->qinfo;
@@ -150,11 +197,6 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q,
goto unlock;
}
- if (qinfo->ctx_num >= WD_MAX_CTX_NUM) {
- WD_ERR("err: create too many compress ctx!\n");
- goto unlock;
- }
-
ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, &ctx_id, 0,
WD_MAX_CTX_NUM);
if (ret) {
@@ -357,4 +399,3 @@ void wcrypto_del_comp_ctx(void *ctx)
free(cctx);
}
-
--
2.25.1

View File

@ -0,0 +1,409 @@
From f669f0bf233a1441fd98b4fc79400af2bbeae78f Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Fri, 24 Nov 2023 11:57:05 +0800
Subject: [PATCH 087/114] uadk/v1: check whether the data address pointer is
not null
The data address pointers were used without address verification,
which may cause null pointer risks.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
v1/wd_aead.c | 22 +++++++++++++++++-----
v1/wd_cipher.c | 22 +++++++++++++++++-----
v1/wd_comp.c | 10 +++++-----
v1/wd_dh.c | 6 +++---
v1/wd_digest.c | 19 +++++++++++++------
v1/wd_ecc.c | 8 ++++----
v1/wd_rng.c | 13 +++++++++----
v1/wd_rsa.c | 12 +++++++++---
v1/wd_util.c | 7 +++++++
v1/wd_util.h | 1 +
10 files changed, 85 insertions(+), 35 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index a82d51d..f688309 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -124,7 +124,7 @@ static int get_iv_block_size(int mode)
static int create_ctx_para_check(struct wd_queue *q,
struct wcrypto_aead_ctx_setup *setup)
{
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("input param is NULL\n");
return -WD_EINVAL;
}
@@ -542,26 +542,38 @@ static int param_check(struct wcrypto_aead_ctx *a_ctx,
void **tag, __u32 num)
{
__u32 i;
+ int ret;
if (unlikely(!a_ctx || !a_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) {
- WD_ERR("input param err!\n");
+ WD_ERR("invalid: input param err!\n");
return -WD_EINVAL;
}
for (i = 0; i < num; i++) {
if (unlikely(!a_opdata[i])) {
- WD_ERR("aead opdata[%u] is NULL!\n", i);
+ WD_ERR("invalid: aead opdata[%u] is NULL\n", i);
+ return -WD_EINVAL;
+ }
+
+ ret = wd_check_src_dst(a_opdata[i]->in, a_opdata[i]->in_bytes, a_opdata[i]->out, a_opdata[i]->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(!a_opdata[i]->iv)) {
+ WD_ERR("invalid: aead input iv is NULL!\n");
return -WD_EINVAL;
}
if (unlikely(tag && !tag[i])) {
- WD_ERR("tag[%u] is NULL!\n", i);
+ WD_ERR("invalid: tag[%u] is NULL!\n", i);
return -WD_EINVAL;
}
}
if (unlikely(tag && !a_ctx->setup.cb)) {
- WD_ERR("aead ctx call back is NULL!\n");
+ WD_ERR("invalid: aead ctx call back is NULL!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 3e6fb3d..60a0f25 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -107,7 +107,7 @@ static __u32 get_iv_block_size(int alg, int mode)
static int create_ctx_para_check(struct wd_queue *q,
struct wcrypto_cipher_ctx_setup *setup)
{
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("%s: input param err!\n", __func__);
return -WD_EINVAL;
}
@@ -426,26 +426,38 @@ static int param_check(struct wcrypto_cipher_ctx *c_ctx,
void **tag, __u32 num)
{
__u32 i;
+ int ret;
if (unlikely(!c_ctx || !c_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) {
- WD_ERR("input param err!\n");
+ WD_ERR("invalid: input param err!\n");
return -WD_EINVAL;
}
for (i = 0; i < num; i++) {
if (unlikely(!c_opdata[i])) {
- WD_ERR("cipher opdata[%u] is NULL!\n", i);
+ WD_ERR("invalid: cipher opdata[%u] is NULL!\n", i);
+ return -WD_EINVAL;
+ }
+
+ ret = wd_check_src_dst(c_opdata[i]->in, c_opdata[i]->in_bytes, c_opdata[i]->out, c_opdata[i]->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
+ if (c_ctx->setup.mode != WCRYPTO_CIPHER_ECB && !c_opdata[i]->iv) {
+ WD_ERR("invalid: cipher input iv is NULL!\n");
return -WD_EINVAL;
}
if (unlikely(tag && !tag[i])) {
- WD_ERR("tag[%u] is NULL!\n", i);
+ WD_ERR("invalid: tag[%u] is NULL!\n", i);
return -WD_EINVAL;
}
}
if (unlikely(tag && !c_ctx->setup.cb)) {
- WD_ERR("cipher ctx call back is NULL!\n");
+ WD_ERR("invalid: cipher ctx call back is NULL!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index 154db19..3d2fcf1 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -60,8 +60,8 @@ static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *s
{
struct q_info *qinfo;
- if (!q || !setup) {
- WD_ERR("err: q or setup is NULL!\n");
+ if (!q || !q->qinfo || !setup) {
+ WD_ERR("%s: input param err!\n", __func__);
return -WD_EINVAL;
}
@@ -255,8 +255,8 @@ int wcrypto_do_comp(void *ctx, struct wcrypto_comp_op_data *opdata, void *tag)
__u64 recv_count = 0;
int ret;
- if (!ctx || !opdata) {
- WD_ERR("input parameter err!\n");
+ if (unlikely(!ctx || !opdata || !opdata->in || !opdata->out)) {
+ WD_ERR("invalid: comp input parameter err!\n");
return -EINVAL;
}
@@ -267,7 +267,7 @@ int wcrypto_do_comp(void *ctx, struct wcrypto_comp_op_data *opdata, void *tag)
msg = &cookie->msg;
if (tag) {
if (!cctx->cb) {
- WD_ERR("ctx call back is null!\n");
+ WD_ERR("invalid: ctx call back is null!\n");
ret = -WD_EINVAL;
goto err_put_cookie;
}
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index 9ed0e0d..27bcb5a 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -56,7 +56,7 @@ struct wcrypto_dh_ctx {
static int create_ctx_param_check(struct wd_queue *q,
struct wcrypto_dh_ctx_setup *setup)
{
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("%s(): input parameter err!\n", __func__);
return -WD_EINVAL;
}
@@ -299,12 +299,12 @@ static int do_dh_prepare(struct wcrypto_dh_op_data *opdata,
int ret;
if (unlikely(!ctxt || !opdata)) {
- WD_ERR("input parameter err!\n");
+ WD_ERR("invalid: dh input parameter err!\n");
return -WD_EINVAL;
}
if (unlikely(tag && !ctxt->setup.cb)) {
- WD_ERR("ctx call back is null!\n");
+ WD_ERR("invalid: ctx call back is null!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index f6c8b84..b617350 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -89,7 +89,7 @@ static void del_ctx_key(struct wcrypto_digest_ctx *ctx)
static int create_ctx_para_check(struct wd_queue *q,
struct wcrypto_digest_ctx_setup *setup)
{
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("%s: input param err!\n", __func__);
return -WD_EINVAL;
}
@@ -377,6 +377,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
{
enum wcrypto_digest_alg alg;
__u32 i;
+ int ret;
if (unlikely(!d_ctx || !d_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) {
WD_ERR("input param err!\n");
@@ -387,7 +388,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
for (i = 0; i < num; i++) {
if (unlikely(!d_opdata[i])) {
- WD_ERR("digest opdata[%u] is NULL!\n", i);
+ WD_ERR("invalid: digest opdata[%u] is NULL!\n", i);
return -WD_EINVAL;
}
@@ -396,6 +397,12 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
return -WD_EINVAL;
}
+ ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, d_opdata[i]->out, d_opdata[i]->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
if (d_opdata[i]->has_next) {
if (unlikely(num != 1)) {
WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n");
@@ -414,8 +421,8 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
WD_ERR("failed to check digest mac length!\n");
return -WD_EINVAL;
}
- if (d_ctx->setup.alg == WCRYPTO_AES_GMAC &&
- d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN) {
+ if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC &&
+ (!d_opdata[i]->iv || d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN))) {
WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n",
d_opdata[i]->iv_bytes);
return -WD_EINVAL;
@@ -423,13 +430,13 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
}
if (unlikely(tag && !tag[i])) {
- WD_ERR("tag[%u] is NULL!\n", i);
+ WD_ERR("invalid: tag[%u] is NULL!\n", i);
return -WD_EINVAL;
}
}
if (unlikely(tag && !d_ctx->setup.cb)) {
- WD_ERR("digest ctx call back is NULL!\n");
+ WD_ERR("invalid: digest ctx call back is NULL!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index c4fab63..7650b2b 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -1006,7 +1006,7 @@ static bool is_key_width_support(__u32 key_bits)
static int param_check(struct wd_queue *q, struct wcrypto_ecc_ctx_setup *setup)
{
- if (unlikely(!q || !setup)) {
+ if (unlikely(!q || !q->qinfo || !setup)) {
WD_ERR("input parameter error!\n");
return -WD_EINVAL;
}
@@ -1663,7 +1663,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num)
int wcrypto_do_ecxdh(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag)
{
if (unlikely(!opdata)) {
- WD_ERR("do ecxdh: opdata null!\n");
+ WD_ERR("invalid: do ecxdh: opdata null!\n");
return -WD_EINVAL;
}
@@ -2176,7 +2176,7 @@ void wcrypto_get_ecdsa_sign_in_params(struct wcrypto_ecc_in *in,
int wcrypto_do_ecdsa(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag)
{
if (unlikely(!opdata)) {
- WD_ERR("do ecdsa: opdata null!\n");
+ WD_ERR("invalid: do ecdsa: opdata null!\n");
return -WD_EINVAL;
}
@@ -2463,7 +2463,7 @@ int wcrypto_do_sm2(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag)
struct wcrypto_ecc_in *in;
if (unlikely(!opdata)) {
- WD_ERR("do sm2: opdata null!\n");
+ WD_ERR("invalid: do sm2: opdata null!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index cc8a594..927665f 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -48,7 +48,7 @@ static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup,
struct q_info *qinfo;
int ret = -WD_EINVAL;
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("input parameter err!\n");
return ret;
}
@@ -202,8 +202,13 @@ static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr,
struct wcrypto_rng_msg *req;
int ret;
- if (!ctxt || !opdata) {
- WD_ERR("input parameter err!\n");
+ if (unlikely(!ctxt || !opdata)) {
+ WD_ERR("invalid: rng input parameter err!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely((opdata->in_bytes && !opdata->out))) {
+ WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n");
return -WD_EINVAL;
}
@@ -213,7 +218,7 @@ static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr,
if (tag) {
if (!ctxt->setup.cb) {
- WD_ERR("ctx call back is null!\n");
+ WD_ERR("invalid: ctx call back is null!\n");
wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
return -WD_EINVAL;
}
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
index 4a2a5b5..9e467d0 100644
--- a/v1/wd_rsa.c
+++ b/v1/wd_rsa.c
@@ -549,7 +549,7 @@ static void del_ctx(struct wcrypto_rsa_ctx *c)
static int check_q_setup(struct wd_queue *q, struct wcrypto_rsa_ctx_setup *setup)
{
- if (!q || !setup) {
+ if (!q || !q->qinfo || !setup) {
WD_ERR("create rsa ctx input parameter err!\n");
return -WD_EINVAL;
}
@@ -957,12 +957,18 @@ static int do_rsa_prepare(struct wcrypto_rsa_ctx *ctxt,
int ret;
if (unlikely(!ctxt || !opdata)) {
- WD_ERR("input parameter err!\n");
+ WD_ERR("invalid: input parameter err!\n");
+ return -WD_EINVAL;
+ }
+
+ ret = wd_check_src_dst(opdata->in, opdata->in_bytes, opdata->out, opdata->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
return -WD_EINVAL;
}
if (unlikely(tag && !ctxt->setup.cb)) {
- WD_ERR("ctx call back is null!\n");
+ WD_ERR("invalid: ctx call back is null!\n");
return -WD_EINVAL;
}
diff --git a/v1/wd_util.c b/v1/wd_util.c
index a1d08b4..f31d138 100644
--- a/v1/wd_util.c
+++ b/v1/wd_util.c
@@ -182,3 +182,10 @@ int wd_burst_recv(struct wd_queue *q, void **resp, __u32 num)
{
return drv_recv(q, resp, num);
}
+
+int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes)
+{
+ if (unlikely((in_bytes && !src) || (out_bytes && !dst)))
+ return -WD_EINVAL;
+ return 0;
+}
diff --git a/v1/wd_util.h b/v1/wd_util.h
index a8c6b15..bf17058 100644
--- a/v1/wd_util.h
+++ b/v1/wd_util.h
@@ -404,5 +404,6 @@ void drv_set_sgl_pri(struct wd_sgl *sgl, void *priv);
void *drv_get_sgl_pri(struct wd_sgl *sgl);
struct wd_mm_br *drv_get_br(void *pool);
void wd_sgl_memset(struct wd_sgl *sgl, int ch);
+int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes);
#endif
--
2.25.1

View File

@ -0,0 +1,66 @@
From 80f2ff4c5181dac5fc5dff113d06c4429d3aa029 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 16:51:02 +0800
Subject: [PATCH 088/114] uadk/v1: remove print actions after wd_get_cookies
Print information after wd_get_cookies returning EBUSY
can seriously affect performance,so remove it.
Signed-off-by: Wenkai Lin <linwenkai6hisilicon.com>
---
v1/wd_aead.c | 4 +---
v1/wd_cipher.c | 4 +---
v1/wd_digest.c | 4 +---
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index f688309..38429fc 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -593,10 +593,8 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **opdata,
return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num);
- if (unlikely(ret)) {
- WD_ERR("failed to get cookies %d!\n", ret);
+ if (unlikely(ret))
return ret;
- }
for (i = 0; i < num; i++) {
cookies[i]->tag.priv = opdata[i]->priv;
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 60a0f25..f95015d 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -477,10 +477,8 @@ int wcrypto_burst_cipher(void *ctx, struct wcrypto_cipher_op_data **c_opdata,
return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num);
- if (unlikely(ret)) {
- WD_ERR("failed to get cookies %d!\n", ret);
+ if (unlikely(ret))
return ret;
- }
for (i = 0; i < num; i++) {
cookies[i]->tag.priv = c_opdata[i]->priv;
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index b617350..b8ea5ce 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -456,10 +456,8 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata,
return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num);
- if (unlikely(ret)) {
- WD_ERR("failed to get cookies %d!\n", ret);
+ if (unlikely(ret))
return ret;
- }
for (i = 0; i < num; i++) {
cookies[i]->tag.priv = opdata[i]->priv;
--
2.25.1

View File

@ -0,0 +1,81 @@
From 2edce8cc047c73341d5fde1ec6639e3a61681f64 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 16:54:46 +0800
Subject: [PATCH 089/114] uadk: fix header file is not self contained
Header files are not self contained, fix it.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd.h | 1 +
include/wd_alg_common.h | 1 +
include/wd_cipher.h | 1 +
include/wd_sched.h | 1 +
include/wd_util.h | 2 ++
5 files changed, 6 insertions(+)
diff --git a/include/wd.h b/include/wd.h
index 0e67cad..6ee2ef5 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -7,6 +7,7 @@
#ifndef __WD_H
#define __WD_H
#include <errno.h>
+#include <numa.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index 77845a4..5652db3 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -9,6 +9,7 @@
#include <pthread.h>
#include <stdbool.h>
+#include <numa.h>
#include "wd.h"
#include "wd_alg.h"
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 7e63402..a712b53 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,6 +8,7 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
+#include <asm/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index a492d70..b145172 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,6 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
+#include <asm/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index be9798c..78c5d23 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -13,7 +13,9 @@
#include <sys/shm.h>
#include <asm/types.h>
+#include "wd.h"
#include "wd_sched.h"
+#include "wd_alg.h"
#ifdef __cplusplus
extern "C" {
--
2.25.1

View File

@ -0,0 +1,49 @@
From 5de69884dea416eea90b2f5a76ac1fcf1a70f8a9 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:00:48 +0800
Subject: [PATCH 090/114] uadk\sec: modify improper comments.
Modify or delete improper comments in uadk/sec module.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
wd_digest.c | 2 +-
wd_util.c | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/wd_digest.c b/wd_digest.c
index 2307bf1..bc67878 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -131,7 +131,7 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
int ret;
if (!key || !sess) {
- WD_ERR("failed to check key param!\n");
+ WD_ERR("invalid: failed to check input param, sess or key is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_util.c b/wd_util.c
index a9640c3..d1d4037 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -408,7 +408,6 @@ void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool)
pool->pool_num = 0;
}
-/* fix me: this is old wd_get_req_from_pool */
void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool,
int ctx_idx, __u32 tag)
{
@@ -1344,7 +1343,6 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
return head + offset;
}
-/* fix me: all return value here, and no config input */
int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
{
struct async_task_queue *task_queue;
--
2.25.1

View File

@ -0,0 +1,126 @@
From 81d5593a3f9f6e5c763f81f6e7d393dc5efda961 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:02:26 +0800
Subject: [PATCH 091/114] uadk: fixed some input parameter checking issues
Inside the asynchronous packet receiving interface of all submodules.
When the number of expected received packets is 0. Failure to intercept
will result in abnormal packet recycling.
As a result, the number of normal service packets does not match.
In addition, when the expected value is 0, it will cause the while loop
control adjustment to flip, resulting in other receiving operations.
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
wd_aead.c | 2 +-
wd_cipher.c | 2 +-
wd_comp.c | 4 ++--
wd_dh.c | 4 ++--
wd_digest.c | 2 +-
wd_ecc.c | 4 ++--
wd_rsa.c | 4 ++--
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c
index 87d61c3..ff43086 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -816,7 +816,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
+ if (unlikely(!count || !expt)) {
WD_ERR("invalid: aead poll ctx input param is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_cipher.c b/wd_cipher.c
index 58d34f7..0187c9c 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -730,7 +730,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
+ if (unlikely(!count || !expt)) {
WD_ERR("invalid: cipher poll ctx input param is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_comp.c b/wd_comp.c
index 21c9928..57e8b8f 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -340,8 +340,8 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
- WD_ERR("invalid: comp poll count is 0!\n");
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: comp poll count or expt is 0!\n");
return -WD_EINVAL;
}
diff --git a/wd_dh.c b/wd_dh.c
index 40a52e5..dac55ca 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -438,8 +438,8 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
- WD_ERR("invalid: count is NULL!\n");
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: dh poll count or expt is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_digest.c b/wd_digest.c
index bc67878..1f2b3b2 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -701,7 +701,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
+ if (unlikely(!count || !expt)) {
WD_ERR("invalid: digest poll ctx input param is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_ecc.c b/wd_ecc.c
index 4323e54..b5e7e36 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2272,8 +2272,8 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
- WD_ERR("invalid: param count is NULL!\n");
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: ecc poll param count or expt is NULL!\n");
return -WD_EINVAL;
}
diff --git a/wd_rsa.c b/wd_rsa.c
index 1813676..b71540f 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -495,8 +495,8 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (unlikely(!count)) {
- WD_ERR("invalid: param count is NULL!\n");
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: rsa poll count or expt is NULL!\n");
return -WD_EINVAL;
}
--
2.25.1

View File

@ -0,0 +1,197 @@
From 7a129d1ee851524a6166341c492e874705540ca2 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:05:32 +0800
Subject: [PATCH 092/114] uadk: code cleanup
Add the input pointer checking.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
include/wd_util.h | 12 ++++++++++++
wd.c | 2 +-
wd_aead.c | 11 +++++++++++
wd_cipher.c | 11 +++++++++++
wd_digest.c | 8 +++++++-
wd_sched.c | 14 ++++++++++++--
wd_util.c | 8 ++++++++
7 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index 78c5d23..3059ac1 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -235,6 +235,18 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx,
void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int ctx_idx,
__u32 tag);
+/*
+ * wd_check_src_dst() - Check the request input and output
+ * @src: input data pointer.
+ * @in_bytes: input data length.
+ * @dst: output data pointer.
+ * @out_bytes: output data length.
+ *
+ * Return -WD_EINVAL when in_bytes or out_bytes is non-zero, the
+ * corresponding input or output pointers is NULL, otherwise return 0.
+ */
+int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes);
+
/*
* wd_check_datalist() - Check the data list length
* @head: Data list's head pointer.
diff --git a/wd.c b/wd.c
index ddde38d..a6e207d 100644
--- a/wd.c
+++ b/wd.c
@@ -756,7 +756,7 @@ struct uacce_dev *wd_find_dev_by_numa(struct uacce_dev_list *list, int numa_id)
}
while (p) {
- if (numa_id != p->dev->numa_id) {
+ if (p->dev && numa_id != p->dev->numa_id) {
p = p->next;
continue;
}
diff --git a/wd_aead.c b/wd_aead.c
index ff43086..6d49d76 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -361,6 +361,11 @@ static int wd_aead_param_check(struct wd_aead_sess *sess,
return -WD_EINVAL;
}
+ if (unlikely(!req->iv || !req->mac)) {
+ WD_ERR("invalid: aead input iv or mac is NULL!\n");
+ return -WD_EINVAL;
+ }
+
if (unlikely(sess->cmode == WD_CIPHER_CBC && req->in_bytes == 0)) {
WD_ERR("aead input data length is zero!\n");
return -WD_EINVAL;
@@ -384,6 +389,12 @@ static int wd_aead_param_check(struct wd_aead_sess *sess,
return -WD_EINVAL;
}
+ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
if (req->data_fmt == WD_SGL_BUF) {
len = req->in_bytes + req->assoc_bytes;
ret = wd_check_datalist(req->list_src, len);
diff --git a/wd_cipher.c b/wd_cipher.c
index 0187c9c..47c0bf8 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -542,6 +542,11 @@ static int cipher_iv_len_check(struct wd_cipher_req *req,
if (sess->mode == WD_CIPHER_ECB)
return 0;
+ if (!req->iv) {
+ WD_ERR("invalid: cipher input iv is NULL!\n");
+ ret = -WD_EINVAL;
+ }
+
switch (sess->alg) {
case WD_CIPHER_AES:
case WD_CIPHER_SM4:
@@ -589,6 +594,12 @@ static int wd_cipher_check_params(handle_t h_sess,
return -WD_EINVAL;
}
+ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
if (req->data_fmt == WD_SGL_BUF) {
ret = wd_check_datalist(req->list_src, req->in_bytes);
if (unlikely(ret)) {
diff --git a/wd_digest.c b/wd_digest.c
index 1f2b3b2..9008bcb 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -514,12 +514,18 @@ static int wd_digest_param_check(struct wd_digest_sess *sess,
return ret;
if (unlikely(sess->alg == WD_DIGEST_AES_GMAC &&
- req->iv_bytes != GMAC_IV_LEN)) {
+ (!req->iv || req->iv_bytes != GMAC_IV_LEN))) {
WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n",
req->iv_bytes);
return -WD_EINVAL;
}
+ ret = wd_check_src_dst(req->in, req->in_bytes, req->out, req->out_bytes);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: in/out addr is NULL when in/out size is non-zero!\n");
+ return -WD_EINVAL;
+ }
+
if (req->data_fmt == WD_SGL_BUF) {
ret = wd_check_datalist(req->list_in, req->in_bytes);
if (unlikely(ret)) {
diff --git a/wd_sched.c b/wd_sched.c
index d1c829f..7aeea73 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -311,8 +311,8 @@ static int session_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *
__u16 i;
int ret;
- if (unlikely(!count || !sched_ctx)) {
- WD_ERR("invalid: sched ctx is NULL or count is zero!\n");
+ if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) {
+ WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n");
return -WD_EINVAL;
}
@@ -375,6 +375,11 @@ static int sched_none_poll_policy(handle_t h_sched_ctx,
__u32 poll_num = 0;
int ret;
+ if (!sched_ctx || !sched_ctx->poll_func) {
+ WD_ERR("invalid: sched ctx or poll_func is NULL!\n");
+ return -WD_EINVAL;
+ }
+
while (loop_times > 0) {
/* Default use ctx 0 */
loop_times--;
@@ -417,6 +422,11 @@ static int sched_single_poll_policy(handle_t h_sched_ctx,
__u32 poll_num = 0;
int ret;
+ if (!sched_ctx || !sched_ctx->poll_func) {
+ WD_ERR("invalid: sched ctx or poll_func is NULL!\n");
+ return -WD_EINVAL;
+ }
+
while (loop_times > 0) {
/* Default async mode use ctx 0 */
loop_times--;
diff --git a/wd_util.c b/wd_util.c
index d1d4037..10b0ab9 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -459,6 +459,14 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag)
__atomic_clear(&p->used[tag - 1], __ATOMIC_RELEASE);
}
+int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes)
+{
+ if ((in_bytes && !src) || (out_bytes && !dst))
+ return -WD_EINVAL;
+
+ return 0;
+}
+
int wd_check_datalist(struct wd_datalist *head, __u32 size)
{
struct wd_datalist *tmp = head;
--
2.25.1

View File

@ -0,0 +1,431 @@
From e0ace2af02926648ec44070ac3b5e5328365f849 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:08:58 +0800
Subject: [PATCH 093/114] uadk: fix sec send and recv check failed
The send and recv pointers should be assigned at the beginning,
not during wd initialization.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_sec.c | 260 ++++++++++++++++++++++++++++---------------------
1 file changed, 149 insertions(+), 111 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 03e7037..9bf7e68 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -539,12 +539,93 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = {
static int hisi_sec_init(struct wd_alg_driver *drv, void *conf);
static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+
+static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+
+static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+
+static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_cipher_send(drv, ctx, msg);
+ return hisi_sec_cipher_send_v3(drv, ctx, msg);
+}
+
+static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_cipher_recv(drv, ctx, msg);
+ return hisi_sec_cipher_recv_v3(drv, ctx, msg);
+}
+
+static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_digest_send(drv, ctx, msg);
+ return hisi_sec_digest_send_v3(drv, ctx, msg);
+}
+
+static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_digest_recv(drv, ctx, msg);
+ return hisi_sec_digest_recv_v3(drv, ctx, msg);
+}
+
+static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_aead_send(drv, ctx, msg);
+ return hisi_sec_aead_send_v3(drv, ctx, msg);
+}
+
+static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info q_info = qp->q_info;
+
+ if (q_info.hw_type == HISI_QM_API_VER2_BASE)
+ return hisi_sec_aead_recv(drv, ctx, msg);
+ return hisi_sec_aead_recv_v3(drv, ctx, msg);
+}
+
static int hisi_sec_get_usage(void *param)
{
return 0;
}
-#define GEN_SEC_ALG_DRIVER(sec_alg_name) \
+#define GEN_SEC_ALG_DRIVER(sec_alg_name, alg_type) \
{\
.drv_name = "hisi_sec2",\
.alg_name = (sec_alg_name),\
@@ -555,57 +636,59 @@ static int hisi_sec_get_usage(void *param)
.fallback = 0,\
.init = hisi_sec_init,\
.exit = hisi_sec_exit,\
+ .send = alg_type##_send,\
+ .recv = alg_type##_recv,\
.get_usage = hisi_sec_get_usage,\
}
static struct wd_alg_driver cipher_alg_driver[] = {
- GEN_SEC_ALG_DRIVER("ecb(aes)"),
- GEN_SEC_ALG_DRIVER("cbc(aes)"),
- GEN_SEC_ALG_DRIVER("xts(aes)"),
- GEN_SEC_ALG_DRIVER("ecb(sm4)"),
- GEN_SEC_ALG_DRIVER("cbc(sm4)"),
- GEN_SEC_ALG_DRIVER("ctr(sm4)"),
- GEN_SEC_ALG_DRIVER("xts(sm4)"),
- GEN_SEC_ALG_DRIVER("ecb(des)"),
- GEN_SEC_ALG_DRIVER("cbc(des)"),
- GEN_SEC_ALG_DRIVER("ecb(des3_ede)"),
- GEN_SEC_ALG_DRIVER("cbc(des3_ede)"),
-
- GEN_SEC_ALG_DRIVER("ctr(aes)"),
- GEN_SEC_ALG_DRIVER("ofb(aes)"),
- GEN_SEC_ALG_DRIVER("cfb(aes)"),
- GEN_SEC_ALG_DRIVER("cbc-cs1(aes)"),
- GEN_SEC_ALG_DRIVER("cbc-cs2(aes)"),
- GEN_SEC_ALG_DRIVER("cbc-cs3(aes)"),
- GEN_SEC_ALG_DRIVER("ofb(sm4)"),
- GEN_SEC_ALG_DRIVER("cfb(sm4)"),
- GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)"),
- GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)"),
- GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)"),
+ GEN_SEC_ALG_DRIVER("ecb(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("xts(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("ecb(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("ctr(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("xts(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("ecb(des)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc(des)", cipher),
+ GEN_SEC_ALG_DRIVER("ecb(des3_ede)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc(des3_ede)", cipher),
+
+ GEN_SEC_ALG_DRIVER("ctr(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("ofb(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("cfb(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs1(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs2(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs3(aes)", cipher),
+ GEN_SEC_ALG_DRIVER("ofb(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("cfb(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)", cipher),
+ GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)", cipher),
};
static struct wd_alg_driver digest_alg_driver[] = {
- GEN_SEC_ALG_DRIVER("sm3"),
- GEN_SEC_ALG_DRIVER("md5"),
- GEN_SEC_ALG_DRIVER("sha1"),
- GEN_SEC_ALG_DRIVER("sha224"),
- GEN_SEC_ALG_DRIVER("sha256"),
- GEN_SEC_ALG_DRIVER("sha384"),
- GEN_SEC_ALG_DRIVER("sha512"),
- GEN_SEC_ALG_DRIVER("sha512-224"),
- GEN_SEC_ALG_DRIVER("sha512-256"),
- GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)"),
- GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)"),
- GEN_SEC_ALG_DRIVER("cmac(aes)"),
- GEN_SEC_ALG_DRIVER("gmac(aes)"),
+ GEN_SEC_ALG_DRIVER("sm3", digest),
+ GEN_SEC_ALG_DRIVER("md5", digest),
+ GEN_SEC_ALG_DRIVER("sha1", digest),
+ GEN_SEC_ALG_DRIVER("sha224", digest),
+ GEN_SEC_ALG_DRIVER("sha256", digest),
+ GEN_SEC_ALG_DRIVER("sha384", digest),
+ GEN_SEC_ALG_DRIVER("sha512", digest),
+ GEN_SEC_ALG_DRIVER("sha512-224", digest),
+ GEN_SEC_ALG_DRIVER("sha512-256", digest),
+ GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)", digest),
+ GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)", digest),
+ GEN_SEC_ALG_DRIVER("cmac(aes)", digest),
+ GEN_SEC_ALG_DRIVER("gmac(aes)", digest),
};
static struct wd_alg_driver aead_alg_driver[] = {
- GEN_SEC_ALG_DRIVER("ccm(aes)"),
- GEN_SEC_ALG_DRIVER("gcm(aes)"),
- GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))"),
- GEN_SEC_ALG_DRIVER("ccm(sm4)"),
- GEN_SEC_ALG_DRIVER("gcm(sm4)"),
+ GEN_SEC_ALG_DRIVER("ccm(aes)", aead),
+ GEN_SEC_ALG_DRIVER("gcm(aes)", aead),
+ GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))", aead),
+ GEN_SEC_ALG_DRIVER("ccm(sm4)", aead),
+ GEN_SEC_ALG_DRIVER("gcm(sm4)", aead),
};
static void dump_sec_msg(void *msg, const char *alg)
@@ -1092,10 +1175,10 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
return 0;
}
-int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
+static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_cipher_msg *msg = cipher_msg;
+ struct wd_cipher_msg *msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
int ret;
@@ -1137,10 +1220,10 @@ int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_m
return 0;
}
-int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
+static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_cipher_msg *recv_msg = cipher_msg;
+ struct wd_cipher_msg *recv_msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
int ret;
@@ -1295,10 +1378,10 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
return 0;
}
-int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
+static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_cipher_msg *msg = cipher_msg;
+ struct wd_cipher_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -1385,10 +1468,10 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "cipher");
}
-int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
+static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_cipher_msg *recv_msg = cipher_msg;
+ struct wd_cipher_msg *recv_msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -1658,10 +1741,10 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
return 0;
}
-int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_digest_msg *msg = digest_msg;
+ struct wd_digest_msg *msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
__u8 scene;
@@ -1725,10 +1808,10 @@ put_sgl:
return ret;
}
-int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_digest_msg *recv_msg = digest_msg;
+ struct wd_digest_msg *recv_msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
int ret;
@@ -1902,10 +1985,10 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe,
sqe->bd_param |= (__u16)(de | scene);
}
-int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_digest_msg *msg = digest_msg;
+ struct wd_digest_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -2001,10 +2084,10 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "digest");
}
-int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_digest_msg *recv_msg = digest_msg;
+ struct wd_digest_msg *recv_msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -2473,10 +2556,10 @@ int aead_msg_state_check(struct wd_aead_msg *msg)
return 0;
}
-int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
+static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_aead_msg *msg = aead_msg;
+ struct wd_aead_msg *msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
int ret;
@@ -2595,10 +2678,10 @@ static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg)
qp->q_info.qp_mode == CTX_MODE_SYNC;
}
-int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
+static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_aead_msg *recv_msg = aead_msg;
+ struct wd_aead_msg *recv_msg = wd_msg;
struct hisi_sec_sqe sqe;
__u16 count = 0;
int ret;
@@ -2857,10 +2940,10 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
return 0;
}
-int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
+static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_aead_msg *msg = aead_msg;
+ struct wd_aead_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -2957,10 +3040,10 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "aead");
}
-int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
+static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
- struct wd_aead_msg *recv_msg = aead_msg;
+ struct wd_aead_msg *recv_msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
int ret;
@@ -2985,50 +3068,6 @@ int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_ms
return 0;
}
-static void hisi_sec_driver_adapter(struct hisi_qp *qp)
-{
- struct hisi_qm_queue_info q_info = qp->q_info;
- int alg_num, i;
-
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) {
- WD_INFO("hisi sec init HIP08!\n");
- alg_num = ARRAY_SIZE(cipher_alg_driver);
- for (i = 0; i < alg_num; i++) {
- cipher_alg_driver[i].send = hisi_sec_cipher_send;
- cipher_alg_driver[i].recv = hisi_sec_cipher_recv;
- }
-
- alg_num = ARRAY_SIZE(digest_alg_driver);
- for (i = 0; i < alg_num; i++) {
- digest_alg_driver[i].send = hisi_sec_digest_send;
- digest_alg_driver[i].recv = hisi_sec_digest_recv;
- }
- alg_num = ARRAY_SIZE(aead_alg_driver);
- for (i = 0; i < alg_num; i++) {
- aead_alg_driver[i].send = hisi_sec_aead_send;
- aead_alg_driver[i].recv = hisi_sec_aead_recv;
- }
- } else {
- WD_INFO("hisi sec init HIP09!\n");
- alg_num = ARRAY_SIZE(cipher_alg_driver);
- for (i = 0; i < alg_num; i++) {
- cipher_alg_driver[i].send = hisi_sec_cipher_send_v3;
- cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3;
- }
-
- alg_num = ARRAY_SIZE(digest_alg_driver);
- for (i = 0; i < alg_num; i++) {
- digest_alg_driver[i].send = hisi_sec_digest_send_v3;
- digest_alg_driver[i].recv = hisi_sec_digest_recv_v3;
- }
- alg_num = ARRAY_SIZE(aead_alg_driver);
- for (i = 0; i < alg_num; i++) {
- aead_alg_driver[i].send = hisi_sec_aead_send_v3;
- aead_alg_driver[i].recv = hisi_sec_aead_recv_v3;
- }
- }
-}
-
static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
{
struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv;
@@ -3069,7 +3108,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
config->ctxs[i].sqn = qm_priv.sqn;
}
memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- hisi_sec_driver_adapter((struct hisi_qp *)h_qp);
drv->priv = priv;
return 0;
--
2.25.1

View File

@ -0,0 +1,94 @@
From 90511556722f51dcd6a6a4172943ee32e52db267 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:12:17 +0800
Subject: [PATCH 094/114] uadk: code cleanup for error codes and variable type
Unify the use of error return name. Modify the variable
type in hisi_sec to reduce variable conversion.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
drv/hisi_sec.c | 12 ++++++------
wd.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 9bf7e68..2f03d1f 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -517,12 +517,12 @@ struct hisi_sec_sqe3 {
__le32 counter;
} __attribute__((packed, aligned(4)));
-static int g_digest_a_alg[WD_DIGEST_TYPE_MAX] = {
+static __u32 g_digest_a_alg[WD_DIGEST_TYPE_MAX] = {
A_ALG_SM3, A_ALG_MD5, A_ALG_SHA1, A_ALG_SHA256, A_ALG_SHA224,
A_ALG_SHA384, A_ALG_SHA512, A_ALG_SHA512_224, A_ALG_SHA512_256
};
-static int g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = {
+static __u32 g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = {
A_ALG_HMAC_SM3, A_ALG_HMAC_MD5, A_ALG_HMAC_SHA1,
A_ALG_HMAC_SHA256, A_ALG_HMAC_SHA224, A_ALG_HMAC_SHA384,
A_ALG_HMAC_SHA512, A_ALG_HMAC_SHA512_224, A_ALG_HMAC_SHA512_256,
@@ -1518,7 +1518,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
if (msg->mode == WD_DIGEST_NORMAL)
sqe->type2.mac_key_alg |=
- (__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET;
+ g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET;
else if (msg->mode == WD_DIGEST_HMAC) {
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
WD_ERR("failed to check digest key_bytes, size = %u\n",
@@ -1530,7 +1530,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->key;
sqe->type2.mac_key_alg |=
- (__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
+ g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
} else {
WD_ERR("failed to check digest mode, mode = %u\n", msg->mode);
return -WD_EINVAL;
@@ -1887,7 +1887,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
if (msg->mode == WD_DIGEST_NORMAL) {
sqe->auth_mac_key |=
- (__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
+ g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
} else if (msg->mode == WD_DIGEST_HMAC) {
ret = hmac_key_len_check(msg);
if (ret)
@@ -1897,7 +1897,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
WORD_BYTES) << SEC_AKEY_OFFSET_V3;
sqe->a_key_addr = (__u64)(uintptr_t)msg->key;
sqe->auth_mac_key |=
- (__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
+ g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
if (msg->alg == WD_DIGEST_AES_GMAC) {
sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3;
diff --git a/wd.c b/wd.c
index a6e207d..be374f5 100644
--- a/wd.c
+++ b/wd.c
@@ -228,7 +228,7 @@ static int get_dev_info(struct uacce_dev *dev)
return ret;
else if (value == 1) {
WD_ERR("skip isolated uacce device!\n");
- return -ENODEV;
+ return -WD_ENODEV;
}
}
@@ -237,7 +237,7 @@ static int get_dev_info(struct uacce_dev *dev)
return ret;
else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) {
WD_ERR("skip none sva uacce device!\n");
- return -ENODEV;
+ return -WD_ENODEV;
}
ret = get_int_attr(dev, "region_mmio_size", &value);
--
2.25.1

View File

@ -0,0 +1,37 @@
From f118a291c4aacebf60c3c532d004581d125df6a1 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 17:14:45 +0800
Subject: [PATCH 095/114] uadk/sec: add a return value judgement
Add return value judgement of aead_get_aes_key_len().
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
drv/hisi_sec.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 2f03d1f..9102a27 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -2152,6 +2152,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
case WD_CIPHER_AES:
sqe->type2.c_alg = C_ALG_AES;
ret = aead_get_aes_key_len(msg, &c_key_len);
+ if (ret)
+ return ret;
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
break;
default:
@@ -2721,6 +2723,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
case WD_CIPHER_AES:
sqe->c_mode_alg |= C_ALG_AES << SEC_CALG_OFFSET_V3;
ret = aead_get_aes_key_len(msg, &c_key_len);
+ if (ret)
+ return ret;
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
break;
default:
--
2.25.1

View File

@ -0,0 +1,31 @@
From 697b131a5a08586fb731c160c89c86e107f11984 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:17:22 +0800
Subject: [PATCH 096/114] uadk: Add file association
Add wd_comp file to zip.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
Makefile.am | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 657ed20..e9ec47a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -121,9 +121,9 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma
libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL)
libwd_crypto_la_DEPENDENCIES= libwd.la
-libhisi_zip_la_LIBADD= -lwd -ldl
+libhisi_zip_la_LIBADD= -lwd -ldl -lwd_comp
libhisi_zip_la_LDFLAGS=$(UADK_VERSION)
-libhisi_zip_la_DEPENDENCIES= libwd.la
+libhisi_zip_la_DEPENDENCIES= libwd.la libwd_comp.la
libhisi_sec_la_LIBADD= -lwd -lwd_crypto
libhisi_sec_la_LDFLAGS=$(UADK_VERSION)
--
2.25.1

View File

@ -0,0 +1,39 @@
From 044afdf1f90573c3a44187f7759461f496bf7bf8 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:18:43 +0800
Subject: [PATCH 097/114] uadk: fix the failure process bug
After a failure message is returned due to a calloc exception,
the mp-ref count must be decreased by 1. Otherwise, an infinite
loop occurs when the process invokes the mp command to destroy
the process and cannot exit.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
wd_mempool.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wd_mempool.c b/wd_mempool.c
index cb8c80b..ed107d1 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -573,7 +573,7 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
bp = calloc(1, sizeof(struct blkpool));
if (!bp) {
WD_ERR("failed to alloc memory for blkpool!\n");
- return (handle_t)(-WD_ENOMEM);
+ goto err_sub_ref;
}
bp->top = block_num;
@@ -597,6 +597,7 @@ err_free_mem:
free_mem_to_mempool(bp);
err_free_bp:
free(bp);
+err_sub_ref:
wd_atomic_sub(&mp->ref, 1);
return (handle_t)(-WD_ENOMEM);
}
--
2.25.1

View File

@ -0,0 +1,28 @@
From f7a2fb057185759708d8b9712608150c9dccafef Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:20:38 +0800
Subject: [PATCH 098/114] uadk: fix the failure process bug
After the sem_post operation of full_sem fails, it need to
restore empty_sem to ensure that resources are available.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
wd_util.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/wd_util.c b/wd_util.c
index 10b0ab9..4867d63 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1398,6 +1398,7 @@ err_out:
task_queue->cur_task--;
task_queue->prod = curr_prod;
pthread_mutex_unlock(&task_queue->lock);
+ sem_post(&task_queue->empty_sem);
return ret;
}
--
2.25.1

View File

@ -0,0 +1,36 @@
From 9de8de67355430cfa9764109655af988cb7c031e Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:23:32 +0800
Subject: [PATCH 099/114] uadk: fix the failure process+bug
Assign numa_num to sched_ctx before err_out
for wd_scheduling_rr_release release memoryc orrectly.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
wd_sched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_sched.c b/wd_sched.c
index 7aeea73..419280e 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -642,6 +642,7 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
WD_ERR("failed to alloc memory for sched_ctx!\n");
goto err_out;
}
+ sched_ctx->numa_num = numa_num;
sched->h_sched_ctx = (handle_t)sched_ctx;
if (sched_type == SCHED_POLICY_NONE ||
@@ -662,7 +663,6 @@ simple_ok:
sched_ctx->poll_func = func;
sched_ctx->policy = sched_type;
sched_ctx->type_num = type_num;
- sched_ctx->numa_num = numa_num;
memset(sched_ctx->numa_map, -1, sizeof(int) * NUMA_NUM_NODES);
sched->sched_init = sched_table[sched_type].sched_init;
--
2.25.1

28
0100-uadk-bugfix.patch Normal file
View File

@ -0,0 +1,28 @@
From bf5a2e34368228538436a3856fd69167a6897516 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:25:47 +0800
Subject: [PATCH 100/114] uadk: bugfix
Replace strncpy with memcpy to avoid compilation warnings.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
wd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd.c b/wd.c
index be374f5..b08abab 100644
--- a/wd.c
+++ b/wd.c
@@ -426,7 +426,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
wd_ctx_init_qfrs_offs(ctx);
- strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
+ memcpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
return (handle_t)ctx;
--
2.25.1

View File

@ -0,0 +1,39 @@
From 111d3b3688063ec0f40171f837f0f0bde68b7e25 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:29:22 +0800
Subject: [PATCH 101/114] uadk v1: adapter code cleanup
Delete unnecessary processing.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
v1/wd_adapter.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 6b0b4d8..6e95562 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -209,9 +209,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, tmp);
if (ptr == MAP_FAILED) {
- int value = errno;
-
- WD_ERR("wd drv mmap fail!(err =%d)\n", value);
+ WD_ERR("wd drv mmap fail!(err = %d)\n", errno);
return NULL;
}
@@ -219,7 +217,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
qinfo->ss_size = tmp;
tmp = 0;
while (ret > 0) {
- info = (unsigned long)i;
+ info = i;
ret = ioctl(qinfo->fd, WD_UACCE_CMD_GET_SS_DMA, &info);
if (ret < 0) {
drv_show_ss_slices(q);
--
2.25.1

View File

@ -0,0 +1,40 @@
From f99c4bfe4aec8110043bd88df0f52b47ed8e05e8 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:30:23 +0800
Subject: [PATCH 102/114] uadk v1: fix wd_rng resource release bug
Before wd_free_id and ctx_num are released, check
whether ctx_num is less than or equal to 0 to
avoid repeated release.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
v1/wd_rng.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index 927665f..24a4b7a 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -144,14 +144,14 @@ void wcrypto_del_rng_ctx(void *ctx)
wd_uninit_cookie_pool(&cx->pool);
wd_spinlock(&qinfo->qlock);
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1,
- WD_MAX_CTX_NUM);
- qinfo->ctx_num--;
- if (qinfo->ctx_num < 0) {
+ if (qinfo->ctx_num <= 0) {
wd_unspinlock(&qinfo->qlock);
WD_ERR("repeat delete trng ctx!\n");
return;
}
+ qinfo->ctx_num--;
+ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1,
+ WD_MAX_CTX_NUM);
wd_unspinlock(&qinfo->qlock);
free(ctx);
--
2.25.1

View File

@ -0,0 +1,235 @@
From 294719db475aeb6f13dbc8b364b6ce1e48846f40 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:33:19 +0800
Subject: [PATCH 103/114] uadk v1: code cleanup for error codes and header
files
Unify the use of error return name. Adjusting the
sequence of header files.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
v1/wd.c | 63 +++++++++++++++++++++++++++++----------------------------
1 file changed, 32 insertions(+), 31 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c
index 3839304..26e7af3 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -14,18 +14,18 @@
* limitations under the License.
*/
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/ioctl.h>
-#include <errno.h>
#include <sys/mman.h>
-#include <string.h>
-#include <dirent.h>
#include <sys/poll.h>
-#include <limits.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "v1/wd_util.h"
#include "v1/wd_adapter.h"
@@ -94,12 +94,12 @@ static int get_raw_attr(const char *dev_root, const char *attr,
fd = open(attr_path, O_RDONLY, 0);
if (fd < 0) {
WD_ERR("open %s fail, errno = %d!\n", attr_path, errno);
- return -ENODEV;
+ return -WD_ENODEV;
}
size = read(fd, buf, sz);
if (size <= 0) {
WD_ERR("read nothing at %s!\n", attr_path);
- size = -ENODEV;
+ size = -WD_ENODEV;
}
close(fd);
@@ -214,7 +214,7 @@ static bool is_weight_more(unsigned int new, unsigned int old)
ins_old = GET_AVAILABLE_INSTANCES(old);
dis_old = GET_NODE_DISTANCE(old);
- dbg("dis_new %u, ins_new %u,dis_old %u, ins_old %u\n",
+ dbg("dis_new %u, ins_new %u, dis_old %u, ins_old %u\n",
dis_new, ins_new, dis_old, ins_old);
if (dis_new > dis_old)
@@ -240,16 +240,16 @@ static int get_int_attr_all(struct dev_info *dinfo)
/* ret == 1 means device has been isolated */
ret = get_int_attr(dinfo, "isolate");
if (ret < 0)
- return -ENODEV;
+ return -WD_ENODEV;
else if (ret == 1)
- return -EBUSY;
+ return -WD_EBUSY;
/* ret == 0 means device has no available queues */
ret = get_int_attr(dinfo, "available_instances");
if (ret < 0)
- return -ENODEV;
+ return -WD_ENODEV;
else if (ret == 0)
- return -EBUSY;
+ return -WD_EBUSY;
dinfo->available_instances = ret;
@@ -318,13 +318,13 @@ static int get_dev_info(struct dev_info *dinfo, const char *alg)
LINUX_DEV_DIR, dinfo->name);
if (ret <= 0) {
WD_ERR("snprintf err, ret %d!\n", ret);
- return -EINVAL;
+ return -WD_EINVAL;
}
ret = access(buf, F_OK);
if (ret < 0) {
WD_ERR("failed to check file path %s, ret: %d\n", buf, ret);
- return -ENODEV;
+ return -WD_ENODEV;
}
ret = get_str_attr_all(dinfo, alg);
@@ -407,7 +407,7 @@ static int get_denoted_dev(struct wd_capa *capa, const char *dev,
if (!get_dev_info(dinfop, capa->alg))
return 0;
WD_ERR("%s not available, will try other devices\n", dev);
- return -ENODEV;
+ return -WD_ENODEV;
}
static int find_available_dev(struct dev_info *dinfop,
@@ -425,7 +425,7 @@ static int find_available_dev(struct dev_info *dinfop,
wd_class = opendir(WD_UACCE_CLASS_DIR);
if (!wd_class) {
WD_ERR("WD framework is not enabled on the system, errno = %d!\n", errno);
- return -ENODEV;
+ return -WD_ENODEV;
}
while (true) {
@@ -444,7 +444,7 @@ static int find_available_dev(struct dev_info *dinfop,
find_node = true;
break;
}
- } else if (ret == -EPFNOSUPPORT || ret == -EBUSY || ret == -ENODEV) {
+ } else if (ret == -EPFNOSUPPORT || ret == -WD_EBUSY || ret == -WD_ENODEV) {
continue;
} else {
closedir(wd_class);
@@ -470,12 +470,12 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop,
if (dev[0] && dev[0] != '/' && !strstr(dev, "../")) {
if (!dinfop) {
WD_ERR("dinfop NULL!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
if (q->node_mask) {
WD_ERR("dev and node cannot be denoted together!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
if (!get_denoted_dev(capa, dev, dinfop))
@@ -485,7 +485,7 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop,
ret = find_available_dev(dinfop, capa, q->node_mask);
if (ret <= 0 && dinfop) {
WD_ERR("get /%s path fail!\n", dinfop->name);
- return -ENODEV;
+ return -WD_ENODEV;
}
if (num) {
@@ -496,14 +496,14 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop,
dev_path:
if (!dinfop) {
WD_ERR("dinfop NULL!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
ret = snprintf(q->dev_path, PATH_STR_SIZE, "%s/%s",
LINUX_DEV_DIR, dinfop->name);
if (ret <= 0) {
WD_ERR("snprintf err, ret %d!\n", ret);
- return -EINVAL;
+ return -WD_EINVAL;
}
return 0;
}
@@ -654,7 +654,7 @@ int wd_send(struct wd_queue *q, void *req)
{
if (unlikely(!q || !req)) {
WD_ERR("wd send input parameter null!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
return wd_burst_send(q, &req, 1);
}
@@ -663,7 +663,7 @@ int wd_recv(struct wd_queue *q, void **resp)
{
if (unlikely(!q || !resp)) {
WD_ERR("wd recv input parameter null!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
return wd_burst_recv(q, resp, 1);
}
@@ -676,11 +676,11 @@ int wd_wait(struct wd_queue *q, __u16 ms)
int ret;
if (unlikely(!q))
- return -EINVAL;
+ return -WD_EINVAL;
priv = &q->capa.priv;
if (unlikely(!priv->is_poll))
- return -EINVAL;
+ return -WD_EINVAL;
qinfo = q->qinfo;
fds[0].fd = qinfo->fd;
@@ -688,7 +688,7 @@ int wd_wait(struct wd_queue *q, __u16 ms)
ret = poll(fds, 1, ms);
if (unlikely(ret < 0))
- return -ENODEV;
+ return -WD_ENODEV;
/* return 0 for no data, 1 for new message */
return ret;
@@ -735,7 +735,7 @@ int wd_share_reserved_memory(struct wd_queue *q,
/* Just share DMA memory from 'q' in NO-IOMMU mode */
if (qinfo->iommu_type) {
WD_ERR("IOMMU opened, not support share mem!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
if (qinfo->iommu_type != tqinfo->iommu_type) {
@@ -871,6 +871,7 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
else
munmap(addr, size);
}
+
int wd_register_log(wd_log log)
{
if (!log) {
--
2.25.1

View File

@ -0,0 +1,160 @@
From 98c371e0c0ff955befb8a10a9b426bb5c0aea776 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:35:02 +0800
Subject: [PATCH 104/114] uadk: concentrate the same definitions
The sec algorithm has multiple common header files,
so they are centrally stored in wd_alg_common.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
drv/hisi_sec.c | 11 ++---------
include/wd_alg_common.h | 13 +++++++++++++
include/wd_cipher.h | 1 -
include/wd_digest.h | 2 --
wd_aead.c | 9 ---------
wd_cipher.c | 7 -------
wd_digest.c | 9 ---------
7 files changed, 15 insertions(+), 37 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 9102a27..5b114f6 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -63,13 +63,6 @@
#define SEC_MAC_LEN_MASK 0x1F
#define SEC_AUTH_LEN_MASK 0x3F
-#define DES_KEY_SIZE 8
-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define AES_KEYSIZE_128 16
-#define AES_KEYSIZE_192 24
-#define AES_KEYSIZE_256 32
-
#define DES3_BLOCK_SIZE 8
#define AES_BLOCK_SIZE 16
#define CTR_128BIT_COUNTER 16
@@ -823,9 +816,9 @@ static void update_iv_sgl(struct wd_cipher_msg *msg)
static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
{
- if (msg->key_bytes == SEC_3DES_2KEY_SIZE) {
+ if (msg->key_bytes == DES3_2KEY_SIZE) {
*c_key_len = CKEY_LEN_3DES_2KEY;
- } else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) {
+ } else if (msg->key_bytes == DES3_3KEY_SIZE) {
*c_key_len = CKEY_LEN_3DES_3KEY;
} else {
WD_ERR("failed to check 3des key size, size = %u\n",
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index 5652db3..32b8630 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -29,6 +29,19 @@ extern "C" {
#define CTX_TYPE_INVALID 9999
#define POLL_TIME 1000
+/* Key size of chiper */
+#define MAX_CIPHER_KEY_SIZE 64
+#define AES_KEYSIZE_128 16
+#define AES_KEYSIZE_192 24
+#define AES_KEYSIZE_256 32
+#define SM4_KEY_SIZE 16
+#define DES_KEY_SIZE 8
+#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE)
+#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
+
+/* Key size of digest */
+#define MAX_HMAC_KEY_SIZE 128U
+
enum alg_task_type {
TASK_MIX = 0x0,
TASK_HW,
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index a712b53..d54f7fe 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -18,7 +18,6 @@ extern "C" {
#define AES_BLOCK_SIZE 16
#define GCM_IV_SIZE 12
#define DES3_BLOCK_SIZE 8
-#define MAX_CIPHER_KEY_SIZE 64
#define MAX_IV_SIZE AES_BLOCK_SIZE
/**
diff --git a/include/wd_digest.h b/include/wd_digest.h
index ad4d579..f0916c3 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -14,8 +14,6 @@
extern "C" {
#endif
-#define MAX_HMAC_KEY_SIZE 128U
-
/**
* wd_digest_type - Algorithm type of digest
* algorithm should be offered by struct wd_digest_arg
diff --git a/wd_aead.c b/wd_aead.c
index 6d49d76..34a3b86 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -10,15 +10,6 @@
#include "include/drv/wd_aead_drv.h"
#include "wd_aead.h"
-#define XTS_MODE_KEY_DIVISOR 2
-#define SM4_KEY_SIZE 16
-#define DES_KEY_SIZE 8
-#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define AES_KEYSIZE_128 16
-#define AES_KEYSIZE_192 24
-#define AES_KEYSIZE_256 32
-
#define WD_AEAD_CCM_GCM_MIN 4U
#define WD_AEAD_CCM_GCM_MAX 16
diff --git a/wd_cipher.c b/wd_cipher.c
index 47c0bf8..f35ce6f 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -13,13 +13,6 @@
#define XTS_MODE_KEY_SHIFT 1
#define XTS_MODE_KEY_LEN_MASK 0x1
-#define SM4_KEY_SIZE 16
-#define DES_KEY_SIZE 8
-#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define AES_KEYSIZE_128 16
-#define AES_KEYSIZE_192 24
-#define AES_KEYSIZE_256 32
#define DES_WEAK_KEY_NUM 16
diff --git a/wd_digest.c b/wd_digest.c
index 9008bcb..acf341a 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -10,16 +10,7 @@
#include "include/drv/wd_digest_drv.h"
#include "wd_digest.h"
-#define XTS_MODE_KEY_DIVISOR 2
-#define SM4_KEY_SIZE 16
-#define DES_KEY_SIZE 8
-#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
#define GMAC_IV_LEN 16
-#define AES_KEYSIZE_128 16
-#define AES_KEYSIZE_192 24
-#define AES_KEYSIZE_256 32
-
-#define DES_WEAK_KEY_NUM 4
static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
--
2.25.1

View File

@ -0,0 +1,133 @@
From 6ca1f2190a37490b5dc84f04f70cca945355da1e Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:36:12 +0800
Subject: [PATCH 105/114] uadk v1: optimize the function length
The number of lines in the param_check function exceeds 50,
so subfunctions are added for optimization.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
v1/wd_digest.c | 83 ++++++++++++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 30 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index b8ea5ce..df8a8af 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -371,21 +371,62 @@ static int digest_recv_sync(struct wcrypto_digest_ctx *d_ctx,
return recv_count;
}
+static int stream_mode_param_check(struct wcrypto_digest_ctx *d_ctx,
+ struct wcrypto_digest_op_data *d_opdata, __u32 num)
+{
+ enum wcrypto_digest_alg alg = d_ctx->setup.alg;
+
+ if (unlikely(num != 1)) {
+ WD_ERR("invalid: wcrypto_burst_digest does not support stream mode, num = %u!\n",
+ num);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(d_opdata->in_bytes % d_ctx->align_sz)) {
+ WD_ERR("invalid: digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(d_opdata->out_bytes < g_digest_mac_full_len[alg])) {
+ WD_ERR("invalid: digest stream mode out buffer space is not enough!\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
+static int block_mode_param_check(struct wcrypto_digest_ctx *d_ctx,
+ struct wcrypto_digest_op_data *d_opdata)
+{
+ enum wcrypto_digest_alg alg = d_ctx->setup.alg;
+
+ if (unlikely(d_opdata->out_bytes > g_digest_mac_len[alg])) {
+ WD_ERR("invalid: failed to check digest mac length!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC &&
+ (!d_opdata->iv || d_opdata->iv_bytes != SEC_GMAC_IV_LEN))) {
+ WD_ERR("invalid: failed to check digest aes_gmac iv length, iv_bytes = %u\n",
+ d_opdata->iv_bytes);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
static int param_check(struct wcrypto_digest_ctx *d_ctx,
struct wcrypto_digest_op_data **d_opdata,
void **tag, __u32 num)
{
- enum wcrypto_digest_alg alg;
__u32 i;
int ret;
if (unlikely(!d_ctx || !d_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) {
- WD_ERR("input param err!\n");
+ WD_ERR("invalid: input param err!\n");
return -WD_EINVAL;
}
- alg = d_ctx->setup.alg;
-
for (i = 0; i < num; i++) {
if (unlikely(!d_opdata[i])) {
WD_ERR("invalid: digest opdata[%u] is NULL!\n", i);
@@ -397,37 +438,19 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
return -WD_EINVAL;
}
- ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, d_opdata[i]->out, d_opdata[i]->out_bytes);
+ ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes,
+ d_opdata[i]->out, d_opdata[i]->out_bytes);
if (unlikely(ret)) {
WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
return -WD_EINVAL;
}
- if (d_opdata[i]->has_next) {
- if (unlikely(num != 1)) {
- WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n");
- return -WD_EINVAL;
- }
- if (unlikely(d_opdata[i]->in_bytes % d_ctx->align_sz)) {
- WD_ERR("digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz);
- return -WD_EINVAL;
- }
- if (unlikely(d_opdata[i]->out_bytes < g_digest_mac_full_len[alg])) {
- WD_ERR("digest stream mode out buffer space is not enough!\n");
- return -WD_EINVAL;
- }
- } else {
- if (unlikely(d_opdata[i]->out_bytes > g_digest_mac_len[alg])) {
- WD_ERR("failed to check digest mac length!\n");
- return -WD_EINVAL;
- }
- if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC &&
- (!d_opdata[i]->iv || d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN))) {
- WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n",
- d_opdata[i]->iv_bytes);
- return -WD_EINVAL;
- }
- }
+ if (d_opdata[i]->has_next)
+ ret = stream_mode_param_check(d_ctx, d_opdata[i], num);
+ else
+ ret = block_mode_param_check(d_ctx, d_opdata[i]);
+ if (unlikely(ret))
+ return ret;
if (unlikely(tag && !tag[i])) {
WD_ERR("invalid: tag[%u] is NULL!\n", i);
--
2.25.1

View File

@ -0,0 +1,159 @@
From 0580da2ecffbd20a392c987e28a0d164c6aa2b56 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 4 Dec 2023 17:37:24 +0800
Subject: [PATCH 106/114] uadk v1: concentrate the same definitions
The sec algorithm has multiple common header files,
so they are centrally stored in wd_alg_common.
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
v1/drv/hisi_sec_udrv.c | 11 ++---------
v1/wd_aead.c | 15 ---------------
v1/wd_cipher.c | 9 +--------
v1/wd_digest.c | 1 -
v1/wd_util.h | 17 +++++++++++++++++
5 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
index 02a63c2..d046327 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -31,10 +31,6 @@
#include "config.h"
#include "hisi_sec_udrv.h"
-#define DES_KEY_SIZE 8
-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-
#define SEC_HW_TASK_DONE 1
#define SEC_HW_ICV_ERR 0x2
#define SEC_SM4_XTS_GB_V3 0x1
@@ -47,11 +43,8 @@
#define CTR_128BIT_COUNTER 16
#define CTR_128BIT_FLIP 0x2
#define DIF_VERIFY_FAIL 2
-#define AES_BLOCK_SIZE 16
#define WCRYPTO_CIPHER_THEN_DIGEST 0
#define WCRYPTO_DIGEST_THEN_CIPHER 1
-#define CBC_3DES_BLOCK_SIZE 8
-#define CBC_AES_BLOCK_SIZE 16
#define AEAD_IV_MAX_BYTES 64
#define MAX_CCM_AAD_LEN 65279
#define SEC_GMAC_IV_LEN 16
@@ -111,9 +104,9 @@ static int get_aes_c_key_len(__u8 mode, __u16 key_bytes, __u8 *c_key_len)
static int get_3des_c_key_len(struct wcrypto_cipher_msg *msg, __u8 *c_key_len)
{
- if (msg->key_bytes == SEC_3DES_2KEY_SIZE)
+ if (msg->key_bytes == DES3_2KEY_SIZE)
*c_key_len = CKEY_LEN_3DES_2KEY;
- else if (msg->key_bytes == SEC_3DES_3KEY_SIZE)
+ else if (msg->key_bytes == DES3_3KEY_SIZE)
*c_key_len = CKEY_LEN_3DES_3KEY;
else {
WD_ERR("Invalid 3DES key size!\n");
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index 38429fc..380daf0 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -26,24 +26,9 @@
#include "wd_util.h"
#include "wd_aead.h"
-#define MAX_AEAD_KEY_SIZE 64
-#define MAX_AEAD_MAC_SIZE 64
-#define MAX_CIPHER_KEY_SIZE 64
#define MAX_AEAD_AUTH_SIZE 64
-#define MAX_AEAD_ASSOC_SIZE 65536
-#define MAX_HMAC_KEY_SIZE 128
#define MAX_AEAD_RETRY_CNT 20000000
-#define DES_KEY_SIZE 8
-#define SM4_KEY_SIZE 16
-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-
-#define AES_BLOCK_SIZE 16
-#define GCM_BLOCK_SIZE 12
-
-#define MAX_BURST_NUM 16
-
static int g_aead_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = {
WCRYPTO_SM3_LEN, WCRYPTO_MD5_LEN, WCRYPTO_SHA1_LEN,
WCRYPTO_SHA256_LEN, WCRYPTO_SHA224_LEN,
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index f95015d..0877993 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -26,17 +26,10 @@
#include "v1/wd_util.h"
#include "v1/wd_cipher.h"
-#define MAX_CIPHER_KEY_SIZE 64
#define MAX_CIPHER_RETRY_CNT 20000000
#define XTS_MODE_KEY_LEN_MASK 0x1
-#define DES_KEY_SIZE 8
-#define SM4_KEY_SIZE 16
-#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE)
-#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define CBC_3DES_BLOCK_SIZE 8
-#define CBC_AES_BLOCK_SIZE 16
#define DES_WEAK_KEY_NUM 4
static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {0x0101010101010101, 0xFEFEFEFEFEFEFEFE,
0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E};
@@ -300,7 +293,7 @@ static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup,
ret = -WD_EINVAL;
break;
case WCRYPTO_CIPHER_3DES:
- if ((key_len != SEC_3DES_2KEY_SIZE) && (key_len != SEC_3DES_3KEY_SIZE))
+ if ((key_len != DES3_2KEY_SIZE) && (key_len != DES3_3KEY_SIZE))
ret = -WD_EINVAL;
break;
default:
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index df8a8af..cb9b6e0 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -26,7 +26,6 @@
#include "wd_util.h"
#include "wd_digest.h"
-#define MAX_HMAC_KEY_SIZE 128
#define MAX_DIGEST_RETRY_CNT 20000000
#define SEC_SHA1_ALIGN_SZ 64
#define SEC_SHA512_ALIGN_SZ 128
diff --git a/v1/wd_util.h b/v1/wd_util.h
index bf17058..9e5fa90 100644
--- a/v1/wd_util.h
+++ b/v1/wd_util.h
@@ -76,6 +76,23 @@
#define X_DH_OUT_PARAM_NUM 1
#define X_DH_HW_KEY_PARAM_NUM 3
+/* Key size and block size of aead */
+#define MAX_AEAD_KEY_SIZE 64
+#define GCM_BLOCK_SIZE 12
+
+/* Key size and block size of chiper */
+#define MAX_CIPHER_KEY_SIZE 64
+#define AES_BLOCK_SIZE 16
+#define DES_KEY_SIZE 8
+#define SM4_KEY_SIZE 16
+#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE)
+#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
+#define CBC_AES_BLOCK_SIZE 16
+#define CBC_3DES_BLOCK_SIZE 8
+
+/* Key size and block size of digest */
+#define MAX_HMAC_KEY_SIZE 128
+
#define X_DH_OUT_PARAMS_SZ(hsz) ((hsz) * X_DH_OUT_PARAM_NUM)
#define X_DH_HW_KEY_SZ(hsz) ((hsz) * X_DH_HW_KEY_PARAM_NUM)
#define SM2_KG_OUT_PARAMS_SZ(hsz) ((hsz) * SM2_KG_OUT_PARAM_NUM)
--
2.25.1

View File

@ -0,0 +1,87 @@
From d465cfbe854a2b0719de48e9973f1a3aa091c3f7 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Thu, 30 Nov 2023 15:51:26 +0800
Subject: [PATCH 107/114] v1/hpre: fix key transfer error issue
Currently, the RSA algorithm calls qm_crypto_bin_to_hpre_bin() to
transfer the key when sending request. However, the key
needs to be transferred only once, repeated transfer may cause
data inconsistency with original user's data, resulting in
incorrect calculation results.
Therefore, after the key is transferred, the 'dsize' is changed to
the 'bsize', When 'disze' and 'bsize' are equal, no transfer is performed.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
v1/drv/hisi_hpre_udrv.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 193ba56..0d0c3b4 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -136,27 +136,32 @@ static int qm_fill_rsa_crt_prikey2(struct wcrypto_rsa_prikey *prikey,
wd_dq->bsize, wd_dq->dsize, "rsa crt dq");
if (unlikely(ret))
return ret;
+ wd_dq->dsize = wd_dq->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_dp->data, (const char *)wd_dp->data,
wd_dp->bsize, wd_dp->dsize, "rsa crt dp");
if (unlikely(ret))
return ret;
+ wd_dp->dsize = wd_dp->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_q->data, (const char *)wd_q->data,
wd_q->bsize, wd_q->dsize, "rsa crt q");
if (unlikely(ret))
return ret;
+ wd_q->dsize = wd_q->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_p->data,
(const char *)wd_p->data, wd_p->bsize, wd_p->dsize, "rsa crt p");
if (unlikely(ret))
return ret;
+ wd_p->dsize = wd_p->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_qinv->data,
(const char *)wd_qinv->data, wd_qinv->bsize,
wd_qinv->dsize, "rsa crt qinv");
if (unlikely(ret))
return ret;
+ wd_qinv->dsize = wd_qinv->bsize;
*data = wd_dq->data;
return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
@@ -179,11 +184,13 @@ static int qm_fill_rsa_prikey1(struct wcrypto_rsa_prikey *prikey, void **data)
wd_d->bsize, wd_d->dsize, "rsa prikey1 d");
if (unlikely(ret))
return ret;
+ wd_d->dsize = wd_d->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data,
wd_n->bsize, wd_n->dsize, "rsa prikey1 n");
if (unlikely(ret))
return ret;
+ wd_n->dsize = wd_n->bsize;
*data = wd_d->data;
return (int)(wd_n->bsize + wd_d->bsize);
@@ -200,11 +207,13 @@ static int qm_fill_rsa_pubkey(struct wcrypto_rsa_pubkey *pubkey, void **data)
wd_e->bsize, wd_e->dsize, "rsa pubkey e");
if (unlikely(ret))
return ret;
+ wd_e->dsize = wd_e->dsize;
ret = qm_crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data,
wd_n->bsize, wd_n->dsize, "rsa pubkey n");
if (unlikely(ret))
return ret;
+ wd_n->dsize = wd_n->dsize;
*data = wd_e->data;
return (int)(wd_n->bsize + wd_e->bsize);
--
2.25.1

View File

@ -0,0 +1,87 @@
From 40a78df99ab6e13ca8a2fda51a885c089c811f2e Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Thu, 30 Nov 2023 16:40:39 +0800
Subject: [PATCH 108/114] uadk/hisi_hpre: fix key transfer error issue
Currently, the RSA algorithm calls crypto_bin_to_hpre_bin() to
transfer the key when sending request. However, the key
needs to be transferred only once, repeated transfer may cause
data inconsistency with original user's data, resulting in
incorrect calculation results.
Therefore, after the key is transferred, the 'dsize' is changed to
the 'bsize', When 'disze' and 'bsize' are equal, no transfer is performed.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index c7bb70e..61c7855 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -212,27 +212,32 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
wd_dq->bsize, wd_dq->dsize, "rsa crt dq");
if (ret)
return ret;
+ wd_dq->dsize = wd_dq->bsize;
ret = crypto_bin_to_hpre_bin(wd_dp->data, (const char *)wd_dp->data,
wd_dp->bsize, wd_dp->dsize, "rsa crt dp");
if (ret)
return ret;
+ wd_dp->dsize = wd_dp->bsize;
ret = crypto_bin_to_hpre_bin(wd_q->data, (const char *)wd_q->data,
wd_q->bsize, wd_q->dsize, "rsa crt q");
if (ret)
return ret;
+ wd_q->dsize = wd_q->bsize;
ret = crypto_bin_to_hpre_bin(wd_p->data,
(const char *)wd_p->data, wd_p->bsize, wd_p->dsize, "rsa crt p");
if (ret)
return ret;
+ wd_p->dsize = wd_p->bsize;
ret = crypto_bin_to_hpre_bin(wd_qinv->data,
(const char *)wd_qinv->data, wd_qinv->bsize,
wd_qinv->dsize, "rsa crt qinv");
if (ret)
return ret;
+ wd_qinv->dsize = wd_qinv->bsize;
*data = wd_dq->data;
@@ -249,11 +254,13 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
wd_d->bsize, wd_d->dsize, "rsa d");
if (ret)
return ret;
+ wd_d->dsize = wd_d->bsize;
ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data,
wd_n->bsize, wd_n->dsize, "rsa n");
if (ret)
return ret;
+ wd_n->dsize = wd_n->bsize;
*data = wd_d->data;
@@ -270,11 +277,13 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
wd_e->bsize, wd_e->dsize, "rsa e");
if (ret)
return ret;
+ wd_e->dsize = wd_e->bsize;
ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data,
wd_n->bsize, wd_n->dsize, "rsa n");
if (ret)
return ret;
+ wd_n->dsize = wd_n->bsize;
*data = wd_e->data;
--
2.25.1

View File

@ -0,0 +1,54 @@
From 6bb23a7d5d8bf7afda47bddd52e16bf72b446f6b Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Thu, 30 Nov 2023 15:51:28 +0800
Subject: [PATCH 109/114] uadk/v1: remove duplicate header files
Some of the header files are already included in wd.h,
and hisi_rng_udrv.h already includes wd.h. Therefore,
the hisi_rng_udrv.c file does not need to include these
header files repeatedly.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
v1/drv/hisi_rng_udrv.c | 6 ------
v1/drv/hisi_rng_udrv.h | 1 -
2 files changed, 7 deletions(-)
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
index 09fa2c3..86a20cb 100644
--- a/v1/drv/hisi_rng_udrv.c
+++ b/v1/drv/hisi_rng_udrv.c
@@ -18,18 +18,12 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
-#include <assert.h>
#include <string.h>
#include <stdint.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/types.h>
-#include <unistd.h>
-#include "config.h"
#include "hisi_rng_udrv.h"
#define HISI_RNG_BYTES 4
diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h
index 93f2f91..56814a4 100644
--- a/v1/drv/hisi_rng_udrv.h
+++ b/v1/drv/hisi_rng_udrv.h
@@ -18,7 +18,6 @@
#define __HISI_RNG_UDRV_H__
#include <linux/types.h>
-#include "config.h"
#include "v1/wd.h"
#include "v1/wd_util.h"
#include "v1/wd_rng.h"
--
2.25.1

View File

@ -0,0 +1,42 @@
From 4d64eedcb418802a8c6ae376b8d6fdda62ea61eb Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 15:51:29 +0800
Subject: [PATCH 110/114] uadk: fix error writing data to uninitialized memory
After the memory is applied for, the memory
must be initialized before being written.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
drv/hisi_qm_udrv.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index d86a692..8e4c0bb 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -252,11 +252,10 @@ static int hisi_qm_setup_db(handle_t h_ctx, struct hisi_qm_queue_info *q_info)
static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config,
struct hisi_qm_queue_info *q_info)
{
- struct hisi_qp_info qp_cfg;
- struct hisi_qp_ctx qp_ctx;
+ struct hisi_qp_info qp_cfg = {0};
+ struct hisi_qp_ctx qp_ctx = {0};
int ret;
- memset(&qp_ctx, 0, sizeof(struct hisi_qp_ctx));
qp_ctx.qc_type = config->op_type;
q_info->qc_type = qp_ctx.qc_type;
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_QM_SET_QP_CTX, &qp_ctx);
@@ -264,6 +263,7 @@ static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config,
WD_DEV_ERR(h_ctx, "failed to set qc_type!\n");
return ret;
}
+
q_info->sqn = qp_ctx.id;
config->sqn = qp_ctx.id;
--
2.25.1

View File

@ -0,0 +1,36 @@
From d1b4b282c104cc2643e8d2eb83ec74df796b2c24 Mon Sep 17 00:00:00 2001
From: Hao Fang <fanghao11@huawei.com>
Date: Thu, 30 Nov 2023 15:51:30 +0800
Subject: [PATCH 111/114] uadk: drv/qm: fix resource leak by add qp info clear
process
The spin_lock need to destroy and mem region need
to unmap, hisi_qm_clear_info() can do this.
Signed-off-by: Hao Fang <fanghao11@huawei.com>
---
drv/hisi_qm_udrv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 8e4c0bb..76a270e 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -449,10 +449,10 @@ void hisi_qm_free_qp(handle_t h_qp)
}
wd_release_ctx_force(qp->h_ctx);
- wd_ctx_unmap_qfr(qp->h_ctx, UACCE_QFRT_MMIO);
- wd_ctx_unmap_qfr(qp->h_ctx, UACCE_QFRT_DUS);
- if (qp->h_sgl_pool)
- hisi_qm_destroy_sglpool(qp->h_sgl_pool);
+
+ hisi_qm_destroy_sglpool(qp->h_sgl_pool);
+
+ hisi_qm_clear_info(qp);
free(qp);
}
--
2.25.1

View File

@ -0,0 +1,32 @@
From fef7c7a3191e55c6daeb67df5c29b4b841445efe Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Thu, 30 Nov 2023 15:51:31 +0800
Subject: [PATCH 112/114] uadk/v1: fix error writing data to uninitialized
memory
After the memory is applied for, the memory
must be initialized before being written.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
v1/drv/hisi_qm_udrv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
index 6cbcdf5..0ca38d2 100644
--- a/v1/drv/hisi_qm_udrv.c
+++ b/v1/drv/hisi_qm_udrv.c
@@ -458,8 +458,8 @@ static int qm_init_queue_info(struct wd_queue *q)
struct wcrypto_paras *priv = &q->capa.priv;
struct q_info *qinfo = q->qinfo;
struct qm_queue_info *info = qinfo->priv;
- struct hisi_qp_info qp_info;
- struct hisi_qp_ctx qp_ctx;
+ struct hisi_qp_info qp_info = {0};
+ struct hisi_qp_ctx qp_ctx = {0};
int ret;
info->sq_tail_index = 0;
--
2.25.1

View File

@ -0,0 +1,155 @@
From 3e309b7dbcb2f9308a8ccb1b7cb7876f808a7394 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Thu, 30 Nov 2023 16:41:27 +0800
Subject: [PATCH] uadk: check queue status before sending doorbells
When the device needs to be reset, the queue status is
set to disable before resetting. The user process checks
the queue status before sending the doorbell. If the queue
is disable, the user process returns failure.
Currently, the task execution order in user mode is as follows:
1. check the queue status.
2. fill in or parse the BD.
3. send the doorbell to the hardware.
To reduce the possibility of sending doorbells during reset,
the task execution order is modified as follows:
1. fill in or parse the BD.
2. check the queue status.
3. send the doorbell to the hardware.
In addition, a rmb() is added before the doorbell is
sent to ensure that the queue status check is complete.
rmb() and wmb() can be replaced by mb() in hisi_qm_send().
Therefore, the barrier on the wd_ioread() and wd_iowrite()
can be deleted.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_qm_udrv.c | 39 ++++++++++++++++++++++++++++-----------
include/wd.h | 6 ++----
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 4c80959..d8b5271 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -469,11 +469,6 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
q_info = &qp->q_info;
- if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) {
- WD_ERR("wd queue hw error happened before qm send!\n");
- return -WD_HW_EACCESS;
- }
-
pthread_spin_lock(&q_info->sd_lock);
free_num = get_free_num(q_info);
if (!free_num) {
@@ -486,14 +481,26 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
tail = q_info->sq_tail_index;
hisi_qm_fill_sqe(req, q_info, tail, send_num);
tail = (tail + send_num) % q_info->sq_depth;
+
+ /*
+ * Before sending doorbell, check the queue status,
+ * if the queue is disable, return failure.
+ */
+ if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) {
+ pthread_spin_unlock(&q_info->sd_lock);
+ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened before qm send!\n");
+ return -WD_HW_EACCESS;
+ }
+
+ /* Make sure sqe is filled before db ring and queue status check is complete. */
+ mb();
q_info->db(q_info, QM_DBELL_CMD_SQ, tail, 0);
q_info->sq_tail_index = tail;
/* Make sure used_num is changed before the next thread gets free sqe. */
__atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
- *count = send_num;
-
pthread_spin_unlock(&q_info->sd_lock);
+ *count = send_num;
return 0;
}
@@ -509,6 +516,8 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
cqe = q_info->cq_base + i * sizeof(struct cqe);
if (q_info->cqc_phase == CQE_PHASE(cqe)) {
+ /* Make sure cqe valid bit is set */
+ rmb();
j = CQE_SQ_HEAD_INDEX(cqe);
if (unlikely(j >= q_info->sq_depth)) {
pthread_spin_unlock(&q_info->rv_lock);
@@ -529,6 +538,18 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
i++;
}
+ /*
+ * Before sending doorbell, check the queue status,
+ * if the queue is disable, return failure.
+ */
+ if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) {
+ pthread_spin_unlock(&q_info->rv_lock);
+ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened after qm receive!\n");
+ return -WD_HW_EACCESS;
+ }
+
+ /* Make sure queue status check is complete. */
+ rmb();
q_info->db(q_info, QM_DBELL_CMD_CQ, i, q_info->epoll_en);
/* only support one thread poll one queue, so no need protect */
@@ -568,10 +589,6 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
}
*count = recv_num;
- if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) {
- WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n");
- return -WD_HW_EACCESS;
- }
return ret;
}
diff --git a/include/wd.h b/include/wd.h
index 0e67cad..0a654d6 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -167,7 +167,7 @@ static inline uint32_t wd_ioread32(void *addr)
uint32_t ret;
ret = *((volatile uint32_t *)addr);
- rmb();
+
return ret;
}
@@ -176,19 +176,17 @@ static inline uint64_t wd_ioread64(void *addr)
uint64_t ret;
ret = *((volatile uint64_t *)addr);
- rmb();
+
return ret;
}
static inline void wd_iowrite32(void *addr, uint32_t value)
{
- wmb();
*((volatile uint32_t *)addr) = value;
}
static inline void wd_iowrite64(void *addr, uint64_t value)
{
- wmb();
*((volatile uint64_t *)addr) = value;
}
--
2.25.1

View File

@ -0,0 +1,31 @@
From d491b5480de01ea64360c24b6a89db3ddaf640e1 Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Thu, 30 Nov 2023 14:25:14 +0800
Subject: [PATCH 114/114] uadk: zlibwrapper - fix return value for
wd_zlib_uadk_init
It means the UADK compression library has been initialized when
wd_comp_init2_ return -WD_EEXIST. Wd_zlibwrapper doesn't need to
do it again. But WD_EEXIST is not a valid return value for zlib
APIs. So change it to 0.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
wd_zlibwrapper.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index 7189b7f..e562910 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -73,6 +73,7 @@ static int wd_zlib_uadk_init(void)
goto out_freebmp;
}
+ ret = 0;
zlib_config.status = WD_ZLIB_INIT;
out_freebmp:
--
2.25.1

View File

@ -1,7 +1,7 @@
Name: libwd
Summary: User Space Accelerator Development Kit
Version: 2.5.0
Release: 5
Release: 6
License: Apache-2.0
Source: %{name}-%{version}.tar.gz
Vendor: Huawei Corporation
@ -57,6 +57,78 @@ Patch0039: 0039-uadk-cipher-support-sm4-xts-GB-standard.patch
Patch0040: 0040-uadk-v1-cipher-support-sm4-xts-GB-standard.patch
Patch0041: 0041-uadk-v1-digest-support-new-AES-mode-algs.patch
Patch0042: 0042-uadk-v1-fix-long-hash-state-issue.patch
Patch0043: 0043-uadk_tool-delete-redundant-memset-zero.patch
Patch0044: 0044-uadk_tool-fix-possible-memory-leak-in-alg-_uadk_asyn.patch
Patch0045: 0045-uadk_tool-fix-the-called-function-interface.patch
Patch0046: 0046-uadk_tool-release-memory-after-all-tasks-are-complet.patch
Patch0047: 0047-uadk_tool-Optimize-sec-s-sva-benchmark-code.patch
Patch0048: 0048-uadk_tool-Optimize-sec-s-no-sva-benchmark-code.patch
Patch0049: 0049-uadk_tool-Optimize-sec-s-software-benchmark-code.patch
Patch0050: 0050-uadk_tool-add-latency-test-function-for-uadk_tools.patch
Patch0051: 0051-uadk_tool-modify-the-clean-code-issue.patch
Patch0052: 0052-uadk_tool-support-aead-algorithm-decrypto-perf-testi.patch
Patch0053: 0053-uadk_tool-fix-hpre-test-code-issues.patch
Patch0054: 0054-uadk_tool-support-dual-sec-engine-device-testing.patch
Patch0055: 0055-uadk_tool-Support-performance-test-for-TRNG.patch
Patch0056: 0056-uadk-tools-support-new-parameters-for-compression.patch
Patch0057: 0057-uadk_tool-v1-support-aead-algorithm-decrypto-perf-te.patch
Patch0058: 0058-uadk_tool-v1-fix-sec-benchmark-problem.patch
Patch0059: 0059-uadk-tools-misc-fixes-for-uadk-compress-performance.patch
Patch0060: 0060-uadk-tools-fix-lz77_zstd-performance-test-for-nosva-.patch
Patch0061: 0061-uadk-tools-fix-for-uadk-compression-stream-performan.patch
Patch0062: 0062-uadk-tools-fix-for-uadk-tool-sec-aead-async-mode.patch
Patch0063: 0063-uadk-tools-Update-test-function-for-init2.patch
Patch0064: 0064-uadk-support-some-uadk-dfx-stronger-feature.patch
Patch0065: 0065-uadk-sec-added-init2-performance-test.patch
Patch0066: 0066-uadk-comp-added-init2-test-function-for-comp.patch
Patch0067: 0067-uadk_tool-added-init2-test-function-for-hpre.patch
Patch0068: 0068-uadk_tool-use-marco-to-replace-numbers.patch
Patch0069: 0069-uadk_tool-support-test-case-for-aes-cbc-cts-mode.patch
Patch0070: 0070-uadk-tool-initialize-cparams-to-zero.patch
Patch0071: 0071-uadk_tool-fix-the-memory-leak-problem.patch
Patch0072: 0072-uadk_tool-fix-error-writing-data-to-uninitialized-me.patch
Patch0073: 0073-uadk_tool-added-sm4-xts-GB-test.patch
Patch0074: 0074-uadk_tool-initialize-the-return-value-ret-of-the-fun.patch
Patch0075: 0075-add-secure-compilation-option.patch
Patch0076: 0076-uadk-v1-drv-hisi_zip_udrv-fix-unmap-buffer-for-lz77_.patch
Patch0077: 0077-uadk-v1-drv-hisi_zip_udrv-fix-the-wrong-unmapped-add.patch
Patch0078: 0078-uadk-v1-wd_comp-fix-unlocked-queue-resource-change.patch
Patch0079: 0079-uadk-wd_alg-add-registering-driver-parameters-check.patch
Patch0080: 0080-uadk-wd_comp-fix-some-comments.patch
Patch0081: 0081-uadk-fix-the-process-when-ctx-request-fails.patch
Patch0082: 0082-uadk-wd_util-fix-a-theoretically-infinite-loop.patch
Patch0083: 0083-uadk-wd-fix-fscanf-infinite-loop.patch
Patch0084: 0084-uadk-zlibwrapper-fix-wrong-request-check.patch
Patch0085: 0085-uadk-drv-hisi-fix-sgl-copy-offset-error.patch
Patch0086: 0086-uadk-v1-comp-add-comp-ctx-parameters-check.patch
Patch0087: 0087-uadk-v1-check-whether-the-data-address-pointer-is-no.patch
Patch0088: 0088-uadk-v1-remove-print-actions-after-wd_get_cookies.patch
Patch0089: 0089-uadk-fix-header-file-is-not-self-contained.patch
Patch0090: 0090-uadk-sec-modify-improper-comments.patch
Patch0091: 0091-uadk-fixed-some-input-parameter-checking-issues.patch
Patch0092: 0092-uadk-code-cleanup.patch
Patch0093: 0093-uadk-fix-sec-send-and-recv-check-failed.patch
Patch0094: 0094-uadk-code-cleanup-for-error-codes-and-variable-type.patch
Patch0095: 0095-uadk-sec-add-a-return-value-judgement.patch
Patch0096: 0096-uadk-Add-file-association.patch
Patch0097: 0097-uadk-fix-the-failure-process-bug.patch
Patch0098: 0098-uadk-fix-the-failure-process-bug.patch
Patch0099: 0099-uadk-fix-the-failure-process-bug.patch
Patch0100: 0100-uadk-bugfix.patch
Patch0101: 0101-uadk-v1-adapter-code-cleanup.patch
Patch0102: 0102-uadk-v1-fix-wd_rng-resource-release-bug.patch
Patch0103: 0103-uadk-v1-code-cleanup-for-error-codes-and-header-file.patch
Patch0104: 0104-uadk-concentrate-the-same-definitions.patch
Patch0105: 0105-uadk-v1-optimize-the-function-length.patch
Patch0106: 0106-uadk-v1-concentrate-the-same-definitions.patch
Patch0107: 0107-v1-hpre-fix-key-transfer-error-issue.patch
Patch0108: 0108-uadk-hisi_hpre-fix-key-transfer-error-issue.patch
Patch0109: 0109-uadk-v1-remove-duplicate-header-files.patch
Patch0110: 0110-uadk-fix-error-writing-data-to-uninitialized-memory.patch
Patch0111: 0111-uadk-drv-qm-fix-resource-leak-by-add-qp-info-clear-p.patch
Patch0112: 0112-uadk-v1-fix-error-writing-data-to-uninitialized-memo.patch
Patch0113: 0113-uadk-check-queue-status-before-sending-doorbells.patch
Patch0114: 0114-uadk-zlibwrapper-fix-return-value-for-wd_zlib_uadk_i.patch
%description
This package contains the User Space Accelerator Library
@ -229,6 +301,9 @@ fi
/sbin/ldconfig
%changelog
* Tue Dec 05 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-6
- libwd: update the source code
* Tue Oct 31 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.5.0-5
- libwd: update the source code