Skip to contentSkip to conversation

crypto: ccp - Check for CCP before registering crypto algs

PATCH In review Tom Lendacky 3 participants 5 messages Sep 5, 2014 – Sep 24, 2014

Subsystems (2)
lore
Share & tools
lore

Tom Lendacky

author maintainer
#0 lore raw

PATCH 1/1 crypto: ccp - Check for CCP before registering crypto algs

If the ccp is built as a built-in module, then ccp-crypto (whether built as a module or a built-in module) will be able to load and it will register its crypto algorithms. If the system does not have a CCP this will result in -ENODEV being returned whenever a command is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP on the system. The ccp-crypto module can use this to determine if it should register it's crypto alogorithms.

---
 drivers/crypto/ccp/ccp-crypto-main.c |    4 ++++
 drivers/crypto/ccp/ccp-dev.c         |   14 ++++++++++++++
 include/linux/ccp.h                  |   12 ++++++++++++
 3 files changed, 30 insertions(+)
drivers/crypto/ccp/ccp-crypto-main.c +4 -0
index 20dc848..4d4e016 100644
@@ -367,6 +367,10 @@ static int ccp_crypto_init(void)
 {
 	int ret;
 
+	ret = ccp_present();
+	if (ret)
+		return ret;
+
 	spin_lock_init(&req_queue_lock);
 	INIT_LIST_HEAD(&req_queue.cmds);
 	req_queue.backlog = &req_queue.cmds;
drivers/crypto/ccp/ccp-dev.c +14 -0
index a7d1106..c6e6171 100644
@@ -55,6 +55,20 @@ static inline void ccp_del_device(struct ccp_device *ccp)
 }
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void)
+{
+	if (ccp_get_device())
+		return 0;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(ccp_present);
+
+/**
  * ccp_enqueue_cmd - queue an operation for processing by the CCP
  *
  * @cmd: ccp_cmd struct to be processed
include/linux/ccp.h +12 -0
index ebcc9d1..7f43703 100644
@@ -27,6 +27,13 @@ struct ccp_cmd;
 	defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE)
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void);
+
+/**
  * ccp_enqueue_cmd - queue an operation for processing by the CCP
  *
  * @cmd: ccp_cmd struct to be processed
@@ -53,6 +60,11 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd);
 
 #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */
 
+static inline int ccp_present(void)
+{
+	return -ENODEV;
+}
+
 static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
 {
 	return -ENODEV;
Tested-by on v1 1/1
#1 lore raw
Quoted 78 lines · Tom Lendacky

If the ccp is built as a built-in module, then ccp-crypto (whether built as a module or a built-in module) will be able to load and it will register its crypto algorithms. If the system does not have a CCP this will result in -ENODEV being returned whenever a command is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP on the system. The ccp-crypto module can use this to determine if it should register it's crypto alogorithms.

---

drivers/crypto/ccp/ccp-crypto-main.c |    4 ++++
drivers/crypto/ccp/ccp-dev.c         |   14 ++++++++++++++
include/linux/ccp.h                  |   12 ++++++++++++
3 files changed, 30 insertions(+)
drivers/crypto/ccp/ccp-crypto-main.c +4 -0
index 20dc848..4d4e016 100644
@@ -367,6 +367,10 @@ static int ccp_crypto_init(void)
 {
 	int ret;
 
+	ret = ccp_present();
+	if (ret)
+		return ret;
+
 	spin_lock_init(&req_queue_lock);
 	INIT_LIST_HEAD(&req_queue.cmds);
 	req_queue.backlog = &req_queue.cmds;
drivers/crypto/ccp/ccp-dev.c +14 -0
index a7d1106..c6e6171 100644
@@ -55,6 +55,20 @@ static inline void ccp_del_device(struct ccp_device *ccp)
 }
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void)
+{
+	if (ccp_get_device())
+		return 0;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(ccp_present);
+
+/**
 * ccp_enqueue_cmd - queue an operation for processing by the CCP
 *
 * @cmd: ccp_cmd struct to be processed
include/linux/ccp.h +7 -0
index ebcc9d1..7f43703 100644
@@ -27,6 +27,13 @@ struct ccp_cmd;
 	defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE)
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void);
+
+/**
 * ccp_enqueue_cmd - queue an operation for processing by the CCP
 *
 * @cmd: ccp_cmd struct to be processed
@@ -53,6 +60,11 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd);
 

include/linux/ccp.h int ccp_enqueue_cmd(struct ccp_cmd *cmd); · line 70

Quoted 10 lines
include/linux/ccp.h +5 -0
 #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */
 
+static inline int ccp_present(void)
+{
+	return -ENODEV;
+}
+
 static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
 {
 	return -ENODEV;

Thanks Tom!

maintainer
#2 lore raw
Quoted 9 lines · Scot Doyle
Quoted 6 lines · Tom Lendacky

If the ccp is built as a built-in module, then ccp-crypto (whether built as a module or a built-in module) will be able to load and it will register its crypto algorithms. If the system does not have a CCP this will result in -ENODEV being returned whenever a command is attempted to be queued by the registered crypto algorithms.

Quoted 8 lines
Quoted 6 lines

Add an API, ccp_present(), that checks for the presence of a CCP on the system. The ccp-crypto module can use this to determine if it should register it's crypto alogorithms.

Patch applied. Thanks!

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author maintainer
#3 lore raw
Quoted 14 lines · Herbert Xu
Quoted 13 lines · Scot Doyle
Quoted 10 lines · Tom Lendacky

If the ccp is built as a built-in module, then ccp-crypto (whether built as a module or a built-in module) will be able to load and it will register its crypto algorithms. If the system does not have a CCP this will result in -ENODEV being returned whenever a command is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP on the system. The ccp-crypto module can use this to determine if it should register it's crypto alogorithms.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Patch applied. Thanks!

Hi Herbert,

Can you push this patch into the 3.17 release?

Also, it should probably go into to the stable releases. Is this something that you request or should I take care of that?

Thanks,
Tom

maintainer
#4 lore raw
Quoted 18 lines · Tom Lendacky
Quoted 17 lines · Herbert Xu
Quoted 16 lines · Scot Doyle
Quoted 12 lines · Tom Lendacky

If the ccp is built as a built-in module, then ccp-crypto (whether built as a module or a built-in module) will be able to load and it will register its crypto algorithms. If the system does not have a CCP this will result in -ENODEV being returned whenever a command is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP on the system. The ccp-crypto module can use this to determine if it should register it's crypto alogorithms.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Patch applied. Thanks!

Hi Herbert,

Can you push this patch into the 3.17 release?

Thanks for the note, I've moved the patch to the crypto tree.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt