From: Xiangyang Yu yuxiangyang4@huawei.com
mainline inclusion from mainline-v4.19-rc2 commit dd8b083f9a5ed06946d559e0ca1eda0577ef24a9 category: feature bugzilla: 46802 CVE: NA
--------------------------------
Introduce a facility that can be used to receive a notification callback when a new algorithm becomes available. This can be used by existing crypto registrations to trigger a switch from a software-only algorithm to a hardware-accelerated version.
A new CRYPTO_MSG_ALG_LOADED state is introduced to the existing crypto notification chain, and the register/unregister functions are exported so they can be called by subsystems outside of crypto.
Signed-off-by: Martin K. Petersen martin.petersen@oracle.com Suggested-by: Herbert Xu herbert@gondor.apana.org.au Signed-off-by: Martin K. Petersen martin.petersen@oracle.com Signed-off-by: Herbert Xu herbert@gondor.apana.org.au Signed-off-by: Xiangyang Yu yuxiangyang4@huawei.com Acked-by: Xie XiuQi xiexiuqi@huawei.com Reviewed-by: Jason Yan yanaijie@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- crypto/algapi.c | 2 ++ crypto/algboss.c | 2 ++ crypto/internal.h | 8 -------- include/crypto/algapi.h | 10 ++++++++++ 4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/crypto/algapi.c b/crypto/algapi.c index da6b0865f77fa..9201f28182013 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -367,6 +367,8 @@ static void crypto_wait_for_test(struct crypto_larval *larval)
err = wait_for_completion_killable(&larval->completion); WARN_ON(err); + if (!err) + crypto_probing_notify(CRYPTO_MSG_ALG_LOADED, larval);
out: crypto_larval_kill(&larval->alg); diff --git a/crypto/algboss.c b/crypto/algboss.c index 445da4a0618ff..4471b62b8fc65 100644 --- a/crypto/algboss.c +++ b/crypto/algboss.c @@ -272,6 +272,8 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg, return cryptomgr_schedule_probe(data); case CRYPTO_MSG_ALG_REGISTER: return cryptomgr_schedule_test(data); + case CRYPTO_MSG_ALG_LOADED: + break; }
return NOTIFY_DONE; diff --git a/crypto/internal.h b/crypto/internal.h index f8d6efaffef90..ad1556e3ac0bc 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -26,12 +26,6 @@ #include <linux/rwsem.h> #include <linux/slab.h>
-/* Crypto notification events. */ -enum { - CRYPTO_MSG_ALG_REQUEST, - CRYPTO_MSG_ALG_REGISTER, -}; - struct crypto_instance; struct crypto_template;
@@ -89,8 +83,6 @@ struct crypto_alg *crypto_find_alg(const char *alg_name, void *crypto_alloc_tfm(const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask);
-int crypto_register_notifier(struct notifier_block *nb); -int crypto_unregister_notifier(struct notifier_block *nb); int crypto_probing_notify(unsigned long val, void *v);
unsigned int crypto_alg_extsize(struct crypto_alg *alg); diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 6b9cd65976179..b226646302d69 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -427,4 +427,14 @@ static inline void crypto_yield(u32 flags) #endif }
+int crypto_register_notifier(struct notifier_block *nb); +int crypto_unregister_notifier(struct notifier_block *nb); + +/* Crypto notification events. */ +enum { + CRYPTO_MSG_ALG_REQUEST, + CRYPTO_MSG_ALG_REGISTER, + CRYPTO_MSG_ALG_LOADED, +}; + #endif /* _CRYPTO_ALGAPI_H */