Skip to content

Commit 5fdb4b3

Browse files
Chenghai Huangherbertx
authored andcommitted
crypto: hisilicon - add a lock for the qp send operation
Apply for a lock before the qp send operation to ensure no resource race in multi-concurrency situations. This modification has almost no impact on performance. Signed-off-by: Chenghai Huang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f386dc6 commit 5fdb4b3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

drivers/crypto/hisilicon/hpre/hpre_crypto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
575575

576576
do {
577577
atomic64_inc(&dfx[HPRE_SEND_CNT].value);
578+
spin_lock_bh(&ctx->req_lock);
578579
ret = hisi_qp_send(ctx->qp, msg);
580+
spin_unlock_bh(&ctx->req_lock);
579581
if (ret != -EBUSY)
580582
break;
581583
atomic64_inc(&dfx[HPRE_SEND_BUSY_CNT].value);

drivers/crypto/hisilicon/zip/zip_crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
213213
{
214214
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
215215
struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
216+
struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
216217
struct acomp_req *a_req = req->req;
217218
struct hisi_qp *qp = qp_ctx->qp;
218219
struct device *dev = &qp->qm->pdev->dev;
@@ -244,7 +245,9 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
244245

245246
/* send command to start a task */
246247
atomic64_inc(&dfx->send_cnt);
248+
spin_lock_bh(&req_q->req_lock);
247249
ret = hisi_qp_send(qp, &zip_sqe);
250+
spin_unlock_bh(&req_q->req_lock);
248251
if (unlikely(ret < 0)) {
249252
atomic64_inc(&dfx->send_busy_cnt);
250253
ret = -EAGAIN;

0 commit comments

Comments
 (0)