diff --git a/0004-uadk_engine-cleanup-code-style-of-async-functions.patch b/0004-uadk_engine-cleanup-code-style-of-async-functions.patch new file mode 100644 index 0000000000000000000000000000000000000000..68be9126fa53c276df6c5129676af94d548c254b --- /dev/null +++ b/0004-uadk_engine-cleanup-code-style-of-async-functions.patch @@ -0,0 +1,343 @@ +From 54e2cf93c7a362031e7dacf550afe286b5a4656a Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +Date: Fri, 29 Mar 2024 10:13:22 +0800 +Subject: [PATCH 4/7] uadk_engine: cleanup code style of async functions + +Cleanup the return value and judgment code style +of async mode functions. + +Signed-off-by: Zhiqi Song +Signed-off-by: JiangShui Yang +--- + src/uadk_async.c | 126 +++++++++++++++++++++++------------------------ + src/uadk_async.h | 3 ++ + 2 files changed, 64 insertions(+), 65 deletions(-) + +diff --git a/src/uadk_async.c b/src/uadk_async.c +index 726ee09..1558996 100644 +--- a/src/uadk_async.c ++++ b/src/uadk_async.c +@@ -50,83 +50,79 @@ static void async_fd_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, + int async_setup_async_event_notification(struct async_op *op) + { + ASYNC_WAIT_CTX *waitctx; ++ void *custom = NULL; + OSSL_ASYNC_FD efd; +- void *custom; + + memset(op, 0, sizeof(struct async_op)); + op->job = ASYNC_get_current_job(); +- if (op->job == NULL) +- return 1; ++ if (!op->job) ++ return DO_SYNC; + + waitctx = ASYNC_get_wait_ctx(op->job); +- if (waitctx == NULL) +- return 0; ++ if (!waitctx) ++ return UADK_E_FAIL; + +- if (ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, +- &efd, &custom) == 0) { ++ if (!ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, &efd, &custom)) { + efd = eventfd(0, EFD_NONBLOCK); + if (efd == -1) +- return 0; ++ return UADK_E_FAIL; + +- if (ASYNC_WAIT_CTX_set_wait_fd(waitctx, uadk_async_key, efd, +- custom, async_fd_cleanup) == 0) { ++ if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, uadk_async_key, efd, ++ custom, async_fd_cleanup)) { + async_fd_cleanup(waitctx, uadk_async_key, efd, NULL); +- return 0; ++ return UADK_E_FAIL; + } + } + +- return 1; ++ return UADK_E_SUCCESS; + } + + int async_clear_async_event_notification(void) + { +- ASYNC_JOB *job; ++ size_t num_add_fds, num_del_fds; + ASYNC_WAIT_CTX *waitctx; +- OSSL_ASYNC_FD efd; +- size_t num_add_fds; +- size_t num_del_fds; + void *custom = NULL; ++ OSSL_ASYNC_FD efd; ++ ASYNC_JOB *job; + + job = ASYNC_get_current_job(); +- if (job == NULL) +- return 0; ++ if (!job) ++ return UADK_E_FAIL; + + waitctx = ASYNC_get_wait_ctx(job); +- if (waitctx == NULL) +- return 0; ++ if (!waitctx) ++ return UADK_E_FAIL; + +- if (ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &num_add_fds, +- NULL, &num_del_fds) == 0) +- return 0; ++ if (!ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &num_add_fds, NULL, &num_del_fds)) ++ return UADK_E_FAIL; + + if (num_add_fds > 0) { +- if (ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, +- &efd, &custom) == 0) +- return 0; ++ if (!ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, &efd, &custom)) ++ return UADK_E_FAIL; + + async_fd_cleanup(waitctx, uadk_async_key, efd, NULL); + +- if (ASYNC_WAIT_CTX_clear_fd(waitctx, uadk_async_key) == 0) +- return 0; ++ if (!ASYNC_WAIT_CTX_clear_fd(waitctx, uadk_async_key)) ++ return UADK_E_FAIL; + } + +- return 1; ++ return UADK_E_SUCCESS; + } + + void async_poll_task_free(void) + { +- int error; + struct async_poll_task *task; ++ int error; + + /* Disable async poll state first */ + uadk_e_set_async_poll_state(DISABLE_ASYNC_POLLING); + + error = pthread_mutex_lock(&poll_queue.async_task_mutex); +- if (error != 0) ++ if (error) + return; + + task = poll_queue.head; +- if (task != NULL) ++ if (task) + OPENSSL_free(task); + + poll_queue.head = NULL; +@@ -146,13 +142,13 @@ static int async_get_poll_task(int *id) + while (!poll_queue.status[idx]) { + idx = (idx + 1) % ASYNC_QUEUE_TASK_NUM; + if (cnt++ == ASYNC_QUEUE_TASK_NUM) +- return 0; ++ return UADK_E_FAIL; + } + + *id = idx; + poll_queue.rid = (idx + 1) % ASYNC_QUEUE_TASK_NUM; + +- return 1; ++ return UADK_E_SUCCESS; + } + + static struct async_poll_task *async_get_queue_task(void) +@@ -161,11 +157,11 @@ static struct async_poll_task *async_get_queue_task(void) + struct async_poll_task *task_queue; + int idx, ret; + +- if (pthread_mutex_lock(&poll_queue.async_task_mutex) != 0) ++ if (pthread_mutex_lock(&poll_queue.async_task_mutex)) + return NULL; + + ret = async_get_poll_task(&idx); +- if (!ret) ++ if (ret == UADK_E_FAIL) + goto err; + + task_queue = poll_queue.head; +@@ -173,10 +169,10 @@ static struct async_poll_task *async_get_queue_task(void) + poll_queue.is_recv = 0; + + err: +- if (pthread_mutex_unlock(&poll_queue.async_task_mutex) != 0) ++ if (pthread_mutex_unlock(&poll_queue.async_task_mutex)) + return NULL; + +- if (cur_task && cur_task->op == NULL) ++ if (cur_task && !cur_task->op) + return NULL; + + return cur_task; +@@ -184,7 +180,7 @@ err: + + void async_free_poll_task(int id, bool is_cb) + { +- if (pthread_mutex_lock(&poll_queue.async_task_mutex) != 0) ++ if (pthread_mutex_lock(&poll_queue.async_task_mutex)) + return; + + poll_queue.status[id] = 0; +@@ -192,7 +188,7 @@ void async_free_poll_task(int id, bool is_cb) + if (is_cb) + poll_queue.is_recv = 1; + +- if (pthread_mutex_unlock(&poll_queue.async_task_mutex) != 0) ++ if (pthread_mutex_unlock(&poll_queue.async_task_mutex)) + return; + + (void)sem_post(&poll_queue.empty_sem); +@@ -205,17 +201,17 @@ int async_get_free_task(int *id) + int idx, ret; + int cnt = 0; + +- if (sem_wait(&poll_queue.empty_sem) != 0) +- return 0; ++ if (sem_wait(&poll_queue.empty_sem)) ++ return UADK_E_FAIL; + +- if (pthread_mutex_lock(&poll_queue.async_task_mutex) != 0) +- return 0; ++ if (pthread_mutex_lock(&poll_queue.async_task_mutex)) ++ return UADK_E_FAIL; + + idx = poll_queue.sid; + while (poll_queue.status[idx]) { + idx = (idx + 1) % ASYNC_QUEUE_TASK_NUM; + if (cnt++ == ASYNC_QUEUE_TASK_NUM) { +- ret = 0; ++ ret = UADK_E_FAIL; + goto out; + } + } +@@ -226,11 +222,11 @@ int async_get_free_task(int *id) + task_queue = poll_queue.head; + task = &task_queue[idx]; + task->op = NULL; +- ret = 1; ++ ret = UADK_E_SUCCESS; + + out: +- if (pthread_mutex_unlock(&poll_queue.async_task_mutex) != 0) +- return 0; ++ if (pthread_mutex_unlock(&poll_queue.async_task_mutex)) ++ return UADK_E_FAIL; + + return ret; + } +@@ -249,9 +245,9 @@ static int async_add_poll_task(void *ctx, struct async_op *op, enum task_type ty + + ret = sem_post(&poll_queue.full_sem); + if (ret) +- return 0; ++ return UADK_E_FAIL; + +- return 1; ++ return UADK_E_SUCCESS; + } + + int async_pause_job(void *ctx, struct async_op *op, enum task_type type) +@@ -263,16 +259,16 @@ int async_pause_job(void *ctx, struct async_op *op, enum task_type type) + int ret; + + ret = async_add_poll_task(ctx, op, type); +- if (ret == 0) ++ if (!ret) + return ret; + + waitctx = ASYNC_get_wait_ctx((ASYNC_JOB *)op->job); +- if (waitctx == NULL) +- return 0; ++ if (!waitctx) ++ return UADK_E_FAIL; + + do { +- if (ASYNC_pause_job() == 0) +- return 0; ++ if (!ASYNC_pause_job()) ++ return UADK_E_FAIL; + + ret = ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, &efd, &custom); + if (ret <= 0) +@@ -293,13 +289,13 @@ int async_wake_job(ASYNC_JOB *job) + { + ASYNC_WAIT_CTX *waitctx; + OSSL_ASYNC_FD efd; +- void *custom; + uint64_t buf = 1; ++ void *custom; + int ret; + + waitctx = ASYNC_get_wait_ctx(job); +- if (waitctx == NULL) +- return 0; ++ if (!waitctx) ++ return UADK_E_FAIL; + + ret = ASYNC_WAIT_CTX_get_fd(waitctx, uadk_async_key, &efd, &custom); + if (ret > 0) { +@@ -329,7 +325,7 @@ static void *async_poll_process_func(void *args) + int ret, idx; + + while (uadk_e_get_async_poll_state()) { +- if (sem_wait(&poll_queue.full_sem) != 0) { ++ if (sem_wait(&poll_queue.full_sem)) { + if (errno == EINTR) { + /* sem_wait is interrupted by interrupt, continue */ + continue; +@@ -337,7 +333,7 @@ static void *async_poll_process_func(void *args) + } + + task = async_get_queue_task(); +- if (task == NULL) { ++ if (!task) { + (void)sem_post(&poll_queue.full_sem); + usleep(1); + continue; +@@ -364,11 +360,11 @@ int async_module_init(void) + memset(&poll_queue, 0, sizeof(struct async_poll_queue)); + + if (pthread_mutex_init(&(poll_queue.async_task_mutex), NULL) < 0) +- return 0; ++ return UADK_E_FAIL; + + poll_queue.head = OPENSSL_malloc(ASYNC_QUEUE_TASK_NUM * sizeof(struct async_poll_task)); +- if (poll_queue.head == NULL) +- return 0; ++ if (!poll_queue.head) ++ return UADK_E_FAIL; + + if (sem_init(&poll_queue.empty_sem, 0, ASYNC_QUEUE_TASK_NUM) != 0) + goto err; +@@ -384,9 +380,9 @@ int async_module_init(void) + goto err; + + poll_queue.thread_id = thread_id; +- return 1; ++ return UADK_E_SUCCESS; + + err: + async_poll_task_free(); +- return 0; ++ return UADK_E_FAIL; + } +diff --git a/src/uadk_async.h b/src/uadk_async.h +index 6857927..5d73b60 100644 +--- a/src/uadk_async.h ++++ b/src/uadk_async.h +@@ -23,6 +23,9 @@ + #include + + #define ASYNC_QUEUE_TASK_NUM 1024 ++#define UADK_E_SUCCESS 1 ++#define UADK_E_FAIL 0 ++#define DO_SYNC 1 + + struct async_op { + ASYNC_JOB *job; +-- +2.25.1 + diff --git a/0005-cipher-cleanup-repeated-function-invoking.patch b/0005-cipher-cleanup-repeated-function-invoking.patch new file mode 100644 index 0000000000000000000000000000000000000000..edf968d05f2b9ab3cf93ecfb14a2031b357eb676 --- /dev/null +++ b/0005-cipher-cleanup-repeated-function-invoking.patch @@ -0,0 +1,49 @@ +From 1cfb48c6d086fc82ea6b72bd9b8cb3c5cacac2b8 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +Date: Fri, 29 Mar 2024 10:13:23 +0800 +Subject: [PATCH 5/7] cipher: cleanup repeated function invoking + +Cleanup repeated function invoking of EVP_CIPHER_CTX_nid(). + +Signed-off-by: Zhiqi Song +Signed-off-by: JiangShui Yang +--- + src/uadk_cipher.c | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c +index 7b4ebd8..b506c22 100644 +--- a/src/uadk_cipher.c ++++ b/src/uadk_cipher.c +@@ -39,6 +39,7 @@ + #define IV_LEN 16 + #define ENV_ENABLED 1 + #define MAX_KEY_LEN 64 ++#define SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT 192 + + struct cipher_engine { + struct wd_ctx_config ctx_cfg; +@@ -75,8 +76,6 @@ struct cipher_info { + __u32 out_bytes; + }; + +-#define SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT 192 +- + static EVP_CIPHER *uadk_aes_128_cbc; + static EVP_CIPHER *uadk_aes_192_cbc; + static EVP_CIPHER *uadk_aes_256_cbc; +@@ -189,9 +188,9 @@ static int uadk_e_cipher_sw_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, + return 0; + } + +- sw_cipher = sec_ciphers_get_cipher_sw_impl(EVP_CIPHER_CTX_nid(ctx)); ++ nid = EVP_CIPHER_CTX_nid(ctx); ++ sw_cipher = sec_ciphers_get_cipher_sw_impl(nid); + if (unlikely(sw_cipher == NULL)) { +- nid = EVP_CIPHER_CTX_nid(ctx); + fprintf(stderr, "get openssl software cipher failed, nid = %d.\n", nid); + return 0; + } +-- +2.25.1 + diff --git a/0006-digest-add-ctx-allocation-check.patch b/0006-digest-add-ctx-allocation-check.patch new file mode 100644 index 0000000000000000000000000000000000000000..707ae3ad722e8b81443515a0941735f596685302 --- /dev/null +++ b/0006-digest-add-ctx-allocation-check.patch @@ -0,0 +1,29 @@ +From 07324a0cdcad935e7d3449b8ff8907ca1c2a6b58 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +Date: Fri, 29 Mar 2024 10:13:24 +0800 +Subject: [PATCH 6/7] digest: add ctx allocation check + +Add result check of EVP_MD_CTX_new(). + +Signed-off-by: Zhiqi Song +Signed-off-by: JiangShui Yang +--- + src/uadk_digest.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/uadk_digest.c b/src/uadk_digest.c +index 8ab1b83..43bbf60 100644 +--- a/src/uadk_digest.c ++++ b/src/uadk_digest.c +@@ -204,6 +204,8 @@ static int digest_soft_init(struct digest_priv_ctx *md_ctx) + /* Allocate a soft ctx for hardware engine */ + if (md_ctx->soft_ctx == NULL) + md_ctx->soft_ctx = EVP_MD_CTX_new(); ++ if (md_ctx->soft_ctx == NULL) ++ return 0; + + ctx = md_ctx->soft_ctx; + +-- +2.25.1 + diff --git a/0007-sm2-add-ctx-allocation-check.patch b/0007-sm2-add-ctx-allocation-check.patch new file mode 100644 index 0000000000000000000000000000000000000000..fe0356ca9789a2941dad5022e0f5b07a324354c2 --- /dev/null +++ b/0007-sm2-add-ctx-allocation-check.patch @@ -0,0 +1,35 @@ +From 75ee064d69f687aa43cff40ce2061db1afe75f85 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +Date: Fri, 29 Mar 2024 10:13:25 +0800 +Subject: [PATCH 7/7] sm2: add ctx allocation check + +Add result check of EVP_MD_CTX_new(). + +Signed-off-by: Zhiqi Song +Signed-off-by: JiangShui Yang +--- + src/uadk_sm2.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c +index 8421931..c0a5303 100644 +--- a/src/uadk_sm2.c ++++ b/src/uadk_sm2.c +@@ -152,9 +152,13 @@ static int compute_hash(const char *in, size_t in_len, + char *out, size_t out_len, void *usr) + { + const EVP_MD *digest = (const EVP_MD *)usr; +- EVP_MD_CTX *hash = EVP_MD_CTX_new(); ++ EVP_MD_CTX *hash; + int ret = 0; + ++ hash = EVP_MD_CTX_new(); ++ if (!hash) ++ return -1; ++ + if (EVP_DigestInit(hash, digest) == 0 || + EVP_DigestUpdate(hash, in, in_len) == 0 || + EVP_DigestFinal(hash, (void *)out, NULL) == 0) { +-- +2.25.1 + diff --git a/uadk_engine.spec b/uadk_engine.spec index 3cdd1c1f81fe1deb29a936abbcb7f0c9080d6216..91314cb026691550dfe218a68d13fe2ccc90a203 100644 --- a/uadk_engine.spec +++ b/uadk_engine.spec @@ -1,7 +1,7 @@ Name: uadk_engine Summary: UADK Accelerator Engine Version: 1.3.0 -Release: 1 +Release: 2 License: Apache-2.0 Source: %{name}-%{version}.tar.gz ExclusiveOS: linux @@ -16,6 +16,10 @@ ExclusiveArch: aarch64 Patch0001: 0001-v1-dh-add-iova_map-and-iova_unmap-ops.patch Patch0002: 0002-uadk_util-fix-clang-build-error.patch Patch0003: 0003-uadk_engine-add-secure-compilation-option.patch +Patch0004: 0004-uadk_engine-cleanup-code-style-of-async-functions.patch +Patch0005: 0005-cipher-cleanup-repeated-function-invoking.patch +Patch0006: 0006-digest-add-ctx-allocation-check.patch +Patch0007: 0007-sm2-add-ctx-allocation-check.patch %description This package contains the UADK Accelerator Engine @@ -66,6 +70,15 @@ fi /sbin/ldconfig %changelog +* Sun Apr 7 2024 JiangShui Yang 1.2.0-1 +- Backport uadk engine patch + +* Mon Mar 20 2023 linwenkai 1.0.0-10 +- Backport uadk engine build patch + +* Thu Feb 9 2023 linwenkai 1.0.0-9 +- Fix uadk engine build compatiable problem + * Mon Jan 22 2024 Zhangfei Gao 1.3.0-1 - uadk_eingine: update to 1.3.0