From: Chenghai Huang <huangchenghai2@huawei.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
<fanghao11@huawei.com>, <liulongfang@huawei.com>,
<shenyang39@huawei.com>, <songzhiqi1@huawei.com>,
<qianweili@huawei.com>, <linwenkai6@hisilicon.com>,
<taoqi10@huawei.com>, <wangzhou1@hisilicon.com>,
<huangchenghai2@huawei.com>
Subject: [PATCH v2 2/3] crypto: hisilicon - add a lock for the qp send operation
Date: Sat, 31 Aug 2024 17:50:08 +0800 [thread overview]
Message-ID: <20240831095009.446780-3-huangchenghai2@huawei.com> (raw)
In-Reply-To: <20240831095009.446780-1-huangchenghai2@huawei.com>
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 <huangchenghai2@huawei.com>
---
v2:
- Rebased on top of the merged spin_lock type.
---
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 2 ++
drivers/crypto/hisilicon/zip/zip_crypto.c | 3 +++
2 files changed, 5 insertions(+)
diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
index 764532a6ca82..c167dbd6c7d6 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
@@ -575,7 +575,9 @@ static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
do {
atomic64_inc(&dfx[HPRE_SEND_CNT].value);
+ spin_lock_bh(&ctx->req_lock);
ret = hisi_qp_send(ctx->qp, msg);
+ spin_unlock_bh(&ctx->req_lock);
if (ret != -EBUSY)
break;
atomic64_inc(&dfx[HPRE_SEND_BUSY_CNT].value);
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 92d3bd0dfe1b..7327f8f29b01 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -213,6 +213,7 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
{
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
+ struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
struct acomp_req *a_req = req->req;
struct hisi_qp *qp = qp_ctx->qp;
struct device *dev = &qp->qm->pdev->dev;
@@ -244,7 +245,9 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
/* send command to start a task */
atomic64_inc(&dfx->send_cnt);
+ spin_lock_bh(&req_q->req_lock);
ret = hisi_qp_send(qp, &zip_sqe);
+ spin_unlock_bh(&req_q->req_lock);
if (unlikely(ret < 0)) {
atomic64_inc(&dfx->send_busy_cnt);
ret = -EAGAIN;
--
2.33.0
next prev parent reply other threads:[~2024-08-31 9:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-31 9:50 [PATCH v2 0/3] crypto: hisilicon - fix resource contention and abnormal branch processing issues Chenghai Huang
2024-08-31 9:50 ` [PATCH v2 1/3] crypto: hisilicon - fix missed error branch Chenghai Huang
2024-08-31 9:50 ` Chenghai Huang [this message]
2024-08-31 9:50 ` [PATCH v2 3/3] crypto: hisilicon/trng - modifying the order of header files Chenghai Huang
2024-09-06 7:10 ` [PATCH v2 0/3] crypto: hisilicon - fix resource contention and abnormal branch processing issues Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240831095009.446780-3-huangchenghai2@huawei.com \
--to=huangchenghai2@huawei.com \
--cc=davem@davemloft.net \
--cc=fanghao11@huawei.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linwenkai6@hisilicon.com \
--cc=liulongfang@huawei.com \
--cc=qianweili@huawei.com \
--cc=shenyang39@huawei.com \
--cc=songzhiqi1@huawei.com \
--cc=taoqi10@huawei.com \
--cc=wangzhou1@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®