Skip to content

Commit 07547fa

Browse files
committed
crypto: ccree - 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 99c6b20 commit 07547fa

3 files changed

Lines changed: 83 additions & 83 deletions

File tree

drivers/crypto/ccree/cc_aead.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int cc_aead_init(struct crypto_aead *tfm)
138138
ctx->flow_mode = cc_alg->flow_mode;
139139
ctx->auth_mode = cc_alg->auth_mode;
140140
ctx->drvdata = cc_alg->drvdata;
141-
crypto_aead_set_reqsize(tfm, sizeof(struct aead_req_ctx));
141+
crypto_aead_set_reqsize_dma(tfm, sizeof(struct aead_req_ctx));
142142

143143
/* Allocate key buffer, cache line aligned */
144144
ctx->enckey = dma_alloc_coherent(dev, AES_MAX_KEY_SIZE,
@@ -208,7 +208,7 @@ static int cc_aead_init(struct crypto_aead *tfm)
208208
static void cc_aead_complete(struct device *dev, void *cc_req, int err)
209209
{
210210
struct aead_request *areq = (struct aead_request *)cc_req;
211-
struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
211+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(areq);
212212
struct crypto_aead *tfm = crypto_aead_reqtfm(cc_req);
213213
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
214214

@@ -723,7 +723,7 @@ static void cc_set_assoc_desc(struct aead_request *areq, unsigned int flow_mode,
723723
{
724724
struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
725725
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
726-
struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
726+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(areq);
727727
enum cc_req_dma_buf_type assoc_dma_type = areq_ctx->assoc_buff_type;
728728
unsigned int idx = *seq_size;
729729
struct device *dev = drvdata_to_dev(ctx->drvdata);
@@ -762,7 +762,7 @@ static void cc_proc_authen_desc(struct aead_request *areq,
762762
struct cc_hw_desc desc[],
763763
unsigned int *seq_size, int direct)
764764
{
765-
struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
765+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(areq);
766766
enum cc_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type;
767767
unsigned int idx = *seq_size;
768768
struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
@@ -827,7 +827,7 @@ static void cc_proc_cipher_desc(struct aead_request *areq,
827827
unsigned int *seq_size)
828828
{
829829
unsigned int idx = *seq_size;
830-
struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
830+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(areq);
831831
enum cc_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type;
832832
struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
833833
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
@@ -873,7 +873,7 @@ static void cc_proc_digest_desc(struct aead_request *req,
873873
{
874874
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
875875
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
876-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
876+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
877877
unsigned int idx = *seq_size;
878878
unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ?
879879
DRV_HASH_HW_SHA1 : DRV_HASH_HW_SHA256;
@@ -923,7 +923,7 @@ static void cc_set_cipher_desc(struct aead_request *req,
923923
{
924924
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
925925
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
926-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
926+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
927927
unsigned int hw_iv_size = req_ctx->hw_iv_size;
928928
unsigned int idx = *seq_size;
929929
int direct = req_ctx->gen_ctx.op_type;
@@ -965,7 +965,7 @@ static void cc_set_cipher_desc(struct aead_request *req,
965965
static void cc_proc_cipher(struct aead_request *req, struct cc_hw_desc desc[],
966966
unsigned int *seq_size, unsigned int data_flow_mode)
967967
{
968-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
968+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
969969
int direct = req_ctx->gen_ctx.op_type;
970970
unsigned int idx = *seq_size;
971971

@@ -1082,7 +1082,7 @@ static void cc_proc_header_desc(struct aead_request *req,
10821082
struct cc_hw_desc desc[],
10831083
unsigned int *seq_size)
10841084
{
1085-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1085+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
10861086
unsigned int idx = *seq_size;
10871087

10881088
/* Hash associated data */
@@ -1158,7 +1158,7 @@ static void cc_proc_scheme_desc(struct aead_request *req,
11581158
static void cc_mlli_to_sram(struct aead_request *req,
11591159
struct cc_hw_desc desc[], unsigned int *seq_size)
11601160
{
1161-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1161+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
11621162
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
11631163
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
11641164
struct device *dev = drvdata_to_dev(ctx->drvdata);
@@ -1212,7 +1212,7 @@ static void cc_hmac_authenc(struct aead_request *req, struct cc_hw_desc desc[],
12121212
{
12131213
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
12141214
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1215-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1215+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
12161216
int direct = req_ctx->gen_ctx.op_type;
12171217
unsigned int data_flow_mode =
12181218
cc_get_data_flow(direct, ctx->flow_mode,
@@ -1265,7 +1265,7 @@ cc_xcbc_authenc(struct aead_request *req, struct cc_hw_desc desc[],
12651265
{
12661266
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
12671267
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1268-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1268+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
12691269
int direct = req_ctx->gen_ctx.op_type;
12701270
unsigned int data_flow_mode =
12711271
cc_get_data_flow(direct, ctx->flow_mode,
@@ -1312,7 +1312,7 @@ static int validate_data_size(struct cc_aead_ctx *ctx,
13121312
enum drv_crypto_direction direct,
13131313
struct aead_request *req)
13141314
{
1315-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1315+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
13161316
struct device *dev = drvdata_to_dev(ctx->drvdata);
13171317
unsigned int assoclen = areq_ctx->assoclen;
13181318
unsigned int cipherlen = (direct == DRV_CRYPTO_DIRECTION_DECRYPT) ?
@@ -1411,7 +1411,7 @@ static int cc_ccm(struct aead_request *req, struct cc_hw_desc desc[],
14111411
{
14121412
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
14131413
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1414-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1414+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
14151415
unsigned int idx = *seq_size;
14161416
unsigned int cipher_flow_mode;
14171417
dma_addr_t mac_result;
@@ -1533,7 +1533,7 @@ static int config_ccm_adata(struct aead_request *req)
15331533
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
15341534
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
15351535
struct device *dev = drvdata_to_dev(ctx->drvdata);
1536-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1536+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
15371537
//unsigned int size_of_a = 0, rem_a_size = 0;
15381538
unsigned int lp = req->iv[0];
15391539
/* Note: The code assume that req->iv[0] already contains the value
@@ -1591,7 +1591,7 @@ static void cc_proc_rfc4309_ccm(struct aead_request *req)
15911591
{
15921592
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
15931593
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1594-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1594+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
15951595

15961596
/* L' */
15971597
memset(areq_ctx->ctr_iv, 0, AES_BLOCK_SIZE);
@@ -1615,7 +1615,7 @@ static void cc_set_ghash_desc(struct aead_request *req,
16151615
{
16161616
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
16171617
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1618-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1618+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
16191619
unsigned int idx = *seq_size;
16201620

16211621
/* load key to AES*/
@@ -1693,7 +1693,7 @@ static void cc_set_gctr_desc(struct aead_request *req, struct cc_hw_desc desc[],
16931693
{
16941694
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
16951695
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1696-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1696+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
16971697
unsigned int idx = *seq_size;
16981698

16991699
/* load key to AES*/
@@ -1730,7 +1730,7 @@ static void cc_proc_gcm_result(struct aead_request *req,
17301730
{
17311731
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
17321732
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1733-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1733+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
17341734
dma_addr_t mac_result;
17351735
unsigned int idx = *seq_size;
17361736

@@ -1792,7 +1792,7 @@ static void cc_proc_gcm_result(struct aead_request *req,
17921792
static int cc_gcm(struct aead_request *req, struct cc_hw_desc desc[],
17931793
unsigned int *seq_size)
17941794
{
1795-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1795+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
17961796
unsigned int cipher_flow_mode;
17971797

17981798
//in RFC4543 no data to encrypt. just copy data from src to dest.
@@ -1830,7 +1830,7 @@ static int config_gcm_context(struct aead_request *req)
18301830
{
18311831
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
18321832
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1833-
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1833+
struct aead_req_ctx *req_ctx = aead_request_ctx_dma(req);
18341834
struct device *dev = drvdata_to_dev(ctx->drvdata);
18351835

18361836
unsigned int cryptlen = (req_ctx->gen_ctx.op_type ==
@@ -1879,7 +1879,7 @@ static void cc_proc_rfc4_gcm(struct aead_request *req)
18791879
{
18801880
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
18811881
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1882-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1882+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
18831883

18841884
memcpy(areq_ctx->ctr_iv + GCM_BLOCK_RFC4_NONCE_OFFSET,
18851885
ctx->ctr_nonce, GCM_BLOCK_RFC4_NONCE_SIZE);
@@ -1896,7 +1896,7 @@ static int cc_proc_aead(struct aead_request *req,
18961896
struct cc_hw_desc desc[MAX_AEAD_PROCESS_SEQ];
18971897
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
18981898
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1899-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1899+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
19001900
struct device *dev = drvdata_to_dev(ctx->drvdata);
19011901
struct cc_crypto_req cc_req = {};
19021902

@@ -2019,7 +2019,7 @@ static int cc_proc_aead(struct aead_request *req,
20192019

20202020
static int cc_aead_encrypt(struct aead_request *req)
20212021
{
2022-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2022+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
20232023
int rc;
20242024

20252025
memset(areq_ctx, 0, sizeof(*areq_ctx));
@@ -2039,7 +2039,7 @@ static int cc_rfc4309_ccm_encrypt(struct aead_request *req)
20392039
{
20402040
/* Very similar to cc_aead_encrypt() above. */
20412041

2042-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2042+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
20432043
int rc;
20442044

20452045
rc = crypto_ipsec_check_assoclen(req->assoclen);
@@ -2063,7 +2063,7 @@ static int cc_rfc4309_ccm_encrypt(struct aead_request *req)
20632063

20642064
static int cc_aead_decrypt(struct aead_request *req)
20652065
{
2066-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2066+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
20672067
int rc;
20682068

20692069
memset(areq_ctx, 0, sizeof(*areq_ctx));
@@ -2081,7 +2081,7 @@ static int cc_aead_decrypt(struct aead_request *req)
20812081

20822082
static int cc_rfc4309_ccm_decrypt(struct aead_request *req)
20832083
{
2084-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2084+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
20852085
int rc;
20862086

20872087
rc = crypto_ipsec_check_assoclen(req->assoclen);
@@ -2193,7 +2193,7 @@ static int cc_rfc4543_gcm_setauthsize(struct crypto_aead *authenc,
21932193

21942194
static int cc_rfc4106_gcm_encrypt(struct aead_request *req)
21952195
{
2196-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2196+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
21972197
int rc;
21982198

21992199
rc = crypto_ipsec_check_assoclen(req->assoclen);
@@ -2217,7 +2217,7 @@ static int cc_rfc4106_gcm_encrypt(struct aead_request *req)
22172217

22182218
static int cc_rfc4543_gcm_encrypt(struct aead_request *req)
22192219
{
2220-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2220+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
22212221
int rc;
22222222

22232223
rc = crypto_ipsec_check_assoclen(req->assoclen);
@@ -2244,7 +2244,7 @@ static int cc_rfc4543_gcm_encrypt(struct aead_request *req)
22442244

22452245
static int cc_rfc4106_gcm_decrypt(struct aead_request *req)
22462246
{
2247-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2247+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
22482248
int rc;
22492249

22502250
rc = crypto_ipsec_check_assoclen(req->assoclen);
@@ -2268,7 +2268,7 @@ static int cc_rfc4106_gcm_decrypt(struct aead_request *req)
22682268

22692269
static int cc_rfc4543_gcm_decrypt(struct aead_request *req)
22702270
{
2271-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2271+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
22722272
int rc;
22732273

22742274
rc = crypto_ipsec_check_assoclen(req->assoclen);

drivers/crypto/ccree/cc_buffer_mgr.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static inline char *cc_dma_buf_type(enum cc_req_dma_buf_type type)
5252
static void cc_copy_mac(struct device *dev, struct aead_request *req,
5353
enum cc_sg_cpy_direct dir)
5454
{
55-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
55+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
5656
u32 skip = req->assoclen + req->cryptlen;
5757

5858
cc_copy_sg_portion(dev, areq_ctx->backup_mac, req->src,
@@ -456,7 +456,7 @@ int cc_map_cipher_request(struct cc_drvdata *drvdata, void *ctx,
456456

457457
void cc_unmap_aead_request(struct device *dev, struct aead_request *req)
458458
{
459-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
459+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
460460
unsigned int hw_iv_size = areq_ctx->hw_iv_size;
461461
struct cc_drvdata *drvdata = dev_get_drvdata(dev);
462462
int src_direction = (req->src != req->dst ? DMA_TO_DEVICE : DMA_BIDIRECTIONAL);
@@ -546,7 +546,7 @@ static int cc_aead_chain_iv(struct cc_drvdata *drvdata,
546546
struct buffer_array *sg_data,
547547
bool is_last, bool do_chain)
548548
{
549-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
549+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
550550
unsigned int hw_iv_size = areq_ctx->hw_iv_size;
551551
struct device *dev = drvdata_to_dev(drvdata);
552552
gfp_t flags = cc_gfp_flags(&req->base);
@@ -586,7 +586,7 @@ static int cc_aead_chain_assoc(struct cc_drvdata *drvdata,
586586
struct buffer_array *sg_data,
587587
bool is_last, bool do_chain)
588588
{
589-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
589+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
590590
int rc = 0;
591591
int mapped_nents = 0;
592592
struct device *dev = drvdata_to_dev(drvdata);
@@ -652,7 +652,7 @@ static int cc_aead_chain_assoc(struct cc_drvdata *drvdata,
652652
static void cc_prepare_aead_data_dlli(struct aead_request *req,
653653
u32 *src_last_bytes, u32 *dst_last_bytes)
654654
{
655-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
655+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
656656
enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type;
657657
unsigned int authsize = areq_ctx->req_authsize;
658658
struct scatterlist *sg;
@@ -678,7 +678,7 @@ static void cc_prepare_aead_data_mlli(struct cc_drvdata *drvdata,
678678
u32 *src_last_bytes, u32 *dst_last_bytes,
679679
bool is_last_table)
680680
{
681-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
681+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
682682
enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type;
683683
unsigned int authsize = areq_ctx->req_authsize;
684684
struct device *dev = drvdata_to_dev(drvdata);
@@ -790,7 +790,7 @@ static int cc_aead_chain_data(struct cc_drvdata *drvdata,
790790
struct buffer_array *sg_data,
791791
bool is_last_table, bool do_chain)
792792
{
793-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
793+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
794794
struct device *dev = drvdata_to_dev(drvdata);
795795
enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type;
796796
unsigned int authsize = areq_ctx->req_authsize;
@@ -895,7 +895,7 @@ static int cc_aead_chain_data(struct cc_drvdata *drvdata,
895895
static void cc_update_aead_mlli_nents(struct cc_drvdata *drvdata,
896896
struct aead_request *req)
897897
{
898-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
898+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
899899
u32 curr_mlli_size = 0;
900900

901901
if (areq_ctx->assoc_buff_type == CC_DMA_BUF_MLLI) {
@@ -945,7 +945,7 @@ static void cc_update_aead_mlli_nents(struct cc_drvdata *drvdata,
945945

946946
int cc_map_aead_request(struct cc_drvdata *drvdata, struct aead_request *req)
947947
{
948-
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
948+
struct aead_req_ctx *areq_ctx = aead_request_ctx_dma(req);
949949
struct mlli_params *mlli_params = &areq_ctx->mlli_params;
950950
struct device *dev = drvdata_to_dev(drvdata);
951951
struct buffer_array sg_data;

0 commit comments

Comments
 (0)