All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] Add module parameters to control CCP activation
@ 2019-06-24 19:28 Hook, Gary
  2019-06-24 19:28 ` [PATCH 01/11] crypto: ccp - Make CCP debugfs support optional Hook, Gary
                   ` (10 more replies)
  0 siblings, 11 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Firstly, add a switch to allow/disallow debugfs code to be built
into the CCP driver.

This rest of the patch series implements a set of module parameters
that allow fine-tuned control over which CCPs on a system are enabled
by the driver, and how many queues on each device are activated.

Lastly, a switch to enable/disable DMA engine registration is implemented.

The new parameters are also exposed in DebugFS (when enabled).

Details:
nqueues: configure N queues per CCP (default: 0 - all queues enabled)
maxdev: maximum number of devices to enable (default: 0 - all devices activated)
pcidev: Only consider activating devices with the specified PCI ID (default: unset - all devices activated)
buses: Only consider activating devices on the specified PCI buses (default: unset - all devices activated)
dmareg: Register services with the DMA subsystem (default: true)

The maxdev, pcidev and buses parameters aggregate. 

Only activated devices will have their DMA services registered.

---

Gary R Hook (11):
      crypto: ccp - Make CCP debugfs support optional
      crypto: ccp - Add a module parameter to specify a queue count
      crypto: ccp - Expose the value of nqueues in DebugFS
      crypto: ccp - module parameter to limit the number of enabled CCPs
      crypto: ccp - Expose maxdev through DebugFS
      crypto: ccp - Specify a single CCP via PCI device ID
      crypto: ccp - expose the pcidev module parameter in debugfs
      crypto: ccp - module parameter to allow CCP selection by PCI bus
      crypto: ccp - expose pcibus module parameter in debugfs
      crypto: ccp - Add a module parameter to control registration for DMA
      crypto: ccp - Expose the registerdma module parameter in DFS


 drivers/crypto/ccp/Kconfig       |    9 ++
 drivers/crypto/ccp/Makefile      |    4 -
 drivers/crypto/ccp/ccp-debugfs.c |    3 +
 drivers/crypto/ccp/ccp-dev-v5.c  |   24 ++++-
 drivers/crypto/ccp/ccp-dev.h     |   17 ++++
 drivers/crypto/ccp/sp-pci.c      |  172 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 221 insertions(+), 8 deletions(-)

--

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/11] crypto: ccp - Make CCP debugfs support optional
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
@ 2019-06-24 19:28 ` Hook, Gary
  2019-06-24 19:28 ` [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count Hook, Gary
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add a config option to exclude DebugFS support in the CCP driver.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/Kconfig      |    9 +++++++++
 drivers/crypto/ccp/Makefile     |    4 ++--
 drivers/crypto/ccp/ccp-dev-v5.c |    4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/Kconfig b/drivers/crypto/ccp/Kconfig
index b9dfae47aefd..6fcedd7b0d42 100644
--- a/drivers/crypto/ccp/Kconfig
+++ b/drivers/crypto/ccp/Kconfig
@@ -44,3 +44,12 @@ config CRYPTO_DEV_SP_PSP
 	 management commands in Secure Encrypted Virtualization (SEV) mode,
 	 along with software-based Trusted Execution Environment (TEE) to
 	 enable third-party trusted applications.
+
+config CRYPTO_DEV_CCP_DEBUGFS
+	bool "Enable CCP Internals in DebugFS"
+	default n
+	depends on CRYPTO_DEV_SP_CCP
+	help
+	  Expose CCP device information such as operation statistics, feature
+	  information, descriptor queue contents, and module parameter values set
+	  at load time.
diff --git a/drivers/crypto/ccp/Makefile b/drivers/crypto/ccp/Makefile
index 51d1c0cf66c7..6b86f1e6d634 100644
--- a/drivers/crypto/ccp/Makefile
+++ b/drivers/crypto/ccp/Makefile
@@ -5,8 +5,8 @@ ccp-$(CONFIG_CRYPTO_DEV_SP_CCP) += ccp-dev.o \
 	    ccp-ops.o \
 	    ccp-dev-v3.o \
 	    ccp-dev-v5.o \
-	    ccp-dmaengine.o \
-	    ccp-debugfs.o
+	    ccp-dmaengine.o
+ccp-$(CONFIG_CRYPTO_DEV_CCP_DEBUGFS) += ccp-debugfs.o
 ccp-$(CONFIG_PCI) += sp-pci.o
 ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o
 
diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index c9bfd4f439ce..a5bd11831b80 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -973,8 +973,10 @@ static int ccp5_init(struct ccp_device *ccp)
 	if (ret)
 		goto e_hwrng;
 
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
 	/* Set up debugfs entries */
 	ccp5_debugfs_setup(ccp);
+#endif
 
 	return 0;
 
@@ -1012,11 +1014,13 @@ static void ccp5_destroy(struct ccp_device *ccp)
 	/* Remove this device from the list of available units first */
 	ccp_del_device(ccp);
 
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
 	/* We're in the process of tearing down the entire driver;
 	 * when all the devices are gone clean up debugfs
 	 */
 	if (ccp_present())
 		ccp5_debugfs_destroy();
+#endif
 
 	/* Disable and clear interrupts */
 	ccp5_disable_queue_interrupts(ccp);


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
  2019-06-24 19:28 ` [PATCH 01/11] crypto: ccp - Make CCP debugfs support optional Hook, Gary
@ 2019-06-24 19:28 ` Hook, Gary
  2019-06-24 21:54   ` Lendacky, Thomas
  2019-06-24 19:28 ` [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS Hook, Gary
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add a module parameter to limit the number of queues per CCP. The default
(nqueues=0) is to set up every available queue on each device.

The count of queues starts from the first one found on the device (which
is based on the device ID).

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-dev-v5.c |    9 ++++++++-
 drivers/crypto/ccp/ccp-dev.h    |   15 +++++++++++++++
 drivers/crypto/ccp/sp-pci.c     |   15 ++++++++++++++-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index a5bd11831b80..ffd546b951b6 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -14,12 +14,15 @@
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/kthread.h>
-#include <linux/debugfs.h>
 #include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
 #include <linux/compiler.h>
 #include <linux/ccp.h>
 
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
+#include <linux/debugfs.h>
+#endif
+
 #include "ccp-dev.h"
 
 /* Allocate the requested number of contiguous LSB slots
@@ -784,6 +787,7 @@ static irqreturn_t ccp5_irq_handler(int irq, void *data)
 
 static int ccp5_init(struct ccp_device *ccp)
 {
+	unsigned int nqueues = ccp_get_nqueues_param();
 	struct device *dev = ccp->dev;
 	struct ccp_cmd_queue *cmd_q;
 	struct dma_pool *dma_pool;
@@ -856,6 +860,9 @@ static int ccp5_init(struct ccp_device *ccp)
 		init_waitqueue_head(&cmd_q->int_queue);
 
 		dev_dbg(dev, "queue #%u available\n", i);
+
+		if (ccp->cmd_q_count >= nqueues)
+			break;
 	}
 
 	if (ccp->cmd_q_count == 0) {
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index 6810b65c1939..d812446213ee 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -632,6 +632,8 @@ struct ccp5_desc {
 void ccp_add_device(struct ccp_device *ccp);
 void ccp_del_device(struct ccp_device *ccp);
 
+unsigned int ccp_get_nqueues_param(void);
+
 extern void ccp_log_error(struct ccp_device *, int);
 
 struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
@@ -671,4 +673,17 @@ extern const struct ccp_vdata ccpv3;
 extern const struct ccp_vdata ccpv5a;
 extern const struct ccp_vdata ccpv5b;
 
+
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
+
+/* DebugFS stuff */
+typedef struct _modparam {
+                char *paramname;
+                void *param;
+                umode_t parammode;
+        } modparam_t;
+extern void ccp_debugfs_register_modparams(struct dentry *parentdir);
+
+#endif
+
 #endif
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 41bce0a3f4bb..3fab79585f72 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -1,7 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
 /*
  * AMD Secure Processor device driver
  *
- * Copyright (C) 2013,2018 Advanced Micro Devices, Inc.
+ * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
  *
  * Author: Tom Lendacky <thomas.lendacky@amd.com>
  * Author: Gary R Hook <gary.hook@amd.com>
@@ -27,6 +29,17 @@
 #include "ccp-dev.h"
 #include "psp-dev.h"
 
+/*
+ * Limit CCP use to a specifed number of queues per device.
+ */
+static unsigned int nqueues = MAX_HW_QUEUES;
+module_param(nqueues, uint, 0444);
+MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
+
+unsigned int ccp_get_nqueues_param(void) {
+	return nqueues;
+}
+
 #define MSIX_VECTORS			2
 
 struct sp_pci {


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
  2019-06-24 19:28 ` [PATCH 01/11] crypto: ccp - Make CCP debugfs support optional Hook, Gary
  2019-06-24 19:28 ` [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count Hook, Gary
@ 2019-06-24 19:28 ` Hook, Gary
  2019-06-24 21:59   ` Lendacky, Thomas
  2019-06-24 19:28 ` [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs Hook, Gary
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Make module parameters readable in DebugFS.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-debugfs.c |    2 ++
 drivers/crypto/ccp/sp-pci.c      |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
index 4bd26af7098d..c4cc0e60fd50 100644
--- a/drivers/crypto/ccp/ccp-debugfs.c
+++ b/drivers/crypto/ccp/ccp-debugfs.c
@@ -317,6 +317,8 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
 				    &ccp_debugfs_queue_ops);
 	}
 
+	ccp_debugfs_register_modparams(ccp_debugfs_dir);
+
 	return;
 }
 
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 3fab79585f72..c167c4671f45 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -26,6 +26,10 @@
 #include <linux/delay.h>
 #include <linux/ccp.h>
 
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
+#include <linux/debugfs.h>
+#endif
+
 #include "ccp-dev.h"
 #include "psp-dev.h"
 
@@ -36,6 +40,24 @@ static unsigned int nqueues = MAX_HW_QUEUES;
 module_param(nqueues, uint, 0444);
 MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
 
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
+modparam_t      moduleparameters[] = {
+	{"nqueues", &nqueues, S_IRUSR},
+	{NULL, NULL, 0},
+};
+
+void ccp_debugfs_register_modparams(struct dentry *parentdir)
+{
+	int j;
+
+	for (j = 0; moduleparameters[j].paramname; j++)
+		debugfs_create_u32(moduleparameters[j].paramname,
+				   moduleparameters[j].parammode, parentdir,
+				   moduleparameters[j].param);
+}
+
+#endif
+
 unsigned int ccp_get_nqueues_param(void) {
 	return nqueues;
 }


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (2 preceding siblings ...)
  2019-06-24 19:28 ` [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS Hook, Gary
@ 2019-06-24 19:28 ` Hook, Gary
  2019-06-24 22:11   ` Lendacky, Thomas
  2019-06-24 19:29 ` [PATCH 05/11] crypto: ccp - Expose maxdev through DebugFS Hook, Gary
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Provide the ability to constrain the total number of enabled devices in
the system. Once maxdev devices have been configured, additional
devices are ignored.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index c167c4671f45..b81493810689 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -36,6 +36,13 @@
 /*
  * Limit CCP use to a specifed number of queues per device.
  */
+
+static struct mutex devcount_mutex ____cacheline_aligned;
+static unsigned int devcount = 0;
+static unsigned int maxdev = 0;
+module_param(maxdev, uint, 0444);
+MODULE_PARM_DESC(maxdev, "Total number of devices to register");
+
 static unsigned int nqueues = MAX_HW_QUEUES;
 module_param(nqueues, uint, 0444);
 MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
@@ -193,6 +200,9 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	int bar_mask;
 	int ret;
 
+	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
+		return 0;
+
 	ret = -ENOMEM;
 	sp = sp_alloc_struct(dev);
 	if (!sp)
@@ -261,6 +271,11 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (ret)
 		goto e_err;
 
+	/* Increase count of devices */
+	mutex_lock(&devcount_mutex);
+	devcount++;
+	mutex_unlock(&devcount_mutex);
+
 	return 0;
 
 e_err:
@@ -374,6 +389,7 @@ static struct pci_driver sp_pci_driver = {
 
 int sp_pci_init(void)
 {
+        mutex_init(&devcount_mutex);
 	return pci_register_driver(&sp_pci_driver);
 }
 


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 05/11] crypto: ccp - Expose maxdev through DebugFS
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (3 preceding siblings ...)
  2019-06-24 19:28 ` [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 19:29 ` [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID Hook, Gary
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add a read-only debugfs entry for the module parameter 'maxdev'.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index b81493810689..29177d113c90 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -49,6 +49,7 @@ MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
 
 #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
 modparam_t      moduleparameters[] = {
+	{"maxdev", &maxdev, S_IRUSR},
 	{"nqueues", &nqueues, S_IRUSR},
 	{NULL, NULL, 0},
 };


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (4 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 05/11] crypto: ccp - Expose maxdev through DebugFS Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 22:41   ` Lendacky, Thomas
  2019-06-24 19:29 ` [PATCH 07/11] crypto: ccp - expose the pcidev module parameter in debugfs Hook, Gary
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Some processors contain multiple CCPs with differing device IDs. Enable
the selection of specific devices based on ID. The parameter value is
a single PCI ID.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 29177d113c90..b024b92fb749 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -36,6 +36,9 @@
 /*
  * Limit CCP use to a specifed number of queues per device.
  */
+static unsigned int pcidev;
+module_param(pcidev, uint, 0444);
+MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
 
 static struct mutex devcount_mutex ____cacheline_aligned;
 static unsigned int devcount = 0;
@@ -204,6 +207,10 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
 		return 0;
 
+	/* If a specific device ID has been specified, filter for it */
+        if (pcidev && (pdev->device != pcidev))
+                        return 0;
+
 	ret = -ENOMEM;
 	sp = sp_alloc_struct(dev);
 	if (!sp)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 07/11] crypto: ccp - expose the pcidev module parameter in debugfs
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (5 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 19:29 ` [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus Hook, Gary
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add pcidev to the CCP's debugfs information

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index b024b92fb749..bcd1e233dce7 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -54,6 +54,7 @@ MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
 modparam_t      moduleparameters[] = {
 	{"maxdev", &maxdev, S_IRUSR},
 	{"nqueues", &nqueues, S_IRUSR},
+	{"pcidev", &pcidev, S_IRUSR},
 	{NULL, NULL, 0},
 };
 


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (6 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 07/11] crypto: ccp - expose the pcidev module parameter in debugfs Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 22:42   ` Lendacky, Thomas
  2019-06-24 19:29 ` [PATCH 09/11] crypto: ccp - expose pcibus module parameter in debugfs Hook, Gary
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add a module parameter that allows specification of one or more CCPs
based on PCI bus identifiers. The value of the parameter is a comma-
separated list of bus numbers, in no particular order.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |   58 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index bcd1e233dce7..a563d85b242e 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -40,6 +40,13 @@ static unsigned int pcidev;
 module_param(pcidev, uint, 0444);
 MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
 
+#define MAXCCPS 32
+static char *buses;
+static unsigned int n_pcibus = 0;
+static unsigned int pcibus[MAXCCPS];
+module_param(buses, charp, 0444);
+MODULE_PARM_DESC(buses, "PCI Bus number(s), comma-separated. List CCPs with 'lspci |grep Enc'");
+
 static struct mutex devcount_mutex ____cacheline_aligned;
 static unsigned int devcount = 0;
 static unsigned int maxdev = 0;
@@ -50,6 +57,37 @@ static unsigned int nqueues = MAX_HW_QUEUES;
 module_param(nqueues, uint, 0444);
 MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
 
+#define COMMA   ','
+static void ccp_parse_pci_buses(void)
+{
+	unsigned int busno;
+	unsigned int eos = 0;
+	int ret;
+	char *comma;
+	char *tok;
+
+	/* Nothing on the command line? */
+	if (!buses)
+		return;
+
+	comma = tok = buses;
+	while (!eos && *tok && (n_pcibus < MAXCCPS)) {
+		while (*comma && *comma != COMMA)
+			comma++;
+		if (*comma == COMMA)
+			*comma = '\0';
+		else
+			eos = 1;
+		ret = kstrtouint(tok, 0, &busno);
+		if (ret) {
+			pr_info("%s: Parsing error (%d) '%s'\n", __func__, ret, buses);
+			return;
+		}
+		pcibus[n_pcibus++] = busno;
+		tok = ++comma;
+	}
+}
+
 #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
 modparam_t      moduleparameters[] = {
 	{"maxdev", &maxdev, S_IRUSR},
@@ -204,6 +242,7 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	void __iomem * const *iomap_table;
 	int bar_mask;
 	int ret;
+	int j;
 
 	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
 		return 0;
@@ -212,6 +251,25 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         if (pcidev && (pdev->device != pcidev))
                         return 0;
 
+	/*
+	* Look for (1) a specific device, (2) devices on a certain
+	* bus, or (3) a specific device number. If both parameters
+	* are zero accept any device.
+	*/
+	ccp_parse_pci_buses();
+	if (n_pcibus) {
+		int match = 0;
+
+		/* Scan the list of buses for a match */
+		for (j = 0 ; j < n_pcibus ; j++)
+			if (pcibus[j] == pdev->bus->number) {
+				match = 1;
+				break;
+			}
+		if (!match)
+			return 0;
+	}
+
 	ret = -ENOMEM;
 	sp = sp_alloc_struct(dev);
 	if (!sp)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 09/11] crypto: ccp - expose pcibus module parameter in debugfs
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (7 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 19:29 ` [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA Hook, Gary
  2019-06-24 19:29 ` [PATCH 11/11] crypto: ccp - Expose the registerdma module parameter in DFS Hook, Gary
  10 siblings, 0 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add module parameter pcibus as a read-only variable to the CCP's
debugfs info.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-debugfs.c |    1 +
 drivers/crypto/ccp/ccp-dev.h     |    1 +
 drivers/crypto/ccp/sp-pci.c      |   47 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
index c4cc0e60fd50..7a223b71eee8 100644
--- a/drivers/crypto/ccp/ccp-debugfs.c
+++ b/drivers/crypto/ccp/ccp-debugfs.c
@@ -318,6 +318,7 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
 	}
 
 	ccp_debugfs_register_modparams(ccp_debugfs_dir);
+	ccp_debugfs_register_buses(ccp_debugfs_dir);
 
 	return;
 }
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index d812446213ee..cd1bd78d95cc 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -683,6 +683,7 @@ typedef struct _modparam {
                 umode_t parammode;
         } modparam_t;
 extern void ccp_debugfs_register_modparams(struct dentry *parentdir);
+extern void ccp_debugfs_register_buses(struct dentry *parentdir);
 
 #endif
 
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index a563d85b242e..86dee2a66f00 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -62,6 +62,7 @@ static void ccp_parse_pci_buses(void)
 {
 	unsigned int busno;
 	unsigned int eos = 0;
+	char *busarg;
 	int ret;
 	char *comma;
 	char *tok;
@@ -70,7 +71,9 @@ static void ccp_parse_pci_buses(void)
 	if (!buses)
 		return;
 
-	comma = tok = buses;
+	busarg = kstrdup(buses, GFP_KERNEL);
+
+	comma = tok = busarg;
 	while (!eos && *tok && (n_pcibus < MAXCCPS)) {
 		while (*comma && *comma != COMMA)
 			comma++;
@@ -81,11 +84,15 @@ static void ccp_parse_pci_buses(void)
 		ret = kstrtouint(tok, 0, &busno);
 		if (ret) {
 			pr_info("%s: Parsing error (%d) '%s'\n", __func__, ret, buses);
-			return;
+			n_pcibus = 0; /* pretend there was no parameter */
+			goto err;
 		}
 		pcibus[n_pcibus++] = busno;
 		tok = ++comma;
 	}
+
+err:
+	kfree(busarg);
 }
 
 #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
@@ -106,6 +113,41 @@ void ccp_debugfs_register_modparams(struct dentry *parentdir)
 				   moduleparameters[j].param);
 }
 
+static ssize_t ccp_debugfs_buses_read(struct file *filp, char __user *ubuf,
+				      size_t count, loff_t *offp)
+{
+	char *string = filp->private_data;
+	unsigned int oboff = 0;
+	unsigned plen = 1023;
+	ssize_t ret;
+	char *obuf;
+
+	if (!string)
+		string = "(ALL)";
+	obuf = kmalloc(plen + 1, GFP_KERNEL);
+	if (!obuf)
+		return -ENOMEM;
+
+	oboff += snprintf(obuf, plen, "%s\n", string);
+
+	ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+	kfree(obuf);
+
+	return ret;
+}
+
+static const struct file_operations ccp_debugfs_char_ops = {
+	.owner = THIS_MODULE,
+	.open = simple_open,
+	.read = ccp_debugfs_buses_read,
+	.write = NULL,
+};
+
+void ccp_debugfs_register_buses(struct dentry *parentdir)
+{
+        debugfs_create_file("buses", S_IRUSR, parentdir, buses, &ccp_debugfs_char_ops);
+}
+
 #endif
 
 unsigned int ccp_get_nqueues_param(void) {
@@ -457,6 +499,7 @@ static struct pci_driver sp_pci_driver = {
 int sp_pci_init(void)
 {
         mutex_init(&devcount_mutex);
+	ccp_parse_pci_buses();
 	return pci_register_driver(&sp_pci_driver);
 }
 


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (8 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 09/11] crypto: ccp - expose pcibus module parameter in debugfs Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  2019-06-24 22:45   ` Lendacky, Thomas
  2019-06-24 19:29 ` [PATCH 11/11] crypto: ccp - Expose the registerdma module parameter in DFS Hook, Gary
  10 siblings, 1 reply; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

The CCP driver is able to act as a DMA engine. Add a module parameter that
allows this feature to be enabled/disabled.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-dev-v5.c |   11 +++++++----
 drivers/crypto/ccp/ccp-dev.h    |    1 +
 drivers/crypto/ccp/sp-pci.c     |    8 ++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index ffd546b951b6..dfd803f6fb55 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -976,9 +976,11 @@ static int ccp5_init(struct ccp_device *ccp)
 		goto e_kthread;
 
 	/* Register the DMA engine support */
-	ret = ccp_dmaengine_register(ccp);
-	if (ret)
-		goto e_hwrng;
+	if (ccp_register_dma()) {
+		ret = ccp_dmaengine_register(ccp);
+		if (ret)
+			goto e_hwrng;
+	}
 
 #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
 	/* Set up debugfs entries */
@@ -1013,7 +1015,8 @@ static void ccp5_destroy(struct ccp_device *ccp)
 	unsigned int i;
 
 	/* Unregister the DMA engine */
-	ccp_dmaengine_unregister(ccp);
+	if (ccp_register_dma())
+		ccp_dmaengine_unregister(ccp);
 
 	/* Unregister the RNG */
 	ccp_unregister_rng(ccp);
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index cd1bd78d95cc..323f7d8ce454 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -647,6 +647,7 @@ int ccp_register_rng(struct ccp_device *ccp);
 void ccp_unregister_rng(struct ccp_device *ccp);
 int ccp_dmaengine_register(struct ccp_device *ccp);
 void ccp_dmaengine_unregister(struct ccp_device *ccp);
+unsigned int ccp_register_dma(void);
 
 void ccp5_debugfs_setup(struct ccp_device *ccp);
 void ccp5_debugfs_destroy(void);
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 86dee2a66f00..5b0a9c145c5a 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -57,6 +57,10 @@ static unsigned int nqueues = MAX_HW_QUEUES;
 module_param(nqueues, uint, 0444);
 MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
 
+static unsigned int registerdma = 1;
+module_param(registerdma, uint, 0444);
+MODULE_PARM_DESC(registerdma, "Register services with the DMA engine (default: 1)");
+
 #define COMMA   ','
 static void ccp_parse_pci_buses(void)
 {
@@ -154,6 +158,10 @@ unsigned int ccp_get_nqueues_param(void) {
 	return nqueues;
 }
 
+unsigned int ccp_register_dma(void) {
+	return registerdma;
+}
+
 #define MSIX_VECTORS			2
 
 struct sp_pci {


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 11/11] crypto: ccp - Expose the registerdma module parameter in DFS
  2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
                   ` (9 preceding siblings ...)
  2019-06-24 19:29 ` [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA Hook, Gary
@ 2019-06-24 19:29 ` Hook, Gary
  10 siblings, 0 replies; 19+ messages in thread
From: Hook, Gary @ 2019-06-24 19:29 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Add a read-only variable to report the value of the parameter

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/sp-pci.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 5b0a9c145c5a..c1c1e05a7c0f 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -104,6 +104,7 @@ modparam_t      moduleparameters[] = {
 	{"maxdev", &maxdev, S_IRUSR},
 	{"nqueues", &nqueues, S_IRUSR},
 	{"pcidev", &pcidev, S_IRUSR},
+	{"registerdma", &registerdma, S_IRUSR},
 	{NULL, NULL, 0},
 };
 


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count
  2019-06-24 19:28 ` [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count Hook, Gary
@ 2019-06-24 21:54   ` Lendacky, Thomas
  0 siblings, 0 replies; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 21:54 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:28 PM, Hook, Gary wrote:
> Add a module parameter to limit the number of queues per CCP. The default
> (nqueues=0) is to set up every available queue on each device.

This doesn't match the code...  nqueues defaults to MAX_HW_QUEUES below.
The way it is coded nqueues=0 and nqueues=1 are exactly the same.

> 
> The count of queues starts from the first one found on the device (which
> is based on the device ID).
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/ccp-dev-v5.c |    9 ++++++++-
>  drivers/crypto/ccp/ccp-dev.h    |   15 +++++++++++++++
>  drivers/crypto/ccp/sp-pci.c     |   15 ++++++++++++++-
>  3 files changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
> index a5bd11831b80..ffd546b951b6 100644
> --- a/drivers/crypto/ccp/ccp-dev-v5.c
> +++ b/drivers/crypto/ccp/ccp-dev-v5.c
> @@ -14,12 +14,15 @@
>  #include <linux/kernel.h>
>  #include <linux/pci.h>
>  #include <linux/kthread.h>
> -#include <linux/debugfs.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/interrupt.h>
>  #include <linux/compiler.h>
>  #include <linux/ccp.h>
>  
> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
> +#include <linux/debugfs.h>
> +#endif
> +

This belongs in the first patch.

>  #include "ccp-dev.h"
>  
>  /* Allocate the requested number of contiguous LSB slots
> @@ -784,6 +787,7 @@ static irqreturn_t ccp5_irq_handler(int irq, void *data)
>  
>  static int ccp5_init(struct ccp_device *ccp)
>  {
> +	unsigned int nqueues = ccp_get_nqueues_param();
>  	struct device *dev = ccp->dev;
>  	struct ccp_cmd_queue *cmd_q;
>  	struct dma_pool *dma_pool;
> @@ -856,6 +860,9 @@ static int ccp5_init(struct ccp_device *ccp)
>  		init_waitqueue_head(&cmd_q->int_queue);
>  
>  		dev_dbg(dev, "queue #%u available\n", i);
> +
> +		if (ccp->cmd_q_count >= nqueues)
> +			break;

In reference to my comment above, this is where nqueues=0 or 1 results
in the same thing happening.

>  	}
>  
>  	if (ccp->cmd_q_count == 0) {
> diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
> index 6810b65c1939..d812446213ee 100644
> --- a/drivers/crypto/ccp/ccp-dev.h
> +++ b/drivers/crypto/ccp/ccp-dev.h
> @@ -632,6 +632,8 @@ struct ccp5_desc {
>  void ccp_add_device(struct ccp_device *ccp);
>  void ccp_del_device(struct ccp_device *ccp);
>  
> +unsigned int ccp_get_nqueues_param(void);
> +
>  extern void ccp_log_error(struct ccp_device *, int);
>  
>  struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
> @@ -671,4 +673,17 @@ extern const struct ccp_vdata ccpv3;
>  extern const struct ccp_vdata ccpv5a;
>  extern const struct ccp_vdata ccpv5b;
>  
> +
> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
> +
> +/* DebugFS stuff */
> +typedef struct _modparam {
> +                char *paramname;
> +                void *param;
> +                umode_t parammode;
> +        } modparam_t;
> +extern void ccp_debugfs_register_modparams(struct dentry *parentdir);
> +
> +#endif
> +

You've created this typedef/struct (which should be just a struct, not
a typedef) which isn't used and reference to a function that doesn't exist
yet.

>  #endif
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index 41bce0a3f4bb..3fab79585f72 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -1,7 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
>  /*
>   * AMD Secure Processor device driver
>   *
> - * Copyright (C) 2013,2018 Advanced Micro Devices, Inc.
> + * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
>   *
>   * Author: Tom Lendacky <thomas.lendacky@amd.com>
>   * Author: Gary R Hook <gary.hook@amd.com>
> @@ -27,6 +29,17 @@
>  #include "ccp-dev.h"
>  #include "psp-dev.h"
>  
> +/*
> + * Limit CCP use to a specifed number of queues per device.
> + */
> +static unsigned int nqueues = MAX_HW_QUEUES;
> +module_param(nqueues, uint, 0444);
> +MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
> +
> +unsigned int ccp_get_nqueues_param(void) {
> +	return nqueues;
> +}
> +

You should define this module parameter in the file where it is used and
then you won't need the function.

Thanks,
Tom

>  #define MSIX_VECTORS			2
>  
>  struct sp_pci {
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS
  2019-06-24 19:28 ` [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS Hook, Gary
@ 2019-06-24 21:59   ` Lendacky, Thomas
  2019-06-25 13:06     ` Gary R Hook
  0 siblings, 1 reply; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 21:59 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:28 PM, Hook, Gary wrote:
> Make module parameters readable in DebugFS.

Not sure why you have this...  you can access the module parameters in
/sys/module/ccp/parameters. You can then get/set them based on the
value in the module_param() definition.

Thanks,
Tom

> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/ccp-debugfs.c |    2 ++
>  drivers/crypto/ccp/sp-pci.c      |   22 ++++++++++++++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
> index 4bd26af7098d..c4cc0e60fd50 100644
> --- a/drivers/crypto/ccp/ccp-debugfs.c
> +++ b/drivers/crypto/ccp/ccp-debugfs.c
> @@ -317,6 +317,8 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>  				    &ccp_debugfs_queue_ops);
>  	}
>  
> +	ccp_debugfs_register_modparams(ccp_debugfs_dir);
> +
>  	return;
>  }
>  
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index 3fab79585f72..c167c4671f45 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -26,6 +26,10 @@
>  #include <linux/delay.h>
>  #include <linux/ccp.h>
>  
> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
> +#include <linux/debugfs.h>
> +#endif
> +
>  #include "ccp-dev.h"
>  #include "psp-dev.h"
>  
> @@ -36,6 +40,24 @@ static unsigned int nqueues = MAX_HW_QUEUES;
>  module_param(nqueues, uint, 0444);
>  MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
>  
> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
> +modparam_t      moduleparameters[] = {
> +	{"nqueues", &nqueues, S_IRUSR},
> +	{NULL, NULL, 0},
> +};
> +
> +void ccp_debugfs_register_modparams(struct dentry *parentdir)
> +{
> +	int j;
> +
> +	for (j = 0; moduleparameters[j].paramname; j++)
> +		debugfs_create_u32(moduleparameters[j].paramname,
> +				   moduleparameters[j].parammode, parentdir,
> +				   moduleparameters[j].param);
> +}
> +
> +#endif
> +
>  unsigned int ccp_get_nqueues_param(void) {
>  	return nqueues;
>  }
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs
  2019-06-24 19:28 ` [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs Hook, Gary
@ 2019-06-24 22:11   ` Lendacky, Thomas
  0 siblings, 0 replies; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 22:11 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:28 PM, Hook, Gary wrote:
> Provide the ability to constrain the total number of enabled devices in
> the system. Once maxdev devices have been configured, additional
> devices are ignored.
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/sp-pci.c |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index c167c4671f45..b81493810689 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -36,6 +36,13 @@
>  /*
>   * Limit CCP use to a specifed number of queues per device.
>   */
> +
> +static struct mutex devcount_mutex ____cacheline_aligned;

I don't think I'd worry about the cache alignment since this is only
used at module load.

> +static unsigned int devcount = 0;
> +static unsigned int maxdev = 0;
> +module_param(maxdev, uint, 0444);
> +MODULE_PARM_DESC(maxdev, "Total number of devices to register");
> +
>  static unsigned int nqueues = MAX_HW_QUEUES;
>  module_param(nqueues, uint, 0444);
>  MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
> @@ -193,6 +200,9 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	int bar_mask;
>  	int ret;
>  
> +	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
> +		return 0;
> +

You need the mutex to protect the use of devcount. You could use an
atomic instead of the int/mutex combination.

And this will mess with the PSP support. It should be in the CCP
specific files, not here.

>  	ret = -ENOMEM;
>  	sp = sp_alloc_struct(dev);
>  	if (!sp)
> @@ -261,6 +271,11 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	if (ret)
>  		goto e_err;
>  
> +	/* Increase count of devices */
> +	mutex_lock(&devcount_mutex);
> +	devcount++;
> +	mutex_unlock(&devcount_mutex);
> +
>  	return 0;
>  
>  e_err:
> @@ -374,6 +389,7 @@ static struct pci_driver sp_pci_driver = {
>  
>  int sp_pci_init(void)
>  {
> +        mutex_init(&devcount_mutex);

Tab instead of spaces.

Thanks,
Tom

>  	return pci_register_driver(&sp_pci_driver);
>  }
>  
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID
  2019-06-24 19:29 ` [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID Hook, Gary
@ 2019-06-24 22:41   ` Lendacky, Thomas
  0 siblings, 0 replies; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 22:41 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:29 PM, Hook, Gary wrote:
> Some processors contain multiple CCPs with differing device IDs. Enable
> the selection of specific devices based on ID. The parameter value is
> a single PCI ID.
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/sp-pci.c |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index 29177d113c90..b024b92fb749 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -36,6 +36,9 @@
>  /*
>   * Limit CCP use to a specifed number of queues per device.
>   */
> +static unsigned int pcidev;
> +module_param(pcidev, uint, 0444);
> +MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
>  
>  static struct mutex devcount_mutex ____cacheline_aligned;
>  static unsigned int devcount = 0;
> @@ -204,6 +207,10 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
>  		return 0;
>  
> +	/* If a specific device ID has been specified, filter for it */
> +        if (pcidev && (pdev->device != pcidev))
> +                        return 0;
> +

Again, this could interfere with devices that support the CCP and PSP, so
additional checking. You could get away with this check for the ccpv5b
device, but not the ccpv5a device.

Thanks,
Tom

>  	ret = -ENOMEM;
>  	sp = sp_alloc_struct(dev);
>  	if (!sp)
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus
  2019-06-24 19:29 ` [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus Hook, Gary
@ 2019-06-24 22:42   ` Lendacky, Thomas
  0 siblings, 0 replies; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 22:42 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:29 PM, Hook, Gary wrote:
> Add a module parameter that allows specification of one or more CCPs
> based on PCI bus identifiers. The value of the parameter is a comma-
> separated list of bus numbers, in no particular order.
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/sp-pci.c |   58 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index bcd1e233dce7..a563d85b242e 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -40,6 +40,13 @@ static unsigned int pcidev;
>  module_param(pcidev, uint, 0444);
>  MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
>  
> +#define MAXCCPS 32
> +static char *buses;
> +static unsigned int n_pcibus = 0;
> +static unsigned int pcibus[MAXCCPS];
> +module_param(buses, charp, 0444);
> +MODULE_PARM_DESC(buses, "PCI Bus number(s), comma-separated. List CCPs with 'lspci |grep Enc'");
> +
>  static struct mutex devcount_mutex ____cacheline_aligned;
>  static unsigned int devcount = 0;
>  static unsigned int maxdev = 0;
> @@ -50,6 +57,37 @@ static unsigned int nqueues = MAX_HW_QUEUES;
>  module_param(nqueues, uint, 0444);
>  MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
>  
> +#define COMMA   ','
> +static void ccp_parse_pci_buses(void)
> +{
> +	unsigned int busno;
> +	unsigned int eos = 0;
> +	int ret;
> +	char *comma;
> +	char *tok;
> +
> +	/* Nothing on the command line? */
> +	if (!buses)
> +		return;
> +
> +	comma = tok = buses;
> +	while (!eos && *tok && (n_pcibus < MAXCCPS)) {
> +		while (*comma && *comma != COMMA)
> +			comma++;
> +		if (*comma == COMMA)
> +			*comma = '\0';
> +		else
> +			eos = 1;
> +		ret = kstrtouint(tok, 0, &busno);
> +		if (ret) {
> +			pr_info("%s: Parsing error (%d) '%s'\n", __func__, ret, buses);
> +			return;
> +		}
> +		pcibus[n_pcibus++] = busno;
> +		tok = ++comma;
> +	}
> +}
> +
>  #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
>  modparam_t      moduleparameters[] = {
>  	{"maxdev", &maxdev, S_IRUSR},
> @@ -204,6 +242,7 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	void __iomem * const *iomap_table;
>  	int bar_mask;
>  	int ret;
> +	int j;
>  
>  	if (maxdev && (devcount >= maxdev)) /* Too many devices? */
>  		return 0;
> @@ -212,6 +251,25 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>          if (pcidev && (pdev->device != pcidev))
>                          return 0;
>  
> +	/*
> +	* Look for (1) a specific device, (2) devices on a certain
> +	* bus, or (3) a specific device number. If both parameters
> +	* are zero accept any device.
> +	*/
> +	ccp_parse_pci_buses();
> +	if (n_pcibus) {
> +		int match = 0;
> +
> +		/* Scan the list of buses for a match */
> +		for (j = 0 ; j < n_pcibus ; j++)
> +			if (pcibus[j] == pdev->bus->number) {
> +				match = 1;
> +				break;
> +			}
> +		if (!match)
> +			return 0;
> +	}

Same comment as before in regards to CCP and PSP interaction.

Thanks,
Tom

> +
>  	ret = -ENOMEM;
>  	sp = sp_alloc_struct(dev);
>  	if (!sp)
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA
  2019-06-24 19:29 ` [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA Hook, Gary
@ 2019-06-24 22:45   ` Lendacky, Thomas
  0 siblings, 0 replies; 19+ messages in thread
From: Lendacky, Thomas @ 2019-06-24 22:45 UTC (permalink / raw)
  To: Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 2:29 PM, Hook, Gary wrote:
> The CCP driver is able to act as a DMA engine. Add a module parameter that
> allows this feature to be enabled/disabled.
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/ccp-dev-v5.c |   11 +++++++----
>  drivers/crypto/ccp/ccp-dev.h    |    1 +
>  drivers/crypto/ccp/sp-pci.c     |    8 ++++++++
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
> index ffd546b951b6..dfd803f6fb55 100644
> --- a/drivers/crypto/ccp/ccp-dev-v5.c
> +++ b/drivers/crypto/ccp/ccp-dev-v5.c
> @@ -976,9 +976,11 @@ static int ccp5_init(struct ccp_device *ccp)
>  		goto e_kthread;
>  
>  	/* Register the DMA engine support */
> -	ret = ccp_dmaengine_register(ccp);
> -	if (ret)
> -		goto e_hwrng;
> +	if (ccp_register_dma()) {
> +		ret = ccp_dmaengine_register(ccp);
> +		if (ret)
> +			goto e_hwrng;
> +	}
>  
>  #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
>  	/* Set up debugfs entries */
> @@ -1013,7 +1015,8 @@ static void ccp5_destroy(struct ccp_device *ccp)
>  	unsigned int i;
>  
>  	/* Unregister the DMA engine */
> -	ccp_dmaengine_unregister(ccp);
> +	if (ccp_register_dma())
> +		ccp_dmaengine_unregister(ccp);
>  
>  	/* Unregister the RNG */
>  	ccp_unregister_rng(ccp);
> diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
> index cd1bd78d95cc..323f7d8ce454 100644
> --- a/drivers/crypto/ccp/ccp-dev.h
> +++ b/drivers/crypto/ccp/ccp-dev.h
> @@ -647,6 +647,7 @@ int ccp_register_rng(struct ccp_device *ccp);
>  void ccp_unregister_rng(struct ccp_device *ccp);
>  int ccp_dmaengine_register(struct ccp_device *ccp);
>  void ccp_dmaengine_unregister(struct ccp_device *ccp);
> +unsigned int ccp_register_dma(void);
>  
>  void ccp5_debugfs_setup(struct ccp_device *ccp);
>  void ccp5_debugfs_destroy(void);
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index 86dee2a66f00..5b0a9c145c5a 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -57,6 +57,10 @@ static unsigned int nqueues = MAX_HW_QUEUES;
>  module_param(nqueues, uint, 0444);
>  MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
>  
> +static unsigned int registerdma = 1;
> +module_param(registerdma, uint, 0444);
> +MODULE_PARM_DESC(registerdma, "Register services with the DMA engine (default: 1)");

Same comment as earlier, this can live in the CCP related files. Also,
only doing this for v5, not v3 too?

Thanks,
Tom

> +
>  #define COMMA   ','
>  static void ccp_parse_pci_buses(void)
>  {
> @@ -154,6 +158,10 @@ unsigned int ccp_get_nqueues_param(void) {
>  	return nqueues;
>  }
>  
> +unsigned int ccp_register_dma(void) {
> +	return registerdma;
> +}
> +
>  #define MSIX_VECTORS			2
>  
>  struct sp_pci {
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS
  2019-06-24 21:59   ` Lendacky, Thomas
@ 2019-06-25 13:06     ` Gary R Hook
  0 siblings, 0 replies; 19+ messages in thread
From: Gary R Hook @ 2019-06-25 13:06 UTC (permalink / raw)
  To: Lendacky, Thomas, Hook, Gary, linux-crypto; +Cc: herbert, davem

On 6/24/19 4:59 PM, Lendacky, Thomas wrote:
> On 6/24/19 2:28 PM, Hook, Gary wrote:
>> Make module parameters readable in DebugFS.
> 
> Not sure why you have this...  you can access the module parameters in
> /sys/module/ccp/parameters. You can then get/set them based on the
> value in the module_param() definition.

I'll take "who's an idiot" for $200, Alex.

There'll be v2 patchset a-comin'.

grh


> 
> Thanks,
> Tom
> 
>>
>> Signed-off-by: Gary R Hook <gary.hook@amd.com>
>> ---
>>   drivers/crypto/ccp/ccp-debugfs.c |    2 ++
>>   drivers/crypto/ccp/sp-pci.c      |   22 ++++++++++++++++++++++
>>   2 files changed, 24 insertions(+)
>>
>> diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
>> index 4bd26af7098d..c4cc0e60fd50 100644
>> --- a/drivers/crypto/ccp/ccp-debugfs.c
>> +++ b/drivers/crypto/ccp/ccp-debugfs.c
>> @@ -317,6 +317,8 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>>   				    &ccp_debugfs_queue_ops);
>>   	}
>>   
>> +	ccp_debugfs_register_modparams(ccp_debugfs_dir);
>> +
>>   	return;
>>   }
>>   
>> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
>> index 3fab79585f72..c167c4671f45 100644
>> --- a/drivers/crypto/ccp/sp-pci.c
>> +++ b/drivers/crypto/ccp/sp-pci.c
>> @@ -26,6 +26,10 @@
>>   #include <linux/delay.h>
>>   #include <linux/ccp.h>
>>   
>> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
>> +#include <linux/debugfs.h>
>> +#endif
>> +
>>   #include "ccp-dev.h"
>>   #include "psp-dev.h"
>>   
>> @@ -36,6 +40,24 @@ static unsigned int nqueues = MAX_HW_QUEUES;
>>   module_param(nqueues, uint, 0444);
>>   MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
>>   
>> +#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
>> +modparam_t      moduleparameters[] = {
>> +	{"nqueues", &nqueues, S_IRUSR},
>> +	{NULL, NULL, 0},
>> +};
>> +
>> +void ccp_debugfs_register_modparams(struct dentry *parentdir)
>> +{
>> +	int j;
>> +
>> +	for (j = 0; moduleparameters[j].paramname; j++)
>> +		debugfs_create_u32(moduleparameters[j].paramname,
>> +				   moduleparameters[j].parammode, parentdir,
>> +				   moduleparameters[j].param);
>> +}
>> +
>> +#endif
>> +
>>   unsigned int ccp_get_nqueues_param(void) {
>>   	return nqueues;
>>   }
>>


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-06-25 13:06 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 19:28 [PATCH 00/11] Add module parameters to control CCP activation Hook, Gary
2019-06-24 19:28 ` [PATCH 01/11] crypto: ccp - Make CCP debugfs support optional Hook, Gary
2019-06-24 19:28 ` [PATCH 02/11] crypto: ccp - Add a module parameter to specify a queue count Hook, Gary
2019-06-24 21:54   ` Lendacky, Thomas
2019-06-24 19:28 ` [PATCH 03/11] crypto: ccp - Expose the value of nqueues in DebugFS Hook, Gary
2019-06-24 21:59   ` Lendacky, Thomas
2019-06-25 13:06     ` Gary R Hook
2019-06-24 19:28 ` [PATCH 04/11] crypto: ccp - module parameter to limit the number of enabled CCPs Hook, Gary
2019-06-24 22:11   ` Lendacky, Thomas
2019-06-24 19:29 ` [PATCH 05/11] crypto: ccp - Expose maxdev through DebugFS Hook, Gary
2019-06-24 19:29 ` [PATCH 06/11] crypto: ccp - Specify a single CCP via PCI device ID Hook, Gary
2019-06-24 22:41   ` Lendacky, Thomas
2019-06-24 19:29 ` [PATCH 07/11] crypto: ccp - expose the pcidev module parameter in debugfs Hook, Gary
2019-06-24 19:29 ` [PATCH 08/11] crypto: ccp - module parameter to allow CCP selection by PCI bus Hook, Gary
2019-06-24 22:42   ` Lendacky, Thomas
2019-06-24 19:29 ` [PATCH 09/11] crypto: ccp - expose pcibus module parameter in debugfs Hook, Gary
2019-06-24 19:29 ` [PATCH 10/11] crypto: ccp - Add a module parameter to control registration for DMA Hook, Gary
2019-06-24 22:45   ` Lendacky, Thomas
2019-06-24 19:29 ` [PATCH 11/11] crypto: ccp - Expose the registerdma module parameter in DFS Hook, Gary

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.