crypto: caam: pass key buffers with typesafe pointers
PATCH 1/2 crypto: caam: pass key buffers with typesafe pointers
The 'key' field is defined as a 'u64' and used for two different pieces of information: either to store a pointer or a dma_addr_t. The former leads to a build error on 32-bit machines:
drivers/crypto/caam/caamalg_desc.c: In function 'cnstr_shdsc_aead_null_encap':drivers/crypto/caam/caamalg_desc.c:67:27: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] drivers/crypto/caam/caamalg_desc.c: In function 'cnstr_shdsc_aead_null_decap':drivers/crypto/caam/caamalg_desc.c:143:27: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
Using a union to provide correct types gets rid of the warnings and as well as a couple of redundant casts.
--- drivers/crypto/caam/caamalg.c | 60 +++++++++++++++++++------------------- drivers/crypto/caam/caamalg_desc.c | 56 +++++++++++++++++------------------ drivers/crypto/caam/desc_constr.h | 5 +++- 3 files changed, 62 insertions(+), 59 deletions(-)
drivers/crypto/caam/caamalg.c +30 -30
@@ -162,10 +162,10 @@ static int aead_null_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_AEAD_NULL_ENC_LEN ) { ctx->adata.key_inline = true; - ctx->adata.key = (uintptr_t )ctx->key; + ctx->adata.key_virt = ctx->key; }else { ctx->adata.key_inline = false; - ctx->adata.key = ctx->key_dma; + ctx->adata.key_dma = ctx->key_dma; }/* aead_encrypt shared descriptor */
@@ -185,10 +185,10 @@ static int aead_null_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_AEAD_NULL_DEC_LEN ) { ctx->adata.key_inline = true; - ctx->adata.key = (uintptr_t )ctx->key; + ctx->adata.key_virt = ctx->key; }else { ctx->adata.key_inline = false; - ctx->adata.key = ctx->key_dma; + ctx->adata.key_dma = ctx->key_dma; }/* aead_decrypt shared descriptor */
@@ -262,14 +262,14 @@ static int aead_set_sh_desc(struct crypto_aead *aead)return -EINVAL ;if (inl_mask &1 ) - ctx->adata.key = (uintptr_t )ctx->key; + ctx->adata.key_virt = ctx->key;else - ctx->adata.key = ctx->key_dma; + ctx->adata.key_dma = ctx->key_dma;if (inl_mask &2 ) - ctx->cdata.key = (uintptr_t )(ctx->key + ctx->adata.keylen_pad); + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;else - ctx->cdata.key = ctx->key_dma + ctx->adata.keylen_pad; + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad; ctx->adata.key_inline = !!(inl_mask &1 ); ctx->cdata.key_inline = !!(inl_mask &2 );
@@ -298,14 +298,14 @@ static int aead_set_sh_desc(struct crypto_aead *aead)return -EINVAL ;if (inl_mask &1 ) - ctx->adata.key = (uintptr_t )ctx->key; + ctx->adata.key_virt = ctx->key;else - ctx->adata.key = ctx->key_dma; + ctx->adata.key_dma = ctx->key_dma;if (inl_mask &2 ) - ctx->cdata.key = (uintptr_t )(ctx->key + ctx->adata.keylen_pad); + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;else - ctx->cdata.key = ctx->key_dma + ctx->adata.keylen_pad; + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad; ctx->adata.key_inline = !!(inl_mask &1 ); ctx->cdata.key_inline = !!(inl_mask &2 );
@@ -337,14 +337,14 @@ static int aead_set_sh_desc(struct crypto_aead *aead)return -EINVAL ;if (inl_mask &1 ) - ctx->adata.key = (uintptr_t )ctx->key; + ctx->adata.key_virt = ctx->key;else - ctx->adata.key = ctx->key_dma; + ctx->adata.key_dma = ctx->key_dma;if (inl_mask &2 ) - ctx->cdata.key = (uintptr_t )(ctx->key + ctx->adata.keylen_pad); + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;else - ctx->cdata.key = ctx->key_dma + ctx->adata.keylen_pad; + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad; ctx->adata.key_inline = !!(inl_mask &1 ); ctx->cdata.key_inline = !!(inl_mask &2 );
@@ -395,10 +395,10 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_GCM_ENC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_enc;
@@ -417,10 +417,10 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_GCM_DEC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_dec;
@@ -464,10 +464,10 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_RFC4106_ENC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_enc;
@@ -486,10 +486,10 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_RFC4106_DEC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_dec;
@@ -534,10 +534,10 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_RFC4543_ENC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_enc;
@@ -556,10 +556,10 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead)*/ if (rem_bytes >=DESC_RFC4543_DEC_LEN ) { ctx->cdata.key_inline = true; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; }else { ctx->cdata.key_inline = false; - ctx->cdata.key = ctx->key_dma; + ctx->cdata.key_dma = ctx->key_dma; } desc = ctx->sh_desc_dec;
@@ -794,7 +794,7 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,return -ENOMEM ; } ctx->cdata.keylen = keylen; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; ctx->cdata.key_inline = true;/* ablkcipher_encrypt shared descriptor */
@@ -857,7 +857,7 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,return -ENOMEM ; } ctx->cdata.keylen = keylen; - ctx->cdata.key = (uintptr_t )ctx->key; + ctx->cdata.key_virt = ctx->key; ctx->cdata.key_inline = true;/* xts_ablkcipher_encrypt shared descriptor */
drivers/crypto/caam/caamalg_desc.c +28 -28
179 lines not on this page · raw message
drivers/crypto/caam/desc_constr.h +4 -1
@@ -446,7 +446,10 @@ struct alginfo {u32 algtype;unsigned int keylen;unsigned int keylen_pad; -u64 key; +union { +dma_addr_t key_dma; +void *key_virt; + };bool key_inline; };
Signature · 1 line
2.9.0
PATCH 2/2 crypto: caam: make aamalg_desc a proper module
The drivers/crypto/caam/ directory is entered during build only for building modules when CONFIG_CRYPTO_DEV_FSL_CAAM=m, but CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is defined as a 'bool' symbol, meaning that caamalg_desc.c is always compiled into built-in code, or not at all, leading to a link failure:
ERROR: "cnstr_shdsc_xts_ablkcipher_decap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_xts_ablkcipher_encap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_aead_givencap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_aead_decap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_aead_encap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_aead_null_decap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_aead_null_encap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_rfc4106_decap" [drivers/crypto/caam/caamalg.ko] undefined!
ERROR: "cnstr_shdsc_rfc4106_encap" [drivers/crypto/caam/caamalg.ko] undefined!
...
Making caamalg_desc itself a loadable module fixes this configuration by ensuring the driver gets built. Aside from making the symbol 'tristate', I'm adding appropriate module metadata here.
--- drivers/crypto/caam/Kconfig | 2 +- drivers/crypto/caam/caamalg_desc.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/crypto/caam/Kconfig +1 -1
@@ -136,4 +136,4 @@ config CRYPTO_DEV_FSL_CAAM_DEBUG information in the CAAM driver. config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC - def_bool CRYPTO_DEV_FSL_CAAM_CRYPTO_API + def_tristate CRYPTO_DEV_FSL_CAAM_CRYPTO_API
drivers/crypto/caam/caamalg_desc.c +4 -0
@@ -1300,3 +1300,7 @@ void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata)#endif }EXPORT_SYMBOL (cnstr_shdsc_xts_ablkcipher_decap); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("FSL CAAM descriptor support" ); +MODULE_AUTHOR ("Freescale Semiconductor - NMG/STC" );
Signature · 1 line
2.9.0
Herbert Xu
maintainerQuoted 9 lines · Arnd Bergmann
The 'key' field is defined as a 'u64' and used for two different pieces of information: either to store a pointer or a
dma_addr_t. The former leads to a build error on 32-bit machines:
drivers/crypto/caam/caamalg_desc.c: In function 'cnstr_shdsc_aead_null_encap':drivers/crypto/caam/caamalg_desc.c:67:27: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]drivers/crypto/caam/caamalg_desc.c: In function 'cnstr_shdsc_aead_null_decap':drivers/crypto/caam/caamalg_desc.c:143:27: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
Quoted 5 lines
Using a union to provide correct types gets rid of the warnings and as well as a couple of redundant casts.
Fixes db57656b0072 ("crypto: caam - group algorithm related params")Signed-off-by Arnd Bergmann <[email protected]>
Both patches applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt