diff mbox series

[04/11] crypto: ccp - module parameter to limit the number of enabled CCPs

Message ID 156140453629.116890.465562924738110016.stgit@sosrh3.amd.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series Add module parameters to control CCP activation | expand

Commit Message

Gary R Hook June 24, 2019, 7:28 p.m. UTC
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(+)

Comments

Tom Lendacky June 24, 2019, 10:11 p.m. UTC | #1
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);
>  }
>  
>
diff mbox series

Patch

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);
 }