From: taoqi 30043660 taoqi10@huawei.com
The system does not check whether the pointer is NULL before releasing the pointer.
Signed-off-by: taoqi 30043660 taoqi10@huawei.com --- wd_mempool.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/wd_mempool.c b/wd_mempool.c index ff9910a..ffb2f47 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -230,8 +230,12 @@ static struct bitmap *create_bitmap(int bits)
static void destroy_bitmap(struct bitmap *bm) { - free(bm->map); - free(bm); + if (bm) { + if (bm->map) + free(bm->map); + + free(bm); + } }
static unsigned long _find_next_bit(unsigned long *map, unsigned long bits, @@ -893,8 +897,10 @@ static int init_mempool(struct mempool *mp)
static void uninit_mempool(struct mempool *mp) { - destroy_bitmap(mp->bitmap); - mp->bitmap = NULL; + if (mp->bitmap) { + destroy_bitmap(mp->bitmap); + mp->bitmap = NULL; + } }
handle_t wd_mempool_create(size_t size, int node)
Return value of numa_node_of_cpu may be -1, it can't be used as numa map index.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_sched.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/wd_sched.c b/wd_sched.c index 9a52c4d..cbd7a9b 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -177,6 +177,11 @@ static handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param) int node = numa_node_of_cpu(cpu); struct sched_key *skey;
+ if (node < 0) { + WD_ERR("invalid: failed to get numa node!\n"); + return (handle_t)(-WD_EINVAL); + } + if (!sched_ctx) { WD_ERR("invalid: sched ctx is NULL!\n"); return (handle_t)(-WD_EINVAL);
From: taoqi 30043660 taoqi10@huawei.com
The FD handle is repeatedly released when the "goto err_read" statement is executed.
Signed-off-by: taoqi 30043660 taoqi10@huawei.com --- wd_mempool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/wd_mempool.c b/wd_mempool.c index ffb2f47..a051791 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -650,14 +650,13 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size) goto err_read; }
- close(fd); - ret = strtol(buf, NULL, 10); if (errno == ERANGE) { WD_ERR("failed to strtol %s, out of range!\n", buf); goto err_read; }
+ close(fd); return ret;
err_read:
From: Kai Ye yekai13@huawei.com
Get the sec sva status by completed bd3 as failed. It can help locate sva problems.
Signed-off-by: Kai Ye yekai13@huawei.com --- drv/hisi_sec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index e6589a0..22a5e41 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -1344,8 +1344,8 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
done = sqe->done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->error_type) { - WD_ERR("failed to parse cipher BD3! done=0x%x, etype=0x%x\n", - done, sqe->error_type); + WD_ERR("failed to parse cipher BD3! done=0x%x, etype=0x%x, sva_status=0x%x\n", + done, sqe->error_type, sqe->check_sum.hac_sva_status); recv_msg->result = WD_IN_EPARA; } else { recv_msg->result = WD_SUCCESS; @@ -1965,8 +1965,8 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
done = sqe->done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->error_type) { - WD_ERR("failed to parse digest BD3! done=0x%x, etype=0x%x\n", - done, sqe->error_type); + WD_ERR("failed to parse digest BD3! done=0x%x, etype=0x%x, sva_status=0x%x\n", + done, sqe->error_type, sqe->check_sum.hac_sva_status); recv_msg->result = WD_IN_EPARA; } else { recv_msg->result = WD_SUCCESS; @@ -2917,8 +2917,9 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, icv = (sqe->done_flag & SEC_ICV_MASK) >> 1; if (done != SEC_HW_TASK_DONE || sqe->error_type || icv == SEC_HW_ICV_ERR) { - WD_ERR("failed to parse aead BD3! done=0x%x, etype=0x%x, icv=0x%x\n", - done, sqe->error_type, icv); + WD_ERR("failed to parse aead BD3!\n" + "done=0x%x, etype=0x%x, icv=0x%x, sva_status=0x%x\n", + done, sqe->error_type, icv, sqe->check_sum.hac_sva_status); recv_msg->result = WD_IN_EPARA; } else { recv_msg->result = WD_SUCCESS;
printf format of unsigned int should be %u.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/wd_util.c b/wd_util.c index 78c39be..a180451 100644 --- a/wd_util.c +++ b/wd_util.c @@ -973,8 +973,8 @@ static int wd_parse_env(struct wd_env_config *config) 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", - var->name, var->def_val); + WD_INFO("no %s environment variable! Use default: %s\n", + var->name, var->def_val); }
ret = var->parse_fn(config, var_s); @@ -1875,7 +1875,7 @@ static int file_check_valid(char *lib_file) static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver) { if (!fb_driver->init) { - WD_ERR("soft sec driver have no init interface.\n"); + WD_ERR("soft acc driver have no init interface.\n"); return -WD_EINVAL; }
@@ -1887,7 +1887,7 @@ static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver) static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver) { if (!fb_driver->exit) { - WD_ERR("soft sec driver have no exit interface.\n"); + WD_ERR("soft acc driver have no exit interface.\n"); return; }
@@ -2529,7 +2529,7 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs) op_type_num = ctx_params->op_type_num; ctx_set_num = wd_get_ctx_numbers(*ctx_params, op_type_num); if (!ctx_set_num || !op_type_num) { - WD_ERR("invalid: ctx_set_num is %d, op_type_num is %d!\n", + WD_ERR("invalid: ctx_set_num is %u, op_type_num is %u!\n", ctx_set_num, op_type_num); ret = -WD_EINVAL; goto out_freelist;
From: Zhiqi Song songzhiqi1@huawei.com
modify members of struct wd_env_config_per_numa, ctx number's type should be u32 and node's should be int.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com Tested-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_util.h | 14 +++----------- wd_util.c | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h index 9ef2328..89016ab 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -53,17 +53,9 @@ struct wd_ctx_range {
struct wd_env_config_per_numa { /* Config begin */ - unsigned long node; - unsigned long sync_ctx_num; - unsigned long async_ctx_num; - /* - * Define which polling thread to poll each async ctx, polling thread - * number stars from 0. - * - * async_ctx_poll: 0, 0, 0, 1, 1, means polling thread 0 polls async - * ctx 0, 1, 2, polling thread 1 polls async ctx 3, 4. - */ - unsigned long *async_ctx_poll; + int node; + __u32 sync_ctx_num; + __u32 async_ctx_num;
/* * +---------+-----------------+---------------+ diff --git a/wd_util.c b/wd_util.c index a180451..3ce5f56 100644 --- a/wd_util.c +++ b/wd_util.c @@ -461,9 +461,9 @@ void dump_env_info(struct wd_env_config *config) continue;
ctx_table = config_numa->ctx_table; - WD_ERR("-> %s: %d: sync num: %lu\n", __func__, i, + WD_ERR("-> %s: %d: sync num: %u\n", __func__, i, config_numa->sync_ctx_num); - WD_ERR("-> %s: %d: async num: %lu\n", __func__, i, + WD_ERR("-> %s: %d: async num: %u\n", __func__, i, config_numa->async_ctx_num); for (j = 0; j < CTX_MODE_MAX; j++) for (k = 0; k < config_numa->op_type_num; k++) {
From: liulongfang liulongfang@huawei.com
In the current acquisition method, if there is no scheduling domain of the specified mode and operation type in the specified numa domain, it will search the scheduling domains in each numa, and find a valid scheduling domain for use.
However, the operation mode will not be strictly matched during the query, which will lead to the use of the compressed type queue in the decompression type task, that will eventually lead to task data errors.
Therefore, this operation type also needs to be strictly matched. If it doesn't match, you need to report an error.
Signed-off-by: liulongfang liulongfang@huawei.com --- wd_sched.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/wd_sched.c b/wd_sched.c index cbd7a9b..bb5264e 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -103,7 +103,6 @@ static struct sched_ctx_region *sched_get_ctx_range(struct wd_sched_ctx *sched_c { struct wd_sched_info *sched_info; int numa_id; - int type;
sched_info = sched_ctx->sched_info; if (key->numa_id >= 0 && @@ -112,10 +111,8 @@ static struct sched_ctx_region *sched_get_ctx_range(struct wd_sched_ctx *sched_c
/* If the key->numa_id is not exist, we should scan for a region */ for (numa_id = 0; numa_id < sched_ctx->numa_num; numa_id++) { - for (type = 0; type < sched_ctx->type_num; type++) { - if (sched_info[numa_id].ctx_region[key->mode][type].valid) - return &sched_info[numa_id].ctx_region[key->mode][type]; - } + if (sched_info[numa_id].ctx_region[key->mode][key->type].valid) + return &sched_info[numa_id].ctx_region[key->mode][key->type]; }
return NULL;
If no ctx is available, uadk cannot run properly, an error should be reported.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_sched.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/wd_sched.c b/wd_sched.c index bb5264e..871e72f 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -84,8 +84,7 @@ struct wd_sched_ctx {
static bool sched_key_valid(struct wd_sched_ctx *sched_ctx, const struct sched_key *key) { - if (key->numa_id >= sched_ctx->numa_num || - key->mode >= SCHED_MODE_BUTT || + if (key->numa_id >= sched_ctx->numa_num || key->mode >= SCHED_MODE_BUTT || key->type >= sched_ctx->type_num) { WD_ERR("invalid: sched key's numa: %d, mode: %u, type: %u!\n", key->numa_id, key->mode, key->type); @@ -193,6 +192,7 @@ static handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param) if (!param) { memset(skey, 0, sizeof(struct sched_key)); skey->numa_id = sched_ctx->numa_map[node]; + WD_INFO("session don't set scheduler parameters!\n"); } else if (param->numa_id < 0) { skey->type = param->type; skey->numa_id = sched_ctx->numa_map[node]; @@ -203,14 +203,21 @@ static handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param)
if (skey->numa_id < 0) { WD_ERR("failed to get valid sched numa region!\n"); - free(skey); - return (handle_t)(-WD_EINVAL); + goto out; }
skey->sync_ctxid = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); skey->async_ctxid = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + if (skey->sync_ctxid == INVALID_POS && skey->async_ctxid == INVALID_POS) { + WD_ERR("failed to get valid sync_ctxid or async_ctxid!\n"); + goto out; + }
return (handle_t)skey; + +out: + free(skey); + return (handle_t)(-WD_EINVAL); }
/* @@ -222,7 +229,7 @@ static handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param) * The user must init the schedule info through session_sched_init */ static __u32 session_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, - const int sched_mode) + const int sched_mode) { struct sched_key *key = (struct sched_key *)sched_key;
@@ -244,7 +251,7 @@ static int session_poll_region(struct wd_sched_ctx *sched_ctx, __u32 begin, __u32 i; int ret;
- /* i is the pos of ctxs, the max is end */ + /* i is the pos of sched_ctxs, the max is end */ for (i = begin; i <= end; i++) { /* * RR schedule, one time poll one package, @@ -370,6 +377,7 @@ static int sched_none_poll_policy(handle_t h_sched_ctx,
while (loop_times > 0) { /* Default use ctx 0 */ + loop_times--; ret = sched_ctx->poll_func(0, 1, &poll_num); if ((ret < 0) && (ret != -EAGAIN)) return ret; @@ -411,6 +419,7 @@ static int sched_single_poll_policy(handle_t h_sched_ctx,
while (loop_times > 0) { /* Default async mode use ctx 0 */ + loop_times--; ret = sched_ctx->poll_func(0, 1, &poll_num); if ((ret < 0) && (ret != -EAGAIN)) return ret; @@ -480,7 +489,8 @@ static void wd_sched_map_cpus_to_dev(struct wd_sched_ctx *sched_ctx) } }
-int wd_sched_rr_instance(const struct wd_sched *sched, struct sched_params *param) +int wd_sched_rr_instance(const struct wd_sched *sched, + struct sched_params *param) { struct wd_sched_info *sched_info = NULL; struct wd_sched_ctx *sched_ctx = NULL; @@ -606,7 +616,8 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, return NULL;
if (sched_type >= SCHED_POLICY_BUTT || !type_num) { - WD_ERR("invalid: sched_type is %u or type_num is %u!\n", sched_type, type_num); + WD_ERR("invalid: sched_type is %u or type_num is %u!\n", + sched_type, type_num); return NULL; }
From: Longfang Liu liulongfang@huawei.com
Some header files are not used in wd_alg.c and can be deleted.
In addition, the traversal linked list pnext may be empty, and judgment needs to be added.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- include/wd_alg.h | 4 ---- wd_alg.c | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/include/wd_alg.h b/include/wd_alg.h index 0f446cf..060e874 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -9,11 +9,7 @@ #include <fcntl.h> #include <stdbool.h> #include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <syslog.h> #include <unistd.h> -#include <asm/types.h>
#ifdef __cplusplus extern "C" { diff --git a/wd_alg.c b/wd_alg.c index ffcadac..d3f47bd 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -4,9 +4,7 @@ */
#define _GNU_SOURCE -#include <ctype.h> #include <dirent.h> -#include <errno.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -241,7 +239,8 @@ void wd_enable_drv(struct wd_alg_driver *drv) pnext = pnext->next; }
- pnext->available = wd_alg_check_available(drv->calc_type, drv->drv_name); + if (pnext) + pnext->available = wd_alg_check_available(drv->calc_type, drv->drv_name); pthread_mutex_unlock(&mutex); }
@@ -260,7 +259,8 @@ void wd_disable_drv(struct wd_alg_driver *drv) pnext = pnext->next; }
- pnext->available = false; + if (pnext) + pnext->available = false; pthread_mutex_unlock(&mutex); }