Commit 39a76cf1 authored by Herbert Xu's avatar Herbert Xu

crypto: sun8i-ss - Remove GFP_DMA and add DMA alignment padding

GFP_DMA does not guarantee that the returned memory is aligned
for DMA.  In fact for sun8i-ss it is superfluous and can be removed.

However, kmalloc may start returning DMA-unaligned memory in future
so fix this by adding the alignment by hand.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Tested-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Acked-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 4f289826
...@@ -452,7 +452,7 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, ...@@ -452,7 +452,7 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
} }
kfree_sensitive(op->key); kfree_sensitive(op->key);
op->keylen = keylen; op->keylen = keylen;
op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); op->key = kmemdup(key, keylen, GFP_KERNEL);
if (!op->key) if (!op->key)
return -ENOMEM; return -ENOMEM;
...@@ -475,7 +475,7 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, ...@@ -475,7 +475,7 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
kfree_sensitive(op->key); kfree_sensitive(op->key);
op->keylen = keylen; op->keylen = keylen;
op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); op->key = kmemdup(key, keylen, GFP_KERNEL);
if (!op->key) if (!op->key)
return -ENOMEM; return -ENOMEM;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -527,7 +528,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss) ...@@ -527,7 +528,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss)
init_completion(&ss->flows[i].complete); init_completion(&ss->flows[i].complete);
ss->flows[i].biv = devm_kmalloc(ss->dev, AES_BLOCK_SIZE, ss->flows[i].biv = devm_kmalloc(ss->dev, AES_BLOCK_SIZE,
GFP_KERNEL | GFP_DMA); GFP_KERNEL);
if (!ss->flows[i].biv) { if (!ss->flows[i].biv) {
err = -ENOMEM; err = -ENOMEM;
goto error_engine; goto error_engine;
...@@ -535,7 +536,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss) ...@@ -535,7 +536,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss)
for (j = 0; j < MAX_SG; j++) { for (j = 0; j < MAX_SG; j++) {
ss->flows[i].iv[j] = devm_kmalloc(ss->dev, AES_BLOCK_SIZE, ss->flows[i].iv[j] = devm_kmalloc(ss->dev, AES_BLOCK_SIZE,
GFP_KERNEL | GFP_DMA); GFP_KERNEL);
if (!ss->flows[i].iv[j]) { if (!ss->flows[i].iv[j]) {
err = -ENOMEM; err = -ENOMEM;
goto error_engine; goto error_engine;
...@@ -544,13 +545,15 @@ static int allocate_flows(struct sun8i_ss_dev *ss) ...@@ -544,13 +545,15 @@ static int allocate_flows(struct sun8i_ss_dev *ss)
/* the padding could be up to two block. */ /* the padding could be up to two block. */
ss->flows[i].pad = devm_kmalloc(ss->dev, MAX_PAD_SIZE, ss->flows[i].pad = devm_kmalloc(ss->dev, MAX_PAD_SIZE,
GFP_KERNEL | GFP_DMA); GFP_KERNEL);
if (!ss->flows[i].pad) { if (!ss->flows[i].pad) {
err = -ENOMEM; err = -ENOMEM;
goto error_engine; goto error_engine;
} }
ss->flows[i].result = devm_kmalloc(ss->dev, SHA256_DIGEST_SIZE, ss->flows[i].result =
GFP_KERNEL | GFP_DMA); devm_kmalloc(ss->dev, max(SHA256_DIGEST_SIZE,
dma_get_cache_alignment()),
GFP_KERNEL);
if (!ss->flows[i].result) { if (!ss->flows[i].result) {
err = -ENOMEM; err = -ENOMEM;
goto error_engine; goto error_engine;
......
...@@ -79,10 +79,10 @@ int sun8i_ss_hmac_setkey(struct crypto_ahash *ahash, const u8 *key, ...@@ -79,10 +79,10 @@ int sun8i_ss_hmac_setkey(struct crypto_ahash *ahash, const u8 *key,
memcpy(tfmctx->key, key, keylen); memcpy(tfmctx->key, key, keylen);
} }
tfmctx->ipad = kzalloc(bs, GFP_KERNEL | GFP_DMA); tfmctx->ipad = kzalloc(bs, GFP_KERNEL);
if (!tfmctx->ipad) if (!tfmctx->ipad)
return -ENOMEM; return -ENOMEM;
tfmctx->opad = kzalloc(bs, GFP_KERNEL | GFP_DMA); tfmctx->opad = kzalloc(bs, GFP_KERNEL);
if (!tfmctx->opad) { if (!tfmctx->opad) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_opad; goto err_opad;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
*/ */
#include "sun8i-ss.h" #include "sun8i-ss.h"
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <crypto/internal/rng.h> #include <crypto/internal/rng.h>
...@@ -25,7 +27,7 @@ int sun8i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, ...@@ -25,7 +27,7 @@ int sun8i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
ctx->seed = NULL; ctx->seed = NULL;
} }
if (!ctx->seed) if (!ctx->seed)
ctx->seed = kmalloc(slen, GFP_KERNEL | GFP_DMA); ctx->seed = kmalloc(slen, GFP_KERNEL);
if (!ctx->seed) if (!ctx->seed)
return -ENOMEM; return -ENOMEM;
...@@ -58,6 +60,7 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, ...@@ -58,6 +60,7 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
struct sun8i_ss_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm); struct sun8i_ss_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm);
struct rng_alg *alg = crypto_rng_alg(tfm); struct rng_alg *alg = crypto_rng_alg(tfm);
struct sun8i_ss_alg_template *algt; struct sun8i_ss_alg_template *algt;
unsigned int todo_with_padding;
struct sun8i_ss_dev *ss; struct sun8i_ss_dev *ss;
dma_addr_t dma_iv, dma_dst; dma_addr_t dma_iv, dma_dst;
unsigned int todo; unsigned int todo;
...@@ -81,7 +84,11 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, ...@@ -81,7 +84,11 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
todo = dlen + PRNG_SEED_SIZE + PRNG_DATA_SIZE; todo = dlen + PRNG_SEED_SIZE + PRNG_DATA_SIZE;
todo -= todo % PRNG_DATA_SIZE; todo -= todo % PRNG_DATA_SIZE;
d = kzalloc(todo, GFP_KERNEL | GFP_DMA); todo_with_padding = ALIGN(todo, dma_get_cache_alignment());
if (todo_with_padding < todo || todo < dlen)
return -EOVERFLOW;
d = kzalloc(todo_with_padding, GFP_KERNEL);
if (!d) if (!d)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment