WSL2-Linux-Kernel/drivers/crypto/qat
Giovanni Cabiddu a2ae48bd82 crypto: qat - fix deadlock in backlog processing
[ Upstream commit 203b01001c4d741205b9c329acddc5193ed56fbd ]

If a request has the flag CRYPTO_TFM_REQ_MAY_BACKLOG set, the function
qat_alg_send_message_maybacklog(), enqueues it in a backlog list if
either (1) there is already at least one request in the backlog list, or
(2) the HW ring is nearly full or (3) the enqueue to the HW ring fails.
If an interrupt occurs right before the lock in qat_alg_backlog_req() is
taken and the backlog queue is being emptied, then there is no request
in the HW queues that can trigger a subsequent interrupt that can clear
the backlog queue. In addition subsequent requests are enqueued to the
backlog list and not sent to the hardware.

Fix it by holding the lock while taking the decision if the request
needs to be included in the backlog queue or not. This synchronizes the
flow with the interrupt handler that drains the backlog queue.

For performance reasons, the logic has been changed to try to enqueue
first without holding the lock.

Fixes: 3868238397 ("crypto: qat - add backlog mechanism")
Reported-by: Mikulas Patocka <mpatocka@redhat.com>
Closes: https://lore.kernel.org/all/af9581e2-58f9-cc19-428f-6f18f1f83d54@redhat.com/T/
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:08:24 +01:00
..
qat_4xxx crypto: qat - re-enable registration of algorithms 2022-07-29 17:25:28 +02:00
qat_c3xxx crypto: qat - remove the unnecessary get_vintmsk_offset() 2021-08-21 15:44:56 +08:00
qat_c3xxxvf crypto: qat - flush vf workqueue at driver removal 2021-08-21 15:44:56 +08:00
qat_c62x crypto: qat - remove the unnecessary get_vintmsk_offset() 2021-08-21 15:44:56 +08:00
qat_c62xvf crypto: qat - flush vf workqueue at driver removal 2021-08-21 15:44:56 +08:00
qat_common crypto: qat - fix deadlock in backlog processing 2023-11-20 11:08:24 +01:00
qat_dh895xcc crypto: qat - set COMPRESSION capability for DH895XCC 2022-06-09 10:23:05 +02:00
qat_dh895xccvf crypto: qat - flush vf workqueue at driver removal 2021-08-21 15:44:56 +08:00
Kconfig crypto: qat - replace CRYPTO_AES with CRYPTO_LIB_AES in Kconfig 2021-01-14 17:10:25 +11:00
Makefile crypto: qat - add qat_4xxx driver 2020-11-20 14:45:34 +11:00