* [PATCH 1/3] crypto: marvell/cesa - Fix DMA cache leaks on hash setup errors
2026-11-18 7:56 [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Haoxiang Li
@ 2026-11-18 7:56 ` Haoxiang Li
2026-11-18 7:56 ` [PATCH 2/3] crypto: marvell/cesa - Fix padding cleanup " Haoxiang Li
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-18 7:56 UTC (permalink / raw)
To: schalla, bbhushan2, herbert; +Cc: linux-crypto, linux-kernel, Haoxiang Li
The hash DMA initialization error path frees TDMA descriptors and unmaps
the source scatterlist, but leaves the DMA cache allocated.
Use the full DMA cleanup helper on this path. Clear the cache pointer
after freeing it to prevent stale-pointer reuse on subsequent requests.
Fixes: 7850c91b175d ("crypto: marvell/cesa - fix memory leak")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
drivers/crypto/marvell/cesa/hash.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index 2f203042d9bd..35f5937b2f8b 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -65,6 +65,7 @@ mv_cesa_ahash_dma_free_cache(struct mv_cesa_ahash_dma_req *req)
dma_pool_free(cesa_dev->dma->cache_pool, req->cache,
req->cache_dma);
+ req->cache = NULL;
}
static int mv_cesa_ahash_dma_alloc_padding(struct mv_cesa_ahash_dma_req *req,
@@ -747,8 +748,7 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)
return 0;
err_free_tdma:
- mv_cesa_dma_cleanup(basereq);
- dma_unmap_sg(cesa_dev->dev, req->src, creq->src_nents, DMA_TO_DEVICE);
+ mv_cesa_ahash_dma_cleanup(req);
err:
mv_cesa_ahash_last_cleanup(req);
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/3] crypto: marvell/cesa - Fix padding cleanup on hash setup errors
2026-11-18 7:56 [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Haoxiang Li
2026-11-18 7:56 ` [PATCH 1/3] crypto: marvell/cesa - Fix DMA cache leaks on hash setup errors Haoxiang Li
@ 2026-11-18 7:56 ` Haoxiang Li
2026-11-18 7:56 ` [PATCH 3/3] crypto: marvell/cesa - Free hash padding when queueing fails Haoxiang Li
2026-11-27 5:13 ` [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-18 7:56 UTC (permalink / raw)
To: schalla, bbhushan2, herbert; +Cc: linux-crypto, linux-kernel, Haoxiang Li
The hash DMA initialization error path clears the TDMA chain before
calling mv_cesa_ahash_last_cleanup(). The empty chain makes the request
appear to be a non-DMA request, so padding is not released. This also
happens if the first TDMA descriptor allocation fails after padding has
been allocated.
Call the DMA-specific padding cleanup helper directly, since this is
already known to be the DMA initialization path.
Fixes: 53da740fed30 ("crypto: marvell - Move tdma chain out of mv_cesa_tdma_req and remove it")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
drivers/crypto/marvell/cesa/hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index 35f5937b2f8b..f698d3df535b 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -751,7 +751,7 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)
mv_cesa_ahash_dma_cleanup(req);
err:
- mv_cesa_ahash_last_cleanup(req);
+ mv_cesa_ahash_dma_last_cleanup(req);
return ret;
}
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/3] crypto: marvell/cesa - Free hash padding when queueing fails
2026-11-18 7:56 [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Haoxiang Li
2026-11-18 7:56 ` [PATCH 1/3] crypto: marvell/cesa - Fix DMA cache leaks on hash setup errors Haoxiang Li
2026-11-18 7:56 ` [PATCH 2/3] crypto: marvell/cesa - Fix padding cleanup " Haoxiang Li
@ 2026-11-18 7:56 ` Haoxiang Li
2026-11-27 5:13 ` [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-18 7:56 UTC (permalink / raw)
To: schalla, bbhushan2, herbert; +Cc: linux-crypto, linux-kernel, Haoxiang Li
A final hash request rejected by the queue runs generic request cleanup,
which releases the DMA cache and TDMA descriptors but leaves padding
allocated. The request will not reach completion cleanup after rejection.
Release padding before generic cleanup, while the TDMA chain still
identifies the request as a DMA request. Keep resources allocated for
requests accepted normally or as backlog.
Fixes: db509a45339f ("crypto: marvell/cesa - add TDMA support")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
drivers/crypto/marvell/cesa/hash.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index f698d3df535b..d2fe96d865bd 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -796,8 +796,11 @@ static int mv_cesa_ahash_queue_req(struct ahash_request *req)
ret = mv_cesa_queue_req(&req->base, &creq->base);
- if (mv_cesa_req_needs_cleanup(&req->base, ret))
+ if (mv_cesa_req_needs_cleanup(&req->base, ret)) {
+ if (creq->last_req)
+ mv_cesa_ahash_last_cleanup(req);
mv_cesa_ahash_cleanup(req);
+ }
return ret;
}
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup
2026-11-18 7:56 [PATCH 0/3] crypto: marvell/cesa - Fix hash DMA buffer cleanup Haoxiang Li
` (2 preceding siblings ...)
2026-11-18 7:56 ` [PATCH 3/3] crypto: marvell/cesa - Free hash padding when queueing fails Haoxiang Li
@ 2026-11-27 5:13 ` Herbert Xu
3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2026-11-27 5:13 UTC (permalink / raw)
To: Haoxiang Li; +Cc: schalla, bbhushan2, linux-crypto, linux-kernel
On Wed, Nov 18, 2026 at 03:56:33PM +0800, Haoxiang Li wrote:
> This series fixes DMA cache and padding buffer leaks in the CESA hash
> request error paths.
>
> The DMA cache is not released when request preparation fails. Padding
> cleanup can also be skipped because request type detection depends on a
> TDMA chain that has already been cleared. In addition, final requests
> rejected by the queue leave their padding allocated.
>
> The patches address these cleanup paths and clear the DMA cache pointer
> after freeing it to prevent stale-pointer reuse.
>
> Testing:
> - ARM compile testing of hash.o for each intermediate revision, using
> Clang with W=1 and KCFLAGS=-Werror.
> - Userspace mock tests of extracted driver functions covering allocation
> failures, queue rejection, backlog acceptance, completion cleanup,
> retries and non-DMA requests.
>
> The mock tests, which is assisted by codex, validate resource lifetimes
> with DMA pools and hardware interfaces mocked. No hardware testing was performed.
>
> Haoxiang Li (3):
> crypto: marvell/cesa - Fix DMA cache leaks on hash setup errors
> crypto: marvell/cesa - Fix padding cleanup on hash setup errors
> crypto: marvell/cesa - Free hash padding when queueing fails
>
> drivers/crypto/marvell/cesa/hash.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
>
> base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
> --
> 2.25.1
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