When executing an asynchronous task, the scheduler may incorrectly specify a synchronous queue. This will cause an error in the queue configuration parameters and result in a segment error. In wd_get_msg_from_pool(), msg_num == 0 indicates that the asynchronous task scheduler is executed but the synchronous queue is specified.Therefore, when msg_num == 0 is detected in this function, the program needs to return an exception immediately to avoid errors.
Signed-off-by: Qi Tao taoqi10@huawei.com --- wd_aead.c | 2 +- wd_agg.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 2 +- wd_dh.c | 6 ++++-- wd_digest.c | 4 ++-- wd_ecc.c | 6 ++++-- wd_rsa.c | 6 ++++-- wd_util.c | 4 ++++ 9 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c index 65949f7a..608f0e6d 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -805,7 +805,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) idx, (void **)&msg); if (unlikely(msg_id < 0)) { WD_ERR("failed to get msg from pool!\n"); - return -WD_EBUSY; + return msg_id; }
fill_request_msg(msg, req, sess); diff --git a/wd_agg.c b/wd_agg.c index e493bb81..b536efe5 100644 --- a/wd_agg.c +++ b/wd_agg.c @@ -1192,8 +1192,8 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo ctx = config->ctxs + idx; msg_id = wd_get_msg_from_pool(&wd_agg_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("busy, failed to get agg msg from pool!\n"); - return -WD_EBUSY; + WD_ERR("failed to get agg msg from pool!\n"); + return msg_id; }
if (is_input) diff --git a/wd_cipher.c b/wd_cipher.c index 646aa891..f6b035a5 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -741,8 +741,8 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) msg_id = wd_get_msg_from_pool(&wd_cipher_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("busy, failed to get msg from pool!\n"); - return -WD_EBUSY; + WD_ERR("failed to get msg from pool!\n"); + return msg_id; }
fill_request_msg(msg, req, sess); diff --git a/wd_comp.c b/wd_comp.c index 34ddbcf2..0fa5f926 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -860,7 +860,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); if (unlikely(tag < 0)) { WD_ERR("failed to get msg from pool!\n"); - return -WD_EBUSY; + return tag; } fill_comp_msg(sess, msg, req); msg->tag = tag; diff --git a/wd_dh.c b/wd_dh.c index cdcba149..043c3be9 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -422,8 +422,10 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_dh_setting.pool, idx, (void **)&msg); - if (mid < 0) - return -WD_EBUSY; + if (unlikely(mid < 0)) { + WD_ERR("failed to get msg from pool!\n"); + return mid; + }
ret = fill_dh_msg(msg, req, (struct wd_dh_sess *)sess); if (ret) diff --git a/wd_digest.c b/wd_digest.c index 943fd8ce..58f621af 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -706,8 +706,8 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) msg_id = wd_get_msg_from_pool(&wd_digest_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("busy, failed to get msg from pool!\n"); - return -WD_EBUSY; + WD_ERR("failed to get msg from pool!\n"); + return msg_id; }
fill_request_msg(msg, req, dsess); diff --git a/wd_ecc.c b/wd_ecc.c index 7c0c77ac..b1712c50 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2268,8 +2268,10 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_ecc_setting.pool, idx, (void **)&msg); - if (mid < 0) - return -WD_EBUSY; + if (unlikely(mid < 0)) { + WD_ERR("failed to get msg from pool!\n"); + return mid; + }
ret = fill_ecc_msg(msg, req, (struct wd_ecc_sess *)sess); if (ret) diff --git a/wd_rsa.c b/wd_rsa.c index b858491f..366e7660 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -483,8 +483,10 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_rsa_setting.pool, idx, (void **)&msg); - if (mid < 0) - return -WD_EBUSY; + if (unlikely(mid < 0)) { + WD_ERR("failed to get msg from pool!\n"); + return mid; + }
ret = fill_rsa_msg(msg, req, (struct wd_rsa_sess *)sess); if (ret) diff --git a/wd_util.c b/wd_util.c index 8adfd4c3..d58e8b85 100644 --- a/wd_util.c +++ b/wd_util.c @@ -442,6 +442,10 @@ int wd_get_msg_from_pool(struct wd_async_msg_pool *pool, __u32 cnt = 0; __u32 idx = p->tail;
+ /* Scheduler set a sync ctx */ + if (!msg_num) + return -WD_EINVAL; + while (__atomic_test_and_set(&p->used[idx], __ATOMIC_ACQUIRE)) { idx = (idx + 1) % msg_num; cnt++;