* [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg()
@ 2025-05-19 15:13 Ovidiu Panait
2025-05-19 15:13 ` [PATCH 2/3] crypto: sun8i-ce - remove ivlen field of sun8i_cipher_req_ctx Ovidiu Panait
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ovidiu Panait @ 2025-05-19 15:13 UTC (permalink / raw)
To: clabbe.montjoie, herbert, davem, linux-crypto
Cc: wens, jernej.skrabec, samuel, linux-arm-kernel, linux-sunxi,
linux-kernel, Ovidiu Panait
In sun8i_ce_cipher_unprepare(), dma_unmap_sg() is incorrectly called with
the number of entries returned by dma_map_sg(), rather than using the
original number of entries passed when mapping the scatterlist.
To fix this, stash the original number of entries passed to dma_map_sg()
in the request context.
Fixes: 0605fa0f7826 ("crypto: sun8i-ce - split into prepare/run/unprepare")
Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
index f9cf00d690e2..7cd3b13f3bdc 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
@@ -278,8 +278,8 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
}
chan->timeout = areq->cryptlen;
- rctx->nr_sgs = nr_sgs;
- rctx->nr_sgd = nr_sgd;
+ rctx->nr_sgs = ns;
+ rctx->nr_sgd = nd;
return 0;
theend_sgs:
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] crypto: sun8i-ce - remove ivlen field of sun8i_cipher_req_ctx
2025-05-19 15:13 [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Ovidiu Panait
@ 2025-05-19 15:13 ` Ovidiu Panait
2025-05-19 15:13 ` [PATCH 3/3] crypto: sun8i-ce - use helpers to get hash block and digest sizes Ovidiu Panait
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ovidiu Panait @ 2025-05-19 15:13 UTC (permalink / raw)
To: clabbe.montjoie, herbert, davem, linux-crypto
Cc: wens, jernej.skrabec, samuel, linux-arm-kernel, linux-sunxi,
linux-kernel, Ovidiu Panait
Remove `ivlen` field of `sun8i_cipher_req_ctx`, as it is not really useful.
The iv length returned by crypto_skcipher_ivsize() is already available
everywhere and can be used instead.
Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 11 ++++++-----
drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 2 --
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
index 7cd3b13f3bdc..5663df49dd81 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
@@ -206,15 +206,14 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
cet->t_key = desc_addr_val_le32(ce, rctx->addr_key);
ivsize = crypto_skcipher_ivsize(tfm);
- if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) {
- rctx->ivlen = ivsize;
+ if (areq->iv && ivsize > 0) {
if (rctx->op_dir & CE_DECRYPTION) {
offset = areq->cryptlen - ivsize;
scatterwalk_map_and_copy(chan->backup_iv, areq->src,
offset, ivsize, 0);
}
memcpy(chan->bounce_iv, areq->iv, ivsize);
- rctx->addr_iv = dma_map_single(ce->dev, chan->bounce_iv, rctx->ivlen,
+ rctx->addr_iv = dma_map_single(ce->dev, chan->bounce_iv, ivsize,
DMA_TO_DEVICE);
if (dma_mapping_error(ce->dev, rctx->addr_iv)) {
dev_err(ce->dev, "Cannot DMA MAP IV\n");
@@ -296,7 +295,8 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
theend_iv:
if (areq->iv && ivsize > 0) {
if (!dma_mapping_error(ce->dev, rctx->addr_iv))
- dma_unmap_single(ce->dev, rctx->addr_iv, rctx->ivlen, DMA_TO_DEVICE);
+ dma_unmap_single(ce->dev, rctx->addr_iv, ivsize,
+ DMA_TO_DEVICE);
offset = areq->cryptlen - ivsize;
if (rctx->op_dir & CE_DECRYPTION) {
@@ -345,7 +345,8 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine,
if (areq->iv && ivsize > 0) {
if (cet->t_iv)
- dma_unmap_single(ce->dev, rctx->addr_iv, rctx->ivlen, DMA_TO_DEVICE);
+ dma_unmap_single(ce->dev, rctx->addr_iv, ivsize,
+ DMA_TO_DEVICE);
offset = areq->cryptlen - ivsize;
if (rctx->op_dir & CE_DECRYPTION) {
memcpy(areq->iv, chan->backup_iv, ivsize);
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
index 83df4d719053..0f9a89067016 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
@@ -260,7 +260,6 @@ static inline __le32 desc_addr_val_le32(struct sun8i_ce_dev *dev,
* struct sun8i_cipher_req_ctx - context for a skcipher request
* @op_dir: direction (encrypt vs decrypt) for this request
* @flow: the flow to use for this request
- * @ivlen: size of bounce_iv
* @nr_sgs: The number of source SG (as given by dma_map_sg())
* @nr_sgd: The number of destination SG (as given by dma_map_sg())
* @addr_iv: The IV addr returned by dma_map_single, need to unmap later
@@ -270,7 +269,6 @@ static inline __le32 desc_addr_val_le32(struct sun8i_ce_dev *dev,
struct sun8i_cipher_req_ctx {
u32 op_dir;
int flow;
- unsigned int ivlen;
int nr_sgs;
int nr_sgd;
dma_addr_t addr_iv;
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] crypto: sun8i-ce - use helpers to get hash block and digest sizes
2025-05-19 15:13 [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Ovidiu Panait
2025-05-19 15:13 ` [PATCH 2/3] crypto: sun8i-ce - remove ivlen field of sun8i_cipher_req_ctx Ovidiu Panait
@ 2025-05-19 15:13 ` Ovidiu Panait
2025-05-20 8:24 ` [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Corentin Labbe
2025-06-13 9:33 ` Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Ovidiu Panait @ 2025-05-19 15:13 UTC (permalink / raw)
To: clabbe.montjoie, herbert, davem, linux-crypto
Cc: wens, jernej.skrabec, samuel, linux-arm-kernel, linux-sunxi,
linux-kernel, Ovidiu Panait
Use crypto_ahash_blocksize() and crypto_ahash_digestsize() helpers instead
of directly accessing 'struct ahash_alg' members.
Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
index bef44f350167..13bdfb8a2c62 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
@@ -342,8 +342,8 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash.base);
ce = algt->ce;
- bs = algt->alg.hash.base.halg.base.cra_blocksize;
- digestsize = algt->alg.hash.base.halg.digestsize;
+ bs = crypto_ahash_blocksize(tfm);
+ digestsize = crypto_ahash_digestsize(tfm);
if (digestsize == SHA224_DIGEST_SIZE)
digestsize = SHA256_DIGEST_SIZE;
if (digestsize == SHA384_DIGEST_SIZE)
@@ -455,7 +455,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
err_unmap_result:
dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE);
if (!err)
- memcpy(areq->result, result, algt->alg.hash.base.halg.digestsize);
+ memcpy(areq->result, result, crypto_ahash_digestsize(tfm));
err_unmap_src:
dma_unmap_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE);
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg()
2025-05-19 15:13 [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Ovidiu Panait
2025-05-19 15:13 ` [PATCH 2/3] crypto: sun8i-ce - remove ivlen field of sun8i_cipher_req_ctx Ovidiu Panait
2025-05-19 15:13 ` [PATCH 3/3] crypto: sun8i-ce - use helpers to get hash block and digest sizes Ovidiu Panait
@ 2025-05-20 8:24 ` Corentin Labbe
2025-06-13 9:33 ` Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Corentin Labbe @ 2025-05-20 8:24 UTC (permalink / raw)
To: Ovidiu Panait
Cc: herbert, davem, linux-crypto, wens, jernej.skrabec, samuel,
linux-arm-kernel, linux-sunxi, linux-kernel
Le Mon, May 19, 2025 at 06:13:48PM +0300, Ovidiu Panait a écrit :
> In sun8i_ce_cipher_unprepare(), dma_unmap_sg() is incorrectly called with
> the number of entries returned by dma_map_sg(), rather than using the
> original number of entries passed when mapping the scatterlist.
>
> To fix this, stash the original number of entries passed to dma_map_sg()
> in the request context.
>
> Fixes: 0605fa0f7826 ("crypto: sun8i-ce - split into prepare/run/unprepare")
> Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
> ---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
Hello
All patches are:
Acked-by: Corentin LABBE <clabbe.montjoie@gmail.com>
Tested-by: Corentin LABBE <clabbe.montjoie@gmail.com>
Thanks
Regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg()
2025-05-19 15:13 [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Ovidiu Panait
` (2 preceding siblings ...)
2025-05-20 8:24 ` [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Corentin Labbe
@ 2025-06-13 9:33 ` Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2025-06-13 9:33 UTC (permalink / raw)
To: Ovidiu Panait
Cc: clabbe.montjoie, davem, linux-crypto, wens, jernej.skrabec,
samuel, linux-arm-kernel, linux-sunxi, linux-kernel
On Mon, May 19, 2025 at 06:13:48PM +0300, Ovidiu Panait wrote:
> In sun8i_ce_cipher_unprepare(), dma_unmap_sg() is incorrectly called with
> the number of entries returned by dma_map_sg(), rather than using the
> original number of entries passed when mapping the scatterlist.
>
> To fix this, stash the original number of entries passed to dma_map_sg()
> in the request context.
>
> Fixes: 0605fa0f7826 ("crypto: sun8i-ce - split into prepare/run/unprepare")
> Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
> ---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-13 9:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 15:13 [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Ovidiu Panait
2025-05-19 15:13 ` [PATCH 2/3] crypto: sun8i-ce - remove ivlen field of sun8i_cipher_req_ctx Ovidiu Panait
2025-05-19 15:13 ` [PATCH 3/3] crypto: sun8i-ce - use helpers to get hash block and digest sizes Ovidiu Panait
2025-05-20 8:24 ` [PATCH 1/3] crypto: sun8i-ce - fix nents passed to dma_unmap_sg() Corentin Labbe
2025-06-13 9:33 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).