1 From 3ee50c896d712dc2fc8f34c2cd1918d035e74045 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Fri, 20 Dec 2019 16:02:15 -0300
4 Subject: [PATCH 04/11] crypto: qce - save a sg table slot for result buf
6 When ctr-aes-qce is used for gcm-mode, an extra sg entry for the
7 authentication tag is present, causing trouble when the qce driver
8 prepares the dst-results sg table for dma.
10 It computes the number of entries needed with sg_nents_for_len, leaving
11 out the tag entry. Then it creates a sg table with that number plus
12 one, used to store a result buffer.
14 When copying the sg table, there's no limit to the number of entries
15 copied, so the extra slot is filled with the authentication tag sg.
16 When the driver tries to add the result sg, the list is full, and it
19 By limiting the number of sg entries copied to the dest table, the slot
20 for the result buffer is guaranteed to be unused.
22 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
23 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
25 drivers/crypto/qce/dma.c | 6 ++++--
26 drivers/crypto/qce/dma.h | 3 ++-
27 drivers/crypto/qce/skcipher.c | 4 ++--
28 3 files changed, 8 insertions(+), 5 deletions(-)
30 --- a/drivers/crypto/qce/dma.c
31 +++ b/drivers/crypto/qce/dma.c
32 @@ -47,7 +47,8 @@ void qce_dma_release(struct qce_dma_data
36 -qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl)
37 +qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl,
40 struct scatterlist *sg = sgt->sgl, *sg_last = NULL;
42 @@ -60,12 +61,13 @@ qce_sgtable_add(struct sg_table *sgt, st
44 return ERR_PTR(-EINVAL);
46 - while (new_sgl && sg) {
47 + while (new_sgl && sg && max_ents) {
48 sg_set_page(sg, sg_page(new_sgl), new_sgl->length,
52 new_sgl = sg_next(new_sgl);
57 --- a/drivers/crypto/qce/dma.h
58 +++ b/drivers/crypto/qce/dma.h
59 @@ -42,6 +42,7 @@ int qce_dma_prep_sgs(struct qce_dma_data
60 void qce_dma_issue_pending(struct qce_dma_data *dma);
61 int qce_dma_terminate_all(struct qce_dma_data *dma);
63 -qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add);
64 +qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add,
68 --- a/drivers/crypto/qce/skcipher.c
69 +++ b/drivers/crypto/qce/skcipher.c
70 @@ -95,13 +95,13 @@ qce_skcipher_async_req_handle(struct cry
72 sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
74 - sg = qce_sgtable_add(&rctx->dst_tbl, req->dst);
75 + sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, rctx->dst_nents - 1);
81 - sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg);
82 + sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg, 1);