!35 Update the uadk package to 2.3.27

From: @youngersun 
Reviewed-by: @hao-fang 
Signed-off-by: @hao-fang
This commit is contained in:
openeuler-ci-bot 2022-02-22 11:03:43 +00:00 committed by Gitee
commit 4a6267d0cd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
36 changed files with 38699 additions and 1 deletions

View File

@ -0,0 +1,421 @@
From 0ec02e23cfc86ea664905a11b28635cab12ee29a Mon Sep 17 00:00:00 2001
From: Liulongfang <liulongfang@foxmail.com>
Date: Wed, 5 Jan 2022 14:46:54 +0800
Subject: [PATCH 29/53] uadk/tools: modify NO-SVA test scenario
In the No-SVA scenario, the user's business data needs to be copied
from the user memory to the block memory allocated by the user mode
through the copy method.
After the business execution is completed, it needs to be copied back.
The test tool should truly reflect the copy operation process.
Signed-off-by: Liulongfang <liulongfang@foxmail.com>
---
uadk_tool/Makefile.am | 2 +-
uadk_tool/sec_wd_benchmark.c | 122 +++++++++++++++++++++++++++++------
uadk_tool/uadk_benchmark.c | 2 +-
3 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 36536a2..f79a6e3 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -16,7 +16,7 @@ uadk_tool_LDADD=$(libwd_la_OBJECTS) \
../.libs/libhisi_sec.a \
../.libs/libhisi_hpre.a \
../.libs/libhisi_zip.a \
- include/libcrypto.a -ldl -lnuma
+ $(top_srcdir)/uadk_tool/include/libcrypto.a -ldl -lnuma
else
uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \
-L$(top_srcdir)/uadk_tool/include -l:libcrypto.so.1.1 -lnuma
diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/sec_wd_benchmark.c
index c650e9a..dffd3a7 100644
--- a/uadk_tool/sec_wd_benchmark.c
+++ b/uadk_tool/sec_wd_benchmark.c
@@ -36,6 +36,7 @@ struct thread_queue_res {
struct wcrypto_async_tag {
void *ctx;
+ char *out_buf;
int thread_id;
int cnt;
};
@@ -54,17 +55,34 @@ static unsigned int g_pktlen;
static void *cipher_async_cb(void *message, void *cipher_tag)
{
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)cipher_tag;
+ struct wcrypto_cipher_msg *req = (struct wcrypto_cipher_msg *)message;
+
+ // no-sva data copy from uadk to user
+ memcpy(async_tag->out_buf, req->out, g_pktlen);
+
return NULL;
}
-static void *aead_async_cb(void *message, void *cipher_tag)
+static void *aead_async_cb(void *message, void *aead_tag)
{
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)aead_tag;
+ struct wcrypto_aead_msg *req = (struct wcrypto_aead_msg *)message;
+
+ // no-sva data copy from uadk to user
+ memcpy(async_tag->out_buf, req->out, g_pktlen);
+
return NULL;
}
static void *digest_async_cb(void *message, void *digest_tag)
{
- // struct WCRYPTO_req *req = (struct WCRYPTO_req *)data;
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)digest_tag;
+ struct wcrypto_digest_msg *req = (struct wcrypto_digest_msg *)message;
+
+ // no-sva data copy from uadk to user
+ memcpy(async_tag->out_buf, req->out, 16);
+
return NULL;
}
@@ -563,6 +581,8 @@ static void *sec_wd_async_run(void *arg)
struct wcrypto_async_tag *tag = NULL;
char priv_key[MAX_IVK_LENTH];
struct thread_bd_res *bd_res;
+ char *src_data_buf = NULL;
+ char *out_data_buf = NULL;
struct wd_queue *queue;
void *ctx = NULL;
void **res_in;
@@ -584,13 +604,27 @@ static void *sec_wd_async_run(void *arg)
res_out = bd_res->out;
res_iv = bd_res->iv;
+ /* create user data buffer */
+ src_data_buf = malloc(g_pktlen * sizeof(char));
+ if (!src_data_buf)
+ return NULL;
+
+ get_rand_data(src_data_buf, g_pktlen);
+ out_data_buf = malloc(g_pktlen * sizeof(char));
+ if (!out_data_buf) {
+ free(src_data_buf);
+ return NULL;
+ }
+
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag
if (!tag) {
SEC_TST_PRT("wcrypto async alloc tag fail!\n");
+ free(src_data_buf);
+ free(out_data_buf);
return NULL;
}
- tag->thread_id = pdata->td_id;
+ tag->out_buf = out_data_buf;
switch(pdata->subtype) {
case CIPHER_TYPE:
@@ -607,7 +641,7 @@ static void *sec_wd_async_run(void *arg)
ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup);
if (!ctx) {
SEC_TST_PRT("wd create cipher ctx fail!\n");
- return NULL;
+ goto async_err;
}
tag->ctx = ctx;
@@ -615,7 +649,7 @@ static void *sec_wd_async_run(void *arg)
if (ret) {
SEC_TST_PRT("wd cipher set key fail!\n");
wcrypto_del_cipher_ctx(ctx);
- return NULL;
+ goto async_err;
}
if (queue->capa.priv.direction == 0)
@@ -637,6 +671,9 @@ static void *sec_wd_async_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(copdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -672,7 +709,7 @@ static void *sec_wd_async_run(void *arg)
ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
if (!ctx) {
SEC_TST_PRT("wd create aead ctx fail!\n");
- return NULL;
+ goto async_err;
}
tag->ctx = ctx;
@@ -680,7 +717,7 @@ static void *sec_wd_async_run(void *arg)
if (ret) {
SEC_TST_PRT("wd aead set key fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto async_err;
}
authsize = 16; //set defaut size
@@ -688,7 +725,7 @@ static void *sec_wd_async_run(void *arg)
if (ret) {
SEC_TST_PRT("set authsize fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto async_err;
}
if (queue->capa.priv.direction == 0) {
@@ -715,6 +752,9 @@ static void *sec_wd_async_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(aopdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -750,7 +790,7 @@ static void *sec_wd_async_run(void *arg)
ctx = wcrypto_create_digest_ctx(queue, &digest_setup);
if (!ctx) {
SEC_TST_PRT("wd create digest ctx fail!\n");
- return NULL;
+ goto async_err;
}
tag->ctx = ctx;
@@ -760,7 +800,7 @@ static void *sec_wd_async_run(void *arg)
if (ret) {
SEC_TST_PRT("wd digest set key fail!\n");
wcrypto_del_digest_ctx(ctx);
- return NULL;
+ goto async_err;
}
}
@@ -777,6 +817,9 @@ static void *sec_wd_async_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(dopdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -802,7 +845,7 @@ static void *sec_wd_async_run(void *arg)
add_send_complete();
while (1) {
- if (get_recv_time() > 0) // wait Async mode finish recv
+ if (get_recv_time() == g_thread_num) // wait Async mode finish recv
break;
usleep(SEND_USLEEP);
}
@@ -819,6 +862,10 @@ static void *sec_wd_async_run(void *arg)
break;
}
+async_err:
+ free(tag);
+ free(src_data_buf);
+ free(out_data_buf);
return NULL;
}
@@ -834,6 +881,8 @@ static void *sec_wd_sync_run(void *arg)
char priv_key[MAX_IVK_LENTH];
struct thread_bd_res *bd_res;
struct wd_queue *queue;
+ char *src_data_buf = NULL;
+ char *out_data_buf = NULL;
void *ctx = NULL;
void *tag = NULL;
void **res_in;
@@ -855,6 +904,18 @@ static void *sec_wd_sync_run(void *arg)
res_out = bd_res->out;
res_iv = bd_res->iv;
+ /* create user data buffer */
+ src_data_buf = malloc(g_pktlen * sizeof(char));
+ if (!src_data_buf)
+ return NULL;
+
+ get_rand_data(src_data_buf, g_pktlen);
+ out_data_buf = malloc(g_pktlen * sizeof(char));
+ if (!out_data_buf) {
+ free(src_data_buf);
+ return NULL;
+ }
+
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
switch(pdata->subtype) {
@@ -871,14 +932,14 @@ static void *sec_wd_sync_run(void *arg)
ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup);
if (!ctx) {
SEC_TST_PRT("wd create cipher ctx fail!\n");
- return NULL;
+ goto sync_err;
}
ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize);
if (ret) {
SEC_TST_PRT("wd cipher set key fail!\n");
wcrypto_del_cipher_ctx(ctx);
- return NULL;
+ goto sync_err;
}
if (queue->capa.priv.direction == 0)
@@ -899,6 +960,9 @@ static void *sec_wd_sync_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(copdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_cipher(ctx, &copdata, tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -916,6 +980,9 @@ static void *sec_wd_sync_run(void *arg)
copdata.in = res_in[i];
copdata.out = res_out[i];
copdata.iv = res_iv[i];
+
+ // no-sva data copy from uadk to user
+ memcpy(out_data_buf, copdata.out, g_pktlen);
}
wcrypto_del_cipher_ctx(ctx);
@@ -933,14 +1000,14 @@ static void *sec_wd_sync_run(void *arg)
ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
if (!ctx) {
SEC_TST_PRT("wd create aead ctx fail!\n");
- return NULL;
+ goto sync_err;
}
ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize);
if (ret) {
SEC_TST_PRT("wd aead set key fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto sync_err;
}
authsize = 16; //set defaut size
@@ -948,7 +1015,7 @@ static void *sec_wd_sync_run(void *arg)
if (ret) {
SEC_TST_PRT("set authsize fail!\n");
wcrypto_del_aead_ctx(ctx);
- return NULL;
+ goto sync_err;
}
if (queue->capa.priv.direction == 0) {
@@ -974,6 +1041,9 @@ static void *sec_wd_sync_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(aopdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_aead(ctx, &aopdata, tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -991,6 +1061,9 @@ static void *sec_wd_sync_run(void *arg)
aopdata.in = res_in[i];
aopdata.out = res_out[i];
aopdata.iv = res_iv[i];
+
+ // no-sva data copy from uadk to user
+ memcpy(out_data_buf, aopdata.out, g_pktlen);
}
wcrypto_del_aead_ctx(ctx);
@@ -1008,7 +1081,7 @@ static void *sec_wd_sync_run(void *arg)
ctx = wcrypto_create_digest_ctx(queue, &digest_setup);
if (!ctx) {
SEC_TST_PRT("wd create digest ctx fail!\n");
- return NULL;
+ goto sync_err;
}
if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) {
@@ -1017,7 +1090,7 @@ static void *sec_wd_sync_run(void *arg)
if (ret) {
SEC_TST_PRT("wd digest set key fail!\n");
wcrypto_del_digest_ctx(ctx);
- return NULL;
+ goto sync_err;
}
}
@@ -1033,6 +1106,9 @@ static void *sec_wd_sync_run(void *arg)
if (get_run_state() == 0)
break;
+ // no-sva data copy to uadk
+ memcpy(dopdata.in, src_data_buf, g_pktlen);
+
ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag);
if (ret == -WD_EBUSY) {
usleep(SEND_USLEEP * try_cnt);
@@ -1048,7 +1124,10 @@ static void *sec_wd_sync_run(void *arg)
try_cnt = 0;
i = count % MAX_BLOCK_NM;
dopdata.in = res_in[i];
- dopdata.out = res_out[i];
+ dopdata.out = res_out[i];
+
+ // no-sva data copy from uadk to user
+ memcpy(out_data_buf, dopdata.out, 16);
}
wcrypto_del_digest_ctx(ctx);
break;
@@ -1056,6 +1135,9 @@ static void *sec_wd_sync_run(void *arg)
add_recv_data(count);
+sync_err:
+ free(src_data_buf);
+ free(out_data_buf);
return NULL;
}
@@ -1097,7 +1179,6 @@ int sec_wd_sync_threads(struct acc_option *options)
sync_error:
return ret;
-
}
int sec_wd_async_threads(struct acc_option *options)
@@ -1185,4 +1266,3 @@ int sec_wd_benchmark(struct acc_option *options)
return 0;
}
-
diff --git a/uadk_tool/uadk_benchmark.c b/uadk_tool/uadk_benchmark.c
index 5773b2c..8067ed7 100644
--- a/uadk_tool/uadk_benchmark.c
+++ b/uadk_tool/uadk_benchmark.c
@@ -551,7 +551,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 threads\n");
+ ACC_TST_PRT(" set the number of process\n");
ACC_TST_PRT(" [--thread]:\n");
ACC_TST_PRT(" set the number of threads\n");
ACC_TST_PRT(" [--ctxnum]:\n");
--
2.25.1

View File

@ -0,0 +1,31 @@
From 4478ede7a98cc9f84b30bb5766007b2acbec1a2f Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:32 +0800
Subject: [PATCH 30/53] wd: fix wd_parse_async_poll_num
skip parse poll number if inner poll is not enabled.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/wd_util.c b/wd_util.c
index e04747b..58463e9 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -759,6 +759,11 @@ int wd_parse_async_poll_num(struct wd_env_config *config, const char *s)
char *left, *section, *start;
int node, poll_num, ret;
+ if (!config->enable_internal_poll) {
+ WD_ERR("internal poll not enabled, skip parse poll number!\n");
+ return 0;
+ }
+
start = strdup(s);
if (!start)
return -ENOMEM;
--
2.25.1

View File

@ -0,0 +1,81 @@
From 8094e7a2344cf558eb056e7afc153299a3642f39 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:28 +0800
Subject: [PATCH 31/53] uadk: optimize wd_init_async_polling_thread_per_numa
use fmin to get poll thread num.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index 58463e9..fd132aa 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -10,6 +10,7 @@
#include <semaphore.h>
#include <string.h>
#include <ctype.h>
+#include <math.h>
#include "wd_alg_common.h"
#include "wd_util.h"
#include "wd_sched.h"
@@ -1295,7 +1296,8 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
struct wd_env_config_per_numa *config_numa)
{
struct async_task_queue *task_queue, *queue_head;
- int i, j, poll_thread_num, ret;
+ int i, j, ret;
+ double num;
if (!config_numa->async_ctx_num)
return 0;
@@ -1307,13 +1309,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM;
}
- poll_thread_num = config_numa->async_poll_num;
- if (poll_thread_num > config_numa->async_ctx_num) {
- poll_thread_num = config_numa->async_ctx_num;
- WD_ERR("downgrade poll thread num from %lu to %lu.\n",
- config_numa->async_poll_num,
- config_numa->async_ctx_num);
- }
+ num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
/* make max task queues as the number of async ctxs */
queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head));
@@ -1321,7 +1317,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
return -WD_ENOMEM;
task_queue = queue_head;
- for (i = 0; i < poll_thread_num; task_queue++, i++) {
+ for (i = 0; i < num; task_queue++, i++) {
ret = wd_init_one_task_queue(task_queue, config->alg_poll_ctx);
if (ret) {
for (j = 0; j < i; task_queue++, j++)
@@ -1340,15 +1336,14 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
struct wd_env_config_per_numa *config_numa)
{
struct async_task_queue *task_queue, *head;
- int i, n;
+ double num;
+ int i;
head = config_numa->async_task_queue_array;
task_queue = head;
- n = config_numa->async_poll_num;
- if (config_numa->async_poll_num > config_numa->async_ctx_num)
- n = config_numa->async_ctx_num;
+ num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
- for (i = 0; i < n; task_queue++, i++)
+ for (i = 0; i < num; task_queue++, i++)
wd_uninit_one_task_queue(task_queue);
free(head);
config_numa->async_task_queue_array = NULL;
--
2.25.1

View File

@ -0,0 +1,113 @@
From a3b74902cadf6dd671a093c6747a5bd624d09cc4 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:29 +0800
Subject: [PATCH 32/53] uadk: env: fix wd_add_task_to_async_queue
clear global information if an add task error occurred.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index fd132aa..676f475 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -45,7 +45,9 @@ struct async_task {
struct async_task_queue {
struct async_task *head;
int depth;
+ /* the producer offset of task queue */
int prod;
+ /* the consumer offset of task queue */
int cons;
int cur_task;
int left_task;
@@ -1113,8 +1115,8 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
{
struct async_task_queue *task_queue;
- struct async_task *head, *task;
- int prod, ret;
+ struct async_task *task;
+ int curr_prod, ret;
if (!config->enable_internal_poll)
return 0;
@@ -1131,14 +1133,13 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
pthread_mutex_lock(&task_queue->lock);
- prod = task_queue->prod;
- head = task_queue->head;
- task = head + prod;
- /* fix me */
+ /* get an available async task and fill ctx idx */
+ curr_prod = task_queue->prod;
+ task = task_queue->head + curr_prod;
task->idx = idx;
- prod = (prod + 1) % task_queue->depth;
- task_queue->prod = prod;
+ /* update global information of task queue */
+ task_queue->prod = (curr_prod + 1) % task_queue->depth;
task_queue->cur_task++;
task_queue->left_task--;
@@ -1147,10 +1148,19 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
ret = sem_post(&task_queue->full_sem);
if (ret) {
WD_ERR("failed to post full_sem!\n");
- return ret;
+ goto err_out;
}
return 0;
+
+err_out:
+ pthread_mutex_lock(&task_queue->lock);
+ task_queue->left_task++;
+ task_queue->cur_task--;
+ task_queue->prod = curr_prod;
+ pthread_mutex_unlock(&task_queue->lock);
+
+ return ret;
}
static void *async_poll_process_func(void *args)
@@ -1216,18 +1226,18 @@ static int wd_init_one_task_queue(struct async_task_queue *task_queue,
void *alg_poll_ctx)
{
- struct async_task *task_head;
+ struct async_task *head;
pthread_t thread_id;
pthread_attr_t attr;
int depth, ret;
task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH;
- task_head = calloc(task_queue->depth, sizeof(struct async_task));
- if (!task_head)
+ head = calloc(task_queue->depth, sizeof(*head));
+ if (!head)
return -WD_ENOMEM;
- task_queue->head = task_head;
+ task_queue->head = head;
task_queue->left_task = depth;
task_queue->alg_poll_ctx = alg_poll_ctx;
@@ -1268,7 +1278,7 @@ err_uninit_full_sem:
err_uninit_empty_sem:
sem_destroy(&task_queue->empty_sem);
err_free_head:
- free(task_head);
+ free(head);
ret = -errno;
return ret;
}
--
2.25.1

View File

@ -0,0 +1,41 @@
From 72f58fe17adc3396a5c6826c5acf9a235b02b635 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:30 +0800
Subject: [PATCH 33/53] uadk: optimize find_async_queue
No need to determine offset size before modulo.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index 676f475..9e96114 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1069,7 +1069,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
struct wd_env_config_per_numa *config_numa;
struct wd_ctx_range **ctx_table;
struct async_task_queue *head;
- unsigned long offset;
+ unsigned long offset = 0;
int num = 0;
int i;
@@ -1093,10 +1093,8 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
for (i = 0; i < config_numa->op_type_num; i++) {
if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
- offset = idx - ctx_table[CTX_MODE_ASYNC][i].begin;
- if (offset >= config_numa->async_poll_num)
- offset = offset % config_numa->async_poll_num;
-
+ offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) %
+ config_numa->async_poll_num;
break;
}
}
--
2.25.1

View File

@ -0,0 +1,41 @@
From e2b9b8fbf8ee1f8e9775b473de7ee464f32aed50 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:27 +0800
Subject: [PATCH 34/53] uadk: fix check_after_sink
No need to check last ret, it cause check_after_sink.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/wd.c b/wd.c
index 25386d7..238ce8a 100644
--- a/wd.c
+++ b/wd.c
@@ -171,11 +171,7 @@ static int get_dev_info(struct uacce_dev *dev)
if (ret < 0)
return ret;
- ret = get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
- if (ret < 0)
- return ret;
-
- return 0;
+ return get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
}
static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
@@ -215,7 +211,7 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
goto out_dir;
ret = get_dev_info(dev);
- if (ret) {
+ if (ret < 0) {
WD_ERR("failed to get dev info: ret = %d!\n", ret);
goto out_dir;
}
--
2.25.1

View File

@ -0,0 +1,42 @@
From 6ede569a63ce4f4ead3865b96c5dfff4e9b2fcaf Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 16:48:01 +0800
Subject: [PATCH 35/53] uadk: fix wd_request_ctx
wd_get_accel_name and strncpy should use relative path.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/wd.c b/wd.c
index 238ce8a..746fa02 100644
--- a/wd.c
+++ b/wd.c
@@ -328,11 +328,11 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
if (!ctx)
return 0;
- ctx->dev_name = wd_get_accel_name(char_dev_path, 0);
+ ctx->dev_name = wd_get_accel_name(dev->char_dev_path, 0);
if (!ctx->dev_name)
goto free_ctx;
- ctx->drv_name = wd_get_accel_name(char_dev_path, 1);
+ ctx->drv_name = wd_get_accel_name(dev->char_dev_path, 1);
if (!ctx->drv_name)
goto free_dev_name;
@@ -342,7 +342,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
wd_ctx_init_qfrs_offs(ctx);
- strncpy(ctx->dev_path, char_dev_path, MAX_DEV_NAME_LEN);
+ strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
ctx->fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
--
2.25.1

View File

@ -0,0 +1,77 @@
From cca176ed2ab3a34e5eb73cc70247c0f2dd02bdac Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 21:26:09 +0800
Subject: [PATCH 36/53] uadk: fix sched params begin issue
begin field of sched params need to be smaller than end,
otherwise begin ctx is used all the time. So add a check
to prevent invalid user input.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_sched.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/wd_sched.c b/wd_sched.c
index a85fd95..aeaf11b 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -93,7 +93,7 @@ static __u32 sched_get_next_pos_rr(struct sched_ctx_region *region,
if (pos < region->end)
region->last++;
- else if (pos >= region->end)
+ else
region->last = region->begin;
pthread_mutex_unlock(&region->lock);
@@ -209,12 +209,12 @@ static int session_sched_poll_policy(handle_t sched_ctx,
if (!sched_ctx || !count || !ctx) {
WD_ERR("ERROR: %s the para is NULL!\n", __FUNCTION__);
- return -EINVAL;
+ return -WD_EINVAL;
}
if (ctx->numa_num > NUMA_NUM_NODES) {
WD_ERR("ERROR: %s ctx numa num is invalid!\n", __FUNCTION__);
- return -EINVAL;
+ return -WD_EINVAL;
}
sched_info = ctx->sched_info;
@@ -359,7 +359,12 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
if (!sched || !sched->h_sched_ctx || !param) {
WD_ERR("ERROR: %s para err: sched of h_sched_ctx is NULL!\n",
__FUNCTION__);
- return -EINVAL;
+ return -WD_EINVAL;
+ }
+
+ if (param->begin > param->end) {
+ WD_ERR("ERROR: sched_params's begin is larger than end!\n");
+ return -WD_EINVAL;
}
numa_id = param->numa_id;
@@ -372,7 +377,7 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
(type >= sched_ctx->type_num)) {
WD_ERR("ERROR: %s para err: numa_id=%d, mode=%u, type=%u!\n",
__FUNCTION__, numa_id, mode, type);
- return -EINVAL;
+ return -WD_EINVAL;
}
sched_info = sched_ctx->sched_info;
@@ -380,7 +385,7 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
if (!sched_info[numa_id].ctx_region[mode]) {
WD_ERR("ERROR: %s para err: ctx_region:numa_id=%d, mode=%u is NULL!\n",
__FUNCTION__, numa_id, mode);
- return -EINVAL;
+ return -WD_EINVAL;
}
sched_info[numa_id].ctx_region[mode][type].begin = param->begin;
--
2.25.1

View File

@ -0,0 +1,88 @@
From d25bfc4577d47cbf5254b565876b4ca943580881 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Thu, 6 Jan 2022 21:25:48 +0800
Subject: [PATCH 37/53] uadk: optimize wd_request_ctx
open fd first is more reasonable since it often goes wrong.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/wd.c b/wd.c
index 746fa02..787d74b 100644
--- a/wd.c
+++ b/wd.c
@@ -300,11 +300,6 @@ static struct uacce_dev *clone_uacce_dev(struct uacce_dev *dev)
return new;
}
-static void free_uacce_dev(struct uacce_dev *dev)
-{
- free(dev);
-}
-
static void wd_ctx_init_qfrs_offs(struct wd_ctx_h *ctx)
{
memcpy(&ctx->qfrs_offs, &ctx->dev->qfrs_offs,
@@ -316,6 +311,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
struct wd_ctx_h *ctx;
char char_dev_path[PATH_MAX];
char *ptrRet = NULL;
+ int fd;
if (!dev || !strlen(dev->dev_root))
return 0;
@@ -324,9 +320,15 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
if (ptrRet == NULL)
return 0;
+ fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ WD_ERR("failed to open %s!(err = %d)\n", char_dev_path, -errno);
+ return 0;
+ }
+
ctx = calloc(1, sizeof(struct wd_ctx_h));
if (!ctx)
- return 0;
+ goto close_fd;
ctx->dev_name = wd_get_accel_name(dev->char_dev_path, 0);
if (!ctx->dev_name)
@@ -340,27 +342,23 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
if (!ctx->dev)
goto free_drv_name;
+ ctx->fd = fd;
+
wd_ctx_init_qfrs_offs(ctx);
strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
- ctx->fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
- if (ctx->fd < 0) {
- WD_ERR("failed to open %s (%d).\n", char_dev_path, -errno);
- goto free_dev;
- }
-
return (handle_t)ctx;
-free_dev:
- free_uacce_dev(ctx->dev);
free_drv_name:
free(ctx->drv_name);
free_dev_name:
free(ctx->dev_name);
free_ctx:
free(ctx);
+close_fd:
+ close(fd);
return 0;
}
--
2.25.1

View File

@ -0,0 +1,32 @@
From 556bf83c694c85c124b90428cb7622cc7babd411 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 10 Jan 2022 18:52:02 +0800
Subject: [PATCH 38/53] uadk: env: bugfix for wd_init_resource
If sched is internal alloc, free it and set to NULL.
Otherwise do not free sched resource from user input.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c
index 9e96114..2e0e062 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1412,7 +1412,10 @@ static int wd_init_resource(struct wd_env_config *config,
err_uninit_alg:
ops->alg_uninit();
err_uninit_sched:
- wd_uninit_sched_config(config->sched);
+ if (config->internal_sched) {
+ wd_uninit_sched_config(config->sched);
+ config->sched = NULL;
+ }
err_uninit_ctx:
wd_free_ctx(config->ctx_config);
return ret;
--
2.25.1

View File

@ -0,0 +1,256 @@
From 388f0f7959acc5130c43b7a7d4a43603724a20a5 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 10 Jan 2022 18:52:03 +0800
Subject: [PATCH 39/53] uadk: env: fix wd ctx num init
No need to set environment variables for ctx num init,
because environment variables need to parse after set,
add wd_parse_ctx_attr to set environment config directly.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_util.h | 1 -
wd_util.c | 152 +++++++++++++---------------------------------
2 files changed, 43 insertions(+), 110 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index 81f4ba8..de2cd44 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -72,7 +72,6 @@ struct wd_env_config {
const struct wd_config_variable *table;
__u32 table_size;
__u16 numa_num;
- __u8 disable_env;
__u8 op_type_num;
};
diff --git a/wd_util.c b/wd_util.c
index 2e0e062..ad108bf 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -474,8 +474,10 @@ static int wd_alloc_numa(struct wd_env_config *config,
/* alloc and init config_per_numa and all uacce dev */
ret = wd_set_config_numa(config, numa_dev_num, max_node);
- if (ret)
+ if (ret) {
+ WD_ERR("failed to set numa config, ret = %d!\n", ret);
goto free_list;
+ }
/* set device and device num for config numa from uacce_dev list */
wd_set_numa_dev(head, config);
@@ -801,11 +803,8 @@ static int wd_parse_env(struct wd_env_config *config)
for (i = 0; i < config->table_size; i++) {
var = config->table + i;
- if (config->disable_env)
- var_s = var->def_val;
- else
- var_s = secure_getenv(var->name);
+ var_s = secure_getenv(var->name);
if (!var_s || !strlen(var_s)) {
var_s = var->def_val;
WD_ERR("no %s environment variable! Use default: %s\n",
@@ -839,6 +838,40 @@ static void wd_free_env(struct wd_env_config *config)
}
}
+static int wd_parse_ctx_attr(struct wd_env_config *env_config,
+ struct wd_ctx_attr *attr)
+{
+ struct wd_env_config_per_numa *config_numa;
+ int ret;
+
+ config_numa = wd_get_config_numa(env_config, attr->node);
+ if (!config_numa) {
+ WD_ERR("%s got wrong numa node!\n", __func__);
+ return -WD_EINVAL;
+ }
+
+ config_numa->op_type_num = env_config->op_type_num;
+ ret = wd_alloc_ctx_table(config_numa);
+ if (ret)
+ return ret;
+
+ config_numa->ctx_table[attr->mode][attr->type].size = attr->num;
+ wd_fill_ctx_table(env_config);
+
+ /* Use default sched and disable internal poll */
+ env_config->sched = NULL;
+ env_config->enable_internal_poll = 0;
+ config_numa->async_poll_num = 0;
+
+ return 0;
+}
+
+static int wd_init_env_config(struct wd_env_config *config,
+ struct wd_ctx_attr *attr)
+{
+ return attr ? wd_parse_ctx_attr(config, attr) : wd_parse_env(config);
+}
+
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
{
struct wd_ctx_range **ctx_table = config->ctx_table;
@@ -869,6 +902,7 @@ static int get_op_type(struct wd_env_config_per_numa *config,
return i;
}
+ WD_ERR("failed to get op type!\n");
return -WD_EINVAL;
}
@@ -1030,6 +1064,7 @@ static int wd_init_sched_config(struct wd_env_config *config)
config->internal_sched = false;
type_num = config->op_type_num;
if (!config->sched) {
+ WD_ERR("no sched is specified, alloc a default sched!\n");
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
max_node, func);
if (!config->sched)
@@ -1430,100 +1465,6 @@ static void wd_uninit_resource(struct wd_env_config *config)
wd_free_ctx(config->ctx_config);
}
-static void *wd_alloc_table(const struct wd_config_variable *table,
- __u32 table_size)
-{
- struct wd_config_variable *alg_table;
- int i, j;
-
- alg_table = malloc(table_size * sizeof(struct wd_config_variable));
- if (!alg_table)
- return NULL;
-
- memcpy(alg_table, table,
- table_size * sizeof(struct wd_config_variable));
- for (i = 0; i < table_size - 1; i++) {
- alg_table[i].def_val = malloc(MAX_STR_LEN);
- if (!alg_table[i].def_val) {
- WD_ERR("%s malloc fail\n", __func__);
- goto free_mem;
- }
- }
-
- return alg_table;
-
-free_mem:
- for (j = 0; j < i; j++)
- free(alg_table[j].def_val);
-
- free(alg_table);
- return NULL;
-}
-
-static int wd_alg_table_init(const struct wd_config_variable *table,
- __u32 table_size,
- struct wd_ctx_attr *attr,
- struct wd_env_config *env_config)
-{
- struct wd_config_variable *var_tbl;
- const char *type_tbl;
- int ret;
-
- if (!attr) {
- env_config->disable_env = 0;
- env_config->table = table;
- return 0;
- }
-
- env_config->disable_env = 1;
-
- var_tbl = wd_alloc_table(table, table_size);
- if (!var_tbl)
- return -WD_ENOMEM;
-
- env_config->table = var_tbl;
-
- /**
- * Below def_val's memory is allocated from wd_alloc_table,
- * the length of memory allocated to def_val is MAX_STR_LEN.
- *
- * We use mode and type as index of a string two-dimensional
- * array to init def_val.
- */
- if (env_config->op_type_num == 1)
- type_tbl = ctx_type[attr->mode][attr->type];
- else
- type_tbl = comp_ctx_type[attr->mode][attr->type];
-
- ret = snprintf(var_tbl[0].def_val, MAX_STR_LEN, "%s%u%c%u",
- type_tbl, attr->num, '@', attr->node);
- if (ret < 0)
- return -errno;
-
- return 0;
-}
-
-static void wd_alg_table_uninit(struct wd_env_config *config)
-{
- struct wd_config_variable *table;
- int i;
-
- if (!config->disable_env)
- return;
-
- table = (struct wd_config_variable *)config->table;
- if (!table)
- return;
-
- for (i = 0; i < config->table_size - 1; i++) {
- free(table[i].def_val);
- table[i].def_val = NULL;
- }
-
- free(table);
- table = NULL;
-}
-
int wd_alg_env_init(struct wd_env_config *env_config,
const struct wd_config_variable *table,
const struct wd_alg_ops *ops,
@@ -1534,18 +1475,14 @@ int wd_alg_env_init(struct wd_env_config *env_config,
env_config->op_type_num = ops->op_type_num;
env_config->alg_poll_ctx = ops->alg_poll_ctx;
+ env_config->table = table;
env_config->table_size = table_size;
- ret = wd_alg_table_init(table, table_size,
- ctx_attr, env_config);
- if (ret)
- return ret;
-
ret = wd_alloc_numa(env_config, ops);
if (ret)
- goto table_uninit;
+ return ret;
- ret = wd_parse_env(env_config);
+ ret = wd_init_env_config(env_config, ctx_attr);
if (ret)
goto free_numa;
@@ -1562,8 +1499,6 @@ free_env:
wd_free_env(env_config);
free_numa:
wd_free_numa(env_config);
-table_uninit:
- wd_alg_table_uninit(env_config);
return ret;
}
@@ -1576,7 +1511,6 @@ void wd_alg_env_uninit(struct wd_env_config *env_config)
wd_uninit_resource(env_config);
wd_free_env(env_config);
wd_free_numa(env_config);
- wd_alg_table_uninit(env_config);
}
int wd_alg_get_env_param(struct wd_env_config *env_config,
--
2.25.1

View File

@ -0,0 +1,39 @@
From f4cd396150be285aa614f4272a51cd3dacf99096 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 10 Jan 2022 20:01:41 +0800
Subject: [PATCH 40/53] uadk: modify for free and return
After free local variable, no need to set NULL.
If return value is not associated with other
functions, no need to set value, return directly.
Signed-off-by: JunchongPan <panjunchong@hisilicon.com>
---
wd_util.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index ad108bf..c2c109c 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -599,7 +599,6 @@ free_mem:
}
free(ctx_table);
- ctx_table = NULL;
return ret;
}
@@ -652,8 +651,7 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
config_numa = wd_get_config_numa(config, node);
if (!config_numa) {
WD_ERR("%s got wrong numa node: %s!\n", __func__, section);
- ret = -WD_EINVAL;
- return ret;
+ return -WD_EINVAL;
}
config_numa->op_type_num = config->op_type_num;
--
2.25.1

View File

@ -0,0 +1,516 @@
From b8c3d3c5f1b3db3b89ed975bb51c7546676f2bd1 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 10 Jan 2022 18:52:04 +0800
Subject: [PATCH 41/53] uadk: include: fix uadk compatibility
Fix that C++ program can't call the uadk interface.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/drv/wd_aead_drv.h | 9 +++++++++
include/drv/wd_cipher_drv.h | 9 +++++++++
include/drv/wd_comp_drv.h | 8 ++++++++
include/drv/wd_dh_drv.h | 8 ++++++++
include/drv/wd_digest_drv.h | 9 +++++++++
include/drv/wd_ecc_drv.h | 8 ++++++++
include/drv/wd_rsa_drv.h | 8 ++++++++
include/hisi_qm_udrv.h | 8 ++++++++
include/uacce.h | 9 +++++++++
include/wd.h | 8 ++++++++
include/wd_aead.h | 8 ++++++++
include/wd_alg_common.h | 8 ++++++++
include/wd_cipher.h | 8 ++++++++
include/wd_common.h | 8 ++++++++
include/wd_comp.h | 8 ++++++++
include/wd_dh.h | 8 ++++++++
include/wd_digest.h | 8 ++++++++
include/wd_rsa.h | 8 ++++++++
include/wd_sched.h | 8 ++++++++
include/wd_util.h | 8 ++++++++
20 files changed, 164 insertions(+)
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
index d2016f0..78a5673 100644
--- a/include/drv/wd_aead_drv.h
+++ b/include/drv/wd_aead_drv.h
@@ -7,6 +7,10 @@
#include "include/wd_alg_common.h"
#include "include/wd_aead.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct wd_aead_msg {
struct wd_aead_req req;
/* Request identifier */
@@ -87,4 +91,9 @@ static void __attribute__((constructor)) set_aead_driver(void) \
wd_aead_set_driver(&drv); \
}
#endif
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_AEAD_DRV_H */
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index d6798c0..e649869 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -7,6 +7,10 @@
#include "../wd_cipher.h"
#include "../wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* fixme wd_cipher_msg */
struct wd_cipher_msg {
struct wd_cipher_req req;
@@ -72,4 +76,9 @@ static void __attribute__((constructor)) set_driver(void) \
wd_cipher_set_driver(&drv); \
}
#endif
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_CIPHER_DRV_H */
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index b4dc722..8146a50 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -7,6 +7,10 @@
#include <pthread.h>
#include "../wd_comp.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
enum wd_comp_strm_pos {
WD_COMP_STREAM_NEW,
WD_COMP_STREAM_OLD,
@@ -79,4 +83,8 @@ static void __attribute__((constructor)) set_driver(void) \
}
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_COMP_DRV_H */
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index 08212b1..5d436d1 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -6,6 +6,10 @@
#include "../wd_dh.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
@@ -45,4 +49,8 @@ static void __attribute__((constructor)) set_driver_dh(void) \
}
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_DH_DRV_H */
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
index ac3b028..fdde772 100644
--- a/include/drv/wd_digest_drv.h
+++ b/include/drv/wd_digest_drv.h
@@ -6,6 +6,10 @@
#include "include/wd_digest.h"
#include "include/wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* fixme wd_digest_msg */
struct wd_digest_msg {
struct wd_digest_req req;
@@ -75,4 +79,9 @@ static void __attribute__((constructor)) set_drivers(void) \
wd_digest_set_driver(&drv); \
}
#endif
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_DIGEST_DRV_H */
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 9f4575f..7e0d27e 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -7,6 +7,10 @@
#include "../wd_ecc.h"
#include "../wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* ECC */
#define ECDH_IN_PARAM_NUM 2
#define ECDH_OUT_PARAM_NUM 2
@@ -198,4 +202,8 @@ static void __attribute__((constructor)) set_driver_ecc(void) \
}
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_ECC_DRV_H */
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index 3c4b144..948625f 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -5,6 +5,10 @@
#include "../wd_rsa.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct wd_rsa_kg_in {
__u8 *e;
__u8 *p;
@@ -70,4 +74,8 @@ static void __attribute__((constructor)) set_driver_rsa(void) \
}
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_RSA_DRV_H */
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 11ee4ad..707d0e3 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -12,6 +12,10 @@
#include "wd.h"
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define WD_CAPA_PRIV_DATA_SIZE 64
#define QM_L32BITS_MASK 0xffffffff
@@ -180,4 +184,8 @@ __u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
void hisi_qm_enable_interrupt(handle_t ctx, __u8 enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/uacce.h b/include/uacce.h
index 7c69df8..07e36fe 100644
--- a/include/uacce.h
+++ b/include/uacce.h
@@ -10,6 +10,10 @@
#include <linux/types.h>
#include <linux/ioctl.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define UACCE_CMD_START _IO('W', 0)
#define UACCE_CMD_PUT_Q _IO('W', 1)
#define UACCE_CMD_GET_SS_DMA _IOR('W', 100, unsigned long)
@@ -33,4 +37,9 @@ enum uacce_qfrt {
UACCE_QFRT_DUS = 1, /* device user share */
UACCE_QFRT_MAX,
};
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/wd.h b/include/wd.h
index ac564d8..273cbb8 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -14,6 +14,10 @@
#include <unistd.h>
#include "uacce.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define PATH_STR_SIZE 256
#define MAX_ATTR_STR_SIZE 384
#define WD_NAME_SIZE 64
@@ -483,4 +487,8 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats);
*/
void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/wd_aead.h b/include/wd_aead.h
index 6377008..f169812 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -14,6 +14,10 @@
#include "wd_digest.h"
#include "wd.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* wd_aead_op_type - Algorithm type of option
*/
@@ -214,4 +218,8 @@ void wd_aead_ctx_num_uninit(void);
int wd_aead_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_AEAD_H */
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index 01a12ca..94336f0 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -12,6 +12,10 @@
#include "wd.h"
#include "wd_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
@@ -103,4 +107,8 @@ struct wd_datalist {
struct wd_datalist *next;
};
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 8c73396..660d7e8 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -11,6 +11,10 @@
#include "wd.h"
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define AES_KEYSIZE_128 16
#define AES_KEYSIZE_192 24
#define AES_KEYSIZE_256 32
@@ -185,4 +189,8 @@ void wd_cipher_ctx_num_uninit(void);
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_CIPHER_H */
diff --git a/include/wd_common.h b/include/wd_common.h
index 61919d5..91dd066 100644
--- a/include/wd_common.h
+++ b/include/wd_common.h
@@ -7,9 +7,17 @@
#ifndef __WD_COMMON_H
#define __WD_COMMON_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
enum wd_buff_type {
WD_FLAT_BUF,
WD_SGL_BUF,
};
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_COMMON_H */
diff --git a/include/wd_comp.h b/include/wd_comp.h
index b6225df..460cfa7 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -12,6 +12,10 @@
#include "wd.h"
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
enum wd_comp_alg_type {
WD_DEFLATE,
WD_ZLIB,
@@ -217,4 +221,8 @@ void wd_comp_ctx_num_uninit(void);
int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_COMP_H */
diff --git a/include/wd_dh.h b/include/wd_dh.h
index c0bce85..f342722 100644
--- a/include/wd_dh.h
+++ b/include/wd_dh.h
@@ -12,6 +12,10 @@
#include "wd.h"
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define BYTE_BITS 8
#define BYTE_BITS_SHIFT 3
#define GET_NEGATIVE(val) (0 - (val))
@@ -69,4 +73,8 @@ void wd_dh_ctx_num_uninit(void);
int wd_dh_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_DH_H */
diff --git a/include/wd_digest.h b/include/wd_digest.h
index 8e8e236..7e93a80 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -11,6 +11,10 @@
#include "wd_alg_common.h"
#include "wd.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define MAX_HMAC_KEY_SIZE 128U
/**
@@ -209,4 +213,8 @@ void wd_digest_ctx_num_uninit(void);
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_DIGEST_H */
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 044819b..081bc2a 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -12,6 +12,10 @@
#include "wd.h"
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define BYTE_BITS 8
#define BYTE_BITS_SHIFT 3
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
@@ -216,4 +220,8 @@ void wd_rsa_ctx_num_uninit(void);
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_RSA_H */
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 78125f4..2ae6103 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -8,6 +8,10 @@
#define SCHED_SAMPLE_h
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define INVALID_POS 0xFFFFFFFF
/* The global policy type */
@@ -56,4 +60,8 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
*/
void wd_sched_rr_release(struct wd_sched *sched);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/wd_util.h b/include/wd_util.h
index de2cd44..ef95907 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -10,6 +10,10 @@
#include <stdbool.h>
#include "wd_alg_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define FOREACH_NUMA(i, config, config_numa) \
for (i = 0, config_numa = config->config_per_numa; \
i < config->numa_num; config_numa++, i++)
@@ -309,4 +313,8 @@ int wd_set_ctx_attr(struct wd_ctx_attr *ctx_attr,
*/
int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __WD_UTIL_H */
--
2.25.1

View File

@ -0,0 +1,50 @@
From bb09e342c186f111600e763ca7a5bfb8713df6f7 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Wed, 12 Jan 2022 09:44:57 +0800
Subject: [PATCH 42/53] uadk: fix for resources are repeatedly released
Segment fault occur when environment resources
are repeatedly released, so add pointer check
for wd_free_ctx and wd_free_env and clear dirty
global Variables.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/wd_util.c b/wd_util.c
index c2c109c..6cae768 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -825,6 +825,9 @@ static void wd_free_env(struct wd_env_config *config)
struct wd_env_config_per_numa *config_numa;
int i, j;
+ if (!config->config_per_numa)
+ return;
+
FOREACH_NUMA(i, config, config_numa) {
if (!config_numa->ctx_table)
continue;
@@ -1010,6 +1013,9 @@ err_free_ctx_config:
static void wd_free_ctx(struct wd_ctx_config *ctx_config)
{
+ if (!ctx_config)
+ return;
+
wd_put_wd_ctx(ctx_config, ctx_config->ctx_num);
free(ctx_config->ctxs);
free(ctx_config);
@@ -1451,6 +1457,7 @@ err_uninit_sched:
}
err_uninit_ctx:
wd_free_ctx(config->ctx_config);
+ config->ctx_config = NULL;
return ret;
}
--
2.25.1

View File

@ -0,0 +1,785 @@
From c421a68ee4f70675235443f9cc968f264c7a39a6 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Thu, 13 Jan 2022 10:37:10 +0800
Subject: [PATCH 43/53] aead: modify the aead's request api
1. Add the parameter of mac address for Openssl engine. Previous
plan not adapted to the Openssl engine, it caused the low performance.
So after modification, user should allocated the mac memory and set
the mac length as doing task.
2. Deleted a parameter in api. the out_buffer_bytes is a redundant
code.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_sec.c | 72 ++----------------
include/wd_aead.h | 6 +-
test/hisi_sec_test/test_hisi_sec.c | 116 ++++++++++++++++++++++-------
uadk_tool/sec_uadk_benchmark.c | 33 ++++----
wd_aead.c | 46 ++++++++----
5 files changed, 152 insertions(+), 121 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index d31a1b9..f5db7eb 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -73,8 +73,8 @@
/* The max BD data length is 16M-512B */
#define MAX_INPUT_DATA_LEN 0xFFFE00
#define MAX_CCM_AAD_LEN 65279
-#define SHA1_ALIGN_SZ 64
-#define SHA512_ALIGN_SZ 128
+#define SHA1_ALIGN_SZ 64U
+#define SHA512_ALIGN_SZ 128U
#define AUTHPAD_OFFSET 2
#define AUTHTYPE_OFFSET 6
@@ -1739,48 +1739,12 @@ static void set_aead_auth_iv(struct wd_aead_msg *msg)
}
}
-static void fill_aead_mac_addr_pbuff(struct wd_aead_msg *msg, __u64 *mac_addr)
-{
- __u64 addr = 0;
-
- if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
- addr = (__u64)(uintptr_t)msg->in + msg->in_bytes + msg->assoc_bytes;
-
- /* AEAD output MAC addr use out addr */
- if (msg->op_type == WD_CIPHER_ENCRYPTION_DIGEST)
- addr = (__u64)(uintptr_t)msg->out + msg->out_bytes - msg->auth_bytes;
-
- *mac_addr = addr;
-}
-
-static void fill_aead_mac_addr_sgl(struct wd_aead_msg *msg, __u64 *mac_addr)
-{
- msg->mac = calloc(1, msg->auth_bytes);
- if (!msg->mac) {
- WD_ERR("failed to alloc mac memory!\n");
- return;
- }
-
- if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
- hisi_qm_sgl_copy(msg->mac, msg->in,
- msg->in_bytes + msg->assoc_bytes,
- msg->auth_bytes, COPY_SGL_TO_PBUFF);
-
- *mac_addr = (__u64)(uintptr_t)msg->mac;
-}
-
static void fill_aead_bd2_addr(struct wd_aead_msg *msg,
struct hisi_sec_sqe *sqe)
{
sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in;
sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out;
-
- /* AEAD input MAC addr use in addr */
- if (msg->data_fmt == WD_FLAT_BUF)
- fill_aead_mac_addr_pbuff(msg, &sqe->type2.mac_addr);
- else
- fill_aead_mac_addr_sgl(msg, &sqe->type2.mac_addr);
-
+ sqe->type2.mac_addr = (__u64)(uintptr_t)msg->mac;
sqe->type2.c_key_addr = (__u64)(uintptr_t)msg->ckey;
sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->akey;
sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
@@ -1939,7 +1903,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
if (recv_msg->auth_bytes == 0)
recv_msg->auth_bytes = sqe->type2.icvw_kmode &
SEC_AUTH_LEN_MASK;
- recv_msg->out_bytes = sqe->type2.clen_ivhlen + recv_msg->auth_bytes +
+ recv_msg->out_bytes = sqe->type2.clen_ivhlen +
sqe->type2.cipher_src_offset;
#ifdef DEBUG
@@ -1961,15 +1925,9 @@ int hisi_sec_aead_recv(handle_t ctx, struct wd_aead_msg *recv_msg)
parse_aead_bd2(&sqe, recv_msg);
- if (recv_msg->data_fmt == WD_SGL_BUF) {
- if (sqe.type_auth_cipher & (SEC_CIPHER_ENC << SEC_CIPHER_OFFSET))
- hisi_qm_sgl_copy(recv_msg->mac, recv_msg->out,
- recv_msg->out_bytes - recv_msg->auth_bytes,
- recv_msg->auth_bytes, COPY_PBUFF_TO_SGL);
-
+ if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
recv_msg->out);
- }
return 0;
}
@@ -2089,18 +2047,10 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
static void fill_aead_bd3_addr(struct wd_aead_msg *msg,
struct hisi_sec_sqe3 *sqe)
{
- __u64 mac_addr;
-
sqe->data_src_addr = (__u64)(uintptr_t)msg->in;
sqe->data_dst_addr = (__u64)(uintptr_t)msg->out;
- /* AEAD input MAC addr use in and out addr */
- if (msg->data_fmt == WD_FLAT_BUF)
- fill_aead_mac_addr_pbuff(msg, &mac_addr);
- else
- fill_aead_mac_addr_sgl(msg, &mac_addr);
-
- sqe->mac_addr = mac_addr;
+ sqe->mac_addr = (__u64)(uintptr_t)msg->mac;
sqe->c_key_addr = (__u64)(uintptr_t)msg->ckey;
sqe->a_key_addr = (__u64)(uintptr_t)msg->akey;
sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
@@ -2237,7 +2187,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
if (recv_msg->auth_bytes == 0)
recv_msg->auth_bytes = (sqe->c_icv_key >> SEC_MAC_OFFSET_V3) &
SEC_MAC_LEN_MASK;
- recv_msg->out_bytes = sqe->c_len_ivin + recv_msg->auth_bytes +
+ recv_msg->out_bytes = sqe->c_len_ivin +
sqe->cipher_src_offset;
#ifdef DEBUG
@@ -2259,15 +2209,9 @@ int hisi_sec_aead_recv_v3(handle_t ctx, struct wd_aead_msg *recv_msg)
parse_aead_bd3(&sqe, recv_msg);
- if (recv_msg->data_fmt == WD_SGL_BUF) {
- if (sqe.c_icv_key & SEC_CIPHER_ENC)
- hisi_qm_sgl_copy(recv_msg->mac, recv_msg->out,
- recv_msg->out_bytes - recv_msg->auth_bytes,
- recv_msg->auth_bytes, COPY_PBUFF_TO_SGL);
-
+ if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type,
recv_msg->in, recv_msg->out);
- }
return 0;
}
diff --git a/include/wd_aead.h b/include/wd_aead.h
index f169812..a632cd8 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -52,11 +52,12 @@ typedef void *wd_alg_aead_cb_t(struct wd_aead_req *req, void *cb_param);
* @ op_type: denoted by enum wd_aead_op_type
* @ src: input data pointer
* @ dst: output data pointer
+ * @ mac: mac data pointer
* @ iv: input iv pointer
* @ in_bytes: input data length
* @ out_bytes: output data length
- * @ out_buf_bytes: output data buffer length
* @ iv_bytes: input iv length
+ * @ mac_bytes: mac data buffer length
* @ assoc_bytes: input associated data length
* @ state: operation result, denoted by WD error code
* @ cb: callback function pointer
@@ -72,11 +73,12 @@ struct wd_aead_req {
struct wd_datalist *list_dst;
void *dst;
};
+ void *mac;
void *iv;
__u32 in_bytes;
__u32 out_bytes;
- __u32 out_buf_bytes;
__u16 iv_bytes;
+ __u16 mac_bytes;
__u16 assoc_bytes;
__u16 state;
__u8 data_fmt;
diff --git a/test/hisi_sec_test/test_hisi_sec.c b/test/hisi_sec_test/test_hisi_sec.c
index dda291d..6f27cd1 100644
--- a/test/hisi_sec_test/test_hisi_sec.c
+++ b/test/hisi_sec_test/test_hisi_sec.c
@@ -279,6 +279,7 @@ static void dump_mem(int sgl, unsigned char *buf, size_t len)
if ((i + 1) % 8 == 0)
SEC_TST_PRT("\n");
}
+ SEC_TST_PRT("\n");
}
}
@@ -2523,6 +2524,7 @@ static int sec_aead_sync_once(void)
unsigned long Perf = 0;
float speed, time_used;
unsigned long cnt = g_times;
+ __u16 mac_bytes;
__u16 auth_size;
__u16 in_size;
__u16 iv_len;
@@ -2553,8 +2555,7 @@ static int sec_aead_sync_once(void)
/* should set key */
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
- if (setup.cmode == WD_CIPHER_CCM ||
- setup.cmode == WD_CIPHER_GCM) {
+ 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) {
SEC_TST_PRT("aead sess set key failed!\n");
@@ -2576,6 +2577,7 @@ static int sec_aead_sync_once(void)
}
auth_size = (__u16)(tv->clen - tv->plen);
+ mac_bytes = auth_size;
ret = wd_aead_set_authsize(h_sess, auth_size);
if (ret) {
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
@@ -2596,6 +2598,18 @@ static int sec_aead_sync_once(void)
}
SEC_TST_PRT("aead get max auth size: %u\n", ret);
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
+ mac_bytes = 16;
+
+ req.mac = malloc(mac_bytes);
+ if (!req.mac) {
+ SEC_TST_PRT("req iv mem malloc failed!\n");
+ ret = -ENOMEM;
+ goto out_key;
+ }
+ memset(req.mac, 0, mac_bytes);
+ req.mac_bytes = mac_bytes;
+
if (g_direction == 0)
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
else
@@ -2609,7 +2623,7 @@ static int sec_aead_sync_once(void)
}
if (in_size > BUFF_SIZE) {
SEC_TST_PRT("alloc in buffer block size too small!\n");
- goto out_key;
+ goto out_mac;
}
unit_sz = cal_unit_sz(in_size, g_sgl_num);
void *src = create_buf(WD_FLAT_BUF, in_size, unit_sz);
@@ -2627,10 +2641,14 @@ static int sec_aead_sync_once(void)
req.in_bytes = tv->plen;
} else {
memcpy(src, tv->assoc, tv->alen);
- memcpy((src + req.assoc_bytes), tv->ctext, tv->clen);
+ memcpy(src + req.assoc_bytes, tv->ctext, tv->clen - auth_size);
req.in_bytes = tv->clen - auth_size;
+ 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);
+
req.src = create_buf(g_data_fmt, in_size, unit_sz);
if (!req.src) {
ret = -ENOMEM;
@@ -2643,21 +2661,19 @@ static int sec_aead_sync_once(void)
dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
if (g_direction == 0) {
- req.out_bytes = req.assoc_bytes + tv->clen;
+ req.out_bytes = req.assoc_bytes + tv->clen - auth_size;
} else {
req.out_bytes = req.assoc_bytes + tv->plen;
}
- req.out_buf_bytes = req.out_bytes + auth_size;
// alloc out buffer memory
- unit_sz = cal_unit_sz(req.out_buf_bytes, g_sgl_num);
- req.dst = create_buf(g_data_fmt, req.out_buf_bytes, unit_sz);
+ unit_sz = cal_unit_sz(req.out_bytes, g_sgl_num);
+ req.dst = create_buf(g_data_fmt, req.out_bytes, unit_sz);
if (!req.dst) {
ret = -ENOMEM;
goto out_dst;
}
- // set iv
req.iv = malloc(AES_BLOCK_SIZE);
if (!req.iv) {
SEC_TST_PRT("req iv mem malloc failed!\n");
@@ -2688,7 +2704,10 @@ 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);
free(req.iv);
out_iv:
@@ -2696,6 +2715,8 @@ out_iv:
out_dst:
free_buf(g_data_fmt, req.src);
out_src:
+out_mac:
+ free(req.mac);
out_key:
wd_aead_free_sess(h_sess);
out:
@@ -2827,6 +2848,7 @@ static int sec_aead_async_once(void)
static pthread_t send_td;
static pthread_t poll_td;
thread_data_d td_data;
+ __u16 mac_bytes;
__u16 auth_size;
__u16 in_size;
__u16 iv_len;
@@ -2857,8 +2879,7 @@ static int sec_aead_async_once(void)
/* should set key */
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
- if (setup.cmode == WD_CIPHER_CCM ||
- setup.cmode == WD_CIPHER_GCM) {
+ 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) {
SEC_TST_PRT("aead sess set key failed!\n");
@@ -2880,6 +2901,7 @@ static int sec_aead_async_once(void)
}
auth_size = (__u16)(tv->clen - tv->plen);
+ mac_bytes = auth_size;
ret = wd_aead_set_authsize(h_sess, auth_size);
if (ret) {
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
@@ -2898,6 +2920,17 @@ static int sec_aead_async_once(void)
goto out_key;
}
SEC_TST_PRT("aead get max auth size: %u\n", ret);
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
+ mac_bytes = 16;
+
+ req.mac = malloc(mac_bytes);
+ if (!req.mac) {
+ SEC_TST_PRT("req iv mem malloc failed!\n");
+ ret = -ENOMEM;
+ goto out_key;
+ }
+ memset(req.mac, 0, mac_bytes);
+ req.mac_bytes = mac_bytes;
if (g_direction == 0)
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
@@ -2908,7 +2941,7 @@ static int sec_aead_async_once(void)
in_size = tv->alen + tv->plen + auth_size;
if (in_size > BUFF_SIZE) {
SEC_TST_PRT("alloc in buffer block size too small!\n");
- goto out_key;
+ goto out_mac;
}
req.assoc_bytes = tv->alen;
unit_sz = cal_unit_sz(BUFF_SIZE, g_sgl_num);
@@ -2931,15 +2964,15 @@ static int sec_aead_async_once(void)
req.in_bytes = tv->plen;
} else {
memcpy(src, tv->assoc, tv->alen);
- memcpy((src + tv->alen), tv->ctext, tv->clen);
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
req.in_bytes = tv->clen - auth_size;
+ memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
}
-
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);
+ 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);
// alloc out buffer memory
@@ -2949,7 +2982,6 @@ static int sec_aead_async_once(void)
goto out_dst;
}
- req.out_buf_bytes = BUFF_SIZE;
if (g_direction == 0)
req.out_bytes = tv->alen + tv->clen;
else
@@ -3010,6 +3042,8 @@ out_iv:
out_dst:
free_buf(g_data_fmt, req.src);
out_src:
+out_mac:
+ free(req.mac);
out_key:
wd_aead_free_sess(h_sess);
out:
@@ -3026,6 +3060,7 @@ static int sec_aead_sync_multi(void)
struct wd_aead_req req;
static pthread_t sendtd[64];
thread_data_d td_data;
+ __u16 mac_bytes;
__u16 auth_size;
__u16 in_size;
__u16 iv_len;
@@ -3056,8 +3091,7 @@ static int sec_aead_sync_multi(void)
/* should set key */
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
- if (setup.cmode == WD_CIPHER_CCM ||
- setup.cmode == WD_CIPHER_GCM) {
+ 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) {
SEC_TST_PRT("aead sess set key failed!\n");
@@ -3079,6 +3113,7 @@ static int sec_aead_sync_multi(void)
}
auth_size = (__u16)(tv->clen - tv->plen);
+ mac_bytes = auth_size;
ret = wd_aead_set_authsize(h_sess, auth_size);
if (ret) {
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
@@ -3098,6 +3133,18 @@ static int sec_aead_sync_multi(void)
}
SEC_TST_PRT("aead get max auth size: %u\n", ret);
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
+ mac_bytes = 16;
+
+ req.mac = malloc(mac_bytes);
+ if (!req.mac) {
+ SEC_TST_PRT("req iv mem malloc failed!\n");
+ ret = -ENOMEM;
+ goto out_key;
+ }
+ memset(req.mac, 0, mac_bytes);
+ req.mac_bytes = mac_bytes;
+
if (g_direction == 0)
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
else
@@ -3108,7 +3155,7 @@ static int sec_aead_sync_multi(void)
in_size = tv->alen + tv->plen + auth_size;
if (in_size > BUFF_SIZE) {
SEC_TST_PRT("alloc in buffer block size too small!\n");
- goto out_key;
+ goto out_mac;
}
unit_sz = cal_unit_sz(BUFF_SIZE, g_sgl_num);
void *src = create_buf(WD_FLAT_BUF, BUFF_SIZE, unit_sz);
@@ -3123,8 +3170,9 @@ static int sec_aead_sync_multi(void)
req.in_bytes = tv->plen;
} else {
memcpy(src, tv->assoc, tv->alen);
- memcpy((src + tv->alen), tv->ctext, tv->clen);
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
req.in_bytes = tv->clen - auth_size;
+ memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
}
req.src = create_buf(g_data_fmt, in_size, unit_sz);
@@ -3137,7 +3185,7 @@ static int sec_aead_sync_multi(void)
(size_t)(req.in_bytes + tv->alen));
free(src);
- SEC_TST_PRT("aead req src in--------->: %u\n", tv->alen + req.in_bytes);
+ 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);
// alloc out buffer memory
@@ -3147,7 +3195,6 @@ static int sec_aead_sync_multi(void)
goto out_dst;
}
- req.out_buf_bytes = BUFF_SIZE;
if (g_direction == 0)
req.out_bytes = tv->alen + tv->clen;
else
@@ -3175,6 +3222,7 @@ static int sec_aead_sync_multi(void)
td_data.recv_num = g_times;
td_data.sum_perf = 0;
+ printf("%s, req->in_bytes:%d\n", __func__, req.in_bytes);
for (i = 0; i < g_thread_num; i++) {
ret = pthread_create(&sendtd[i], NULL, aead_sync_send_thread, &td_data);
if (ret) {
@@ -3200,6 +3248,8 @@ out_iv:
out_dst:
free_buf(g_data_fmt, req.src);
out_src:
+out_mac:
+ free(req.mac);
out_key:
wd_aead_free_sess(h_sess);
out:
@@ -3217,6 +3267,7 @@ static int sec_aead_async_multi(void)
static pthread_t send_td[64];
static pthread_t poll_td;
thread_data_d td_data;
+ __u16 mac_bytes;
__u16 auth_size;
__u16 in_size;
__u16 iv_len;
@@ -3247,8 +3298,7 @@ static int sec_aead_async_multi(void)
/* should set key */
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
- if (setup.cmode == WD_CIPHER_CCM ||
- setup.cmode == WD_CIPHER_GCM) {
+ 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) {
SEC_TST_PRT("aead sess set key failed!\n");
@@ -3270,6 +3320,7 @@ static int sec_aead_async_multi(void)
}
auth_size = (__u16)(tv->clen - tv->plen);
+ mac_bytes = auth_size;
ret = wd_aead_set_authsize(h_sess, auth_size);
if (ret) {
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
@@ -3289,6 +3340,15 @@ static int sec_aead_async_multi(void)
}
SEC_TST_PRT("aead get max auth size: %u\n", ret);
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
+ mac_bytes = 16;
+
+ req.mac = malloc(mac_bytes);
+ if (req.mac == NULL)
+ goto out;
+ memset(req.mac, 0, mac_bytes);
+ req.mac_bytes = mac_bytes;
+
if (g_direction == 0)
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
else
@@ -3321,8 +3381,9 @@ static int sec_aead_async_multi(void)
req.in_bytes = tv->plen;
} else {
memcpy(src, tv->assoc, tv->alen);
- memcpy((src + tv->alen), tv->ctext, tv->clen);
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
req.in_bytes = tv->clen - auth_size;
+ memcpy(req.mac, tv->ctext + (tv->clen - auth_size), auth_size);
}
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
@@ -3338,9 +3399,8 @@ static int sec_aead_async_multi(void)
ret = -1;
goto out;
}
- req.out_buf_bytes = BUFF_SIZE;
if (g_direction == 0)
- req.out_bytes = tv->alen + tv->clen;
+ req.out_bytes = tv->alen + tv->clen - auth_size;
else
req.out_bytes = tv->alen + tv->plen;
@@ -3396,6 +3456,8 @@ static int sec_aead_async_multi(void)
dump_mem(g_data_fmt, req.dst, req.out_bytes);
out:
+ if (req.mac)
+ free(req.mac);
if (req.src)
free_buf(g_data_fmt, req.src);
if (req.dst)
diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c
index 40ba227..d68ac25 100644
--- a/uadk_tool/sec_uadk_benchmark.c
+++ b/uadk_tool/sec_uadk_benchmark.c
@@ -24,6 +24,7 @@ struct thread_pool {
struct bd_pool *pool;
u8 *iv;
u8 *key;
+ u8 *mac;
} g_uadk_pool;
typedef struct uadk_thread_res {
@@ -475,6 +476,7 @@ 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.pool = malloc(g_thread_num * sizeof(struct bd_pool));
if (!g_uadk_pool.pool) {
@@ -611,9 +613,10 @@ static void *sec_uadk_async_run(void *arg)
struct wd_aead_req areq;
struct wd_digest_req dreq;
struct bd_pool *uadk_pool;
- u8 *priv_iv, *priv_key;
+ u8 *priv_iv, *priv_key, *priv_mac;
int try_cnt = 0;
handle_t h_sess;
+ u32 auth_size = 16;
u32 count = 0;
int ret, i = 0;
@@ -623,6 +626,7 @@ 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);
@@ -687,7 +691,7 @@ static void *sec_uadk_async_run(void *arg)
wd_aead_free_sess(h_sess);
return NULL;
}
- ret = wd_aead_set_authsize(h_sess, 16);
+ 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);
@@ -696,16 +700,15 @@ static void *sec_uadk_async_run(void *arg)
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
+ if (areq.op_type)// decrypto
areq.out_bytes = g_pktlen + 16; // aadsize = 16;
- areq.out_buf_bytes = areq.out_bytes + 16; // authsize = 16
- } else {
+ else
areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
- areq.out_buf_bytes = areq.out_bytes + 32;
- }
areq.data_fmt = 0;
areq.state = 0;
@@ -795,8 +798,9 @@ static void *sec_uadk_sync_run(void *arg)
struct wd_aead_req areq;
struct wd_digest_req dreq;
struct bd_pool *uadk_pool;
- u8 *priv_iv, *priv_key;
+ u8 *priv_iv, *priv_key, *priv_mac;
handle_t h_sess;
+ u32 auth_size = 16;
u32 count = 0;
int ret, i = 0;
@@ -806,6 +810,7 @@ static void *sec_uadk_sync_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);
@@ -860,7 +865,7 @@ static void *sec_uadk_sync_run(void *arg)
wd_aead_free_sess(h_sess);
return NULL;
}
- ret = wd_aead_set_authsize(h_sess, 16);
+ 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);
@@ -869,16 +874,16 @@ static void *sec_uadk_sync_run(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.in_bytes = g_pktlen;
- if (areq.op_type) {// decrypto
+ areq.mac_bytes = auth_size;
+ if (areq.op_type)// decrypto
areq.out_bytes = g_pktlen + 16; // aadsize = 16;
- areq.out_buf_bytes = areq.out_bytes + 16; // authsize = 16
- } else {
+ else
areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
- areq.out_buf_bytes = areq.out_bytes + 32;
- }
areq.data_fmt = 0;
areq.state = 0;
diff --git a/wd_aead.c b/wd_aead.c
index ebad440..670bb33 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -305,6 +305,33 @@ void wd_aead_free_sess(handle_t h_sess)
free(sess);
}
+static int aead_mac_param_check(struct wd_aead_sess *sess,
+ struct wd_aead_req *req)
+{
+ int ret = 0;
+
+ switch (sess->cmode) {
+ case WD_CIPHER_CBC:
+ if (req->mac_bytes < g_aead_mac_len[sess->dalg]) {
+ WD_ERR("failed to check cbc-hmac mac buffer length!\n");
+ ret = -WD_EINVAL;
+ }
+ break;
+ case WD_CIPHER_CCM:
+ case WD_CIPHER_GCM:
+ if (req->mac_bytes < WD_AEAD_CCM_GCM_MAX) {
+ WD_ERR("failed to check CCM or GCM mac buffer length!\n");
+ ret = -WD_EINVAL;
+ }
+ break;
+ default:
+ ret = -WD_EINVAL;
+ WD_ERR("set the aead cmode is error!\n");
+ }
+
+ return ret;
+}
+
static int aead_param_check(struct wd_aead_sess *sess,
struct wd_aead_req *req)
{
@@ -328,33 +355,23 @@ static int aead_param_check(struct wd_aead_sess *sess,
}
if (unlikely(req->iv_bytes != get_iv_block_size(sess->cmode))) {
- WD_ERR("failed to check aead IV length!\n");
+ WD_ERR("failed to check aead IV length, size:%u\n", req->iv_bytes);
return -WD_EINVAL;
}
- if (unlikely(req->out_buf_bytes < req->out_bytes)) {
- WD_ERR("failed to check aead out buffer length!\n");
- return -WD_EINVAL;
- }
-
- if (unlikely(req->op_type == WD_CIPHER_ENCRYPTION_DIGEST &&
- req->out_buf_bytes < (req->out_bytes + sess->auth_bytes))) {
- WD_ERR("failed to check aead type or mac length!\n");
+ ret = aead_mac_param_check(sess, req);
+ if (unlikely(ret))
return -WD_EINVAL;
- }
if (req->data_fmt == WD_SGL_BUF) {
len = req->in_bytes + req->assoc_bytes;
- if (req->op_type == WD_CIPHER_DECRYPTION_DIGEST)
- len += sess->auth_bytes;
-
ret = wd_check_datalist(req->list_src, len);
if (unlikely(ret)) {
WD_ERR("failed to check the src datalist!\n");
return -WD_EINVAL;
}
- ret = wd_check_datalist(req->list_dst, req->out_buf_bytes);
+ ret = wd_check_datalist(req->list_dst, req->out_bytes);
if (unlikely(ret)) {
WD_ERR("failed to check the dst datalist!\n");
return -WD_EINVAL;
@@ -480,6 +497,7 @@ static void fill_request_msg(struct wd_aead_msg *msg, struct wd_aead_req *req,
msg->iv = req->iv;
msg->iv_bytes = req->iv_bytes;
msg->assoc_bytes = req->assoc_bytes;
+ msg->mac = req->mac;
msg->auth_bytes = sess->auth_bytes;
msg->data_fmt = req->data_fmt;
}
--
2.25.1

View File

@ -0,0 +1,80 @@
From e191549317c08e340b9406bf2958868b1f119df2 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Thu, 13 Jan 2022 16:33:37 +0800
Subject: [PATCH 44/53] cipher: add semi-weak keys checking
Add semi-weak keys checking based on OpenSSL. it will improve the
security of the system.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
wd_cipher.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/wd_cipher.c b/wd_cipher.c
index 9c1f98c..85f7e65 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -19,15 +19,31 @@
#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
#define WD_POOL_MAX_ENTRIES 1024
-#define DES_WEAK_KEY_NUM 4
+#define DES_WEAK_KEY_NUM 16
#define MAX_RETRY_COUNTS 200000000
#define POLL_SIZE 100000
#define POLL_TIME 1000
-static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {
- 0x0101010101010101, 0xFEFEFEFEFEFEFEFE,
- 0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E
+static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
+ /* weak keys */
+ {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
+ {0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE},
+ {0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E},
+ {0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1},
+ /* semi-weak keys */
+ {0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE},
+ {0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01},
+ {0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1},
+ {0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E},
+ {0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1},
+ {0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01},
+ {0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE},
+ {0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E},
+ {0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E},
+ {0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01},
+ {0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE},
+ {0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1}
};
struct wd_cipher_setting {
@@ -81,12 +97,12 @@ void wd_cipher_set_driver(struct wd_cipher_driver *drv)
wd_cipher_setting.driver = drv;
}
-static bool is_des_weak_key(const __u64 *key)
+static bool is_des_weak_key(const __u8 *key)
{
int i;
for (i = 0; i < DES_WEAK_KEY_NUM; i++) {
- if (*key == des_weak_key[i])
+ if (memcmp(des_weak_keys[i], key, DES_KEY_SIZE) == 0)
return true;
}
@@ -173,7 +189,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
WD_ERR("cipher set key input key length err!\n");
return -WD_EINVAL;
}
- if (sess->alg == WD_CIPHER_DES && is_des_weak_key((__u64 *)key)) {
+ if (sess->alg == WD_CIPHER_DES && is_des_weak_key(key)) {
WD_ERR("input des key is weak key!\n");
return -WD_EINVAL;
}
--
2.25.1

View File

@ -0,0 +1,41 @@
From ef361818b1a67a6540ea4b0d2538090eea56863e Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 15 Jan 2022 16:53:58 +0800
Subject: [PATCH 45/53] uadk: ioctl return result should be printed
ioctl return result may be discarded,
it is useful to debug kernel error,
so it should be printed directly.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/wd.c b/wd.c
index 787d74b..6bbf677 100644
--- a/wd.c
+++ b/wd.c
@@ -386,7 +386,8 @@ int wd_ctx_start(handle_t h_ctx)
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
if (ret)
- WD_ERR("Fail to start on %s (%d).\n", ctx->dev_path, -errno);
+ WD_ERR("Fail to start on %s (%d), ret = %d!\n",
+ ctx->dev_path, -errno, ret);
return ret;
}
@@ -401,7 +402,8 @@ int wd_release_ctx_force(handle_t h_ctx)
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_PUT_Q, NULL);
if (ret)
- WD_ERR("Fail to stop on %s (%d).\n", ctx->dev_path, -errno);
+ WD_ERR("Fail to stop on %s (%d), ret = %d!\n",
+ ctx->dev_path, -errno, ret);
return ret;
}
--
2.25.1

View File

@ -0,0 +1,412 @@
From 282d7d06d0585d117ab62263ab3722950e9693f0 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 15 Jan 2022 16:53:59 +0800
Subject: [PATCH 46/53] uadk: fix environment uninit repeatly error
use wd_uninit_env_config to restore wd_init_env_config do,
move setting gloab environment config to wd_init_env_config.
function should not be set to NULL, because it may used to
uninit resource.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_util.h | 7 ++--
wd_aead.c | 4 +--
wd_cipher.c | 4 +--
wd_comp.c | 4 +--
wd_dh.c | 4 +--
wd_digest.c | 4 +--
wd_ecc.c | 4 +--
wd_rsa.c | 4 +--
wd_util.c | 88 ++++++++++++++++++++++++++++++-----------------
9 files changed, 74 insertions(+), 49 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index ef95907..2d3c1e4 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -66,8 +66,6 @@ struct wd_env_config {
struct wd_env_config_per_numa *config_per_numa;
/* Let's make it as a gobal config, not per numa */
bool enable_internal_poll;
- int (*alg_poll_ctx)(__u32, __u32, __u32 *);
- void (*alg_uninit)(void);
/* resource config */
struct wd_sched *sched;
@@ -263,8 +261,11 @@ int wd_alg_env_init(struct wd_env_config *config,
* wd_alg_env_uninit() - uninit specific wd algorithm environment configuration.
* @config: Pointer of wd_env_config which is used to store environment
* variable information.
+ * @ops: Define functions which will be used by specific wd algorithm
+ * environment init.
*/
-void wd_alg_env_uninit(struct wd_env_config *env_config);
+void wd_alg_env_uninit(struct wd_env_config *env_config,
+ const struct wd_alg_ops *ops);
/*
* wd_add_task_to_async_queue() - Add an async request to its related async
diff --git a/wd_aead.c b/wd_aead.c
index 670bb33..32d06ec 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -716,7 +716,7 @@ int wd_aead_env_init(struct wd_sched *sched)
void wd_aead_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_aead_env_config);
+ return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops);
}
int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -734,7 +734,7 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_aead_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_aead_env_config);
+ return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops);
}
int wd_aead_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_cipher.c b/wd_cipher.c
index 85f7e65..5be3123 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -634,7 +634,7 @@ int wd_cipher_env_init(struct wd_sched *sched)
void wd_cipher_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_cipher_env_config);
+ return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops);
}
int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -652,7 +652,7 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_cipher_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_cipher_env_config);
+ return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops);
}
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_comp.c b/wd_comp.c
index fc355a9..7868551 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -775,7 +775,7 @@ int wd_comp_env_init(struct wd_sched *sched)
void wd_comp_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_comp_env_config);
+ return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops);
}
int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -798,7 +798,7 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_comp_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_comp_env_config);
+ return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops);
}
int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_dh.c b/wd_dh.c
index 7b849ac..1784099 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -564,7 +564,7 @@ int wd_dh_env_init(struct wd_sched *sched)
void wd_dh_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_dh_env_config);
+ return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops);
}
int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -582,7 +582,7 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_dh_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_dh_env_config);
+ return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops);
}
int wd_dh_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_digest.c b/wd_digest.c
index 2b3661d..525d6a9 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -525,7 +525,7 @@ int wd_digest_env_init(struct wd_sched *sched)
void wd_digest_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_digest_env_config);
+ return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops);
}
int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -543,7 +543,7 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_digest_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_digest_env_config);
+ return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops);
}
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_ecc.c b/wd_ecc.c
index e37fb39..e324473 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2286,7 +2286,7 @@ int wd_ecc_env_init(struct wd_sched *sched)
void wd_ecc_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_ecc_env_config);
+ return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops);
}
int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -2304,7 +2304,7 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_ecc_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_ecc_env_config);
+ return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops);
}
int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_rsa.c b/wd_rsa.c
index b6cc0d1..1f911b4 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -1160,7 +1160,7 @@ int wd_rsa_env_init(struct wd_sched *sched)
void wd_rsa_env_uninit(void)
{
- return wd_alg_env_uninit(&wd_rsa_env_config);
+ return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops);
}
int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
@@ -1178,7 +1178,7 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_rsa_ctx_num_uninit(void)
{
- return wd_alg_env_uninit(&wd_rsa_env_config);
+ return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops);
}
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
diff --git a/wd_util.c b/wd_util.c
index 6cae768..38599c2 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -868,11 +868,27 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
}
static int wd_init_env_config(struct wd_env_config *config,
- struct wd_ctx_attr *attr)
+ struct wd_ctx_attr *attr,
+ const struct wd_alg_ops *ops,
+ const struct wd_config_variable *table,
+ __u32 table_size)
{
+ config->op_type_num = ops->op_type_num;
+ config->table_size = table_size;
+ config->table = table;
+
return attr ? wd_parse_ctx_attr(config, attr) : wd_parse_env(config);
}
+static void wd_uninit_env_config(struct wd_env_config *config)
+{
+ config->op_type_num = 0;
+ config->table_size = 0;
+ config->table = NULL;
+
+ wd_free_env(config);
+}
+
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
{
struct wd_ctx_range **ctx_table = config->ctx_table;
@@ -1051,7 +1067,8 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
return 0;
}
-static int wd_init_sched_config(struct wd_env_config *config)
+static int wd_init_sched_config(struct wd_env_config *config,
+ void *alg_poll_ctx)
{
struct wd_env_config_per_numa *config_numa;
int i, j, ret, max_node, type_num;
@@ -1063,7 +1080,7 @@ static int wd_init_sched_config(struct wd_env_config *config)
return -WD_EINVAL;
if (!config->enable_internal_poll)
- func = config->alg_poll_ctx;
+ func = alg_poll_ctx;
config->internal_sched = false;
type_num = config->op_type_num;
@@ -1340,7 +1357,8 @@ static void wd_uninit_one_task_queue(struct async_task_queue *task_queue)
}
static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
- struct wd_env_config_per_numa *config_numa)
+ struct wd_env_config_per_numa *config_numa,
+ void *alg_poll_ctx)
{
struct async_task_queue *task_queue, *queue_head;
int i, j, ret;
@@ -1365,7 +1383,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
task_queue = queue_head;
for (i = 0; i < num; task_queue++, i++) {
- ret = wd_init_one_task_queue(task_queue, config->alg_poll_ctx);
+ ret = wd_init_one_task_queue(task_queue, alg_poll_ctx);
if (ret) {
for (j = 0; j < i; task_queue++, j++)
wd_uninit_one_task_queue(task_queue);
@@ -1386,6 +1404,9 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
double num;
int i;
+ if (!config_numa || !config_numa->async_task_queue_array)
+ return;
+
head = config_numa->async_task_queue_array;
task_queue = head;
num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
@@ -1396,7 +1417,8 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
config_numa->async_task_queue_array = NULL;
}
-static int wd_init_async_polling_thread(struct wd_env_config *config)
+static int wd_init_async_polling_thread(struct wd_env_config *config,
+ void *alg_poll_ctx)
{
struct wd_env_config_per_numa *config_numa;
int i, ret;
@@ -1405,12 +1427,19 @@ static int wd_init_async_polling_thread(struct wd_env_config *config)
return 0;
FOREACH_NUMA(i, config, config_numa) {
- ret = wd_init_async_polling_thread_per_numa(config, config_numa);
+ ret = wd_init_async_polling_thread_per_numa(config, config_numa,
+ alg_poll_ctx);
if (ret)
- return ret;
+ goto out;
}
return 0;
+
+out:
+ FOREACH_NUMA(i, config, config_numa)
+ wd_uninit_async_polling_thread_per_numa(config, config_numa);
+
+ return ret;
}
static void wd_uninit_async_polling_thread(struct wd_env_config *config)
@@ -1434,7 +1463,7 @@ static int wd_init_resource(struct wd_env_config *config,
if (ret)
return ret;
- ret = wd_init_sched_config(config);
+ ret = wd_init_sched_config(config, ops->alg_poll_ctx);
if (ret)
goto err_uninit_ctx;
@@ -1442,7 +1471,7 @@ static int wd_init_resource(struct wd_env_config *config,
if (ret)
goto err_uninit_sched;
- ret = wd_init_async_polling_thread(config);
+ ret = wd_init_async_polling_thread(config, ops->alg_poll_ctx);
if (ret)
goto err_uninit_alg;
@@ -1461,13 +1490,19 @@ err_uninit_ctx:
return ret;
}
-static void wd_uninit_resource(struct wd_env_config *config)
+static void wd_uninit_resource(struct wd_env_config *config,
+ const struct wd_alg_ops *ops)
{
wd_uninit_async_polling_thread(config);
- config->alg_uninit();
- if (config->internal_sched)
+ ops->alg_uninit();
+
+ if (config->internal_sched) {
wd_uninit_sched_config(config->sched);
+ config->sched = NULL;
+ }
+
wd_free_ctx(config->ctx_config);
+ config->ctx_config = NULL;
}
int wd_alg_env_init(struct wd_env_config *env_config,
@@ -1478,43 +1513,32 @@ int wd_alg_env_init(struct wd_env_config *env_config,
{
int ret;
- env_config->op_type_num = ops->op_type_num;
- env_config->alg_poll_ctx = ops->alg_poll_ctx;
- env_config->table = table;
- env_config->table_size = table_size;
-
ret = wd_alloc_numa(env_config, ops);
if (ret)
return ret;
- ret = wd_init_env_config(env_config, ctx_attr);
+ ret = wd_init_env_config(env_config, ctx_attr, ops, table, table_size);
if (ret)
goto free_numa;
ret = wd_init_resource(env_config, ops);
if (ret)
- goto free_env;
-
- /* Use alg_uninit as a sign of initialization complete */
- env_config->alg_uninit = ops->alg_uninit;
+ goto uninit_env_config;
return 0;
-free_env:
- wd_free_env(env_config);
+uninit_env_config:
+ wd_uninit_env_config(env_config);
free_numa:
wd_free_numa(env_config);
return ret;
}
-void wd_alg_env_uninit(struct wd_env_config *env_config)
+void wd_alg_env_uninit(struct wd_env_config *env_config,
+ const struct wd_alg_ops *ops)
{
- /* Check whether the initialization is complete */
- if (!env_config->alg_uninit)
- return;
-
- wd_uninit_resource(env_config);
- wd_free_env(env_config);
+ wd_uninit_resource(env_config, ops);
+ wd_uninit_env_config(env_config);
wd_free_numa(env_config);
}
--
2.25.1

View File

@ -0,0 +1,140 @@
From e4a3312ea000abb796d513c59a8ae10dd9ef605b Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 15 Jan 2022 16:54:00 +0800
Subject: [PATCH 47/53] uadk: fix wd_free_ctx and wd_uninit_sched_config
wd_free_ctx and wd_uninit_sched_config not use struct wd_env_config
as an input parameter, they need to clear wd_env_config member outside,
so optimize it to set null within the function.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 51 ++++++++++++++++++++++++---------------------------
1 file changed, 24 insertions(+), 27 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index 38599c2..8ad2bd0 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1027,14 +1027,18 @@ err_free_ctx_config:
return ret;
}
-static void wd_free_ctx(struct wd_ctx_config *ctx_config)
+static void wd_free_ctx(struct wd_env_config *config)
{
- if (!ctx_config)
+ struct wd_ctx_config *ctx_config;
+
+ if (!config->ctx_config)
return;
+ ctx_config = config->ctx_config;
wd_put_wd_ctx(ctx_config, ctx_config->ctx_num);
free(ctx_config->ctxs);
free(ctx_config);
+ config->ctx_config = NULL;
}
static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
@@ -1067,14 +1071,23 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
return 0;
}
+static void wd_uninit_sched_config(struct wd_env_config *config)
+{
+ if (!config->sched || !config->internal_sched)
+ return;
+
+ wd_sched_rr_release(config->sched);
+ config->sched = NULL;
+}
+
static int wd_init_sched_config(struct wd_env_config *config,
void *alg_poll_ctx)
{
struct wd_env_config_per_numa *config_numa;
int i, j, ret, max_node, type_num;
- struct wd_sched *sched;
void *func = NULL;
+ type_num = config->op_type_num;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -WD_EINVAL;
@@ -1083,7 +1096,6 @@ static int wd_init_sched_config(struct wd_env_config *config,
func = alg_poll_ctx;
config->internal_sched = false;
- type_num = config->op_type_num;
if (!config->sched) {
WD_ERR("no sched is specified, alloc a default sched!\n");
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
@@ -1094,13 +1106,12 @@ static int wd_init_sched_config(struct wd_env_config *config,
config->internal_sched = true;
}
- sched = config->sched;
- sched->name = "SCHED_RR";
+ config->sched->name = "SCHED_RR";
FOREACH_NUMA(i, config, config_numa) {
for (j = 0; j < CTX_MODE_MAX; j++) {
ret = wd_sched_fill_table(config_numa,
- sched, j,
+ config->sched, j,
type_num);
if (ret)
goto err_release_sched;
@@ -1110,13 +1121,9 @@ static int wd_init_sched_config(struct wd_env_config *config,
return 0;
err_release_sched:
- wd_sched_rr_release(sched);
- return ret;
-}
+ wd_uninit_sched_config(config);
-static void wd_uninit_sched_config(struct wd_sched *sched_config)
-{
- return wd_sched_rr_release(sched_config);
+ return ret;
}
static struct async_task_queue *find_async_queue(struct wd_env_config *config,
@@ -1480,13 +1487,9 @@ static int wd_init_resource(struct wd_env_config *config,
err_uninit_alg:
ops->alg_uninit();
err_uninit_sched:
- if (config->internal_sched) {
- wd_uninit_sched_config(config->sched);
- config->sched = NULL;
- }
+ wd_uninit_sched_config(config);
err_uninit_ctx:
- wd_free_ctx(config->ctx_config);
- config->ctx_config = NULL;
+ wd_free_ctx(config);
return ret;
}
@@ -1495,14 +1498,8 @@ static void wd_uninit_resource(struct wd_env_config *config,
{
wd_uninit_async_polling_thread(config);
ops->alg_uninit();
-
- if (config->internal_sched) {
- wd_uninit_sched_config(config->sched);
- config->sched = NULL;
- }
-
- wd_free_ctx(config->ctx_config);
- config->ctx_config = NULL;
+ wd_uninit_sched_config(config);
+ wd_free_ctx(config);
}
int wd_alg_env_init(struct wd_env_config *env_config,
--
2.25.1

View File

@ -0,0 +1,206 @@
From 8ad7bf917ea2940042e707cf37187d2623004bbc Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 15 Jan 2022 16:54:01 +0800
Subject: [PATCH 48/53] uadk: env: fix free ctx table memory leak
Add wd_free_ctx_table to free ctx table of all numa and
wd_free_ctx_table_per_numa to free single numa's ctx table.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_util.h | 2 +-
wd_util.c | 79 +++++++++++++++++++++++------------------------
2 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index 2d3c1e4..c07ecce 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -16,7 +16,7 @@ extern "C" {
#define FOREACH_NUMA(i, config, config_numa) \
for (i = 0, config_numa = config->config_per_numa; \
- i < config->numa_num; config_numa++, i++)
+ config_numa && i < config->numa_num; config_numa++, i++)
struct wd_async_msg_pool {
struct msg_pool *pools;
diff --git a/wd_util.c b/wd_util.c
index 8ad2bd0..7fa688d 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -351,9 +351,6 @@ static void wd_free_numa(struct wd_env_config *config)
struct wd_env_config_per_numa *config_numa;
int i;
- if (!config->config_per_numa)
- return;
-
FOREACH_NUMA(i, config, config_numa)
free(config_numa->dev);
@@ -566,12 +563,12 @@ out:
return -WD_EINVAL;
}
-static int wd_alloc_ctx_table(struct wd_env_config_per_numa *config_numa)
+static int wd_alloc_ctx_table_per_numa(struct wd_env_config_per_numa *config)
{
struct wd_ctx_range **ctx_table;
int i, j, ret;
- if (config_numa->ctx_table)
+ if (config->ctx_table)
return 0;
ctx_table = calloc(1, sizeof(struct wd_ctx_range *) * CTX_MODE_MAX);
@@ -581,27 +578,48 @@ static int wd_alloc_ctx_table(struct wd_env_config_per_numa *config_numa)
for (i = 0; i < CTX_MODE_MAX; i++) {
ctx_table[i] = calloc(1,
sizeof(struct wd_ctx_range) *
- config_numa->op_type_num);
+ config->op_type_num);
if (!ctx_table[i]) {
ret = -WD_ENOMEM;
goto free_mem;
}
}
- config_numa->ctx_table = ctx_table;
+ config->ctx_table = ctx_table;
return 0;
free_mem:
- for (j = 0; j < i; j++) {
+ for (j = 0; j < i; j++)
free(ctx_table[j]);
- ctx_table[j] = NULL;
- }
free(ctx_table);
return ret;
}
+static void wd_free_ctx_table_per_numa(struct wd_env_config_per_numa *config)
+{
+ int i;
+
+ if (!config->ctx_table)
+ return;
+
+ for (i = 0; i < CTX_MODE_MAX; i++)
+ free(config->ctx_table[i]);
+
+ free(config->ctx_table);
+ config->ctx_table = NULL;
+}
+
+static void wd_free_ctx_table(struct wd_env_config *config)
+{
+ struct wd_env_config_per_numa *config_numa;
+ int i;
+
+ FOREACH_NUMA(i, config, config_numa)
+ wd_free_ctx_table_per_numa(config_numa);
+}
+
static int get_and_fill_ctx_num(struct wd_env_config_per_numa *config_numa,
const char *p, int ctx_num)
{
@@ -655,15 +673,18 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
}
config_numa->op_type_num = config->op_type_num;
- ret = wd_alloc_ctx_table(config_numa);
+ ret = wd_alloc_ctx_table_per_numa(config_numa);
if (ret)
return ret;
ret = get_and_fill_ctx_num(config_numa, section, ctx_num);
- if (ret)
+ if (ret) {
WD_ERR("%s got wrong ctx type: %s!\n", __func__, section);
+ wd_free_ctx_table_per_numa(config_numa);
+ return ret;
+ }
- return ret;
+ return 0;
}
static int get_start_ctx_index(struct wd_env_config *config,
@@ -722,9 +743,8 @@ static void wd_fill_ctx_table(struct wd_env_config *config)
static int parse_ctx_num(struct wd_env_config *config, const char *s)
{
- struct wd_env_config_per_numa *config_numa;
char *left, *section, *start;
- int i, ret;
+ int ret;
start = strdup(s);
if (!start)
@@ -744,9 +764,7 @@ static int parse_ctx_num(struct wd_env_config *config, const char *s)
return 0;
err_free_ctx_table:
- FOREACH_NUMA(i, config, config_numa)
- free(config_numa->ctx_table);
-
+ wd_free_ctx_table(config);
free(start);
return ret;
}
@@ -820,25 +838,6 @@ static int wd_parse_env(struct wd_env_config *config)
return 0;
}
-static void wd_free_env(struct wd_env_config *config)
-{
- struct wd_env_config_per_numa *config_numa;
- int i, j;
-
- if (!config->config_per_numa)
- return;
-
- FOREACH_NUMA(i, config, config_numa) {
- if (!config_numa->ctx_table)
- continue;
-
- for (j = 0; j < CTX_MODE_MAX; j++)
- free(config_numa->ctx_table[j]);
-
- free(config_numa->ctx_table);
- }
-}
-
static int wd_parse_ctx_attr(struct wd_env_config *env_config,
struct wd_ctx_attr *attr)
{
@@ -852,7 +851,7 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
}
config_numa->op_type_num = env_config->op_type_num;
- ret = wd_alloc_ctx_table(config_numa);
+ ret = wd_alloc_ctx_table_per_numa(config_numa);
if (ret)
return ret;
@@ -882,11 +881,11 @@ static int wd_init_env_config(struct wd_env_config *config,
static void wd_uninit_env_config(struct wd_env_config *config)
{
+ wd_free_ctx_table(config);
+
config->op_type_num = 0;
config->table_size = 0;
config->table = NULL;
-
- wd_free_env(config);
}
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
--
2.25.1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
From 4491fd2e4fb1c1d101e4c2d45998b484ce946443 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Wed, 19 Jan 2022 11:25:34 +0800
Subject: [PATCH 51/53] uadk: fix for wd_env_config numa_num
numa number should be updated synchronously
with config_per_numa, so set it to zero when
free numa.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_util.h | 2 +-
wd_util.c | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index c07ecce..2d3c1e4 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -16,7 +16,7 @@ extern "C" {
#define FOREACH_NUMA(i, config, config_numa) \
for (i = 0, config_numa = config->config_per_numa; \
- config_numa && i < config->numa_num; config_numa++, i++)
+ i < config->numa_num; config_numa++, i++)
struct wd_async_msg_pool {
struct msg_pool *pools;
diff --git a/wd_util.c b/wd_util.c
index 7fa688d..44c8909 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -356,6 +356,7 @@ static void wd_free_numa(struct wd_env_config *config)
free(config->config_per_numa);
config->config_per_numa = NULL;
+ config->numa_num = 0;
}
/**
@@ -484,6 +485,7 @@ static int wd_alloc_numa(struct wd_env_config *config,
return 0;
free_list:
+ config->numa_num = 0;
wd_free_list_accels(head);
free_numa_dev_num:
free(numa_dev_num);
--
2.25.1

View File

@ -0,0 +1,588 @@
From 92364a0a3a38a02d64cca10d3153e94ee01c3969 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Tue, 25 Jan 2022 14:33:48 +0800
Subject: [PATCH 52/53] hisi-sec: add some dfx information in comments
Add some dfx information in comments to improves locating
efficiency.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_sec.c | 86 ++++++++++++++++++++++++++++++--------------------
wd_aead.c | 39 ++++++++++++++---------
wd_cipher.c | 21 +++++++-----
wd_digest.c | 12 ++++---
4 files changed, 97 insertions(+), 61 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index f5db7eb..14656c8 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -576,7 +576,7 @@ static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
} else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) {
*c_key_len = CKEY_LEN_3DES_3KEY;
} else {
- WD_ERR("invalid 3des key size!\n");
+ WD_ERR("invalid 3des key size, size = %u\n", msg->key_bytes);
return -WD_EINVAL;
}
@@ -602,7 +602,7 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
*c_key_len = CKEY_LEN_256BIT;
break;
default:
- WD_ERR("invalid AES key size!\n");
+ WD_ERR("invalid AES key size, size = %u\n", len);
return -WD_EINVAL;
}
@@ -634,7 +634,7 @@ static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *s
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
break;
default:
- WD_ERR("invalid cipher type!\n");
+ WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -660,7 +660,7 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
c_mode = C_MODE_XTS;
break;
default:
- WD_ERR("invalid cipher mode type!\n");
+ WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
@@ -719,7 +719,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
{
if (msg->in_bytes > MAX_INPUT_DATA_LEN ||
!msg->in_bytes) {
- WD_ERR("input cipher length is error!\n");
+ WD_ERR("input cipher length is error, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
@@ -730,7 +731,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
if (msg->mode == WD_CIPHER_XTS) {
if (msg->in_bytes < AES_BLOCK_SIZE) {
- WD_ERR("input cipher length is too small!\n");
+ WD_ERR("input cipher length is too small, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
@@ -738,13 +740,15 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
if (msg->alg == WD_CIPHER_3DES || msg->alg == WD_CIPHER_DES) {
if (msg->in_bytes & (DES3_BLOCK_SIZE - 1)) {
- WD_ERR("input 3DES or DES cipher parameter is error!\n");
+ WD_ERR("input 3DES or DES cipher parameter is error, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
} else if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) {
if (msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
- WD_ERR("input AES or SM4 cipher parameter is error!\n");
+ WD_ERR("input AES or SM4 cipher parameter is error, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
@@ -1006,7 +1010,7 @@ static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg,
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
break;
default:
- WD_ERR("invalid cipher type!\n");
+ WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1041,7 +1045,7 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg,
c_mode = C_MODE_CFB;
break;
default:
- WD_ERR("invalid cipher mode type!\n");
+ WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
sqe->c_mode_alg |= (__u16)c_mode;
@@ -1201,7 +1205,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
struct hisi_sec_sqe *sqe)
{
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
- WD_ERR("invalid digest type!\n");
+ WD_ERR("invalid digest alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1211,7 +1215,8 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
(__u32)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("invalid digest key_bytes!\n");
+ WD_ERR("invalid digest key_bytes, size = %u\n",
+ msg->key_bytes);
return -WD_EINVAL;
}
sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes /
@@ -1221,7 +1226,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
sqe->type2.mac_key_alg |=
(__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
} else {
- WD_ERR("invalid digest mode!\n");
+ WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
@@ -1298,19 +1303,22 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
}
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
- WD_ERR("digest input length is too long, size:%u!\n", msg->in_bytes);
+ WD_ERR("digest input length is too long, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("digest out length is error, size:%u!\n", msg->out_bytes);
+ WD_ERR("digest out length is error, size = %u\n",
+ msg->out_bytes);
return -WD_EINVAL;
}
if (msg->has_next) {
ret = digest_long_bd_check(msg);
if (ret) {
- WD_ERR("input data isn't aligned, size:%u!\n", msg->in_bytes);
+ WD_ERR("input data isn't aligned, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
}
@@ -1421,7 +1429,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
struct hisi_sec_sqe3 *sqe)
{
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
- WD_ERR("Invalid digest type!\n");
+ WD_ERR("invalid digest type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1432,7 +1440,8 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
(__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
} else if (msg->mode == WD_DIGEST_HMAC) {
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
- WD_ERR("Invalid digest key_bytes!\n");
+ WD_ERR("invalid digest key_bytes, size = %u\n",
+ msg->key_bytes);
return -WD_EINVAL;
}
sqe->auth_mac_key |= (__u32)(msg->key_bytes /
@@ -1441,7 +1450,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
sqe->auth_mac_key |=
(__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
} else {
- WD_ERR("Invalid digest mode!\n");
+ WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
@@ -1601,7 +1610,8 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
*key_len = CKEY_LEN_256BIT;
break;
default:
- WD_ERR("failed to check AES key size!\n");
+ WD_ERR("failed to check AES key size, size = %u\n",
+ msg->ckey_bytes);
return -WD_EINVAL;
}
@@ -1622,7 +1632,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
break;
default:
- WD_ERR("failed to check aead calg type!\n");
+ WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
ret = -WD_EINVAL;
}
@@ -1632,13 +1642,15 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
return ret;
if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth_bytes!\n");
+ WD_ERR("failed to check aead auth_bytes, size = %u\n",
+ msg->auth_bytes);
return -WD_EINVAL;
}
sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES;
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth key bytes!\n");
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
+ msg->akey_bytes);
return -WD_EINVAL;
}
sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes /
@@ -1655,7 +1667,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
d_alg = A_ALG_HMAC_SHA512 << AUTH_ALG_OFFSET;
break;
default:
- WD_ERR("failed to check aead dalg type!\n");
+ WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
ret = -WD_EINVAL;
}
sqe->type2.mac_key_alg |= d_alg;
@@ -1685,7 +1697,8 @@ static int fill_aead_bd2_mode(struct wd_aead_msg *msg,
sqe->type2.icvw_kmode |= msg->auth_bytes;
break;
default:
- WD_ERR("failed to check aead cmode type!\n");
+ WD_ERR("failed to check aead cmode type, cmode = %u\n",
+ msg->cmode);
return -WD_EINVAL;
}
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
@@ -1758,13 +1771,15 @@ static void fill_aead_bd2_addr(struct wd_aead_msg *msg,
static int aead_len_check(struct wd_aead_msg *msg)
{
if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) {
- WD_ERR("aead input data length is too long!\n");
+ WD_ERR("aead input data length is too long, size = %u\n",
+ msg->in_bytes + msg->assoc_bytes);
return -WD_EINVAL;
}
if (unlikely(msg->cmode == WD_CIPHER_CCM &&
msg->assoc_bytes > MAX_CCM_AAD_LEN)) {
- WD_ERR("failed to check ccm aad len, input is too long!\n");
+ WD_ERR("failed to check ccm aad len, input is too long, size = %u\n",
+ msg->assoc_bytes);
return -WD_EINVAL;
}
@@ -1793,7 +1808,7 @@ static int fill_aead_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
sqe->type_auth_cipher |= AUTH_MAC_VERIFY <<
SEC_AUTH_OFFSET;
} else {
- WD_ERR("failed to check aead op type!\n");
+ WD_ERR("failed to check aead op type, op = %u\n", msg->op_type);
return -WD_EINVAL;
}
sqe->sds_sa_type |= (__u8)(de | scene);
@@ -1950,12 +1965,14 @@ static int aead_bd3_msg_check(struct wd_aead_msg *msg)
}
if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth_bytes!\n");
+ WD_ERR("failed to check aead auth_bytes, size = %u\n",
+ msg->auth_bytes);
return -WD_EINVAL;
}
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth key bytes!\n");
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
+ msg->akey_bytes);
return -WD_EINVAL;
}
@@ -1980,7 +1997,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
break;
default:
- WD_ERR("failed to check aead calg type!\n");
+ WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
ret = -WD_EINVAL;
}
@@ -2009,7 +2026,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
d_alg = A_ALG_HMAC_SHA512 << SEC_AUTH_ALG_OFFSET_V3;
break;
default:
- WD_ERR("failed to check aead dalg type!\n");
+ WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
ret = -WD_EINVAL;
}
sqe->auth_mac_key |= d_alg;
@@ -2037,7 +2054,8 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
sqe->c_icv_key |= msg->auth_bytes << SEC_MAC_OFFSET_V3;
break;
default:
- WD_ERR("failed to check aead cmode type!\n");
+ WD_ERR("failed to check aead cmode type, cmode = %u\n",
+ msg->cmode);
return -WD_EINVAL;
}
@@ -2082,7 +2100,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
sqe->auth_mac_key = AUTH_MAC_VERIFY;
sqe->huk_iv_seq = WD_DIGEST_THEN_CIPHER << SEC_SEQ_OFFSET_V3;
} else {
- WD_ERR("failed to check aead op type!\n");
+ WD_ERR("failed to check aead op type, op = %u\n", msg->op_type);
return -WD_EINVAL;
}
sqe->bd_param |= (__u16)(de | scene);
diff --git a/wd_aead.c b/wd_aead.c
index 32d06ec..82a1f97 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -110,7 +110,7 @@ static int cipher_key_len_check(enum wd_cipher_alg alg, __u16 length)
ret = aes_key_len_check(length);
break;
default:
- WD_ERR("failed to check cipher key!\n");
+ WD_ERR("failed to set the cipher alg, alg = %d\n", alg);
return -WD_EINVAL;
}
@@ -143,7 +143,7 @@ int wd_aead_set_ckey(handle_t h_sess, const __u8 *key, __u16 key_len)
int ret;
if (unlikely(!key || !sess)) {
- WD_ERR("failed to check cipher key inpupt param!\n");
+ WD_ERR("failed to check cipher key input param!\n");
return -WD_EINVAL;
}
@@ -189,7 +189,7 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len)
return 0;
err_key_len:
- WD_ERR("failed to check authenticate key length!\n");
+ WD_ERR("failed to check authenticate key length, size = %u\n", key_len);
return -WD_EINVAL;
}
@@ -206,20 +206,23 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize)
if (authsize < WD_AEAD_CCM_GCM_MIN ||
authsize > WD_AEAD_CCM_GCM_MAX ||
authsize % (WD_AEAD_CCM_GCM_MIN >> 1)) {
- WD_ERR("failed to check aead CCM authsize!\n");
+ WD_ERR("failed to check aead CCM authsize, size = %u\n",
+ authsize);
return -WD_EINVAL;
}
} else if (sess->cmode == WD_CIPHER_GCM) {
if (authsize < WD_AEAD_CCM_GCM_MIN << 1 ||
authsize > WD_AEAD_CCM_GCM_MAX) {
- WD_ERR("failed to check aead GCM authsize!\n");
+ WD_ERR("failed to check aead GCM authsize, size = %u\n",
+ authsize);
return -WD_EINVAL;
}
} else {
if (sess->dalg >= WD_DIGEST_TYPE_MAX ||
authsize & (WD_AEAD_CCM_GCM_MAX - 1) ||
authsize > g_aead_mac_len[sess->dalg]) {
- WD_ERR("failed to check aead mac authsize!\n");
+ WD_ERR("failed to check aead mac authsize, size = %u\n",
+ authsize);
return -WD_EINVAL;
}
}
@@ -313,20 +316,22 @@ static int aead_mac_param_check(struct wd_aead_sess *sess,
switch (sess->cmode) {
case WD_CIPHER_CBC:
if (req->mac_bytes < g_aead_mac_len[sess->dalg]) {
- WD_ERR("failed to check cbc-hmac mac buffer length!\n");
+ WD_ERR("failed to check cbc-hmac mac buffer length, size = %u\n",
+ req->mac_bytes);
ret = -WD_EINVAL;
}
break;
case WD_CIPHER_CCM:
case WD_CIPHER_GCM:
if (req->mac_bytes < WD_AEAD_CCM_GCM_MAX) {
- WD_ERR("failed to check CCM or GCM mac buffer length!\n");
+ WD_ERR("failed to check CCM or GCM mac buffer length, size = %u\n",
+ req->mac_bytes);
ret = -WD_EINVAL;
}
break;
default:
ret = -WD_EINVAL;
- WD_ERR("set the aead cmode is error!\n");
+ WD_ERR("set the aead cmode is error, cmode = %d\n", sess->cmode);
}
return ret;
@@ -350,12 +355,14 @@ static int aead_param_check(struct wd_aead_sess *sess,
if (unlikely(sess->cmode == WD_CIPHER_CBC &&
(req->in_bytes & (AES_BLOCK_SIZE - 1)))) {
- WD_ERR("failed to check aead input data length!\n");
+ WD_ERR("failed to check aead input data length, size = %u\n",
+ req->in_bytes);
return -WD_EINVAL;
}
if (unlikely(req->iv_bytes != get_iv_block_size(sess->cmode))) {
- WD_ERR("failed to check aead IV length, size:%u\n", req->iv_bytes);
+ WD_ERR("failed to check aead IV length, size = %u\n",
+ req->iv_bytes);
return -WD_EINVAL;
}
@@ -367,13 +374,15 @@ static int aead_param_check(struct wd_aead_sess *sess,
len = req->in_bytes + req->assoc_bytes;
ret = wd_check_datalist(req->list_src, len);
if (unlikely(ret)) {
- WD_ERR("failed to check the src datalist!\n");
+ WD_ERR("failed to check the src datalist, size = %u\n",
+ len);
return -WD_EINVAL;
}
ret = wd_check_datalist(req->list_dst, req->out_bytes);
if (unlikely(ret)) {
- WD_ERR("failed to check the dst datalist!\n");
+ WD_ERR("failed to check the dst datalist, size = %u\n",
+ req->out_bytes);
return -WD_EINVAL;
}
}
@@ -407,13 +416,13 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
ret = wd_init_ctx_config(&wd_aead_setting.config, config);
if (ret) {
- WD_ERR("failed to set config, ret = %d!\n", ret);
+ WD_ERR("failed to set config, ret = %d\n", ret);
return ret;
}
ret = wd_init_sched(&wd_aead_setting.sched, sched);
if (ret < 0) {
- WD_ERR("failed to set sched, ret = %d!\n", ret);
+ WD_ERR("failed to set sched, ret = %d\n", ret);
goto out;
}
diff --git a/wd_cipher.c b/wd_cipher.c
index 5be3123..0b29fb5 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -126,7 +126,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
int ret = 0;
if (sess->mode == WD_CIPHER_XTS && length == AES_KEYSIZE_192) {
- WD_ERR("unsupported XTS key length, length = %u.\n", length);
+ WD_ERR("unsupported XTS key length, length = %u\n", length);
return -WD_EINVAL;
}
@@ -147,7 +147,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
ret = -WD_EINVAL;
break;
default:
- WD_ERR("cipher input alg err, alg is %d.\n", sess->alg);
+ WD_ERR("cipher input alg err, alg = %d\n", sess->alg);
return -WD_EINVAL;
}
@@ -358,14 +358,16 @@ static int cipher_iv_len_check(struct wd_cipher_req *req,
case WD_CIPHER_AES:
case WD_CIPHER_SM4:
if (req->iv_bytes != AES_BLOCK_SIZE) {
- WD_ERR("AES or SM4 input iv bytes is err!\n");
+ WD_ERR("AES or SM4 input iv bytes is err, size = %u\n",
+ req->iv_bytes);
ret = -WD_EINVAL;
}
break;
case WD_CIPHER_3DES:
case WD_CIPHER_DES:
if (req->iv_bytes != DES3_BLOCK_SIZE) {
- WD_ERR("3DES or DES input iv bytes is err!\n");
+ WD_ERR("3DES or DES input iv bytes is err, size = %u\n",
+ req->iv_bytes);
ret = -WD_EINVAL;
}
break;
@@ -384,7 +386,7 @@ static int wd_cipher_check_params(handle_t h_sess,
int ret = 0;
if (unlikely(!h_sess || !req)) {
- WD_ERR("cipher input sess or req is NULL.\n");
+ WD_ERR("cipher input sess or req is NULL!\n");
return -WD_EINVAL;
}
@@ -394,21 +396,24 @@ static int wd_cipher_check_params(handle_t h_sess,
}
if (unlikely(req->out_buf_bytes < req->in_bytes)) {
- WD_ERR("cipher set out_buf_bytes is error!\n");
+ WD_ERR("cipher set out_buf_bytes is error, size = %u\n",
+ req->out_buf_bytes);
return -WD_EINVAL;
}
if (req->data_fmt == WD_SGL_BUF) {
ret = wd_check_datalist(req->list_src, req->in_bytes);
if (unlikely(ret)) {
- WD_ERR("failed to check the src datalist!\n");
+ WD_ERR("failed to check the src datalist, len = %u\n",
+ req->in_bytes);
return -WD_EINVAL;
}
/* cipher dst len is equal to src len */
ret = wd_check_datalist(req->list_dst, req->in_bytes);
if (unlikely(ret)) {
- WD_ERR("failed to check the dst datalist!\n");
+ WD_ERR("failed to check the dst datalist, len = %u\n",
+ req->in_bytes);
return -WD_EINVAL;
}
}
diff --git a/wd_digest.c b/wd_digest.c
index 525d6a9..d4e710d 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -98,7 +98,8 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
if ((sess->alg <= WD_DIGEST_SHA224 && key_len >
MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 ||
key_len > MAX_HMAC_KEY_SIZE) {
- WD_ERR("failed to check digest key length!\n");
+ WD_ERR("failed to check digest key length, size = %u\n",
+ key_len);
return -WD_EINVAL;
}
@@ -258,20 +259,23 @@ static int digest_param_check(struct wd_digest_sess *sess,
}
if (unlikely(req->out_buf_bytes < req->out_bytes)) {
- WD_ERR("failed to check digest out buffer length!\n");
+ WD_ERR("failed to check digest out buffer length, size = %u\n",
+ req->out_buf_bytes);
return -WD_EINVAL;
}
if (unlikely(sess->alg >= WD_DIGEST_TYPE_MAX || req->out_bytes == 0 ||
req->out_bytes > g_digest_mac_len[sess->alg])) {
- WD_ERR("failed to check digest type or mac length!\n");
+ WD_ERR("failed to check digest type or mac length, alg = %d, out_bytes = %u\n",
+ sess->alg, req->out_bytes);
return -WD_EINVAL;
}
if (req->data_fmt == WD_SGL_BUF) {
ret = wd_check_datalist(req->list_in, req->in_bytes);
if (unlikely(ret)) {
- WD_ERR("failed to check the src datalist!\n");
+ WD_ERR("failed to check the src datalist, size = %u\n",
+ req->in_bytes);
return -WD_EINVAL;
}
}
--
2.25.1

View File

@ -0,0 +1,119 @@
From 7d208baa2ea3b3adb161683e9e2446dd01ae14a0 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Thu, 27 Jan 2022 10:16:59 +0800
Subject: [PATCH 53/53] hisi-sec: delete some dummy parameter checking
1. If an error is detected, the system exits rather than
continues. here is fix it.
2. Due to the auth length checking logic same as the api
layer. So this code is reduntant and needs to be deleted.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_sec.c | 56 +++++++++++++++++---------------------------------
1 file changed, 19 insertions(+), 37 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 14656c8..61e0698 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -1618,6 +1618,17 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
return 0;
}
+static int aead_bd_msg_check(struct wd_aead_msg *msg)
+{
+ if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
+ msg->akey_bytes);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
struct hisi_sec_sqe *sqe)
{
@@ -1633,26 +1644,19 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
break;
default:
WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
- ret = -WD_EINVAL;
+ return -WD_EINVAL;
}
/* CCM/GCM this region is set to 0 */
- if (msg->cmode == WD_CIPHER_CCM ||
- msg->cmode == WD_CIPHER_GCM)
+ if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM)
return ret;
- if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth_bytes, size = %u\n",
- msg->auth_bytes);
- return -WD_EINVAL;
- }
sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES;
- if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth key bytes, size = %u\n",
- msg->akey_bytes);
- return -WD_EINVAL;
- }
+ ret = aead_bd_msg_check(msg);
+ if (ret)
+ return ret;
+
sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes /
WORD_BYTES) << MAC_LEN_OFFSET;
@@ -1957,28 +1961,6 @@ static struct wd_aead_driver hisi_aead_driver = {
WD_AEAD_SET_DRIVER(hisi_aead_driver);
-static int aead_bd3_msg_check(struct wd_aead_msg *msg)
-{
- if (unlikely(!msg->in_bytes)) {
- WD_ERR("failed to check aead in_bytes 0 length!\n");
- return -WD_EINVAL;
- }
-
- if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth_bytes, size = %u\n",
- msg->auth_bytes);
- return -WD_EINVAL;
- }
-
- if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
- WD_ERR("failed to check aead auth key bytes, size = %u\n",
- msg->akey_bytes);
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
struct hisi_sec_sqe3 *sqe)
{
@@ -1998,14 +1980,14 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
break;
default:
WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
- ret = -WD_EINVAL;
+ return -WD_EINVAL;
}
/* CCM/GCM this region is set to 0 */
if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM)
return ret;
- ret = aead_bd3_msg_check(msg);
+ ret = aead_bd_msg_check(msg);
if (ret)
return ret;
--
2.25.1

View File

@ -0,0 +1,45 @@
From bbdb8e4337270cbc1125f9e5fa3b004e98a543d1 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Thu, 10 Feb 2022 14:55:43 +0800
Subject: [PATCH 54/64] hisi-qm-udrv/v1: deleted a dummy branch
Deleted an invalid branch in qm_set_queue_alg_info. the software
won't go to that line of code.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
v1/drv/hisi_qm_udrv.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
index 63f346b..b457efd 100644
--- a/v1/drv/hisi_qm_udrv.c
+++ b/v1/drv/hisi_qm_udrv.c
@@ -423,20 +423,10 @@ static int qm_set_queue_alg_info(struct wd_queue *q)
} else if (!strcmp(alg, "xts(aes)") ||
!strcmp(alg, "xts(sm4)")) {
qinfo->atype = WCRYPTO_CIPHER;
- if (strstr(q->dev_path, "zip")) {
- info->sqe_size = QM_ZIP_BD_SIZE;
- info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_zip_cipher_sqe;
- info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_zip_cipher_sqe;
- ret = WD_SUCCESS;
- } else if (strstr(q->dev_path, "sec")) {
- priv->direction = 0;
- info->sqe_size = QM_SEC_BD_SIZE;
- info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_cipher_sqe;
- info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_cipher_sqe;
- ret = WD_SUCCESS;
- } else { /* To be extended */
- WD_ERR("queue xts alg engine err!\n");
- }
+ info->sqe_size = QM_ZIP_BD_SIZE;
+ info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_zip_cipher_sqe;
+ info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_zip_cipher_sqe;
+ ret = WD_SUCCESS;
} else { /* To be extended */
WD_ERR("queue alg err!\n");
}
--
2.25.1

View File

@ -0,0 +1,51 @@
From 124472212b51781c8ab8ad26131d8442cd049380 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Thu, 10 Feb 2022 14:55:44 +0800
Subject: [PATCH 55/64] hisi-sec/v1: update the SEC BD1 mode configuration
Update SEC BD1 XTS mode CI_GEN config from 3 to 0, because
ZIP XTS LBA hardware accomplish is different from SEC XTS LBA.
So we config SEC BD1 XTS ci_gen=0, which means cipher_ivin_addr
mode.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
v1/drv/hisi_sec_udrv.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
index 2d06bd7..7345baf 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -298,10 +298,11 @@ static int fill_cipher_bd1_type(struct wcrypto_cipher_msg *msg,
fill_bd_addr_type(msg->data_fmt, sqe);
- if (msg->mode == WCRYPTO_CIPHER_XTS)
- sqe->type1.ci_gen = CI_GEN_BY_LBA;
- else
- sqe->type1.ci_gen = CI_GEN_BY_ADDR;
+ /*
+ * BD1 cipher only provides ci_gen=0 for compatibility, so user
+ * should prepare iv[gran_num] and iv_bytes is sum of all grans
+ */
+ sqe->type1.ci_gen = CI_GEN_BY_ADDR;
return WD_SUCCESS;
}
@@ -1453,6 +1454,12 @@ static void parse_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe,
sqe->type1.c_key_addr_l);
drv_iova_unmap(q, cipher_msg->key, (void *)(uintptr_t)dma_addr,
cipher_msg->key_bytes);
+ if (cipher_msg->iv) {
+ dma_addr = DMA_ADDR(sqe->type1.c_ivin_addr_h,
+ sqe->type1.c_ivin_addr_l);
+ drv_iova_unmap(q, cipher_msg->iv, (void *)(uintptr_t)dma_addr,
+ cipher_msg->iv_bytes);
+ }
}
static void cipher_ofb_data_handle(struct wcrypto_cipher_msg *msg)
--
2.25.1

View File

@ -0,0 +1,116 @@
From a1d263fc8bc5aa87a9287b7d5a5fb717a1556bc5 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:49 +0800
Subject: [PATCH 56/64] uadk: optimize algorithm initialization
malloc and memset can be replaced by calloc.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_aead.c | 3 +--
wd_dh.c | 4 +---
wd_digest.c | 4 +---
wd_ecc.c | 4 +---
wd_rsa.c | 4 +---
5 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c
index 82a1f97..d8581db 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -441,12 +441,11 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
}
/* init ctx related resources in specific driver */
- priv = malloc(wd_aead_setting.driver->drv_ctx_size);
+ priv = calloc(1, wd_aead_setting.driver->drv_ctx_size);
if (!priv) {
ret = -WD_ENOMEM;
goto out_priv;
}
- memset(priv, 0, wd_aead_setting.driver->drv_ctx_size);
wd_aead_setting.priv = priv;
ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv);
diff --git a/wd_dh.c b/wd_dh.c
index 1784099..b361d5d 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -127,14 +127,12 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
}
/* initialize ctx related resources in specific driver */
- priv = malloc(wd_dh_setting.driver->drv_ctx_size);
+ priv = calloc(1, wd_dh_setting.driver->drv_ctx_size);
if (!priv) {
- WD_ERR("failed to calloc drv ctx\n");
ret = -WD_ENOMEM;
goto out_priv;
}
- memset(priv, 0, wd_dh_setting.driver->drv_ctx_size);
wd_dh_setting.priv = priv;
ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv,
wd_dh_setting.driver->alg_name);
diff --git a/wd_digest.c b/wd_digest.c
index d4e710d..1c05851 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -203,13 +203,11 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
}
/* init ctx related resources in specific driver */
- priv = malloc(wd_digest_setting.driver->drv_ctx_size);
+ priv = calloc(1, wd_digest_setting.driver->drv_ctx_size);
if (!priv) {
- WD_ERR("failed to alloc digest driver ctx!\n");
ret = -WD_ENOMEM;
goto out_priv;
}
- memset(priv, 0, wd_digest_setting.driver->drv_ctx_size);
wd_digest_setting.priv = priv;
ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv);
diff --git a/wd_ecc.c b/wd_ecc.c
index e324473..89566ea 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -181,14 +181,12 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
}
/* initialize ctx related resources in specific driver */
- priv = malloc(wd_ecc_setting.driver->drv_ctx_size);
+ priv = calloc(1, wd_ecc_setting.driver->drv_ctx_size);
if (!priv) {
- WD_ERR("failed to calloc drv ctx\n");
ret = -WD_ENOMEM;
goto out_priv;
}
- memset(priv, 0, wd_ecc_setting.driver->drv_ctx_size);
wd_ecc_setting.priv = priv;
ret = wd_ecc_setting.driver->init(&wd_ecc_setting.config, priv,
wd_ecc_setting.driver->alg_name);
diff --git a/wd_rsa.c b/wd_rsa.c
index 1f911b4..2e61927 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -167,14 +167,12 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
}
/* initialize ctx related resources in specific driver */
- priv = malloc(wd_rsa_setting.driver->drv_ctx_size);
+ priv = calloc(1, wd_rsa_setting.driver->drv_ctx_size);
if (!priv) {
- WD_ERR("failed to calloc drv ctx\n");
ret = -WD_ENOMEM;
goto out_priv;
}
- memset(priv, 0, wd_rsa_setting.driver->drv_ctx_size);
wd_rsa_setting.priv = priv;
ret = wd_rsa_setting.driver->init(&wd_rsa_setting.config, priv,
wd_rsa_setting.driver->alg_name);
--
2.25.1

View File

@ -0,0 +1,135 @@
From b2bcc88b513328491a0f02700b926678e63c944b Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:50 +0800
Subject: [PATCH 57/64] uadk: fix send exception handling
when qm send message failed, uadk should return immediately
instead of enable interrupt.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_comp.c | 10 +++++++---
drv/hisi_sec.c | 24 ++++++++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index e0e913d..5ea5dc3 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -945,12 +945,16 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
return ret;
}
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
- if (ret < 0 && ret != -WD_EBUSY)
- WD_ERR("qm send is err(%d)!\n", ret);
+ if (ret < 0) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("qm send is err(%d)!\n", ret);
+
+ return ret;
+ }
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
static int get_alg_type(__u32 type)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 61e0698..338823b 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -946,11 +946,13 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg)
@@ -1147,11 +1149,13 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *recv_msg)
@@ -1388,11 +1392,13 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg)
@@ -1544,11 +1550,13 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
@@ -1887,11 +1895,13 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
@@ -2152,11 +2162,13 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
if (msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
- return ret;
+ return 0;
}
static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
--
2.25.1

View File

@ -0,0 +1,165 @@
From c7d657b037cb9a37daaa3df79ac806e6ac1d4fa2 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:51 +0800
Subject: [PATCH 58/64] uadk: sec: fix hisi_sec_digest_send
When digest send a sgl format message, it will use
hisi_sec_fill_sgl to get sgl memory from sgl memory pool,
when send message exit abnormally, sgl should be put back.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_sec.c | 58 +++++++++++++++++++++-----------------------------
1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 338823b..7f5aae2 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -929,10 +929,8 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
sqe.type2.clen_ivhlen |= (__u32)msg->in_bytes;
@@ -1132,10 +1130,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
sqe.c_len_ivin = (__u32)msg->in_bytes;
@@ -1360,10 +1356,8 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
sqe.sds_sa_type |= (__u8)(de | scene);
@@ -1372,10 +1366,8 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd2_alg(msg, &sqe);
- if (ret) {
- WD_ERR("failed to fill digest bd alg!\n");
- return ret;
- }
+ if (ret)
+ goto put_sgl;
qm_fill_digest_long_bd(msg, &sqe);
@@ -1390,15 +1382,18 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
if (ret != -WD_EBUSY)
WD_ERR("digest send sqe is err(%d)!\n", ret);
- if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
-
- return ret;
+ goto put_sgl;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
return 0;
+
+put_sgl:
+ if (msg->data_fmt == WD_SGL_BUF)
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg)
@@ -1517,10 +1512,8 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
sqe.bd_param |= (__u16)(de | scene);
@@ -1529,10 +1522,8 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
sqe.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd3_alg(msg, &sqe);
- if (ret) {
- WD_ERR("failed to fill digest bd alg!\n");
- return ret;
- }
+ if (ret)
+ goto put_sgl;
qm_fill_digest_long_bd3(msg, &sqe);
@@ -1548,15 +1539,18 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
if (ret != -WD_EBUSY)
WD_ERR("digest send sqe is err(%d)!\n", ret);
- if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
-
- return ret;
+ goto put_sgl;
}
hisi_qm_enable_interrupt(ctx, msg->is_polled);
return 0;
+
+put_sgl:
+ if (msg->data_fmt == WD_SGL_BUF)
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+
+ return ret;
}
static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
@@ -1873,10 +1867,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe, msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
fill_aead_bd2_addr(msg, &sqe);
@@ -2141,10 +2133,8 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
- if (ret) {
- WD_ERR("failed to get sgl!\n");
+ if (ret)
return ret;
- }
}
fill_aead_bd3_addr(msg, &sqe);
--
2.25.1

View File

@ -0,0 +1,606 @@
From 42055f42381b51428be8138042f2a7b6b9964c10 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:52 +0800
Subject: [PATCH 59/64] uadk: sec: some clean code
The number of characters in a single line exceeds 80 and
WD_ERR's line change is not aligned.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_sec.c | 175 ++++++++++++++++++++++++++++---------------------
1 file changed, 102 insertions(+), 73 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 7f5aae2..264d850 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -547,18 +547,24 @@ static void update_iv_sgl(struct wd_cipher_msg *msg)
case WD_CIPHER_CBC:
if (msg->op_type == WD_CIPHER_ENCRYPTION &&
msg->out_bytes >= msg->iv_bytes)
- hisi_qm_sgl_copy(msg->iv, msg->out, msg->out_bytes -
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
+ hisi_qm_sgl_copy(msg->iv, msg->out,
+ msg->out_bytes - msg->iv_bytes,
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
+
if (msg->op_type == WD_CIPHER_DECRYPTION &&
msg->in_bytes >= msg->iv_bytes)
- hisi_qm_sgl_copy(msg->iv, msg->in, msg->in_bytes -
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
+ hisi_qm_sgl_copy(msg->iv, msg->in,
+ msg->in_bytes - msg->iv_bytes,
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
+
break;
case WD_CIPHER_OFB:
case WD_CIPHER_CFB:
if (msg->out_bytes >= msg->iv_bytes)
- hisi_qm_sgl_copy(msg->iv, msg->out, msg->out_bytes -
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
+ hisi_qm_sgl_copy(msg->iv, msg->out,
+ msg->out_bytes - msg->iv_bytes,
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
+
break;
case WD_CIPHER_CTR:
ctr_iv_inc(msg->iv, msg->iv_bytes >>
@@ -576,7 +582,8 @@ static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
} else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) {
*c_key_len = CKEY_LEN_3DES_3KEY;
} else {
- WD_ERR("invalid 3des key size, size = %u\n", msg->key_bytes);
+ WD_ERR("failed to check 3des key size, size = %u\n",
+ msg->key_bytes);
return -WD_EINVAL;
}
@@ -602,14 +609,15 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
*c_key_len = CKEY_LEN_256BIT;
break;
default:
- WD_ERR("invalid AES key size, size = %u\n", len);
+ WD_ERR("failed to check AES key size, size = %u\n", len);
return -WD_EINVAL;
}
return 0;
}
-static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
+static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg,
+ struct hisi_sec_sqe *sqe)
{
__u8 c_key_len = 0;
int ret = 0;
@@ -634,14 +642,15 @@ static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *s
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
break;
default:
- WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
+ WD_ERR("failed to check cipher alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
return ret;
}
-static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
+static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg,
+ struct hisi_sec_sqe *sqe)
{
__u16 c_mode;
@@ -660,7 +669,8 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
c_mode = C_MODE_XTS;
break;
default:
- WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
+ WD_ERR("failed to check cipher mode type, mode = %u\n",
+ msg->mode);
return -WD_EINVAL;
}
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
@@ -668,7 +678,8 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
return 0;
}
-static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
+static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg,
+ struct hisi_sec_sqe *sqe)
{
sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in;
sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out;
@@ -688,7 +699,8 @@ static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe
sqe->type2.mac_addr = (__u64)(uintptr_t)msg;
}
-static void parse_cipher_bd2(struct hisi_sec_sqe *sqe, struct wd_cipher_msg *recv_msg)
+static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
+ struct wd_cipher_msg *recv_msg)
{
struct wd_cipher_msg *rmsg;
__u16 done;
@@ -696,7 +708,7 @@ static void parse_cipher_bd2(struct hisi_sec_sqe *sqe, struct wd_cipher_msg *rec
done = sqe->type2.done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "cipher",
- done, sqe->type2.error_type);
+ done, sqe->type2.error_type);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -720,7 +732,7 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
if (msg->in_bytes > MAX_INPUT_DATA_LEN ||
!msg->in_bytes) {
WD_ERR("input cipher length is error, size = %u\n",
- msg->in_bytes);
+ msg->in_bytes);
return -WD_EINVAL;
}
@@ -732,7 +744,7 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
if (msg->mode == WD_CIPHER_XTS) {
if (msg->in_bytes < AES_BLOCK_SIZE) {
WD_ERR("input cipher length is too small, size = %u\n",
- msg->in_bytes);
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
@@ -740,15 +752,15 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
if (msg->alg == WD_CIPHER_3DES || msg->alg == WD_CIPHER_DES) {
if (msg->in_bytes & (DES3_BLOCK_SIZE - 1)) {
- WD_ERR("input 3DES or DES cipher parameter is error, size = %u\n",
- msg->in_bytes);
+ WD_ERR("failed to check input bytes of 3DES or DES, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
} else if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) {
if (msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
- WD_ERR("input AES or SM4 cipher parameter is error, size = %u\n",
- msg->in_bytes);
+ WD_ERR("failed to check input bytes of AES or SM4, size = %u\n",
+ msg->in_bytes);
return -WD_EINVAL;
}
return 0;
@@ -802,7 +814,7 @@ static int hisi_sec_fill_sgl(handle_t h_qp, __u8 **in, __u8 **out,
return -WD_EINVAL;
}
- hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*in));
+ hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in));
if (!hw_sgl_in) {
WD_ERR("failed to get sgl in for hw_v2!\n");
return -WD_EINVAL;
@@ -811,9 +823,10 @@ static int hisi_sec_fill_sgl(handle_t h_qp, __u8 **in, __u8 **out,
if (type == WD_DIGEST) {
hw_sgl_out = *out;
} else {
- hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*out));
+ hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool,
+ (struct wd_datalist *)(*out));
if (!hw_sgl_out) {
- WD_ERR("failed to get hw sgl out!\n");
+ WD_ERR("failed to get hw sgl out for hw_v2!\n");
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
return -WD_EINVAL;
}
@@ -841,7 +854,7 @@ static int hisi_sec_fill_sgl_v3(handle_t h_qp, __u8 **in, __u8 **out,
return -WD_EINVAL;
}
- hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*in));
+ hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in));
if (!hw_sgl_in) {
WD_ERR("failed to get sgl in for hw_v3!\n");
return -WD_EINVAL;
@@ -851,9 +864,10 @@ static int hisi_sec_fill_sgl_v3(handle_t h_qp, __u8 **in, __u8 **out,
hw_sgl_out = *out;
sqe->bd_param |= SEC_PBUFF_MODE_MASK_V3;
} else {
- hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*out));
+ hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool,
+ (struct wd_datalist *)(*out));
if (!hw_sgl_out) {
- WD_ERR("failed to get hw sgl out!\n");
+ WD_ERR("failed to get hw sgl out for hw_v3!\n");
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
return -WD_EINVAL;
}
@@ -943,7 +957,8 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
WD_ERR("cipher send sqe is err(%d)!\n", ret);
if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
+ msg->out);
return ret;
}
@@ -969,7 +984,7 @@ int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg)
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
- recv_msg->out);
+ recv_msg->out);
return 0;
}
@@ -1010,7 +1025,7 @@ static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg,
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
break;
default:
- WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
+ WD_ERR("failed to check cipher alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1045,7 +1060,8 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg,
c_mode = C_MODE_CFB;
break;
default:
- WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
+ WD_ERR("failed to check cipher mode type, mode = %u\n",
+ msg->mode);
return -WD_EINVAL;
}
sqe->c_mode_alg |= (__u16)c_mode;
@@ -1144,7 +1160,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
WD_ERR("cipher send sqe is err(%d)!\n", ret);
if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
+ msg->out);
return ret;
}
@@ -1154,7 +1171,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
return 0;
}
-static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *recv_msg)
+static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
+ struct wd_cipher_msg *recv_msg)
{
struct wd_cipher_msg *rmsg;
__u16 done;
@@ -1162,7 +1180,7 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *re
done = sqe->done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "cipher",
- done, sqe->error_type);
+ done, sqe->error_type);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -1205,7 +1223,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
struct hisi_sec_sqe *sqe)
{
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
- WD_ERR("invalid digest alg type, alg = %u\n", msg->alg);
+ WD_ERR("failed to check digest alg type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1215,8 +1233,8 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
(__u32)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("invalid digest key_bytes, size = %u\n",
- msg->key_bytes);
+ WD_ERR("failed to check digest key_bytes, size = %u\n",
+ msg->key_bytes);
return -WD_EINVAL;
}
sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes /
@@ -1226,7 +1244,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
sqe->type2.mac_key_alg |=
(__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
} else {
- WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
+ WD_ERR("failed to check digest mode, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
@@ -1238,7 +1256,7 @@ static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
{
__u64 total_bits;
- if (msg->has_next && (msg->iv_bytes == 0)) {
+ if (msg->has_next && !msg->iv_bytes) {
/* LONG BD FIRST */
sqe->ai_apd_cs = AI_GEN_INNER;
sqe->ai_apd_cs |= AUTHPAD_NOPAD << AUTHPAD_OFFSET;
@@ -1257,14 +1275,15 @@ static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
}
}
-static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *recv_msg)
+static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
+ struct wd_digest_msg *recv_msg)
{
__u16 done;
done = sqe->type2.done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "digest",
- done, sqe->type2.error_type);
+ done, sqe->type2.error_type);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -1284,9 +1303,12 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *rec
static int digest_long_bd_check(struct wd_digest_msg *msg)
{
- if (msg->alg >= WD_DIGEST_SHA512 && msg->in_bytes & (SHA512_ALIGN_SZ - 1))
- return -WD_EINVAL;
- else if (msg->in_bytes & (SHA1_ALIGN_SZ - 1))
+ __u32 alg_align_sz;
+
+ alg_align_sz = msg->alg >= WD_DIGEST_SHA512 ?
+ SHA512_ALIGN_SZ - 1 : SHA1_ALIGN_SZ - 1;
+
+ if (msg->in_bytes & alg_align_sz)
return -WD_EINVAL;
return 0;
@@ -1297,20 +1319,20 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
int ret;
/* End BD not need to check the input zero bytes */
- if (unlikely(type == BD_TYPE2 && (!msg->has_next && msg->in_bytes == 0))) {
+ if (unlikely(type == BD_TYPE2 && !msg->has_next && !msg->in_bytes)) {
WD_ERR("kunpeng 920, digest mode not support 0 size!\n");
return -WD_EINVAL;
}
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
WD_ERR("digest input length is too long, size = %u\n",
- msg->in_bytes);
+ msg->in_bytes);
return -WD_EINVAL;
}
if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
WD_ERR("digest out length is error, size = %u\n",
- msg->out_bytes);
+ msg->out_bytes);
return -WD_EINVAL;
}
@@ -1318,7 +1340,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
ret = digest_long_bd_check(msg);
if (ret) {
WD_ERR("input data isn't aligned, size = %u\n",
- msg->in_bytes);
+ msg->in_bytes);
return -WD_EINVAL;
}
}
@@ -1430,7 +1452,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
struct hisi_sec_sqe3 *sqe)
{
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
- WD_ERR("invalid digest type, alg = %u\n", msg->alg);
+ WD_ERR("failed to check digest type, alg = %u\n", msg->alg);
return -WD_EINVAL;
}
@@ -1441,8 +1463,8 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
(__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
} else if (msg->mode == WD_DIGEST_HMAC) {
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
- WD_ERR("invalid digest key_bytes, size = %u\n",
- msg->key_bytes);
+ WD_ERR("failed to check digest key bytes, size = %u\n",
+ msg->key_bytes);
return -WD_EINVAL;
}
sqe->auth_mac_key |= (__u32)(msg->key_bytes /
@@ -1451,7 +1473,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
sqe->auth_mac_key |=
(__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
} else {
- WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
+ WD_ERR("failed to check digest mode, mode = %u\n", msg->mode);
return -WD_EINVAL;
}
@@ -1463,7 +1485,7 @@ static void qm_fill_digest_long_bd3(struct wd_digest_msg *msg,
{
__u64 total_bits;
- if (msg->has_next && (msg->iv_bytes == 0)) {
+ if (msg->has_next && !msg->iv_bytes) {
/* LONG BD FIRST */
sqe->auth_mac_key |= AI_GEN_INNER << SEC_AI_GEN_OFFSET_V3;
sqe->stream_scene.stream_auth_pad = AUTHPAD_NOPAD;
@@ -1561,7 +1583,7 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
done = sqe->done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "digest",
- done, sqe->error_type);
+ done, sqe->error_type);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -1613,7 +1635,7 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
break;
default:
WD_ERR("failed to check AES key size, size = %u\n",
- msg->ckey_bytes);
+ msg->ckey_bytes);
return -WD_EINVAL;
}
@@ -1624,7 +1646,7 @@ static int aead_bd_msg_check(struct wd_aead_msg *msg)
{
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
WD_ERR("failed to check aead auth key bytes, size = %u\n",
- msg->akey_bytes);
+ msg->akey_bytes);
return -WD_EINVAL;
}
@@ -1645,7 +1667,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
break;
default:
- WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
+ WD_ERR("failed to check aead calg type, calg = %u\n",
+ msg->calg);
return -WD_EINVAL;
}
@@ -1673,7 +1696,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
d_alg = A_ALG_HMAC_SHA512 << AUTH_ALG_OFFSET;
break;
default:
- WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
+ WD_ERR("failed to check aead dalg type, dalg = %u\n",
+ msg->dalg);
ret = -WD_EINVAL;
}
sqe->type2.mac_key_alg |= d_alg;
@@ -1704,7 +1728,7 @@ static int fill_aead_bd2_mode(struct wd_aead_msg *msg,
break;
default:
WD_ERR("failed to check aead cmode type, cmode = %u\n",
- msg->cmode);
+ msg->cmode);
return -WD_EINVAL;
}
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
@@ -1778,14 +1802,14 @@ static int aead_len_check(struct wd_aead_msg *msg)
{
if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) {
WD_ERR("aead input data length is too long, size = %u\n",
- msg->in_bytes + msg->assoc_bytes);
+ msg->in_bytes + msg->assoc_bytes);
return -WD_EINVAL;
}
if (unlikely(msg->cmode == WD_CIPHER_CCM &&
msg->assoc_bytes > MAX_CCM_AAD_LEN)) {
- WD_ERR("failed to check ccm aad len, input is too long, size = %u\n",
- msg->assoc_bytes);
+ WD_ERR("aead ccm aad length is too long, size = %u\n",
+ msg->assoc_bytes);
return -WD_EINVAL;
}
@@ -1851,7 +1875,7 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
return -WD_EINVAL;
}
- if (unlikely(msg->cmode != WD_CIPHER_CBC && msg->in_bytes == 0)) {
+ if (unlikely(msg->cmode != WD_CIPHER_CBC && !msg->in_bytes)) {
WD_ERR("ccm or gcm not supports 0 packet size at hw_v2!\n");
return -WD_EINVAL;
}
@@ -1866,7 +1890,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
return ret;
if (msg->data_fmt == WD_SGL_BUF) {
- ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe, msg->alg_type);
+ ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out,
+ &sqe, msg->alg_type);
if (ret)
return ret;
}
@@ -1886,7 +1911,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
WD_ERR("aead send sqe is err(%d)!\n", ret);
if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
+ msg->out);
return ret;
}
@@ -1906,7 +1932,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type ||
icv == SEC_HW_ICV_ERR) {
WD_ERR("SEC BD aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
- done, sqe->type2.error_type, icv);
+ done, sqe->type2.error_type, icv);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -1921,7 +1947,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
recv_msg->mac = (__u8 *)(uintptr_t)sqe->type2.mac_addr;
recv_msg->auth_bytes = (sqe->type2.mac_key_alg &
SEC_MAC_LEN_MASK) * WORD_BYTES;
- if (recv_msg->auth_bytes == 0)
+ if (!recv_msg->auth_bytes)
recv_msg->auth_bytes = sqe->type2.icvw_kmode &
SEC_AUTH_LEN_MASK;
recv_msg->out_bytes = sqe->type2.clen_ivhlen +
@@ -1981,7 +2007,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
break;
default:
- WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
+ WD_ERR("failed to check aead calg type, calg = %u\n",
+ msg->calg);
return -WD_EINVAL;
}
@@ -2010,7 +2037,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
d_alg = A_ALG_HMAC_SHA512 << SEC_AUTH_ALG_OFFSET_V3;
break;
default:
- WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
+ WD_ERR("failed to check aead dalg type, dalg = %u\n",
+ msg->dalg);
ret = -WD_EINVAL;
}
sqe->auth_mac_key |= d_alg;
@@ -2039,7 +2067,7 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
break;
default:
WD_ERR("failed to check aead cmode type, cmode = %u\n",
- msg->cmode);
+ msg->cmode);
return -WD_EINVAL;
}
@@ -2151,7 +2179,8 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
WD_ERR("aead send sqe is err(%d)!\n", ret);
if (msg->data_fmt == WD_SGL_BUF)
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
+ msg->out);
return ret;
}
@@ -2171,7 +2200,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
if (done != SEC_HW_TASK_DONE || sqe->error_type ||
icv == SEC_HW_ICV_ERR) {
WD_ERR("SEC BD3 aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
- done, sqe->error_type, icv);
+ done, sqe->error_type, icv);
recv_msg->result = WD_IN_EPARA;
} else {
recv_msg->result = WD_SUCCESS;
@@ -2186,7 +2215,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
recv_msg->mac = (__u8 *)(uintptr_t)sqe->mac_addr;
recv_msg->auth_bytes = ((sqe->auth_mac_key >> SEC_MAC_OFFSET_V3) &
SEC_MAC_LEN_MASK) * WORD_BYTES;
- if (recv_msg->auth_bytes == 0)
+ if (!recv_msg->auth_bytes)
recv_msg->auth_bytes = (sqe->c_icv_key >> SEC_MAC_OFFSET_V3) &
SEC_MAC_LEN_MASK;
recv_msg->out_bytes = sqe->c_len_ivin +
--
2.25.1

View File

@ -0,0 +1,59 @@
From b9b1cb826756b2a27ed99745a5fb9be338abd09f Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:53 +0800
Subject: [PATCH 60/64] uadk: optimize wd_ctx_qfr_mmap
wd_ctx_qfr_mmap may return NULL when user input wrong parameters
or mmap failed, so detail information should be printed.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/wd.c b/wd.c
index 6bbf677..d1652dd 100644
--- a/wd.c
+++ b/wd.c
@@ -386,7 +386,7 @@ int wd_ctx_start(handle_t h_ctx)
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
if (ret)
- WD_ERR("Fail to start on %s (%d), ret = %d!\n",
+ WD_ERR("failed to start on %s (%d), ret = %d!\n",
ctx->dev_path, -errno, ret);
return ret;
@@ -402,7 +402,7 @@ int wd_release_ctx_force(handle_t h_ctx)
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_PUT_Q, NULL);
if (ret)
- WD_ERR("Fail to stop on %s (%d), ret = %d!\n",
+ WD_ERR("failed to stop on %s (%d), ret = %d!\n",
ctx->dev_path, -errno, ret);
return ret;
@@ -415,14 +415,18 @@ void *wd_ctx_mmap_qfr(handle_t h_ctx, enum uacce_qfrt qfrt)
size_t size;
void *addr;
- if (!ctx || qfrt >= UACCE_QFRT_MAX || !ctx->qfrs_offs[qfrt])
+ if (!ctx || qfrt >= UACCE_QFRT_MAX || !ctx->qfrs_offs[qfrt]) {
+ WD_ERR("failed to check input ctx or qfrt!\n");
return NULL;
+ }
size = ctx->qfrs_offs[qfrt];
addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->fd, off);
- if (addr == MAP_FAILED)
+ if (addr == MAP_FAILED) {
+ WD_ERR("failed to mmap, qfrt = %d, err = %d!\n", qfrt, -errno);
return NULL;
+ }
ctx->qfrs_base[qfrt] = addr;
--
2.25.1

View File

@ -0,0 +1,65 @@
From 1da22fb07ffeabe82310b8619563fd5971214e18 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:54 +0800
Subject: [PATCH 61/64] uadk: optimize wd_sched_rr_instance
Schedule ctx numa number and schedule type number should
also be printed, the error information is more usefull
if when it has a comparison.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_sched.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/wd_sched.c b/wd_sched.c
index aeaf11b..ef90233 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -129,7 +129,7 @@ static bool sched_key_valid(struct wd_sched_ctx *ctx,
{
if (key->numa_id >= ctx->numa_num || key->mode >= SCHED_MODE_BUTT ||
key->type >= ctx->type_num) {
- WD_ERR("ERROR: %s key error - numa:%d, mode:%u, type%u!\n",
+ WD_ERR("ERROR: %s key error - numa: %d, mode: %u, type: %u!\n",
__FUNCTION__, key->numa_id, key->mode, key->type);
return false;
}
@@ -372,18 +372,28 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
mode = param->mode;
sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx;
- if ((numa_id >= sched_ctx->numa_num) || (numa_id < 0) ||
- (mode >= SCHED_MODE_BUTT) ||
- (type >= sched_ctx->type_num)) {
- WD_ERR("ERROR: %s para err: numa_id=%d, mode=%u, type=%u!\n",
- __FUNCTION__, numa_id, mode, type);
+ if (numa_id >= sched_ctx->numa_num || numa_id < 0) {
+ WD_ERR("ERROR: %s para err: numa_id = %d, numa_num = %u\n",
+ __FUNCTION__, numa_id, sched_ctx->numa_num);
+ return -WD_EINVAL;
+ }
+
+ if (type >= sched_ctx->type_num) {
+ WD_ERR("ERROR: %s para err: type = %u, type_num = %u\n",
+ __FUNCTION__, type, sched_ctx->type_num);
+ return -WD_EINVAL;
+ }
+
+ if (mode >= SCHED_MODE_BUTT) {
+ WD_ERR("ERROR: %s para err: mode = %u, mode_num = %d!\n",
+ __FUNCTION__, mode, SCHED_MODE_BUTT);
return -WD_EINVAL;
}
sched_info = sched_ctx->sched_info;
if (!sched_info[numa_id].ctx_region[mode]) {
- WD_ERR("ERROR: %s para err: ctx_region:numa_id=%d, mode=%u is NULL!\n",
+ WD_ERR("ERROR: %s ctx_region of numa_id = %d, mode = %u is NULL!\n",
__FUNCTION__, numa_id, mode);
return -WD_EINVAL;
}
--
2.25.1

View File

@ -0,0 +1,127 @@
From b670d346baac3be4b3b55a481c196abbdaf36bd3 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:55 +0800
Subject: [PATCH 62/64] uadk: optimize wd_get_accel_list
wd_get_accel_list should skip nosva device,
so add a step to check sva flags, get_dev_info
should not print error info when device is nosva.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/wd.c b/wd.c
index d1652dd..afcf134 100644
--- a/wd.c
+++ b/wd.c
@@ -44,16 +44,18 @@ static int get_raw_attr(const char *dev_root, const char *attr, char *buf,
ssize_t size;
int fd;
- if (!dev_root || !attr || !buf || !sz)
- return -WD_EINVAL;
-
size = snprintf(attr_file, PATH_STR_SIZE, "%s/%s", dev_root, attr);
- if (size < 0)
+ if (size < 0) {
+ WD_ERR("failed to snprintf, dev_root: %s, attr: %s!\n",
+ dev_root, attr);
return -WD_EINVAL;
+ }
ptrRet = realpath(attr_file, attr_path);
- if (ptrRet == NULL)
+ if (ptrRet == NULL) {
+ WD_ERR("failed to resolve path, attr_file: %s!\n", attr_file);
return -WD_ENODEV;
+ }
fd = open(attr_path, O_RDONLY, 0);
if (fd < 0) {
@@ -78,16 +80,15 @@ static int get_int_attr(struct uacce_dev *dev, const char *attr, int *val)
char buf[MAX_ATTR_STR_SIZE] = {0};
int ret;
- if (!dev || !val)
- return -WD_EINVAL;
-
ret = get_raw_attr(dev->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
if (ret < 0)
return ret;
*val = strtol(buf, NULL, 10);
- if (errno == ERANGE)
+ if (errno == ERANGE) {
+ WD_ERR("failed to strtol %s, out of range!\n", buf);
return -errno;
+ }
return 0;
}
@@ -97,9 +98,6 @@ static int get_str_attr(struct uacce_dev *dev, const char *attr, char *buf,
{
int ret;
- if (!dev)
- return -WD_EINVAL;
-
ret = get_raw_attr(dev->dev_root, attr, buf, buf_sz);
if (ret < 0) {
buf[0] = '\0';
@@ -143,13 +141,19 @@ static int get_dev_info(struct uacce_dev *dev)
ret = get_int_attr(dev, "isolate", &value);
if (ret < 0)
return ret;
- else if (value == 1)
+ else if (value == 1) {
+ WD_ERR("skip isolated uacce device!\n");
return -ENODEV;
+ }
}
ret = get_int_attr(dev, "flags", &dev->flags);
if (ret < 0)
return ret;
+ else if (!(dev->flags & UACCE_DEV_SVA)) {
+ WD_ERR("skip none sva uacce device!\n");
+ return -ENODEV;
+ }
ret = get_int_attr(dev, "region_mmio_size", &value);
if (ret < 0)
@@ -211,10 +215,8 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
goto out_dir;
ret = get_dev_info(dev);
- if (ret < 0) {
- WD_ERR("failed to get dev info: ret = %d!\n", ret);
+ if (ret < 0)
goto out_dir;
- }
break;
}
@@ -529,6 +531,9 @@ int wd_get_avail_ctx(struct uacce_dev *dev)
{
int avail_ctx, ret;
+ if (!dev)
+ return -WD_EINVAL;
+
ret = get_int_attr(dev, "available_instances", &avail_ctx);
if (ret < 0)
return ret;
@@ -551,8 +556,6 @@ static int get_dev_alg_name(const char *d_name, char *dev_alg_name, size_t sz)
ret = get_raw_attr(dev_path, "algorithms", dev_alg_name, sz);
if (ret < 0) {
dev_alg_name[0] = '\0';
- WD_ERR("failed to get alg for %s, ret = %d\n",
- dev_path, ret);
return ret;
}
--
2.25.1

View File

@ -0,0 +1,38 @@
From f266f7920f0f58b71f2755a8cbad284f1848316c Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:56 +0800
Subject: [PATCH 63/64] uadk: fix staic check warning
1.fix unterminated string.
2.fix bit operation of int data.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wd.c b/wd.c
index afcf134..565c173 100644
--- a/wd.c
+++ b/wd.c
@@ -77,7 +77,7 @@ static int get_raw_attr(const char *dev_root, const char *attr, char *buf,
static int get_int_attr(struct uacce_dev *dev, const char *attr, int *val)
{
- char buf[MAX_ATTR_STR_SIZE] = {0};
+ char buf[MAX_ATTR_STR_SIZE] = {'\0'};
int ret;
ret = get_raw_attr(dev->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
@@ -150,7 +150,7 @@ static int get_dev_info(struct uacce_dev *dev)
ret = get_int_attr(dev, "flags", &dev->flags);
if (ret < 0)
return ret;
- else if (!(dev->flags & UACCE_DEV_SVA)) {
+ else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) {
WD_ERR("skip none sva uacce device!\n");
return -ENODEV;
}
--
2.25.1

View File

@ -0,0 +1,134 @@
From 2b4923b7290eba36bc2fefc517129fb30a3d207d Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Mon, 21 Feb 2022 09:14:17 +0800
Subject: [PATCH 64/64] uadk/v1: fix the waiting time for receiving task
SEC device processes tasks quickly. If 'usleep' is used to
wait for the hardware to process tasks, CPU scheduling will
reduce performance. Therefore, increase the number of cycles
to replace 'usleep'.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
v1/wd_aead.c | 15 ++++++++-------
v1/wd_cipher.c | 15 ++++++++-------
v1/wd_digest.c | 15 ++++++++-------
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index 181b971..ad22426 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -35,8 +35,7 @@
#define MAX_AEAD_AUTH_SIZE 64
#define MAX_AEAD_ASSOC_SIZE 65536
#define MAX_HMAC_KEY_SIZE 128
-#define MAX_AEAD_RETRY_CNT 2000000
-#define AEAD_SLEEP_INTERVAL 0xf
+#define MAX_AEAD_RETRY_CNT 20000000
#define DES_KEY_SIZE 8
#define SM4_KEY_SIZE 16
@@ -509,16 +508,18 @@ static int aead_recv_sync(struct wcrypto_aead_ctx *a_ctx,
while (true) {
ret = wd_burst_recv(a_ctx->q, (void **)(resp + recv_count),
num - recv_count);
- if (ret >= 0) {
+ if (ret > 0) {
recv_count += ret;
if (recv_count == num)
break;
- if (++rx_cnt > MAX_AEAD_RETRY_CNT)
+ rx_cnt = 0;
+ } else if (ret == 0) {
+ if (++rx_cnt > MAX_AEAD_RETRY_CNT) {
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
+ __func__, num, recv_count);
break;
-
- if (!(rx_cnt & AEAD_SLEEP_INTERVAL))
- usleep(1);
+ }
} else {
WD_ERR("do aead wcrypto_recv error!\n");
return ret;
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 7df44e7..8bf71be 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -30,8 +30,7 @@
#include "v1/wd_util.h"
#define MAX_CIPHER_KEY_SIZE 64
-#define MAX_CIPHER_RETRY_CNT 2000000
-#define CIPHER_SLEEP_INTERVAL 0xf
+#define MAX_CIPHER_RETRY_CNT 20000000
#define DES_KEY_SIZE 8
#define SM4_KEY_SIZE 16
@@ -379,16 +378,18 @@ static int cipher_recv_sync(struct wcrypto_cipher_ctx *c_ctx,
while (true) {
ret = wd_burst_recv(c_ctx->q, (void **)(resp + recv_count),
num - recv_count);
- if (ret >= 0) {
+ if (ret > 0) {
recv_count += ret;
if (recv_count == num)
break;
- if (++rx_cnt > MAX_CIPHER_RETRY_CNT)
+ rx_cnt = 0;
+ } else if (ret == 0) {
+ if (++rx_cnt > MAX_CIPHER_RETRY_CNT) {
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
+ __func__, num, recv_count);
break;
-
- if (!(rx_cnt & CIPHER_SLEEP_INTERVAL))
- usleep(1);
+ }
} else {
WD_ERR("do cipher wcrypto_recv error!\n");
return ret;
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index aae4823..2179415 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -30,8 +30,7 @@
#include "wd_util.h"
#define MAX_HMAC_KEY_SIZE 128
-#define MAX_DIGEST_RETRY_CNT 2000000
-#define DIGEST_SLEEP_INTERVAL 0xf
+#define MAX_DIGEST_RETRY_CNT 20000000
#define SEC_SHA1_ALIGN_SZ 64
#define SEC_SHA512_ALIGN_SZ 128
@@ -275,16 +274,18 @@ static int digest_recv_sync(struct wcrypto_digest_ctx *d_ctx,
while (true) {
ret = wd_burst_recv(d_ctx->q, (void **)(resp + recv_count),
num - recv_count);
- if (ret >= 0) {
+ if (ret > 0) {
recv_count += ret;
if (recv_count == num)
break;
- if (++rx_cnt > MAX_DIGEST_RETRY_CNT)
+ rx_cnt = 0;
+ } else if (ret == 0) {
+ if (++rx_cnt > MAX_DIGEST_RETRY_CNT) {
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
+ __func__, num, recv_count);
break;
-
- if (!(rx_cnt & DIGEST_SLEEP_INTERVAL))
- usleep(1);
+ }
} else {
WD_ERR("do digest wcrypto_recv error!\n");
return ret;
--
2.25.1

View File

@ -1,7 +1,7 @@
Name: libwd
Summary: User Space Accelerator Development Kit
Version: 2.3.21
Release: 2
Release: 3
License: Apache-2.0
Source: %{name}-%{version}.tar.gz
Vendor: Huawei Corporation
@ -39,6 +39,41 @@ Patch0022: 0022-uadk-v1-delete-unused-parameter.patch
Patch0023: 0023-uadk-env-fix-wd_add_task_to_async_queue-return-value.patch
Patch0024: 0024-uadk-sched-fix-memory-leak.patch
Patch0025: 0025-hisi-sec-bugfix-for-out_bytes-checking.patch
Patch0026: 0026-uadk-tools-modify-NO-SVA-test-scenario.patch
Patch0027: 0027-wd-fix-wd_parse_async_poll_num.patch
Patch0028: 0028-uadk-optimize-wd_init_async_polling_thread_per_numa.patch
Patch0029: 0029-uadk-env-fix-wd_add_task_to_async_queue.patch
Patch0030: 0030-uadk-optimize-find_async_queue.patch
Patch0031: 0031-uadk-fix-check_after_sink.patch
Patch0032: 0032-uadk-fix-wd_request_ctx.patch
Patch0033: 0033-uadk-fix-sched-params-begin-issue.patch
Patch0034: 0034-uadk-optimize-wd_request_ctx.patch
Patch0035: 0035-uadk-env-bugfix-for-wd_init_resource.patch
Patch0036: 0036-uadk-env-fix-wd-ctx-num-init.patch
Patch0037: 0037-uadk-modify-for-free-and-return.patch
Patch0038: 0038-uadk-include-fix-uadk-compatibility.patch
Patch0039: 0039-uadk-fix-for-resources-are-repeatedly-released.patch
Patch0040: 0040-aead-modify-the-aead-s-request-api.patch
Patch0041: 0041-cipher-add-semi-weak-keys-checking.patch
Patch0042: 0042-uadk-ioctl-return-result-should-be-printed.patch
Patch0043: 0043-uadk-fix-environment-uninit-repeatly-error.patch
Patch0044: 0044-uadk-fix-wd_free_ctx-and-wd_uninit_sched_config.patch
Patch0045: 0045-uadk-env-fix-free-ctx-table-memory-leak.patch
Patch0046: 0046-uadk-remove-uadk_benchmark-binary-and-header-file.patch
Patch0047: 0047-uadk-fix-for-wd_env_config-numa_num.patch
Patch0048: 0048-hisi-sec-add-some-dfx-information-in-comments.patch
Patch0049: 0049-hisi-sec-delete-some-dummy-parameter-checking.patch
Patch0050: 0050-hisi-qm-udrv-v1-deleted-a-dummy-branch.patch
Patch0051: 0051-hisi-sec-v1-update-the-SEC-BD1-mode-configuration.patch
Patch0052: 0052-uadk-optimize-algorithm-initialization.patch
Patch0053: 0053-uadk-fix-send-exception-handling.patch
Patch0054: 0054-uadk-sec-fix-hisi_sec_digest_send.patch
Patch0055: 0055-uadk-sec-some-clean-code.patch
Patch0056: 0056-uadk-optimize-wd_ctx_qfr_mmap.patch
Patch0057: 0057-uadk-optimize-wd_sched_rr_instance.patch
Patch0058: 0058-uadk-optimize-wd_get_accel_list.patch
Patch0059: 0059-uadk-fix-staic-check-warning.patch
Patch0060: 0060-uadk-v1-fix-the-waiting-time-for-receiving-task.patch
%description
This package contains the User Space Accelerator Library
@ -196,6 +231,9 @@ fi
/sbin/ldconfig
%changelog
* Mon Feb 21 2022 Yang Shen <shenyang39@huawei.com> 2.3.21-3
- libwd: backport the patch of uadk from 2.3.24 to 2.3.27
* Tue Jan 04 2022 Yang Shen <shenyang39@huawei.com> 2.3.21-2
- libwd: backport the patch of uadk from 2.3.21 to 2.3.24