2019-07-09 15:14:32

by Gary R Hook

[permalink] [raw]
Subject: [PATCH v2 0/4] Add module parameters to control CCP activation

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 allows control over which CCPs on a system are enabled by the
driver, and how many queues on each device are activated.

A switch to enable/disable DMA engine registration is implemented.

Details:
nqueues - configure N queues per CCP (default: 0 - all queues enabled)
max_devs - maximum number of devices to enable (default: 0 - all
devices activated)
dmaengine - Register services with the DMA subsystem (default: true)

Only activated devices will have their DMA services registered,
comprehensively controlled by the dmaengine parameter.

Changes since v1:
- Remove debugfs patches that duplicates sysfs function
- Remove patches for filtering by pcibus and pci device ID
- Utilize underscores for consistency in variable names
- Correct commit message for nqueues regarding default value
- Alter verbage of parameter description (dmaengine)
- Help text in Kconfig: remove reference to parameters in debugfs

---

Gary R Hook (4):
crypto: ccp - Make CCP debugfs support optional
crypto: ccp - Add a module parameter to specify a queue count
crypto: ccp - module parameter to limit the number of enabled CCPs
crypto: ccp - Add a module parameter to control registration for DMA


drivers/crypto/ccp/Kconfig | 8 ++++++++
drivers/crypto/ccp/Makefile | 4 ++--
drivers/crypto/ccp/ccp-dev-v3.c | 2 +-
drivers/crypto/ccp/ccp-dev-v5.c | 11 ++++++-----
drivers/crypto/ccp/ccp-dev.c | 29 ++++++++++++++++++++++++++++-
drivers/crypto/ccp/ccp-dev.h | 1 +
drivers/crypto/ccp/ccp-dmaengine.c | 12 +++++++++++-
7 files changed, 57 insertions(+), 10 deletions(-)

--
Signature


2019-07-09 15:14:32

by Gary R Hook

[permalink] [raw]
Subject: [PATCH v2 2/4] crypto: ccp - Add a module parameter to specify a queue count

Add a module parameter to limit the number of queues per CCP. The default
value (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
varies based on the device ID).

Signed-off-by: Gary R Hook <[email protected]>
---
drivers/crypto/ccp/ccp-dev-v3.c | 2 +-
drivers/crypto/ccp/ccp-dev-v5.c | 7 ++-----
drivers/crypto/ccp/ccp-dev.c | 11 +++++++++++
drivers/crypto/ccp/ccp-dev.h | 1 +
4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c
index 2339a8101a52..16bc45717198 100644
--- a/drivers/crypto/ccp/ccp-dev-v3.c
+++ b/drivers/crypto/ccp/ccp-dev-v3.c
@@ -379,7 +379,7 @@ static int ccp_init(struct ccp_device *ccp)
/* Find available queues */
ccp->qim = 0;
qmr = ioread32(ccp->io_regs + Q_MASK_REG);
- for (i = 0; i < MAX_HW_QUEUES; i++) {
+ for (i = 0; (i < MAX_HW_QUEUES) && (ccp->cmd_q_count < ccp->max_q_count); i++) {
if (!(qmr & (1 << i)))
continue;

diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index 340d0984f8d7..cd4c6b1b5c9c 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -2,16 +2,14 @@
/*
* AMD Cryptographic Coprocessor (CCP) driver
*
- * Copyright (C) 2016,2017 Advanced Micro Devices, Inc.
+ * Copyright (C) 2016,2019 Advanced Micro Devices, Inc.
*
* Author: Gary R Hook <[email protected]>
*/

-#include <linux/module.h>
#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>
@@ -792,8 +790,7 @@ static int ccp5_init(struct ccp_device *ccp)

/* Find available queues */
qmr = ioread32(ccp->io_regs + Q_MASK_REG);
- for (i = 0; i < MAX_HW_QUEUES; i++) {
-
+ for (i = 0; (i < MAX_HW_QUEUES) && (ccp->cmd_q_count < ccp->max_q_count); i++) {
if (!(qmr & (1 << i)))
continue;

diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index f3ff36f93207..23cef87c0950 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -8,6 +8,7 @@
* Author: Gary R Hook <[email protected]>
*/

+#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/sched.h>
@@ -26,6 +27,11 @@

#include "ccp-dev.h"

+/* Limit CCP use to a specifed number of queues per device */
+static unsigned int nqueues = 0;
+module_param(nqueues, uint, 0444);
+MODULE_PARM_DESC(nqueues, "Number of queues per CCP (minimum 1; default: all available)");
+
struct ccp_tasklet_data {
struct completion completion;
struct ccp_cmd *cmd;
@@ -592,6 +598,11 @@ int ccp_dev_init(struct sp_device *sp)
goto e_err;
sp->ccp_data = ccp;

+ if (!nqueues || (nqueues > MAX_HW_QUEUES))
+ ccp->max_q_count = MAX_HW_QUEUES;
+ else
+ ccp->max_q_count = nqueues;
+
ccp->vdata = (struct ccp_vdata *)sp->dev_vdata->ccp_vdata;
if (!ccp->vdata || !ccp->vdata->version) {
ret = -ENODEV;
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index 4a54e731f836..5c96d348ec09 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -379,6 +379,7 @@ struct ccp_device {
*/
struct ccp_cmd_queue cmd_q[MAX_HW_QUEUES];
unsigned int cmd_q_count;
+ unsigned int max_q_count;

/* Support for the CCP True RNG
*/

2019-07-09 15:14:32

by Gary R Hook

[permalink] [raw]
Subject: [PATCH v2 4/4] crypto: ccp - Add a module parameter to control registration for DMA

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 <[email protected]>
---
drivers/crypto/ccp/ccp-dmaengine.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/ccp-dmaengine.c b/drivers/crypto/ccp/ccp-dmaengine.c
index 9aee619db6e4..3f90ce35bee5 100644
--- a/drivers/crypto/ccp/ccp-dmaengine.c
+++ b/drivers/crypto/ccp/ccp-dmaengine.c
@@ -2,7 +2,7 @@
/*
* AMD Cryptographic Coprocessor (CCP) driver
*
- * Copyright (C) 2016,2017 Advanced Micro Devices, Inc.
+ * Copyright (C) 2016,2019 Advanced Micro Devices, Inc.
*
* Author: Gary R Hook <[email protected]>
*/
@@ -35,6 +35,10 @@ static unsigned int dma_chan_attr = CCP_DMA_DFLT;
module_param(dma_chan_attr, uint, 0444);
MODULE_PARM_DESC(dma_chan_attr, "Set DMA channel visibility: 0 (default) = device defaults, 1 = make private, 2 = make public");

+static unsigned int dmaengine = 1;
+module_param(dmaengine, uint, 0444);
+MODULE_PARM_DESC(dmaengine, "Register services with the DMA subsystem (any non-zero value, default: 1)");
+
static unsigned int ccp_get_dma_chan_attr(struct ccp_device *ccp)
{
switch (dma_chan_attr) {
@@ -637,6 +641,9 @@ int ccp_dmaengine_register(struct ccp_device *ccp)
unsigned int i;
int ret;

+ if (!dmaengine)
+ return 0;
+
ccp->ccp_dma_chan = devm_kcalloc(ccp->dev, ccp->cmd_q_count,
sizeof(*(ccp->ccp_dma_chan)),
GFP_KERNEL);
@@ -740,6 +747,9 @@ void ccp_dmaengine_unregister(struct ccp_device *ccp)
{
struct dma_device *dma_dev = &ccp->dma_dev;

+ if (!dmaengine)
+ return;
+
dma_async_device_unregister(dma_dev);

kmem_cache_destroy(ccp->dma_desc_cache);

2019-07-09 15:14:32

by Gary R Hook

[permalink] [raw]
Subject: [PATCH v2 1/4] crypto: ccp - Make CCP debugfs support optional

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

Signed-off-by: Gary R Hook <[email protected]>
---
drivers/crypto/ccp/Kconfig | 8 ++++++++
drivers/crypto/ccp/Makefile | 4 ++--
drivers/crypto/ccp/ccp-dev-v5.c | 4 ++++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/Kconfig b/drivers/crypto/ccp/Kconfig
index b9dfae47aefd..51e46b57ad8e 100644
--- a/drivers/crypto/ccp/Kconfig
+++ b/drivers/crypto/ccp/Kconfig
@@ -44,3 +44,11 @@ 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, and descriptor queue contents.
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 c76a9fa115b8..340d0984f8d7 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -970,8 +970,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;

@@ -1009,11 +1011,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);

2019-07-09 15:14:32

by Gary R Hook

[permalink] [raw]
Subject: [PATCH v2 3/4] crypto: ccp - module parameter to limit the number of enabled CCPs

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

The max_devs parameter may be zero, in which case all CCPs are disabled.
PSPs are always enabled and active.

Disabling the CCPs also disables DMA and RNG registration.

Signed-off-by: Gary R Hook <[email protected]>
---
drivers/crypto/ccp/ccp-dev.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index 23cef87c0950..cba96169ee36 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -2,7 +2,7 @@
/*
* AMD Cryptographic Coprocessor (CCP) driver
*
- * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
+ * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
*
* Author: Tom Lendacky <[email protected]>
* Author: Gary R Hook <[email protected]>
@@ -20,6 +20,7 @@
#include <linux/delay.h>
#include <linux/hw_random.h>
#include <linux/cpu.h>
+#include <linux/atomic.h>
#ifdef CONFIG_X86
#include <asm/cpu_device_id.h>
#endif
@@ -27,11 +28,19 @@

#include "ccp-dev.h"

+#define MAX_CCPS 32
+
/* Limit CCP use to a specifed number of queues per device */
static unsigned int nqueues = 0;
module_param(nqueues, uint, 0444);
MODULE_PARM_DESC(nqueues, "Number of queues per CCP (minimum 1; default: all available)");

+/* Limit the maximum number of configured CCPs */
+static atomic_t dev_count = ATOMIC_INIT(0);
+static unsigned int max_devs = MAX_CCPS;
+module_param(max_devs, uint, 0444);
+MODULE_PARM_DESC(max_devs, "Maximum number of CCPs to enable (default: all; 0 disables all CCPs)");
+
struct ccp_tasklet_data {
struct completion completion;
struct ccp_cmd *cmd;
@@ -592,6 +601,13 @@ int ccp_dev_init(struct sp_device *sp)
struct ccp_device *ccp;
int ret;

+ /*
+ * Check how many we have so far, and stop after reaching
+ * that number
+ */
+ if (atomic_inc_return(&dev_count) > max_devs)
+ return 0; /* don't fail the load */
+
ret = -ENOMEM;
ccp = ccp_alloc_struct(sp);
if (!ccp)

2019-07-26 12:34:18

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] Add module parameters to control CCP activation

Hook, Gary <[email protected]> wrote:
> 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 allows control over which CCPs on a system are enabled by the
> driver, and how many queues on each device are activated.^M
>
> A switch to enable/disable DMA engine registration is implemented.
>
> Details:
> nqueues - configure N queues per CCP (default: 0 - all queues enabled)
> max_devs - maximum number of devices to enable (default: 0 - all
> devices activated)
> dmaengine - Register services with the DMA subsystem (default: true)
>
> Only activated devices will have their DMA services registered,
> comprehensively controlled by the dmaengine parameter.
>
> Changes since v1:
> - Remove debugfs patches that duplicates sysfs function
> - Remove patches for filtering by pcibus and pci device ID
> - Utilize underscores for consistency in variable names
> - Correct commit message for nqueues regarding default value
> - Alter verbage of parameter description (dmaengine)
> - Help text in Kconfig: remove reference to parameters in debugfs
>
> ---
>
> Gary R Hook (4):^M
> crypto: ccp - Make CCP debugfs support optional
> crypto: ccp - Add a module parameter to specify a queue count
> crypto: ccp - module parameter to limit the number of enabled CCPs
> crypto: ccp - Add a module parameter to control registration for DMA
>
>
> drivers/crypto/ccp/Kconfig | 8 ++++++++
> drivers/crypto/ccp/Makefile | 4 ++--
> drivers/crypto/ccp/ccp-dev-v3.c | 2 +-
> drivers/crypto/ccp/ccp-dev-v5.c | 11 ++++++-----
> drivers/crypto/ccp/ccp-dev.c | 29 ++++++++++++++++++++++++++++-
> drivers/crypto/ccp/ccp-dev.h | 1 +
> drivers/crypto/ccp/ccp-dmaengine.c | 12 +++++++++++-
> 7 files changed, 57 insertions(+), 10 deletions(-)

All applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt