crypto: qat - fix mutex lifetimes in the device manager
Subsystems (3)
cover crypto: qat - fix mutex lifetimes in the device manager
Two mutexes used by the QAT driver are initialised or destroyed on paths that do not match their actual lifetime, so with CONFIG_DEBUG_MUTEXES enabled both are reported on a dh895xcc with 32 host-bound VFs.
In summary:
Patch #1: state_lock is initialised at the end of adf_devmgr_add_dev(), after the early return taken when an id mapping for the VF already exists. Since that mapping outlives the VF, recreating VFs on the same BDF leaves the lock uninitialised while adf_dev_up() and adf_dev_down() take it. Move the initialisation up so it happens on every path.
Patch #2: vf2pf_lock is destroyed as part of the VF interrupt teardown in adf_dev_down(), but adf_dev_stop_async() sends the RESTARTING_COMPLETE message to the PF afterwards and takes that lock, so every PF restart locks a destroyed mutex. The notification cannot be moved earlier, so tie the lock lifetime to the accel device instead, next to state_lock in adf_devmgr_add_dev()/adf_devmgr_rm_dev().
Both patches are fixes for stable.
Ahsan Atta (2):
crypto: qat - initialise state_lock on every path in
adf_devmgr_add_dev()
crypto: qat - fix use of destroyed vf2pf_lock on VF restart
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 10 +++++++++- drivers/crypto/intel/qat/qat_common/adf_vf_isr.c | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-)
base-commit: ee0454474a0f1b636dc96217b346e3571878b292
Signature · 1 line
2.50.1
PATCH 1/2 crypto: qat - initialise state_lock on every path in adf_devmgr_add_dev()
state_lock is initialised at the end of adf_devmgr_add_dev(), but the VF on host path whose id mapping already exists returns earlier via 'goto unlock'. That mapping outlives the VF, so this path is taken every time a VF is recreated on a BDF that already hosted one, e.g.:
echo 0 > sriov_numvfs
echo 32 > sriov_numvfs
accel_dev is freshly allocated on each probe, so state_lock is left zeroed and adf_dev_up() takes an uninitialised mutex. With CONFIG_DEBUG_MUTEXES this is reported on a dh895xcc with 32 host-bound VFs:
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0 Call Trace: adf_dev_up+0x27/0xe0 [intel_qat] adf_probe+0x700/0xa80 [qat_dh895xccvf] local_pci_probe+0xd5/0x190
The same happens on teardown when adf_dev_down() locks it again.
Initialise the lock next to the other per-device state, before the tables are updated, so it is done on every path.
--- drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c +1 -1
@@ -137,6 +137,7 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,mutex_lock (&table_lock);atomic_set (&accel_dev->ref_count,0 ); +mutex_init (&accel_dev->state_lock);/* PF on host or VF on guest - optimized to remove redundant is_vf */ if (!accel_dev->is_vf || !pf) {
@@ -210,7 +211,6 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev, map->attached = true;list_add_tail (&map->list, &vfs_table); } -mutex_init (&accel_dev->state_lock); unlock:mutex_unlock (&table_lock);return ret;
Signature · 1 line
2.50.1
PATCH 2/2 crypto: qat - fix use of destroyed vf2pf_lock on VF restart
In reply to Ahsan Attaadf_dev_stop_async() sends the RESTARTING_COMPLETE message after adf_dev_down() has returned, but adf_dev_down() already destroyed the lock that message takes.
Both run in sequence in the same worker, so every PF restart locks a destroyed mutex. With CONFIG_DEBUG_MUTEXES on a dh895xcc with 32 host-bound VFs this trips on the first PF reset:
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0 Workqueue: adf_vf_stop_wq adf_dev_stop_async [intel_qat] Call Trace: adf_gen2_pfvf_send+0x210/0x530 [intel_qat] adf_vf2pf_notify_restart_complete+0x55/0x80 [intel_qat] adf_dev_stop_async+0xdb/0x140 [intel_qat]
The notification cannot move before adf_dev_down(): the PF waits for it before its own reset and the VF must tear down its rings first.
vf2pf_lock protects the VF2PF CSR and is unrelated to the PF2VF bottom half it is initialised alongside. Tie its lifetime to the accel device, next to state_lock in adf_devmgr_add_dev()/adf_devmgr_rm_dev(), so it stays valid for messages sent outside the device up/down cycle. It is only touched for VFs, which set is_vf before adf_devmgr_add_dev() and keep it set until adf_devmgr_rm_dev().
--- drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 8 ++++++++ drivers/crypto/intel/qat/qat_common/adf_vf_isr.c | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c +8 -0
@@ -138,6 +138,12 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,mutex_lock (&table_lock);atomic_set (&accel_dev->ref_count,0 );mutex_init (&accel_dev->state_lock); +/* +* The VF2PF lock is used to send messages to the PF outside of the +* device up/down cycle, so it must live as long as the accel device. +*/ +if (accel_dev->is_vf) +mutex_init (&accel_dev->vf.vf2pf_lock);/* PF on host or VF on guest - optimized to remove redundant is_vf */ if (!accel_dev->is_vf || !pf) {
@@ -257,6 +263,8 @@ void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev, } } unlock: +if (accel_dev->is_vf) +mutex_destroy (&accel_dev->vf.vf2pf_lock);mutex_destroy (&accel_dev->state_lock);list_del (&accel_dev->list);mutex_unlock (&table_lock);
drivers/crypto/intel/qat/qat_common/adf_vf_isr.c +0 -2
@@ -118,7 +118,6 @@ static int adf_setup_pf2vf_bh(struct adf_accel_dev *accel_dev)tasklet_init (&accel_dev->vf.pf2vf_bh_tasklet, (void *)adf_pf2vf_bh_handler, (unsigned long )accel_dev); -mutex_init (&accel_dev->vf.vf2pf_lock);return 0 ; }
@@ -126,7 +125,6 @@ static void adf_cleanup_pf2vf_bh(struct adf_accel_dev *accel_dev) {tasklet_disable (&accel_dev->vf.pf2vf_bh_tasklet);tasklet_kill (&accel_dev->vf.pf2vf_bh_tasklet); -mutex_destroy (&accel_dev->vf.vf2pf_lock); }static irqreturn_t adf_isr (int irq,void *privdata)
Signature · 1 line
2.50.1
Herbert Xu
maintainerQuoted 25 lines · Ahsan Atta
Two mutexes used by the QAT driver are initialised or destroyed on paths that do not match their actual lifetime, so with
CONFIG_DEBUG_MUTEXESenabled both are reported on a dh895xcc with 32 host-bound VFs.In summary:
Patch #1:state_lockis initialised at the end ofadf_devmgr_add_dev(), after the early return taken when an id mapping for the VF already exists. Since that mapping outlives the VF, recreating VFs on the same BDF leaves the lock uninitialised whileadf_dev_up()andadf_dev_down()take it. Move the initialisation up so it happens on every path.Patch #2:
vf2pf_lockis destroyed as part of the VF interrupt teardown inadf_dev_down(), butadf_dev_stop_async()sends theRESTARTING_COMPLETEmessage to the PF afterwards and takes that lock, so every PF restart locks a destroyed mutex. The notification cannot be moved earlier, so tie the lock lifetime to the accel device instead, next tostate_lockin adf_devmgr_add_dev()/adf_devmgr_rm_dev().Both patches are fixes for stable.
Ahsan Atta (2):
crypto: qat - initialisestate_lockon every path in
adf_devmgr_add_dev()
crypto: qat - fix use of destroyedvf2pf_lockon VF restart
Quoted 8 lines
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 10 +++++++++- drivers/crypto/intel/qat/qat_common/adf_vf_isr.c | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-)base-commit:
ee0454474a0f1b636dc96217b346e3571878b292Signature · 1 line
2.50.1
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