Skip to content

Commit 982fd1a

Browse files
Zhiqi Songherbertx
authored andcommitted
crypto: hisilicon/hpre - fix dma unmap sequence
Perform DMA unmapping operations before processing data. Otherwise, there may be unsynchronized data accessed by the CPU when the SWIOTLB is enabled. Signed-off-by: Zhiqi Song <[email protected]> Signed-off-by: Chenghai Huang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 301eee1 commit 982fd1a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/crypto/hisilicon/hpre/hpre_crypto.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,11 +1491,13 @@ static void hpre_ecdh_cb(struct hpre_ctx *ctx, void *resp)
14911491
if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
14921492
atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
14931493

1494+
/* Do unmap before data processing */
1495+
hpre_ecdh_hw_data_clr_all(ctx, req, areq->dst, areq->src);
1496+
14941497
p = sg_virt(areq->dst);
14951498
memmove(p, p + ctx->key_sz - curve_sz, curve_sz);
14961499
memmove(p + curve_sz, p + areq->dst_len - curve_sz, curve_sz);
14971500

1498-
hpre_ecdh_hw_data_clr_all(ctx, req, areq->dst, areq->src);
14991501
kpp_request_complete(areq, ret);
15001502

15011503
atomic64_inc(&dfx[HPRE_RECV_CNT].value);
@@ -1808,9 +1810,11 @@ static void hpre_curve25519_cb(struct hpre_ctx *ctx, void *resp)
18081810
if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
18091811
atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
18101812

1813+
/* Do unmap before data processing */
1814+
hpre_curve25519_hw_data_clr_all(ctx, req, areq->dst, areq->src);
1815+
18111816
hpre_key_to_big_end(sg_virt(areq->dst), CURVE25519_KEY_SIZE);
18121817

1813-
hpre_curve25519_hw_data_clr_all(ctx, req, areq->dst, areq->src);
18141818
kpp_request_complete(areq, ret);
18151819

18161820
atomic64_inc(&dfx[HPRE_RECV_CNT].value);

0 commit comments

Comments
 (0)