Commit 90773bc1 authored by Hook, Gary's avatar Hook, Gary Committed by Herbert Xu

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: default avatarGary R Hook <gary.hook@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent c4a89279
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
* AMD Cryptographic Coprocessor (CCP) driver * AMD Cryptographic Coprocessor (CCP) driver
* *
* Copyright (C) 2013,2017 Advanced Micro Devices, Inc. * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
* *
* Author: Tom Lendacky <thomas.lendacky@amd.com> * Author: Tom Lendacky <thomas.lendacky@amd.com>
* Author: Gary R Hook <gary.hook@amd.com> * Author: Gary R Hook <gary.hook@amd.com>
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/hw_random.h> #include <linux/hw_random.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/atomic.h>
#ifdef CONFIG_X86 #ifdef CONFIG_X86
#include <asm/cpu_device_id.h> #include <asm/cpu_device_id.h>
#endif #endif
...@@ -27,11 +28,19 @@ ...@@ -27,11 +28,19 @@
#include "ccp-dev.h" #include "ccp-dev.h"
#define MAX_CCPS 32
/* Limit CCP use to a specifed number of queues per device */ /* Limit CCP use to a specifed number of queues per device */
static unsigned int nqueues = 0; static unsigned int nqueues = 0;
module_param(nqueues, uint, 0444); module_param(nqueues, uint, 0444);
MODULE_PARM_DESC(nqueues, "Number of queues per CCP (minimum 1; default: all available)"); 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 ccp_tasklet_data {
struct completion completion; struct completion completion;
struct ccp_cmd *cmd; struct ccp_cmd *cmd;
...@@ -592,6 +601,13 @@ int ccp_dev_init(struct sp_device *sp) ...@@ -592,6 +601,13 @@ int ccp_dev_init(struct sp_device *sp)
struct ccp_device *ccp; struct ccp_device *ccp;
int ret; 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; ret = -ENOMEM;
ccp = ccp_alloc_struct(sp); ccp = ccp_alloc_struct(sp);
if (!ccp) if (!ccp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment