Numa node from environment variable should be checked, otherwise, the number of ctx will be set as valid nodes.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 3 +++ wd_util.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/wd.c b/wd.c index 401dd9d..ba73fd1 100644 --- a/wd.c +++ b/wd.c @@ -760,6 +760,9 @@ struct uacce_dev *wd_find_dev_by_numa(struct uacce_dev_list *list, int numa_id) p = p->next; }
+ if (dev == WD_ERR_PTR(-WD_ENODEV)) + WD_ERR("no available device was found in numa %d!\n", numa_id); + return dev; }
diff --git a/wd_util.c b/wd_util.c index 465d958..6e70549 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2001,11 +2001,12 @@ static void add_lib_to_list(struct drv_lib_list *head, tmp->next = node; }
-static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section, - __u32 op_type_num, int is_comp) +static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, struct uacce_dev_list *list, + const char *section, __u32 op_type_num, int is_comp) { struct wd_ctx_nums *ctxs = ctx_params->ctx_set_num; int i, j, ctx_num, node, ret; + struct uacce_dev *dev; char *ctx_section; const char *type;
@@ -2023,6 +2024,10 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section if (!ctx_num) return 0;
+ dev = wd_find_dev_by_numa(list, node); + if (WD_IS_ERR(dev)) + return -WD_ENODEV; + for (i = 0; i < CTX_MODE_MAX; i++) { for (j = 0; j < op_type_num; j++) { type = is_comp ? comp_ctx_type[i][j] : ctx_type[i][0]; @@ -2044,10 +2049,12 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section return -WD_EINVAL; }
-static int wd_env_set_ctx_nums(const char *name, const char *var_s, +static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const char *var_s, struct wd_ctx_params *ctx_params, __u32 op_type_num) { + char alg_type[CRYPTO_MAX_ALG_NAME]; char *left, *section, *start; + struct uacce_dev_list *list; int is_comp; int ret = 0;
@@ -2060,14 +2067,22 @@ static int wd_env_set_ctx_nums(const char *name, const char *var_s, if (!start) return -WD_ENOMEM;
+ wd_get_alg_type(alg_name, alg_type); + list = wd_get_accel_list(alg_type); + if (!list) { + WD_ERR("failed to get devices!\n"); + free(start); + return -WD_ENODEV; + } + left = start; while ((section = strsep(&left, ","))) { - ret = wd_set_ctx_nums(ctx_params, section, op_type_num, is_comp); + ret = wd_set_ctx_nums(ctx_params, list, section, op_type_num, is_comp); if (ret < 0) - goto out_free_str; + break; }
-out_free_str: + wd_free_list_accels(list); free(start); return ret; } @@ -2095,11 +2110,12 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, var_s = secure_getenv(env_name); if (var_s && strlen(var_s)) { /* environment variable has the highest priority */ - ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params, max_op_type); + ret = wd_env_set_ctx_nums(driver->alg_name, env_name, var_s, + ctx_params, max_op_type); if (ret) { WD_ERR("fail to init ctx nums from %s!\n", env_name); numa_free_nodemask(ctx_params->bmp); - return -WD_EINVAL; + return ret; } } else { /* environment variable is not set, try to use user_ctx_params first */ @@ -2593,7 +2609,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) __u32 sched_type = attrs->sched_type; struct wd_ctx_config *ctx_config = NULL; struct wd_sched *alg_sched = NULL; - char alg_type[WD_NAME_SIZE]; + char alg_type[CRYPTO_MAX_ALG_NAME]; char *alg = attrs->alg; int driver_type = UADK_ALG_HW; int ret;