This patchset adds the message pool depth configuration. Users can input value to initialize the message pool.
Weili Qian (3): uadk: add the msg pool depth configuration uadk/v1: add the cookie depth configuration uadk/tool: initialize cparams to zero
include/wd_alg_common.h | 17 +++++++++++++++++ include/wd_util.h | 9 ++++++--- uadk_tool/test/test_sec.c | 4 ++-- v1/wd.h | 8 +++++++- v1/wd_aead.c | 26 +++++++++++++++++--------- v1/wd_cipher.c | 27 +++++++++++++++++---------- v1/wd_comp.c | 4 +++- v1/wd_dh.c | 8 +++++--- v1/wd_digest.c | 28 ++++++++++++++++++---------- v1/wd_ecc.c | 29 +++++++++++++++++++---------- v1/wd_rng.c | 14 ++++++++------ v1/wd_rsa.c | 12 +++++++----- v1/wd_util.c | 16 ++++++++++++++++ v1/wd_util.h | 11 ++++++----- wd_aead.c | 5 ++--- wd_cipher.c | 3 +-- wd_comp.c | 6 ++---- wd_dh.c | 3 +-- wd_digest.c | 3 +-- wd_ecc.c | 6 +----- wd_rsa.c | 6 +----- wd_util.c | 31 ++++++++++++++++++++++++++++--- wd_zlibwrapper.c | 2 +- 23 files changed, 186 insertions(+), 92 deletions(-)
Add the message pool depth configuration. Users can use the 'ctx_msg_num' in 'struct wd_cap_config' to input the depth of message pool. If the input value ranges from 1 to 1024, the input value is used to initialize async message pool. Otherwise, the default value is used to initialize async message pool.
Signed-off-by: Weili Qian qianweili@huawei.com --- include/wd_alg_common.h | 17 +++++++++++++++++ include/wd_util.h | 9 ++++++--- wd_aead.c | 5 ++--- wd_cipher.c | 3 +-- wd_comp.c | 6 ++---- wd_dh.c | 3 +-- wd_digest.c | 3 +-- wd_ecc.c | 6 +----- wd_rsa.c | 6 +----- wd_util.c | 31 ++++++++++++++++++++++++++++--- wd_zlibwrapper.c | 2 +- 11 files changed, 61 insertions(+), 30 deletions(-)
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 8a86656..77845a4 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -55,6 +55,19 @@ struct wd_ctx { __u8 ctx_mode; };
+/** + * struct wd_cap_config - Capabilities. + * @ctx_msg_num: number of asynchronous msg pools that the user wants to allocate. + * Optional, user can set ctx_msg_num based on the number of requests + * and system memory, 1~1024 is valid. If the value is not set or invalid, + * the default value 1024 is used to initialize msg pools. + * @resv: Reserved data. + */ +struct wd_cap_config { + __u32 ctx_msg_num; + __u32 resv; +}; + /** * struct wd_ctx_config - Define a ctx set and its related attributes, which * will be used in the scope of current process. @@ -62,11 +75,13 @@ struct wd_ctx { * @ctxs: Point to a ctx array, length is above ctx_num. * @priv: The attributes of ctx defined by user, which is used by user * defined scheduler. + * @cap: Capabilities input by user. Support set NULL, use default value initialize. */ struct wd_ctx_config { __u32 ctx_num; struct wd_ctx *ctxs; void *priv; + struct wd_cap_config *cap; };
/** @@ -89,11 +104,13 @@ struct wd_ctx_nums { * @ctx_set_num: Each operation type ctx sets numbers. * @bmp: Ctxs distribution. Means users want to run business process on these * numa or request ctx from devices located in these numa. + * @cap: Capabilities input by user. Support set NULL, use default value initialize. */ struct wd_ctx_params { __u32 op_type_num; struct wd_ctx_nums *ctx_set_num; struct bitmask *bmp; + struct wd_cap_config *cap; };
struct wd_ctx_internal { diff --git a/include/wd_util.h b/include/wd_util.h index 144ba59..cb07657 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -19,6 +19,8 @@ extern "C" { #endif
+#define WD_POOL_MAX_ENTRIES 1024 + #define FOREACH_NUMA(i, config, config_numa) \ for ((i) = 0, (config_numa) = (config)->config_per_numa; \ (i) < (config)->numa_num; (config_numa)++, (i)++) @@ -167,9 +169,9 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in); void wd_memset_zero(void *data, __u32 size);
/* - * wd_init_async_request_pool() - Init message pools. + * wd_init_async_request_pool() - Init async message pools. * @pool: Pointer of message pool. - * @pool_num: Message pool number. + * @config: ctx configuration input by user. * @msg_num: Message entry number in one pool. * @msg_size: Size of each message entry. * @@ -186,7 +188,8 @@ void wd_memset_zero(void *data, __u32 size); * +-------+-------+----+-------+ -+- * |<------- msg_num ---------->| */ -int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num, +int wd_init_async_request_pool(struct wd_async_msg_pool *pool, + struct wd_ctx_config *config, __u32 msg_num, __u32 msg_size);
/* diff --git a/wd_aead.c b/wd_aead.c index 7c3f160..cd0812e 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -21,7 +21,6 @@
#define WD_AEAD_CCM_GCM_MIN 4U #define WD_AEAD_CCM_GCM_MAX 16 -#define WD_POOL_MAX_ENTRIES 1024
static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = { WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN, @@ -429,8 +428,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
/* init async request pool */ ret = wd_init_async_request_pool(&wd_aead_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, - sizeof(struct wd_aead_msg)); + config, WD_POOL_MAX_ENTRIES, + sizeof(struct wd_aead_msg)); if (ret < 0) goto out_clear_sched;
diff --git a/wd_cipher.c b/wd_cipher.c index adb6496..8acadcd 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -20,7 +20,6 @@ #define AES_KEYSIZE_192 24 #define AES_KEYSIZE_256 32
-#define WD_POOL_MAX_ENTRIES 1024 #define DES_WEAK_KEY_NUM 16
static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = { @@ -311,7 +310,7 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
/* allocate async pool for every ctx */ ret = wd_init_async_request_pool(&wd_cipher_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_cipher_msg)); if (ret < 0) goto out_clear_sched; diff --git a/wd_comp.c b/wd_comp.c index 93c3031..a23dee1 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -15,7 +15,6 @@ #include "drv/wd_comp_drv.h" #include "wd_comp.h"
-#define WD_POOL_MAX_ENTRIES 1024 #define HW_CTX_SIZE (64 * 1024) #define STREAM_CHUNK (128 * 1024)
@@ -130,9 +129,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc if (ret < 0) goto out_clear_ctx_config;
- /* fix me: sadly find we allocate async pool for every ctx */ ret = wd_init_async_request_pool(&wd_comp_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_comp_msg)); if (ret < 0) goto out_clear_sched; @@ -222,7 +220,7 @@ void wd_comp_uninit(void) int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params) { struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0}; - struct wd_ctx_params comp_ctx_params; + struct wd_ctx_params comp_ctx_params = {0}; int ret = -WD_EINVAL; bool flag;
diff --git a/wd_dh.c b/wd_dh.c index 50a1532..97df515 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -15,7 +15,6 @@ #include "include/drv/wd_dh_drv.h" #include "wd_util.h"
-#define WD_POOL_MAX_ENTRIES 1024 #define DH_MAX_KEY_SIZE 512 #define WD_DH_G2 2
@@ -105,7 +104,7 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
/* initialize async request pool */ ret = wd_init_async_request_pool(&wd_dh_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_dh_msg)); if (ret) goto out_clear_sched; diff --git a/wd_digest.c b/wd_digest.c index c5dbeca..9dc4bb3 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -19,7 +19,6 @@ #define AES_KEYSIZE_192 24 #define AES_KEYSIZE_256 32
-#define WD_POOL_MAX_ENTRIES 1024 #define DES_WEAK_KEY_NUM 4
static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { @@ -243,7 +242,7 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
/* allocate async pool for every ctx */ ret = wd_init_async_request_pool(&wd_digest_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_digest_msg)); if (ret < 0) goto out_clear_sched; diff --git a/wd_ecc.c b/wd_ecc.c index 9f83fea..938e516 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -17,9 +17,6 @@ #include "include/wd_ecc_curve.h" #include "wd_ecc.h"
-#define WD_POOL_MAX_ENTRIES 1024 -#define WD_ECC_CTX_MSG_NUM 64 -#define WD_ECC_MAX_CTX 256 #define ECC_MAX_HW_BITS 521 #define ECC_MAX_KEY_SIZE BITS_TO_BYTES(ECC_MAX_HW_BITS) #define ECC_MAX_IN_NUM 4 @@ -169,9 +166,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch if (ret < 0) goto out_clear_ctx_config;
- /* fix me: sadly find we allocate async pool for every ctx */ ret = wd_init_async_request_pool(&wd_ecc_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_ecc_msg)); if (ret < 0) goto out_clear_sched; diff --git a/wd_rsa.c b/wd_rsa.c index 19a590f..2993637 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -15,9 +15,6 @@ #include "include/drv/wd_rsa_drv.h" #include "wd_rsa.h"
-#define WD_POOL_MAX_ENTRIES 1024 -#define WD_HW_EACCESS 62 - #define RSA_MAX_KEY_SIZE 512
static __thread __u64 balance; @@ -144,9 +141,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch if (ret < 0) goto out_clear_ctx_config;
- /* fix me: sadly find we allocate async pool for every ctx */ ret = wd_init_async_request_pool(&wd_rsa_setting.pool, - config->ctx_num, WD_POOL_MAX_ENTRIES, + config, WD_POOL_MAX_ENTRIES, sizeof(struct wd_rsa_msg)); if (ret < 0) goto out_clear_sched; diff --git a/wd_util.c b/wd_util.c index ef67f1f..937ee2a 100644 --- a/wd_util.c +++ b/wd_util.c @@ -310,6 +310,20 @@ void wd_memset_zero(void *data, __u32 size) *s++ = 0; }
+static void get_ctx_msg_num(struct wd_cap_config *cap, __u32 *msg_num) +{ + if (!cap || !cap->ctx_msg_num) + return; + + if (cap->ctx_msg_num > WD_POOL_MAX_ENTRIES) { + WD_INFO("ctx_msg_num %u is invalid, use default value: %u!\n", + cap->ctx_msg_num, *msg_num); + return; + } + + *msg_num = cap->ctx_msg_num; +} + static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size) { pool->msgs = calloc(1, msg_num * msg_size); @@ -335,6 +349,9 @@ static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
static void uninit_msg_pool(struct msg_pool *pool) { + if (!pool->msg_num) + return; + free(pool->msgs); free(pool->used); pool->msgs = NULL; @@ -342,21 +359,27 @@ static void uninit_msg_pool(struct msg_pool *pool) memset(pool, 0, sizeof(*pool)); }
-int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num, +int wd_init_async_request_pool(struct wd_async_msg_pool *pool, struct wd_ctx_config *config, __u32 msg_num, __u32 msg_size) { + __u32 pool_num = config->ctx_num; __u32 i, j; int ret;
pool->pool_num = pool_num;
- pool->pools = calloc(1, pool->pool_num * sizeof(struct msg_pool)); + pool->pools = calloc(1, pool_num * sizeof(struct msg_pool)); if (!pool->pools) { WD_ERR("failed to alloc memory for async msg pools!\n"); return -WD_ENOMEM; }
- for (i = 0; i < pool->pool_num; i++) { + /* If user set valid msg num, use user's. */ + get_ctx_msg_num(config->cap, &msg_num); + for (i = 0; i < pool_num; i++) { + if (config->ctxs[i].ctx_mode == CTX_MODE_SYNC) + continue; + ret = init_msg_pool(&pool->pools[i], msg_num, msg_size); if (ret < 0) goto err; @@ -2089,6 +2112,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, /* environment variable is not set, try to use user_ctx_params first */ if (user_ctx_params) { copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp); + ctx_params->cap = user_ctx_params->cap; ctx_params->ctx_set_num = user_ctx_params->ctx_set_num; ctx_params->op_type_num = user_ctx_params->op_type_num; if (ctx_params->op_type_num > (__u32)max_op_type) { @@ -2657,6 +2681,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) goto out_freesched; }
+ ctx_config->cap = attrs->ctx_params->cap; ret = alg_init_func(ctx_config, alg_sched); if (ret) goto out_pre_init; diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c index 29b51fb..4b785ce 100644 --- a/wd_zlibwrapper.c +++ b/wd_zlibwrapper.c @@ -40,8 +40,8 @@ static void wd_zlib_unlock(void)
static int wd_zlib_uadk_init(void) { + struct wd_ctx_params cparams = {0}; struct wd_ctx_nums *ctx_set_num; - struct wd_ctx_params cparams; int ret, i;
if (zlib_config.status == WD_ZLIB_INIT)
Add the cookie depth configuration. Users can use the 'flags 0~15bits' in 'struct wd_capa' to input the depth of cookie. If the input value ranges from 1 to 1024, the input value is used to initialize cookie. Otherwise, the default value is used to initialize cookie.
Signed-off-by: Weili Qian qianweili@huawei.com --- v1/wd.h | 8 +++++++- v1/wd_aead.c | 26 +++++++++++++++++--------- v1/wd_cipher.c | 27 +++++++++++++++++---------- v1/wd_comp.c | 4 +++- v1/wd_dh.c | 8 +++++--- v1/wd_digest.c | 28 ++++++++++++++++++---------- v1/wd_ecc.c | 29 +++++++++++++++++++---------- v1/wd_rng.c | 14 ++++++++------ v1/wd_rsa.c | 12 +++++++----- v1/wd_util.c | 16 ++++++++++++++++ v1/wd_util.h | 11 ++++++----- 11 files changed, 123 insertions(+), 60 deletions(-)
diff --git a/v1/wd.h b/v1/wd.h index 1bd9669..176f2ef 100644 --- a/v1/wd.h +++ b/v1/wd.h @@ -174,7 +174,13 @@ struct wd_capa { int throughput; /* latency capability */ int latency; - /* other capabilities */ + /* + * Other capabilities. + * 0~15 bits: number of cookies that the user wants to allocate. + * Optional, user can set value based on the number of requests and system memory, + * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256) + * is used to initialize cookies. + */ __u32 flags;
/* For algorithm parameters, now it is defined in extending notions */ diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 7abb8a0..1720506 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -142,13 +142,23 @@ static int create_ctx_para_check(struct wd_queue *q, return WD_SUCCESS; }
-static void init_aead_cookie(struct wcrypto_aead_ctx *ctx, +static int init_aead_cookie(struct wcrypto_aead_ctx *ctx, struct wcrypto_aead_ctx_setup *setup) { struct wcrypto_aead_cookie *cookie; - __u32 i; + __u32 flags = ctx->q->capa.flags; + __u32 cookies_num, i; + int ret; + + cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); + ret = wd_init_cookie_pool(&ctx->pool, + sizeof(struct wcrypto_aead_cookie), cookies_num); + if (ret) { + WD_ERR("failed to init cookie pool!\n"); + return ret; + }
- for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.alg_type = WCRYPTO_AEAD; @@ -161,6 +171,8 @@ static void init_aead_cookie(struct wcrypto_aead_ctx *ctx, cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id; cookie->msg.usr_data = (uintptr_t)&cookie->tag; } + + return 0; }
static int wcrypto_setup_qinfo(struct wcrypto_aead_ctx_setup *setup, @@ -236,13 +248,9 @@ void *wcrypto_create_aead_ctx(struct wd_queue *q, }
ctx->iv_blk_size = get_iv_block_size(setup->cmode); - ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_aead_cookie), WD_CTX_MSG_NUM); - if (ret) { - WD_ERR("fail to init cookie pool!\n"); + ret = init_aead_cookie(ctx, setup); + if (ret) goto free_ctx_akey; - } - init_aead_cookie(ctx, setup);
return ctx;
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index 3d7d140..55bfbe2 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -122,13 +122,23 @@ static int create_ctx_para_check(struct wd_queue *q, return WD_SUCCESS; }
-static void init_cipher_cookie(struct wcrypto_cipher_ctx *ctx, +static int init_cipher_cookie(struct wcrypto_cipher_ctx *ctx, struct wcrypto_cipher_ctx_setup *setup) { struct wcrypto_cipher_cookie *cookie; - __u32 i; + __u32 flags = ctx->q->capa.flags; + __u32 cookies_num, i; + int ret; + + cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); + ret = wd_init_cookie_pool(&ctx->pool, + sizeof(struct wcrypto_cipher_cookie), cookies_num); + if (ret) { + WD_ERR("failed to init cookie pool!\n"); + return ret; + }
- for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.alg_type = WCRYPTO_CIPHER; @@ -139,6 +149,8 @@ static void init_cipher_cookie(struct wcrypto_cipher_ctx *ctx, cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id; cookie->msg.usr_data = (uintptr_t)&cookie->tag; } + + return 0; }
static int setup_qinfo(struct wcrypto_cipher_ctx_setup *setup, @@ -209,14 +221,9 @@ void *wcrypto_create_cipher_ctx(struct wd_queue *q, }
ctx->iv_blk_size = get_iv_block_size(setup->alg, setup->mode); - - ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_cipher_cookie), WD_CTX_MSG_NUM); - if (ret) { - WD_ERR("fail to init cookie pool!\n"); + ret = init_cipher_cookie(ctx, setup); + if (ret) goto free_ctx_key; - } - init_cipher_cookie(ctx, setup);
return ctx;
diff --git a/v1/wd_comp.c b/v1/wd_comp.c index 9e7ec5a..f898c1d 100644 --- a/v1/wd_comp.c +++ b/v1/wd_comp.c @@ -122,6 +122,7 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q, { struct wcrypto_comp_ctx *ctx; struct q_info *qinfo; + __u32 cookies_num; __u32 ctx_id = 0; int ret;
@@ -169,8 +170,9 @@ void *wcrypto_create_comp_ctx(struct wd_queue *q, goto free_ctx_id; }
+ cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_CTX_COOKIES_NUM); ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_comp_cookie), WD_CTX_MSG_NUM); + sizeof(struct wcrypto_comp_cookie), cookies_num); if (ret) { WD_ERR("fail to init cookie pool!\n"); goto free_ctx_buf; diff --git a/v1/wd_dh.c b/v1/wd_dh.c index 714ae71..9ed0e0d 100644 --- a/v1/wd_dh.c +++ b/v1/wd_dh.c @@ -90,17 +90,19 @@ static int wcrypto_init_dh_cookie(struct wcrypto_dh_ctx *ctx) { struct wcrypto_dh_ctx_setup *setup = &ctx->setup; struct wcrypto_dh_cookie *cookie; + __u32 flags = ctx->q->capa.flags; + __u32 cookies_num, i; int ret; - __u32 i;
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_dh_cookie), WD_HPRE_CTX_MSG_NUM); + sizeof(struct wcrypto_dh_cookie), cookies_num); if (ret) { WD_ERR("fail to init cookie pool!\n"); return ret; }
- for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.is_g2 = (__u8)setup->is_g2; diff --git a/v1/wd_digest.c b/v1/wd_digest.c index 86a7751..546b07e 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -98,13 +98,23 @@ static int create_ctx_para_check(struct wd_queue *q, return WD_SUCCESS; }
-static void init_digest_cookie(struct wcrypto_digest_ctx *ctx, - struct wcrypto_digest_ctx_setup *setup) +static int init_digest_cookie(struct wcrypto_digest_ctx *ctx, + struct wcrypto_digest_ctx_setup *setup) { struct wcrypto_digest_cookie *cookie; - __u32 i; + __u32 flags = ctx->q->capa.flags; + __u32 cookies_num, i; + int ret; + + cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); + ret = wd_init_cookie_pool(&ctx->pool, + sizeof(struct wcrypto_digest_cookie), cookies_num); + if (ret) { + WD_ERR("failed to init cookie pool!\n"); + return ret; + }
- for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.alg_type = WCRYPTO_DIGEST; @@ -117,6 +127,8 @@ static void init_digest_cookie(struct wcrypto_digest_ctx *ctx, cookie->tag.wcrypto_tag.ctx_id = ctx->ctx_id; cookie->msg.usr_data = (uintptr_t)&cookie->tag; } + + return 0; }
static int setup_qinfo(struct wcrypto_digest_ctx_setup *setup, @@ -192,13 +204,9 @@ void *wcrypto_create_digest_ctx(struct wd_queue *q, else ctx->align_sz = SEC_SHA1_ALIGN_SZ;
- ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_digest_cookie), WD_CTX_MSG_NUM); - if (ret) { - WD_ERR("fail to init cookie pool!\n"); + ret = init_digest_cookie(ctx, setup); + if (ret) goto free_ctx_key; - } - init_digest_cookie(ctx, setup);
return ctx;
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c index 93b4e1b..c4fab63 100644 --- a/v1/wd_ecc.c +++ b/v1/wd_ecc.c @@ -1062,15 +1062,25 @@ static void del_ctx_key(struct wd_mm_br *br, } }
-static void init_ctx_cookies(struct wcrypto_ecc_ctx *ctx, - struct wcrypto_ecc_ctx_setup *setup) +static int init_ctx_cookies(struct wcrypto_ecc_ctx *ctx, + struct wcrypto_ecc_ctx_setup *setup) { __u32 hsz = get_hw_keysize(ctx->key_size); struct q_info *qinfo = ctx->q->qinfo; struct wcrypto_ecc_cookie *cookie; - __u32 i; + __u32 flags = ctx->q->capa.flags; + __u32 cookies_num, i; + int ret; + + cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); + ret = wd_init_cookie_pool(&ctx->pool, + sizeof(struct wcrypto_ecc_cookie), cookies_num); + if (ret) { + WD_ERR("fail to init cookie pool!\n"); + return ret; + }
- for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.curve_id = setup->cv.cfg.id; @@ -1082,6 +1092,8 @@ static void init_ctx_cookies(struct wcrypto_ecc_ctx *ctx, cookie->tag.ctx_id = ctx->ctx_id; cookie->msg.usr_data = (uintptr_t)&cookie->tag; } + + return 0; }
static int setup_qinfo(struct wcrypto_ecc_ctx_setup *setup, @@ -1147,13 +1159,10 @@ void *wcrypto_create_ecc_ctx(struct wd_queue *q, ctx->key_size = BITS_TO_BYTES(setup->key_bits); ctx->q = q; ctx->ctx_id = cid + 1; - ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_ecc_cookie), WD_HPRE_CTX_MSG_NUM); - if (ret) { - WD_ERR("fail to init cookie pool!\n"); + + ret = init_ctx_cookies(ctx, setup); + if (ret) goto free_ctx; - } - init_ctx_cookies(ctx, setup);
ret = create_ctx_key(setup, ctx); if (unlikely(ret)) { diff --git a/v1/wd_rng.c b/v1/wd_rng.c index a783f99..cc8a594 100644 --- a/v1/wd_rng.c +++ b/v1/wd_rng.c @@ -26,9 +26,9 @@ #include "wd_util.h" #include "wd_rng.h"
-#define MAX_NUM 10 -#define RNG_RESEND_CNT 8 -#define RNG_RECV_CNT 8 +#define RNG_RESEND_CNT 8 +#define RNG_RECV_CNT 8 +#define WD_RNG_CTX_COOKIE_NUM 256
struct wcrypto_rng_cookie { struct wcrypto_cb_tag tag; @@ -84,7 +84,8 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q, struct wcrypto_rng_cookie *cookie; struct wcrypto_rng_ctx *ctx; struct q_info *qinfo; - __u32 i, ctx_id = 0; + __u32 cookies_num, i; + __u32 ctx_id = 0; int ret;
if (wcrypto_setup_qinfo(setup, q, &ctx_id)) @@ -99,14 +100,15 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q, ctx->q = q; ctx->ctx_id = ctx_id + 1;
+ cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM); ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_rng_cookie), WD_RNG_CTX_MSG_NUM); + sizeof(struct wcrypto_rng_cookie), cookies_num); if (ret) { WD_ERR("fail to init cookie pool!\n"); free(ctx); goto free_ctx_id; } - for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); cookie->msg.alg_type = WCRYPTO_RNG; diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c index 61de3cc..4a2a5b5 100644 --- a/v1/wd_rsa.c +++ b/v1/wd_rsa.c @@ -496,19 +496,21 @@ static void del_ctx_key(struct wcrypto_rsa_ctx_setup *setup, } }
-struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, int ctx_id) +static struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, + int ctx_id, __u32 flags) { struct wcrypto_rsa_cookie *cookie; struct wcrypto_rsa_ctx *ctx; - __u32 i; + __u32 cookies_num, i; int ret;
ctx = calloc(1, sizeof(struct wcrypto_rsa_ctx)); if (!ctx) return ctx;
+ cookies_num = wd_get_ctx_cookies_num(flags, WD_CTX_COOKIES_NUM); ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_rsa_cookie), WD_HPRE_CTX_MSG_NUM); + sizeof(struct wcrypto_rsa_cookie), cookies_num); if (ret) { WD_ERR("fail to init cookie pool!\n"); free(ctx); @@ -518,7 +520,7 @@ struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, int ctx_ memcpy(&ctx->setup, setup, sizeof(*setup)); ctx->ctx_id = ctx_id; ctx->key_size = setup->key_bits >> BYTE_BITS_SHIFT; - for (i = 0; i < ctx->pool.cookies_num; i++) { + for (i = 0; i < cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + i * ctx->pool.cookies_size); if (setup->is_crt) @@ -611,7 +613,7 @@ void *wcrypto_create_rsa_ctx(struct wd_queue *q, struct wcrypto_rsa_ctx_setup *s qinfo->ctx_num++; wd_unspinlock(&qinfo->qlock);
- ctx = create_ctx(setup, cid + 1); + ctx = create_ctx(setup, cid + 1, q->capa.flags); if (!ctx) { WD_ERR("create rsa ctx fail!\n"); goto free_ctx_id; diff --git a/v1/wd_util.c b/v1/wd_util.c index 26f46d4..6b8f944 100644 --- a/v1/wd_util.c +++ b/v1/wd_util.c @@ -157,6 +157,22 @@ put_cookies: return -WD_EBUSY; }
+__u32 wd_get_ctx_cookies_num(__u32 usr_cookies_num, __u32 def_num) +{ + __u32 usr_num = usr_cookies_num & WD_CTX_COOKIES_NUM_MASK; + + if (!usr_num) + return def_num; + + if (usr_num > WD_MAX_CTX_COOKIES_NUM) { + WD_ERR("user msg num %u is invalid, use default value: %u!\n", + usr_num, def_num); + return def_num; + } + + return usr_num; +} + int wd_burst_send(struct wd_queue *q, void **req, __u32 num) { return drv_send(q, req, num); diff --git a/v1/wd_util.h b/v1/wd_util.h index fc4586c..308c53f 100644 --- a/v1/wd_util.h +++ b/v1/wd_util.h @@ -36,11 +36,11 @@ #include "v1/wd_ecc.h" #include "v1/wd_adapter.h"
-#define WD_CTX_MSG_NUM 64 -#define WD_HPRE_CTX_MSG_NUM 64 -#define WD_RNG_CTX_MSG_NUM 256 -#define WD_MAX_CTX_NUM 256 -#define BYTE_BITS 8 +#define WD_CTX_COOKIES_NUM 64 +#define WD_MAX_CTX_COOKIES_NUM 1024 +#define WD_CTX_COOKIES_NUM_MASK 0xffff +#define WD_MAX_CTX_NUM 256 +#define BYTE_BITS 8 #define BYTE_BITS_SHIFT 3 #define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1) #define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1) @@ -380,6 +380,7 @@ int wd_alloc_id(__u8 *buf, __u32 size, __u32 *id, __u32 last_id, __u32 id_max); void wd_free_id(__u8 *buf, __u32 size, __u32 id, __u32 id_max); int wd_get_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num); void wd_put_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num); +__u32 wd_get_ctx_cookies_num(__u32 usr_cookies_num, __u32 def_num); const char *wd_get_drv(struct wd_queue *q); int wd_burst_send(struct wd_queue *q, void **req, __u32 num); int wd_burst_recv(struct wd_queue *q, void **resp, __u32 num);
Initialize cparams to zero.
Signed-off-by: Weili Qian qianweili@huawei.com --- uadk_tool/test/test_sec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c index 657d123..9594e61 100644 --- a/uadk_tool/test/test_sec.c +++ b/uadk_tool/test/test_sec.c @@ -1469,8 +1469,8 @@ out:
static int digest_init2(int type, int mode) { + struct wd_ctx_params cparams = {0}; struct wd_ctx_nums *ctx_set_num; - struct wd_ctx_params cparams; int ret;
if (g_testalg >= MAX_ALGO_PER_TYPE) @@ -2721,8 +2721,8 @@ out:
static int aead_init2(int type, int mode) { + struct wd_ctx_params cparams = {0}; struct wd_ctx_nums *ctx_set_num; - struct wd_ctx_params cparams; int ret;
if (g_testalg >= MAX_ALGO_PER_TYPE)