From: Zhushuai Yin <yinzhushuai@huawei.com> In the normal no-sva mode of uadk_engine, the V1 interface should be used. However, during the dev judgment, the no-sva scenario is not empty, leading to the invocation of the V2 interface, which results in functional failure. Adding a judgment for the sva scenario can resolve this issue. Signed-off-by: Zhushuai Yin <yinzhushuai@huawei.com> --- src/uadk_aead.c | 2 +- src/uadk_cipher.c | 3 ++- src/uadk_cipher_adapter.c | 3 ++- src/uadk_dh.c | 3 ++- src/uadk_digest.c | 2 +- src/uadk_engine_init.c | 11 ++++++----- src/uadk_pkey.c | 3 ++- src/uadk_prov_cipher.c | 2 +- src/uadk_prov_digest.c | 2 +- src/uadk_prov_pkey.c | 4 ++-- src/uadk_rsa.c | 3 ++- src/uadk_utils.c | 14 ++++++++++++++ src/uadk_utils.h | 1 + 13 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/uadk_aead.c b/src/uadk_aead.c index 2d99dc3..6920c04 100644 --- a/src/uadk_aead.c +++ b/src/uadk_aead.c @@ -248,7 +248,7 @@ static int uadk_e_init_aead_cipher(void) return UADK_E_SUCCESS; } - dev = wd_get_accel_dev("aead"); + dev = uadk_get_accel_dev("aead"); if (!dev) { pthread_spin_unlock(&g_aead_engine.lock); fprintf(stderr, "failed to get device for aead.\n"); diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c index f7facc9..9029ece 100644 --- a/src/uadk_cipher.c +++ b/src/uadk_cipher.c @@ -26,6 +26,7 @@ #include "uadk.h" #include "uadk_async.h" #include "uadk_cipher_adapter.h" +#include "uadk_utils.h" #define UADK_DO_SOFT (-0xE0) #define CTX_SYNC_ENC 0 @@ -436,7 +437,7 @@ static int uadk_e_init_cipher(void) return 1; } - dev = wd_get_accel_dev("cipher"); + dev = uadk_get_accel_dev("cipher"); if (!dev) { pthread_spin_unlock(&g_cipher_engine.lock); fprintf(stderr, "failed to get device for cipher.\n"); diff --git a/src/uadk_cipher_adapter.c b/src/uadk_cipher_adapter.c index 3146968..f2559ab 100644 --- a/src/uadk_cipher_adapter.c +++ b/src/uadk_cipher_adapter.c @@ -15,6 +15,7 @@ * */ #include "uadk_cipher_adapter.h" +#include "uadk_utils.h" #define HW_SEC_V2 2 #define HW_SEC_V3 3 @@ -182,7 +183,7 @@ int uadk_e_bind_ciphers(ENGINE *e) { struct uacce_dev *dev; - dev = wd_get_accel_dev("cipher"); + dev = uadk_get_accel_dev("cipher"); if (!dev) { fprintf(stderr, "no device available, switch to software!\n"); return 0; diff --git a/src/uadk_dh.c b/src/uadk_dh.c index fcdc5cd..cae7d0a 100644 --- a/src/uadk_dh.c +++ b/src/uadk_dh.c @@ -26,6 +26,7 @@ #include <uadk/wd_sched.h> #include "uadk.h" #include "uadk_async.h" +#include "uadk_utils.h" #define DH768BITS 768 #define DH1024BITS 1024 @@ -386,7 +387,7 @@ static int uadk_e_dh_init(void) if (g_dh_res.status != UADK_UNINIT) goto unlock; - dev = wd_get_accel_dev("dh"); + dev = uadk_get_accel_dev("dh"); if (!dev) { fprintf(stderr, "no device available, switch to software!\n"); goto err_init; diff --git a/src/uadk_digest.c b/src/uadk_digest.c index 2d26268..88e7fc8 100644 --- a/src/uadk_digest.c +++ b/src/uadk_digest.c @@ -512,7 +512,7 @@ static int uadk_e_init_digest(void) return 1; } - dev = wd_get_accel_dev("digest"); + dev = uadk_get_accel_dev("digest"); if (!dev) { pthread_spin_unlock(&g_digest_engine.lock); fprintf(stderr, "failed to get device for digest.\n"); diff --git a/src/uadk_engine_init.c b/src/uadk_engine_init.c index 6fad2d9..48498c3 100644 --- a/src/uadk_engine_init.c +++ b/src/uadk_engine_init.c @@ -28,6 +28,7 @@ #ifdef KAE #include "v1/uadk_v1.h" #endif +#include "uadk_utils.h" #define UADK_CMD_ENABLE_CIPHER_ENV ENGINE_CMD_BASE #define UADK_CMD_ENABLE_AEAD_ENV (ENGINE_CMD_BASE + 1) @@ -342,7 +343,7 @@ static void bind_fn_uadk_alg(ENGINE *e) { struct uacce_dev *dev; - dev = wd_get_accel_dev("cipher"); + dev = uadk_get_accel_dev("cipher"); if (dev) { if (!uadk_e_bind_ciphers(e)) fprintf(stderr, "uadk bind cipher failed\n"); @@ -351,7 +352,7 @@ static void bind_fn_uadk_alg(ENGINE *e) free(dev); } - dev = wd_get_accel_dev("digest"); + dev = uadk_get_accel_dev("digest"); if (dev) { if (!uadk_e_bind_digest(e)) fprintf(stderr, "uadk bind digest failed\n"); @@ -360,7 +361,7 @@ static void bind_fn_uadk_alg(ENGINE *e) free(dev); } - dev = wd_get_accel_dev("rsa"); + dev = uadk_get_accel_dev("rsa"); if (dev) { if (!uadk_e_bind_rsa(e)) fprintf(stderr, "uadk bind rsa failed\n"); @@ -369,7 +370,7 @@ static void bind_fn_uadk_alg(ENGINE *e) free(dev); } - dev = wd_get_accel_dev("dh"); + dev = uadk_get_accel_dev("dh"); if (dev) { if (!uadk_e_bind_dh(e)) fprintf(stderr, "uadk bind dh failed\n"); @@ -379,7 +380,7 @@ static void bind_fn_uadk_alg(ENGINE *e) } /* find an ecc device, no difference for sm2/ecdsa/ecdh/x25519/x448 */ - dev = wd_get_accel_dev("ecdsa"); + dev = uadk_get_accel_dev("ecdsa"); if (dev) { if (!uadk_e_bind_ecc(e)) fprintf(stderr, "uadk bind ecc failed\n"); diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c index b32b658..94a74d9 100644 --- a/src/uadk_pkey.c +++ b/src/uadk_pkey.c @@ -21,6 +21,7 @@ #include "uadk_async.h" #include "uadk.h" #include "uadk_pkey.h" +#include "uadk_utils.h" #define ECC_MAX_DEV_NUM 16 #define CTX_ASYNC 1 @@ -583,7 +584,7 @@ int uadk_init_ecc(void) goto unlock; /* Find an ecc device, no difference for sm2/ecdsa/ecdh/x25519/x448 */ - dev = wd_get_accel_dev("ecdsa"); + dev = uadk_get_accel_dev("ecdsa"); if (!dev) { fprintf(stderr, "no device available, switch to software!\n"); goto err_init; diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index 198e0ac..e5f1acf 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -1344,7 +1344,7 @@ int uadk_prov_cipher_version(void) struct uacce_dev *dev; int ver; - dev = wd_get_accel_dev("cipher"); + dev = uadk_get_accel_dev("cipher"); if (!dev) { UADK_ERR("no cipher device available!\n"); return 0; diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 6babd4b..001c389 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -1043,7 +1043,7 @@ int uadk_prov_digest_version(void) { struct uacce_dev *dev; - dev = wd_get_accel_dev("digest"); + dev = uadk_get_accel_dev("digest"); if (!dev) { UADK_ERR("no digest device available!\n"); return UADK_DIGEST_FAIL; diff --git a/src/uadk_prov_pkey.c b/src/uadk_prov_pkey.c index ccfc0e7..57ae3a4 100644 --- a/src/uadk_prov_pkey.c +++ b/src/uadk_prov_pkey.c @@ -947,13 +947,13 @@ int uadk_prov_pkey_version(void) { struct uacce_dev *dev1, *dev2; - dev1 = wd_get_accel_dev("rsa"); + dev1 = uadk_get_accel_dev("rsa"); if (!dev1) { UADK_ERR("no pkey device available!\n"); return HW_PKEY_INVALID; } - dev2 = wd_get_accel_dev("sm2"); + dev2 = uadk_get_accel_dev("sm2"); if (!dev2) { free(dev1); return HW_PKEY_V2; diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c index 62118e6..f99b43b 100644 --- a/src/uadk_rsa.c +++ b/src/uadk_rsa.c @@ -23,6 +23,7 @@ #include <uadk/wd_sched.h> #include "uadk_async.h" #include "uadk.h" +#include "uadk_utils.h" #define UN_SET 0 #define IS_SET 1 @@ -837,7 +838,7 @@ static int uadk_e_rsa_init(void) if (g_rsa_res.status != UADK_UNINIT) goto unlock; - dev = wd_get_accel_dev("rsa"); + dev = uadk_get_accel_dev("rsa"); if (!dev) { fprintf(stderr, "no device available, switch to software!\n"); goto err_init; diff --git a/src/uadk_utils.c b/src/uadk_utils.c index 4a50bc4..897b119 100644 --- a/src/uadk_utils.c +++ b/src/uadk_utils.c @@ -15,6 +15,7 @@ * */ #include "uadk_utils.h" +#include <uadk/wd.h> #if defined(__AARCH64_CMODEL_SMALL__) && __AARCH64_CMODEL_SMALL__ @@ -72,3 +73,16 @@ void *uadk_memcpy(void *dstpp, const void *srcpp, size_t len) } #endif + +struct uacce_dev *uadk_get_accel_dev(const char *alg_name) +{ + struct uacce_dev *dev; + + dev = wd_get_accel_dev(alg_name); + if (dev && !(dev->flags & UACCE_DEV_SVA)) { + free(dev); + dev = NULL; + } + + return dev; +} diff --git a/src/uadk_utils.h b/src/uadk_utils.h index b2593e9..337cb29 100644 --- a/src/uadk_utils.h +++ b/src/uadk_utils.h @@ -46,4 +46,5 @@ #endif void *uadk_memcpy(void *dstpp, const void *srcpp, size_t len); +struct uacce_dev *uadk_get_accel_dev(const char *alg_name); #endif -- 2.43.0