crypto: api - Introduce notifier for new crypto algorithms
authorMartin K. Petersen <martin.petersen@oracle.com>
Thu, 30 Aug 2018 15:00:14 +0000 (11:00 -0400)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 4 Sep 2018 03:37:04 +0000 (11:37 +0800)
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>
crypto/algapi.c
crypto/algboss.c
crypto/internal.h
include/crypto/algapi.h

index 496fc51bf215c230b201658e7411942822a2b474..38daa8677da924f567bfb3e48b76b1b0182c69ff 100644 (file)
@@ -372,6 +372,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);
index 5e6df2a087fa68d85f777bc7780bdc317ef34825..527b44d0af21bce4e610f17f1b2d55bf507c1a41 100644 (file)
@@ -274,6 +274,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;
index 9a3f39939fba8a3a91444ffcac1caabb9efb138e..ef769b5e8ad3e7625f327056c8e9f96056fc6b6f 100644 (file)
 #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;
 
@@ -90,8 +84,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);
index 21371ac8f355d5dddc0e00a4652b573641f4d394..4a5ad10e75f0e714f874996dfc9be8879b08a54d 100644 (file)
@@ -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 */