Skip to content

Commit 0a55f4e

Browse files
committed
crypto: octeontx - 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 <herbert@gondor.apana.org.au>
1 parent be75969 commit 0a55f4e

1 file changed

Lines changed: 35 additions & 34 deletions

File tree

drivers/crypto/marvell/octeontx/otx_cptvf_algs.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static inline int validate_hmac_cipher_null(struct otx_cpt_req_info *cpt_req)
103103

104104
req = container_of(cpt_req->areq, struct aead_request, base);
105105
tfm = crypto_aead_reqtfm(req);
106-
rctx = aead_request_ctx(req);
106+
rctx = aead_request_ctx_dma(req);
107107
if (memcmp(rctx->fctx.hmac.s.hmac_calc,
108108
rctx->fctx.hmac.s.hmac_recv,
109109
crypto_aead_authsize(tfm)) != 0)
@@ -155,7 +155,7 @@ static void output_iv_copyback(struct crypto_async_request *areq)
155155
ctx = crypto_skcipher_ctx(stfm);
156156
if (ctx->cipher_type == OTX_CPT_AES_CBC ||
157157
ctx->cipher_type == OTX_CPT_DES3_CBC) {
158-
rctx = skcipher_request_ctx(sreq);
158+
rctx = skcipher_request_ctx_dma(sreq);
159159
req_info = &rctx->cpt_req;
160160
ivsize = crypto_skcipher_ivsize(stfm);
161161
start = sreq->cryptlen - ivsize;
@@ -233,7 +233,7 @@ static inline u32 create_ctx_hdr(struct skcipher_request *req, u32 enc,
233233
u32 *argcnt)
234234
{
235235
struct crypto_skcipher *stfm = crypto_skcipher_reqtfm(req);
236-
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx(req);
236+
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx_dma(req);
237237
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
238238
struct crypto_tfm *tfm = crypto_skcipher_tfm(stfm);
239239
struct otx_cpt_enc_ctx *ctx = crypto_tfm_ctx(tfm);
@@ -303,7 +303,7 @@ static inline u32 create_ctx_hdr(struct skcipher_request *req, u32 enc,
303303
static inline u32 create_input_list(struct skcipher_request *req, u32 enc,
304304
u32 enc_iv_len)
305305
{
306-
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx(req);
306+
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx_dma(req);
307307
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
308308
u32 argcnt = 0;
309309
int ret;
@@ -321,7 +321,7 @@ static inline u32 create_input_list(struct skcipher_request *req, u32 enc,
321321
static inline void create_output_list(struct skcipher_request *req,
322322
u32 enc_iv_len)
323323
{
324-
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx(req);
324+
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx_dma(req);
325325
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
326326
u32 argcnt = 0;
327327

@@ -340,7 +340,7 @@ static inline void create_output_list(struct skcipher_request *req,
340340
static inline int cpt_enc_dec(struct skcipher_request *req, u32 enc)
341341
{
342342
struct crypto_skcipher *stfm = crypto_skcipher_reqtfm(req);
343-
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx(req);
343+
struct otx_cpt_req_ctx *rctx = skcipher_request_ctx_dma(req);
344344
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
345345
u32 enc_iv_len = crypto_skcipher_ivsize(stfm);
346346
struct pci_dev *pdev;
@@ -501,15 +501,16 @@ static int otx_cpt_enc_dec_init(struct crypto_skcipher *tfm)
501501
* allocated since the cryptd daemon uses
502502
* this memory for request_ctx information
503503
*/
504-
crypto_skcipher_set_reqsize(tfm, sizeof(struct otx_cpt_req_ctx) +
505-
sizeof(struct skcipher_request));
504+
crypto_skcipher_set_reqsize_dma(
505+
tfm, sizeof(struct otx_cpt_req_ctx) +
506+
sizeof(struct skcipher_request));
506507

507508
return 0;
508509
}
509510

510511
static int cpt_aead_init(struct crypto_aead *tfm, u8 cipher_type, u8 mac_type)
511512
{
512-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(tfm);
513+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(tfm);
513514

514515
ctx->cipher_type = cipher_type;
515516
ctx->mac_type = mac_type;
@@ -551,7 +552,7 @@ static int cpt_aead_init(struct crypto_aead *tfm, u8 cipher_type, u8 mac_type)
551552
}
552553
}
553554

554-
crypto_aead_set_reqsize(tfm, sizeof(struct otx_cpt_req_ctx));
555+
crypto_aead_set_reqsize_dma(tfm, sizeof(struct otx_cpt_req_ctx));
555556

556557
return 0;
557558
}
@@ -603,7 +604,7 @@ static int otx_cpt_aead_gcm_aes_init(struct crypto_aead *tfm)
603604

604605
static void otx_cpt_aead_exit(struct crypto_aead *tfm)
605606
{
606-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(tfm);
607+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(tfm);
607608

608609
kfree(ctx->ipad);
609610
kfree(ctx->opad);
@@ -619,7 +620,7 @@ static void otx_cpt_aead_exit(struct crypto_aead *tfm)
619620
static int otx_cpt_aead_set_authsize(struct crypto_aead *tfm,
620621
unsigned int authsize)
621622
{
622-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(tfm);
623+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(tfm);
623624

624625
switch (ctx->mac_type) {
625626
case OTX_CPT_SHA1:
@@ -739,7 +740,7 @@ static int copy_pad(u8 mac_type, u8 *out_pad, u8 *in_pad)
739740

740741
static int aead_hmac_init(struct crypto_aead *cipher)
741742
{
742-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(cipher);
743+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(cipher);
743744
int state_size = crypto_shash_statesize(ctx->hashalg);
744745
int ds = crypto_shash_digestsize(ctx->hashalg);
745746
int bs = crypto_shash_blocksize(ctx->hashalg);
@@ -837,7 +838,7 @@ static int otx_cpt_aead_cbc_aes_sha_setkey(struct crypto_aead *cipher,
837838
const unsigned char *key,
838839
unsigned int keylen)
839840
{
840-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(cipher);
841+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(cipher);
841842
struct crypto_authenc_key_param *param;
842843
int enckeylen = 0, authkeylen = 0;
843844
struct rtattr *rta = (void *)key;
@@ -896,7 +897,7 @@ static int otx_cpt_aead_ecb_null_sha_setkey(struct crypto_aead *cipher,
896897
const unsigned char *key,
897898
unsigned int keylen)
898899
{
899-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(cipher);
900+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(cipher);
900901
struct crypto_authenc_key_param *param;
901902
struct rtattr *rta = (void *)key;
902903
int enckeylen = 0;
@@ -932,7 +933,7 @@ static int otx_cpt_aead_gcm_aes_setkey(struct crypto_aead *cipher,
932933
const unsigned char *key,
933934
unsigned int keylen)
934935
{
935-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(cipher);
936+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(cipher);
936937

937938
/*
938939
* For aes gcm we expect to get encryption key (16, 24, 32 bytes)
@@ -965,9 +966,9 @@ static int otx_cpt_aead_gcm_aes_setkey(struct crypto_aead *cipher,
965966
static inline u32 create_aead_ctx_hdr(struct aead_request *req, u32 enc,
966967
u32 *argcnt)
967968
{
968-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
969+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
969970
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
970-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(tfm);
971+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(tfm);
971972
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
972973
struct otx_cpt_fc_ctx *fctx = &rctx->fctx;
973974
int mac_len = crypto_aead_authsize(tfm);
@@ -1050,9 +1051,9 @@ static inline u32 create_aead_ctx_hdr(struct aead_request *req, u32 enc,
10501051
static inline u32 create_hmac_ctx_hdr(struct aead_request *req, u32 *argcnt,
10511052
u32 enc)
10521053
{
1053-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1054+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
10541055
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1055-
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx(tfm);
1056+
struct otx_cpt_aead_ctx *ctx = crypto_aead_ctx_dma(tfm);
10561057
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
10571058

10581059
req_info->ctrl.s.dma_mode = OTX_CPT_DMA_GATHER_SCATTER;
@@ -1076,7 +1077,7 @@ static inline u32 create_hmac_ctx_hdr(struct aead_request *req, u32 *argcnt,
10761077

10771078
static inline u32 create_aead_input_list(struct aead_request *req, u32 enc)
10781079
{
1079-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1080+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
10801081
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
10811082
u32 inputlen = req->cryptlen + req->assoclen;
10821083
u32 status, argcnt = 0;
@@ -1093,7 +1094,7 @@ static inline u32 create_aead_input_list(struct aead_request *req, u32 enc)
10931094
static inline u32 create_aead_output_list(struct aead_request *req, u32 enc,
10941095
u32 mac_len)
10951096
{
1096-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1097+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
10971098
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
10981099
u32 argcnt = 0, outputlen = 0;
10991100

@@ -1111,7 +1112,7 @@ static inline u32 create_aead_output_list(struct aead_request *req, u32 enc,
11111112
static inline u32 create_aead_null_input_list(struct aead_request *req,
11121113
u32 enc, u32 mac_len)
11131114
{
1114-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1115+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
11151116
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
11161117
u32 inputlen, argcnt = 0;
11171118

@@ -1130,7 +1131,7 @@ static inline u32 create_aead_null_input_list(struct aead_request *req,
11301131
static inline u32 create_aead_null_output_list(struct aead_request *req,
11311132
u32 enc, u32 mac_len)
11321133
{
1133-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1134+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
11341135
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
11351136
struct scatterlist *dst;
11361137
u8 *ptr = NULL;
@@ -1217,7 +1218,7 @@ static inline u32 create_aead_null_output_list(struct aead_request *req,
12171218

12181219
static u32 cpt_aead_enc_dec(struct aead_request *req, u8 reg_type, u8 enc)
12191220
{
1220-
struct otx_cpt_req_ctx *rctx = aead_request_ctx(req);
1221+
struct otx_cpt_req_ctx *rctx = aead_request_ctx_dma(req);
12211222
struct otx_cpt_req_info *req_info = &rctx->cpt_req;
12221223
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
12231224
struct pci_dev *pdev;
@@ -1409,7 +1410,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
14091410
.cra_driver_name = "cpt_hmac_sha1_cbc_aes",
14101411
.cra_blocksize = AES_BLOCK_SIZE,
14111412
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1412-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1413+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
14131414
.cra_priority = 4001,
14141415
.cra_alignmask = 0,
14151416
.cra_module = THIS_MODULE,
@@ -1428,7 +1429,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
14281429
.cra_driver_name = "cpt_hmac_sha256_cbc_aes",
14291430
.cra_blocksize = AES_BLOCK_SIZE,
14301431
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1431-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1432+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
14321433
.cra_priority = 4001,
14331434
.cra_alignmask = 0,
14341435
.cra_module = THIS_MODULE,
@@ -1447,7 +1448,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
14471448
.cra_driver_name = "cpt_hmac_sha384_cbc_aes",
14481449
.cra_blocksize = AES_BLOCK_SIZE,
14491450
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1450-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1451+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
14511452
.cra_priority = 4001,
14521453
.cra_alignmask = 0,
14531454
.cra_module = THIS_MODULE,
@@ -1466,7 +1467,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
14661467
.cra_driver_name = "cpt_hmac_sha512_cbc_aes",
14671468
.cra_blocksize = AES_BLOCK_SIZE,
14681469
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1469-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1470+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
14701471
.cra_priority = 4001,
14711472
.cra_alignmask = 0,
14721473
.cra_module = THIS_MODULE,
@@ -1485,7 +1486,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
14851486
.cra_driver_name = "cpt_hmac_sha1_ecb_null",
14861487
.cra_blocksize = 1,
14871488
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1488-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1489+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
14891490
.cra_priority = 4001,
14901491
.cra_alignmask = 0,
14911492
.cra_module = THIS_MODULE,
@@ -1504,7 +1505,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
15041505
.cra_driver_name = "cpt_hmac_sha256_ecb_null",
15051506
.cra_blocksize = 1,
15061507
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1507-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1508+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
15081509
.cra_priority = 4001,
15091510
.cra_alignmask = 0,
15101511
.cra_module = THIS_MODULE,
@@ -1523,7 +1524,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
15231524
.cra_driver_name = "cpt_hmac_sha384_ecb_null",
15241525
.cra_blocksize = 1,
15251526
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1526-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1527+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
15271528
.cra_priority = 4001,
15281529
.cra_alignmask = 0,
15291530
.cra_module = THIS_MODULE,
@@ -1542,7 +1543,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
15421543
.cra_driver_name = "cpt_hmac_sha512_ecb_null",
15431544
.cra_blocksize = 1,
15441545
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1545-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1546+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
15461547
.cra_priority = 4001,
15471548
.cra_alignmask = 0,
15481549
.cra_module = THIS_MODULE,
@@ -1561,7 +1562,7 @@ static struct aead_alg otx_cpt_aeads[] = { {
15611562
.cra_driver_name = "cpt_rfc4106_gcm_aes",
15621563
.cra_blocksize = 1,
15631564
.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
1564-
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx),
1565+
.cra_ctxsize = sizeof(struct otx_cpt_aead_ctx) + CRYPTO_DMA_PADDING,
15651566
.cra_priority = 4001,
15661567
.cra_alignmask = 0,
15671568
.cra_module = THIS_MODULE,

0 commit comments

Comments
 (0)