Skip to content

Commit 18daae5

Browse files
committed
crypto: qce - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment to be sufficient for DMA. This may no longer be the case with upcoming arm64 changes. This patch changes it to explicitly request DMA alignment from the Crypto API. Signed-off-by: Herbert Xu <[email protected]>
1 parent d887dec commit 18daae5

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

drivers/crypto/qce/aead.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void qce_aead_done(void *data)
2424
{
2525
struct crypto_async_request *async_req = data;
2626
struct aead_request *req = aead_request_cast(async_req);
27-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
27+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
2828
struct qce_aead_ctx *ctx = crypto_tfm_ctx(async_req->tfm);
2929
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
3030
struct qce_device *qce = tmpl->qce;
@@ -92,7 +92,7 @@ static void qce_aead_done(void *data)
9292
static struct scatterlist *
9393
qce_aead_prepare_result_buf(struct sg_table *tbl, struct aead_request *req)
9494
{
95-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
95+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
9696
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
9797
struct qce_device *qce = tmpl->qce;
9898

@@ -103,7 +103,7 @@ qce_aead_prepare_result_buf(struct sg_table *tbl, struct aead_request *req)
103103
static struct scatterlist *
104104
qce_aead_prepare_ccm_result_buf(struct sg_table *tbl, struct aead_request *req)
105105
{
106-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
106+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
107107

108108
sg_init_one(&rctx->result_sg, rctx->ccmresult_buf, QCE_BAM_BURST_SIZE);
109109
return qce_sgtable_add(tbl, &rctx->result_sg, QCE_BAM_BURST_SIZE);
@@ -112,7 +112,7 @@ qce_aead_prepare_ccm_result_buf(struct sg_table *tbl, struct aead_request *req)
112112
static struct scatterlist *
113113
qce_aead_prepare_dst_buf(struct aead_request *req)
114114
{
115-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
115+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
116116
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
117117
struct qce_device *qce = tmpl->qce;
118118
struct scatterlist *sg, *msg_sg, __sg[2];
@@ -186,7 +186,7 @@ qce_aead_ccm_prepare_buf_assoclen(struct aead_request *req)
186186
{
187187
struct scatterlist *sg, *msg_sg, __sg[2];
188188
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
189-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
189+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
190190
struct qce_aead_ctx *ctx = crypto_aead_ctx(tfm);
191191
unsigned int assoclen = rctx->assoclen;
192192
unsigned int adata_header_len, cryptlen, totallen;
@@ -300,7 +300,7 @@ qce_aead_ccm_prepare_buf_assoclen(struct aead_request *req)
300300

301301
static int qce_aead_prepare_buf(struct aead_request *req)
302302
{
303-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
303+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
304304
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
305305
struct qce_device *qce = tmpl->qce;
306306
struct scatterlist *sg;
@@ -328,7 +328,7 @@ static int qce_aead_prepare_buf(struct aead_request *req)
328328

329329
static int qce_aead_ccm_prepare_buf(struct aead_request *req)
330330
{
331-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
331+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
332332
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
333333
struct qce_aead_ctx *ctx = crypto_aead_ctx(tfm);
334334
struct scatterlist *sg;
@@ -408,7 +408,7 @@ static int
408408
qce_aead_async_req_handle(struct crypto_async_request *async_req)
409409
{
410410
struct aead_request *req = aead_request_cast(async_req);
411-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
411+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
412412
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
413413
struct qce_aead_ctx *ctx = crypto_tfm_ctx(async_req->tfm);
414414
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
@@ -502,7 +502,7 @@ qce_aead_async_req_handle(struct crypto_async_request *async_req)
502502
static int qce_aead_crypt(struct aead_request *req, int encrypt)
503503
{
504504
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
505-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
505+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
506506
struct qce_aead_ctx *ctx = crypto_aead_ctx(tfm);
507507
struct qce_alg_template *tmpl = to_aead_tmpl(tfm);
508508
unsigned int blocksize = crypto_aead_blocksize(tfm);
@@ -675,8 +675,8 @@ static int qce_aead_init(struct crypto_aead *tfm)
675675
if (IS_ERR(ctx->fallback))
676676
return PTR_ERR(ctx->fallback);
677677

678-
crypto_aead_set_reqsize(tfm, sizeof(struct qce_aead_reqctx) +
679-
crypto_aead_reqsize(ctx->fallback));
678+
crypto_aead_set_reqsize_dma(tfm, sizeof(struct qce_aead_reqctx) +
679+
crypto_aead_reqsize(ctx->fallback));
680680
return 0;
681681
}
682682

drivers/crypto/qce/common.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
44
*/
55

6+
#include <crypto/internal/hash.h>
67
#include <linux/err.h>
78
#include <linux/interrupt.h>
89
#include <linux/types.h>
@@ -147,7 +148,7 @@ static int qce_setup_regs_ahash(struct crypto_async_request *async_req)
147148
{
148149
struct ahash_request *req = ahash_request_cast(async_req);
149150
struct crypto_ahash *ahash = __crypto_ahash_cast(async_req->tfm);
150-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
151+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
151152
struct qce_alg_template *tmpl = to_ahash_tmpl(async_req->tfm);
152153
struct qce_device *qce = tmpl->qce;
153154
unsigned int digestsize = crypto_ahash_digestsize(ahash);
@@ -419,7 +420,7 @@ static unsigned int qce_be32_to_cpu_array(u32 *dst, const u8 *src, unsigned int
419420
static int qce_setup_regs_aead(struct crypto_async_request *async_req)
420421
{
421422
struct aead_request *req = aead_request_cast(async_req);
422-
struct qce_aead_reqctx *rctx = aead_request_ctx(req);
423+
struct qce_aead_reqctx *rctx = aead_request_ctx_dma(req);
423424
struct qce_aead_ctx *ctx = crypto_tfm_ctx(async_req->tfm);
424425
struct qce_alg_template *tmpl = to_aead_tmpl(crypto_aead_reqtfm(req));
425426
struct qce_device *qce = tmpl->qce;

drivers/crypto/qce/sha.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void qce_ahash_done(void *data)
3838
struct crypto_async_request *async_req = data;
3939
struct ahash_request *req = ahash_request_cast(async_req);
4040
struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
41-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
41+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
4242
struct qce_alg_template *tmpl = to_ahash_tmpl(async_req->tfm);
4343
struct qce_device *qce = tmpl->qce;
4444
struct qce_result_dump *result = qce->dma.result_buf;
@@ -75,7 +75,7 @@ static void qce_ahash_done(void *data)
7575
static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
7676
{
7777
struct ahash_request *req = ahash_request_cast(async_req);
78-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
78+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
7979
struct qce_sha_ctx *ctx = crypto_tfm_ctx(async_req->tfm);
8080
struct qce_alg_template *tmpl = to_ahash_tmpl(async_req->tfm);
8181
struct qce_device *qce = tmpl->qce;
@@ -132,7 +132,7 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
132132

133133
static int qce_ahash_init(struct ahash_request *req)
134134
{
135-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
135+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
136136
struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
137137
const u32 *std_iv = tmpl->std_iv;
138138

@@ -147,7 +147,7 @@ static int qce_ahash_init(struct ahash_request *req)
147147

148148
static int qce_ahash_export(struct ahash_request *req, void *out)
149149
{
150-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
150+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
151151
struct qce_sha_saved_state *export_state = out;
152152

153153
memcpy(export_state->pending_buf, rctx->buf, rctx->buflen);
@@ -164,7 +164,7 @@ static int qce_ahash_export(struct ahash_request *req, void *out)
164164

165165
static int qce_ahash_import(struct ahash_request *req, const void *in)
166166
{
167-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
167+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
168168
const struct qce_sha_saved_state *import_state = in;
169169

170170
memset(rctx, 0, sizeof(*rctx));
@@ -183,7 +183,7 @@ static int qce_ahash_import(struct ahash_request *req, const void *in)
183183
static int qce_ahash_update(struct ahash_request *req)
184184
{
185185
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
186-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
186+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
187187
struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
188188
struct qce_device *qce = tmpl->qce;
189189
struct scatterlist *sg_last, *sg;
@@ -275,7 +275,7 @@ static int qce_ahash_update(struct ahash_request *req)
275275

276276
static int qce_ahash_final(struct ahash_request *req)
277277
{
278-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
278+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
279279
struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
280280
struct qce_device *qce = tmpl->qce;
281281

@@ -302,7 +302,7 @@ static int qce_ahash_final(struct ahash_request *req)
302302

303303
static int qce_ahash_digest(struct ahash_request *req)
304304
{
305-
struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
305+
struct qce_sha_reqctx *rctx = ahash_request_ctx_dma(req);
306306
struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
307307
struct qce_device *qce = tmpl->qce;
308308
int ret;
@@ -395,7 +395,7 @@ static int qce_ahash_cra_init(struct crypto_tfm *tfm)
395395
struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
396396
struct qce_sha_ctx *ctx = crypto_tfm_ctx(tfm);
397397

398-
crypto_ahash_set_reqsize(ahash, sizeof(struct qce_sha_reqctx));
398+
crypto_ahash_set_reqsize_dma(ahash, sizeof(struct qce_sha_reqctx));
399399
memset(ctx, 0, sizeof(*ctx));
400400
return 0;
401401
}

0 commit comments

Comments
 (0)