Skip to content
/ linux Public

Commit 3acd247

Browse files
Chenghai Huanggregkh
authored andcommitted
crypto: hisilicon/qm - centralize the sending locks of each module into qm
[ Upstream commit 8cd9b60 ] When a single queue used by multiple tfms, the protection of shared resources by individual module driver programs is no longer sufficient. The hisi_qp_send needs to be ensured by the lock in qp. Fixes: 5fdb4b3 ("crypto: hisilicon - add a lock for the qp send operation") Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Weili Qian <qianweili@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 23fcfd8 commit 3acd247

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

drivers/crypto/hisilicon/hpre/hpre_crypto.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ struct hpre_ctx {
109109
struct hisi_qp *qp;
110110
struct device *dev;
111111
struct hpre *hpre;
112-
spinlock_t req_lock;
113112
unsigned int key_sz;
114113
bool crt_g2_mode;
115114
union {
@@ -410,7 +409,6 @@ static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type)
410409

411410
qp->qp_ctx = ctx;
412411
qp->req_cb = hpre_alg_cb;
413-
spin_lock_init(&ctx->req_lock);
414412
ctx->qp = qp;
415413
ctx->dev = &qp->qm->pdev->dev;
416414
hpre = container_of(ctx->qp->qm, struct hpre, qm);
@@ -478,9 +476,7 @@ static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
478476

479477
do {
480478
atomic64_inc(&dfx[HPRE_SEND_CNT].value);
481-
spin_lock_bh(&ctx->req_lock);
482479
ret = hisi_qp_send(ctx->qp, msg);
483-
spin_unlock_bh(&ctx->req_lock);
484480
if (ret != -EBUSY)
485481
break;
486482
atomic64_inc(&dfx[HPRE_SEND_BUSY_CNT].value);

drivers/crypto/hisilicon/qm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,26 +2360,33 @@ EXPORT_SYMBOL_GPL(hisi_qm_stop_qp);
23602360
int hisi_qp_send(struct hisi_qp *qp, const void *msg)
23612361
{
23622362
struct hisi_qp_status *qp_status = &qp->qp_status;
2363-
u16 sq_tail = qp_status->sq_tail;
2364-
u16 sq_tail_next = (sq_tail + 1) % qp->sq_depth;
2365-
void *sqe = qm_get_avail_sqe(qp);
2363+
u16 sq_tail, sq_tail_next;
2364+
void *sqe;
23662365

2366+
spin_lock_bh(&qp->qp_lock);
23672367
if (unlikely(atomic_read(&qp->qp_status.flags) == QP_STOP ||
23682368
atomic_read(&qp->qm->status.flags) == QM_STOP ||
23692369
qp->is_resetting)) {
2370+
spin_unlock_bh(&qp->qp_lock);
23702371
dev_info_ratelimited(&qp->qm->pdev->dev, "QP is stopped or resetting\n");
23712372
return -EAGAIN;
23722373
}
23732374

2374-
if (!sqe)
2375+
sqe = qm_get_avail_sqe(qp);
2376+
if (!sqe) {
2377+
spin_unlock_bh(&qp->qp_lock);
23752378
return -EBUSY;
2379+
}
23762380

2381+
sq_tail = qp_status->sq_tail;
2382+
sq_tail_next = (sq_tail + 1) % qp->sq_depth;
23772383
memcpy(sqe, msg, qp->qm->sqe_size);
23782384
qp->msg[sq_tail] = msg;
23792385

23802386
qm_db(qp->qm, qp->qp_id, QM_DOORBELL_CMD_SQ, sq_tail_next, 0);
23812387
atomic_inc(&qp->qp_status.used);
23822388
qp_status->sq_tail = sq_tail_next;
2389+
spin_unlock_bh(&qp->qp_lock);
23832390

23842391
return 0;
23852392
}
@@ -2956,6 +2963,7 @@ static int hisi_qp_memory_init(struct hisi_qm *qm, size_t dma_size, int id,
29562963
qp->qm = qm;
29572964
qp->qp_id = id;
29582965

2966+
spin_lock_init(&qp->qp_lock);
29592967
spin_lock_init(&qp->backlog.lock);
29602968
INIT_LIST_HEAD(&qp->backlog.list);
29612969

drivers/crypto/hisilicon/zip/zip_crypto.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
217217
{
218218
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
219219
struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
220-
struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
221220
struct acomp_req *a_req = req->req;
222221
struct hisi_qp *qp = qp_ctx->qp;
223222
struct device *dev = &qp->qm->pdev->dev;
@@ -250,9 +249,7 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
250249

251250
/* send command to start a task */
252251
atomic64_inc(&dfx->send_cnt);
253-
spin_lock_bh(&req_q->req_lock);
254252
ret = hisi_qp_send(qp, &zip_sqe);
255-
spin_unlock_bh(&req_q->req_lock);
256253
if (unlikely(ret < 0)) {
257254
atomic64_inc(&dfx->send_busy_cnt);
258255
ret = -EAGAIN;

include/linux/hisi_acc_qm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ struct hisi_qp {
473473
u16 pasid;
474474
struct uacce_queue *uacce_q;
475475

476+
spinlock_t qp_lock;
476477
struct instance_backlog backlog;
477478
const void **msg;
478479
};

0 commit comments

Comments
 (0)