276 lines
8.0 KiB
Diff
276 lines
8.0 KiB
Diff
From 12deb741e44def7839ae99caac8858be52a9ec74 Mon Sep 17 00:00:00 2001
|
|
From: Hao Fang <fanghao11@huawei.com>
|
|
Date: Sat, 25 Nov 2023 16:13:29 +0800
|
|
Subject: [PATCH 78/82] uadk_engine: async: fix add async send timeout
|
|
|
|
The system does not keep busy in normal, only add
|
|
a timeout mechanism to exit the while loop.
|
|
|
|
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
|
---
|
|
src/uadk.h | 1 +
|
|
src/uadk_aead.c | 39 ++++++++++++++++++++++++++-------------
|
|
src/uadk_cipher.c | 13 ++++++++++---
|
|
src/uadk_dh.c | 13 +++++++++----
|
|
src/uadk_digest.c | 14 ++++++++++----
|
|
src/uadk_pkey.c | 13 +++++++++----
|
|
src/uadk_rsa.c | 12 +++++++++---
|
|
7 files changed, 74 insertions(+), 31 deletions(-)
|
|
|
|
diff --git a/src/uadk.h b/src/uadk.h
|
|
index c5ebf32..1945ba2 100644
|
|
--- a/src/uadk.h
|
|
+++ b/src/uadk.h
|
|
@@ -21,6 +21,7 @@
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
#define ENV_STRING_LEN 256
|
|
+#define ENGINE_SEND_MAX_CNT 90000000
|
|
#define ENGINE_RECV_MAX_CNT 60000000
|
|
#define UADK_UNINIT 0
|
|
#define UADK_INIT_SUCCESS 1
|
|
diff --git a/src/uadk_aead.c b/src/uadk_aead.c
|
|
index c2646f1..40a35e3 100644
|
|
--- a/src/uadk_aead.c
|
|
+++ b/src/uadk_aead.c
|
|
@@ -27,7 +27,7 @@
|
|
#include "uadk_async.h"
|
|
#include "uadk_utils.h"
|
|
|
|
-#define RET_FAIL -1
|
|
+#define RET_FAIL (-1)
|
|
#define STATE_FAIL 0xFFFF
|
|
#define CTX_SYNC_ENC 0
|
|
#define CTX_SYNC_DEC 1
|
|
@@ -521,17 +521,9 @@ static void *uadk_e_aead_cb(struct wd_aead_req *req, void *data)
|
|
return NULL;
|
|
}
|
|
|
|
-static int do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
|
|
- unsigned char *out, const unsigned char *in, size_t inlen)
|
|
+static void do_aead_async_prepare(struct aead_priv_ctx *priv, unsigned char *out,
|
|
+ const unsigned char *in, size_t inlen)
|
|
{
|
|
- struct uadk_e_cb_info *cb_param;
|
|
- int ret;
|
|
-
|
|
- if (unlikely(priv->req.assoc_bytes + inlen > AEAD_BLOCK_SIZE)) {
|
|
- fprintf(stderr, "aead input data length is too long!\n");
|
|
- return 0;
|
|
- }
|
|
-
|
|
priv->req.in_bytes = inlen;
|
|
/* AAD data is input or output together with plaintext or ciphertext. */
|
|
if (priv->req.assoc_bytes) {
|
|
@@ -542,6 +534,21 @@ static int do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
|
|
priv->req.src = (unsigned char *)in;
|
|
priv->req.dst = out;
|
|
}
|
|
+}
|
|
+
|
|
+static int do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
|
|
+ unsigned char *out, const unsigned char *in, size_t inlen)
|
|
+{
|
|
+ struct uadk_e_cb_info *cb_param;
|
|
+ int cnt = 0;
|
|
+ int ret;
|
|
+
|
|
+ if (unlikely(priv->req.assoc_bytes + inlen > AEAD_BLOCK_SIZE)) {
|
|
+ fprintf(stderr, "aead input data length is too long!\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ do_aead_async_prepare(priv, out, in, inlen);
|
|
|
|
cb_param = malloc(sizeof(struct uadk_e_cb_info));
|
|
if (unlikely(!cb_param)) {
|
|
@@ -562,8 +569,14 @@ static int do_aead_async(struct aead_priv_ctx *priv, struct async_op *op,
|
|
|
|
do {
|
|
ret = wd_do_aead_async(priv->sess, &priv->req);
|
|
- if (unlikely(ret < 0 && ret != -EBUSY)) {
|
|
- fprintf(stderr, "do aead async operation failed.\n");
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret != -EBUSY))
|
|
+ fprintf(stderr, "do aead async operation failed.\n");
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do aead async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op->idx, 0);
|
|
ret = 0;
|
|
goto free_cb_param;
|
|
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c
|
|
index 472c47c..007eca3 100644
|
|
--- a/src/uadk_cipher.c
|
|
+++ b/src/uadk_cipher.c
|
|
@@ -652,7 +652,7 @@ static int do_cipher_sync(struct cipher_priv_ctx *priv)
|
|
static int do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *op)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
- int idx, ret;
|
|
+ int idx, ret, cnt;
|
|
|
|
if (unlikely(priv->switch_flag == UADK_DO_SOFT)) {
|
|
fprintf(stderr, "switch to soft cipher.\n");
|
|
@@ -668,11 +668,18 @@ static int do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *op)
|
|
if (!ret)
|
|
return 0;
|
|
|
|
+ cnt = 0;
|
|
op->idx = idx;
|
|
do {
|
|
ret = wd_do_cipher_async(priv->sess, &priv->req);
|
|
- if (ret < 0 && ret != -EBUSY) {
|
|
- fprintf(stderr, "do sec cipher failed, switch to soft cipher.\n");
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret != -EBUSY))
|
|
+ fprintf(stderr, "do cipher async operation failed.\n");
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do cipher async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op->idx, 0);
|
|
return 0;
|
|
}
|
|
diff --git a/src/uadk_dh.c b/src/uadk_dh.c
|
|
index 62c75fe..328bb80 100644
|
|
--- a/src/uadk_dh.c
|
|
+++ b/src/uadk_dh.c
|
|
@@ -716,7 +716,7 @@ static int dh_do_crypto(struct uadk_dh_sess *dh_sess)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
struct async_op op;
|
|
- int idx, ret;
|
|
+ int idx, ret, cnt;
|
|
|
|
ret = async_setup_async_event_notification(&op);
|
|
if (!ret) {
|
|
@@ -742,12 +742,17 @@ static int dh_do_crypto(struct uadk_dh_sess *dh_sess)
|
|
goto err;
|
|
|
|
op.idx = idx;
|
|
-
|
|
+ cnt = 0;
|
|
do {
|
|
ret = wd_do_dh_async(dh_sess->sess, &dh_sess->req);
|
|
- if (ret < 0 && ret != -EBUSY) {
|
|
- if (ret == -WD_HW_EACCESS)
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret == -WD_HW_EACCESS))
|
|
uadk_e_dh_set_status();
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do dh async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op.idx, 0);
|
|
goto err;
|
|
}
|
|
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
|
|
index 06851f1..cbcae1f 100644
|
|
--- a/src/uadk_digest.c
|
|
+++ b/src/uadk_digest.c
|
|
@@ -750,7 +750,7 @@ static int do_digest_sync(struct digest_priv_ctx *priv)
|
|
static int do_digest_async(struct digest_priv_ctx *priv, struct async_op *op)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
- int idx, ret;
|
|
+ int idx, ret, cnt;
|
|
|
|
if (unlikely(priv->switch_flag == UADK_DO_SOFT)) {
|
|
fprintf(stderr, "async cipher init failed.\n");
|
|
@@ -767,11 +767,17 @@ static int do_digest_async(struct digest_priv_ctx *priv, struct async_op *op)
|
|
return 0;
|
|
|
|
op->idx = idx;
|
|
-
|
|
+ cnt = 0;
|
|
do {
|
|
ret = wd_do_digest_async(priv->sess, &priv->req);
|
|
- if (ret < 0 && ret != -EBUSY) {
|
|
- fprintf(stderr, "do sec digest async failed.\n");
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret != -EBUSY))
|
|
+ fprintf(stderr, "do digest async operation failed.\n");
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do digest async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op->idx, 0);
|
|
return 0;
|
|
}
|
|
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
|
|
index a950f6d..986851f 100644
|
|
--- a/src/uadk_pkey.c
|
|
+++ b/src/uadk_pkey.c
|
|
@@ -302,7 +302,7 @@ int uadk_ecc_crypto(handle_t sess, struct wd_ecc_req *req, void *usr)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
struct async_op op;
|
|
- int idx, ret;
|
|
+ int idx, ret, cnt;
|
|
|
|
ret = async_setup_async_event_notification(&op);
|
|
if (!ret) {
|
|
@@ -321,12 +321,17 @@ int uadk_ecc_crypto(handle_t sess, struct wd_ecc_req *req, void *usr)
|
|
goto err;
|
|
|
|
op.idx = idx;
|
|
-
|
|
+ cnt = 0;
|
|
do {
|
|
ret = wd_do_ecc_async(sess, req);
|
|
- if (ret < 0 && ret != -EBUSY) {
|
|
- if (ret == -WD_HW_EACCESS)
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret == -WD_HW_EACCESS))
|
|
uadk_e_ecc_set_status();
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do ecc async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op.idx, 0);
|
|
goto err;
|
|
}
|
|
diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c
|
|
index c9e2b34..24dd7b9 100644
|
|
--- a/src/uadk_rsa.c
|
|
+++ b/src/uadk_rsa.c
|
|
@@ -1099,7 +1099,7 @@ static int rsa_do_crypto(struct uadk_rsa_sess *rsa_sess)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
struct async_op op;
|
|
- int idx, ret;
|
|
+ int idx, ret, cnt;
|
|
|
|
ret = async_setup_async_event_notification(&op);
|
|
if (!ret) {
|
|
@@ -1128,11 +1128,17 @@ static int rsa_do_crypto(struct uadk_rsa_sess *rsa_sess)
|
|
goto err;
|
|
|
|
op.idx = idx;
|
|
+ cnt = 0;
|
|
do {
|
|
ret = wd_do_rsa_async(rsa_sess->sess, &(rsa_sess->req));
|
|
- if (ret < 0 && ret != -EBUSY) {
|
|
- if (ret == -WD_HW_EACCESS)
|
|
+ if (unlikely(ret < 0)) {
|
|
+ if (unlikely(ret == -WD_HW_EACCESS))
|
|
uadk_e_rsa_set_status();
|
|
+ else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
|
|
+ fprintf(stderr, "do rsa async operation timeout.\n");
|
|
+ else
|
|
+ continue;
|
|
+
|
|
async_free_poll_task(op.idx, 0);
|
|
goto err;
|
|
}
|
|
--
|
|
2.25.1
|
|
|