crypto: qat - state change fixes
Subsystems (2)
Giovanni Cabiddu
maintainercover crypto: qat - state change fixes
This set combines a set of fixes in the QAT driver related to the core state machines and the change in state that can be triggered through sysfs.
Here is a summary of the changes:
* Patch #1 resolves a bug that prevents resources to be freed up.
* Patch #2 is a simple cleanup.
* Patch #3 fix the behaviour of the command up triggered through a write to /sys/bus/pci/devices/<BDF>/qat/state.
* Patches #4 and #5 fix a corner case in the un-registration of algorithms in the state machines.
Giovanni Cabiddu (5):
crypto: qat - fix state machines cleanup paths
crypto: qat - do not shadow error code
crypto: qat - ignore subsequent state up commands
crypto: qat - fix unregistration of crypto algorithms
crypto: qat - fix unregistration of compression algorithms
.../intel/qat/qat_common/adf_common_drv.h | 2 ++ drivers/crypto/intel/qat/qat_common/adf_init.c | 17 ++++++++--------- drivers/crypto/intel/qat/qat_common/adf_sysfs.c | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 12 deletions(-)
base-commit: be369945f2f612c40f771fe265db1ca658cdc0d1
Signature · 1 line
2.41.0
Giovanni Cabiddu
maintainerPATCH 1/5 crypto: qat - fix state machines cleanup paths
Commit 1bdc85550a2b ("crypto: qat - fix concurrency issue when device state changes") introduced the function adf_dev_down() which wraps the functions adf_dev_stop() and adf_dev_shutdown().
In a subsequent change, the sequence adf_dev_stop() followed by adf_dev_shutdown() was then replaced across the driver with just a call to the function adf_dev_down().
The functions adf_dev_stop() and adf_dev_shutdown() are called in error paths to stop the accelerator and free up resources and can be called even if the counterparts adf_dev_init() and adf_dev_start() did not complete successfully.
However, the implementation of adf_dev_down() prevents the stop/shutdown sequence if the device is found already down.
For example, if adf_dev_init() fails, the device status is not set as started and therefore a call to adf_dev_down() won't be calling adf_dev_shutdown() to undo what adf_dev_init() did.
Do not check if a device is started in adf_dev_down() but do the equivalent check in adf_sysfs.c when handling a DEV_DOWN command from the user.
--- drivers/crypto/intel/qat/qat_common/adf_init.c | 7 ------- drivers/crypto/intel/qat/qat_common/adf_sysfs.c | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_init.c +0 -7
@@ -428,13 +428,6 @@ int adf_dev_down(struct adf_accel_dev *accel_dev, bool reconfig)mutex_lock (&accel_dev->state_lock); -if (!adf_dev_started (accel_dev)) { -dev_info (&GET_DEV (accel_dev),"Device qat_dev%d already down\n" , - accel_dev->accel_id); - ret = -EINVAL ; - goto out; - } -if (reconfig) { ret =adf_dev_shutdown_cache_cfg (accel_dev); goto out;
drivers/crypto/intel/qat/qat_common/adf_sysfs.c +7 -0
@@ -52,6 +52,13 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,case DEV_DOWN :dev_info (dev,"Stopping device qat_dev%d\n" , accel_id); +if (!adf_dev_started (accel_dev)) { +dev_info (&GET_DEV (accel_dev),"Device qat_dev%d already down\n" , + accel_id); + +break ; + } + ret =adf_dev_down (accel_dev, true);if (ret <0 )return -EINVAL ;
Signature · 1 line
2.41.0
Giovanni Cabiddu
maintainerPATCH 2/5 crypto: qat - do not shadow error code
In reply to Giovanni CabidduDo not shadow the return code from adf_dev_down() in the error path of the DEV_DOWN command.
--- drivers/crypto/intel/qat/qat_common/adf_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_sysfs.c +2 -2
@@ -60,8 +60,8 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, } ret =adf_dev_down (accel_dev, true); -if (ret <0 ) -return -EINVAL ; +if (ret) +return ret;break ;case DEV_UP :
Signature · 1 line
2.41.0
Giovanni Cabiddu
maintainerPATCH 3/5 crypto: qat - ignore subsequent state up commands
In reply to Giovanni CabidduIf the device is already in the up state, a subsequent write of up to the sysfs attribute /sys/bus/pci/devices/<BDF>/qat/state brings the device down.
Fix this behaviour by ignoring subsequent up commands if the device is already in the up state.
--- drivers/crypto/intel/qat/qat_common/adf_sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_sysfs.c +3 -1
@@ -68,7 +68,9 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,dev_info (dev,"Starting device qat_dev%d\n" , accel_id); ret =adf_dev_up (accel_dev, true); -if (ret <0 ) { +if (ret == -EALREADY ) { +break ; + }else if (ret) {dev_err (dev,"Failed to start device qat_dev%d\n" , accel_id);adf_dev_down (accel_dev, true);
Signature · 1 line
2.41.0
Giovanni Cabiddu
maintainerPATCH 4/5 crypto: qat - fix unregistration of crypto algorithms
In reply to Giovanni CabidduThe function adf_dev_init(), through the subsystem qat_crypto, populates the list of list of crypto instances accel_dev->crypto_list. If the list of instances is not empty, the function adf_dev_start() will then call qat_algs_registers() and qat_asym_algs_register() to register the crypto algorithms into the crypto framework.
If any of the functions in adf_dev_start() fail, the caller of such function, in the error path calls adf_dev_down() which in turn call adf_dev_stop() and adf_dev_shutdown(), see for example the function state_store in adf_sriov.c.
However, if the registration of crypto algorithms is not done, adf_dev_stop() will try to unregister the algorithms regardless. This might cause the counter active_devs in qat_algs.c and qat_asym_algs.c to get to a negative value.
Add a new state, ADF_STATUS_CRYPTO_ALGS_REGISTERED, which tracks if the crypto algorithms are registered into the crypto framework. Then use this to unregister the algorithms if such flag is set. This ensures that the crypto algorithms are only unregistered if previously registered.
--- drivers/crypto/intel/qat/qat_common/adf_common_drv.h | 1 + drivers/crypto/intel/qat/qat_common/adf_init.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_common_drv.h +1 -0
@@ -25,6 +25,7 @@#define ADF_STATUS_AE_STARTED 6#define ADF_STATUS_PF_RUNNING 7#define ADF_STATUS_IRQ_ALLOCATED 8 +#define ADF_STATUS_CRYPTO_ALGS_REGISTERED 9enum adf_dev_reset_mode {ADF_DEV_RESET_ASYNC =0 ,
drivers/crypto/intel/qat/qat_common/adf_init.c +4 -1
@@ -227,6 +227,7 @@ static int adf_dev_start(struct adf_accel_dev *accel_dev)clear_bit (ADF_STATUS_STARTED , &accel_dev->status);return -EFAULT ; } +set_bit (ADF_STATUS_CRYPTO_ALGS_REGISTERED , &accel_dev->status);if (!list_empty (&accel_dev->compression_list) &&qat_comp_algs_register ()) { dev_err(&GET_DEV(accel_dev),
@@ -267,10 +268,12 @@ static void adf_dev_stop(struct adf_accel_dev *accel_dev)clear_bit (ADF_STATUS_STARTING , &accel_dev->status);clear_bit (ADF_STATUS_STARTED , &accel_dev->status); -if (!list_empty (&accel_dev->crypto_list)) { +if (!list_empty (&accel_dev->crypto_list) && +test_bit (ADF_STATUS_CRYPTO_ALGS_REGISTERED , &accel_dev->status)) {qat_algs_unregister ();qat_asym_algs_unregister (); } +clear_bit (ADF_STATUS_CRYPTO_ALGS_REGISTERED , &accel_dev->status);if (!list_empty (&accel_dev->compression_list))qat_comp_algs_unregister ();
Signature · 1 line
2.41.0
Giovanni Cabiddu
maintainerPATCH 5/5 crypto: qat - fix unregistration of compression algorithms
In reply to Giovanni CabidduThe function adf_dev_init(), through the subsystem qat_compression, populates the list of list of compression instances accel_dev->compression_list. If the list of instances is not empty, the function adf_dev_start() will then call qat_compression_registers() register the compression algorithms into the crypto framework.
If any of the functions in adf_dev_start() fail, the caller of such function, in the error path calls adf_dev_down() which in turn call adf_dev_stop() and adf_dev_shutdown(), see for example the function state_store in adf_sriov.c.
However, if the registration of compression algorithms is not done, adf_dev_stop() will try to unregister the algorithms regardless. This might cause the counter active_devs in qat_compression.c to get to a negative value.
Add a new state, ADF_STATUS_COMPRESSION_ALGS_REGISTERED, which tracks if the compression algorithms are registered into the crypto framework. Then use this to unregister the algorithms if such flag is set. This ensures that the compression algorithms are only unregistered if previously registered.
--- drivers/crypto/intel/qat/qat_common/adf_common_drv.h | 1 + drivers/crypto/intel/qat/qat_common/adf_init.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_common_drv.h +1 -0
@@ -26,6 +26,7 @@#define ADF_STATUS_PF_RUNNING 7#define ADF_STATUS_IRQ_ALLOCATED 8#define ADF_STATUS_CRYPTO_ALGS_REGISTERED 9 +#define ADF_STATUS_COMP_ALGS_REGISTERED 10enum adf_dev_reset_mode {ADF_DEV_RESET_ASYNC =0 ,
drivers/crypto/intel/qat/qat_common/adf_init.c +4 -1
@@ -236,6 +236,7 @@ static int adf_dev_start(struct adf_accel_dev *accel_dev)clear_bit (ADF_STATUS_STARTED , &accel_dev->status);return -EFAULT ; } +set_bit (ADF_STATUS_COMP_ALGS_REGISTERED , &accel_dev->status);adf_dbgfs_add (accel_dev);
@@ -275,8 +276,10 @@ static void adf_dev_stop(struct adf_accel_dev *accel_dev) }clear_bit (ADF_STATUS_CRYPTO_ALGS_REGISTERED , &accel_dev->status); -if (!list_empty (&accel_dev->compression_list)) +if (!list_empty (&accel_dev->compression_list) && +test_bit (ADF_STATUS_COMP_ALGS_REGISTERED , &accel_dev->status))qat_comp_algs_unregister (); +clear_bit (ADF_STATUS_COMP_ALGS_REGISTERED , &accel_dev->status);list_for_each_entry (service, &service_table, list) {if (!test_bit (accel_dev->accel_id, service->start_status))
Signature · 1 line
2.41.0
Herbert Xu
maintainerQuoted 19 lines · Giovanni Cabiddu
This set combines a set of fixes in the QAT driver related to the core state machines and the change in state that can be triggered through sysfs.
Here is a summary of the changes:
* Patch #1 resolves a bug that prevents resources to be freed up.
* Patch #2 is a simple cleanup.
* Patch #3 fix the behaviour of the commanduptriggered through a write to /sys/bus/pci/devices/<BDF>/qat/state.
* Patches #4 and #5 fix a corner case in the un-registration of algorithms in the state machines.Giovanni Cabiddu (5):
crypto: qat - fix state machines cleanup paths
crypto: qat - do not shadow error code
crypto: qat - ignore subsequent state up commands
crypto: qat - fix unregistration of crypto algorithms
crypto: qat - fix unregistration of compression algorithms
Quoted 9 lines
.../intel/qat/qat_common/adf_common_drv.h | 2 ++ drivers/crypto/intel/qat/qat_common/adf_init.c | 17 ++++++++--------- drivers/crypto/intel/qat/qat_common/adf_sysfs.c | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 12 deletions(-)base-commit:
be369945f2f612c40f771fe265db1ca658cdc0d1Signature · 1 line
2.41.0
All 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