crypto: caam - save caam memory to support crypto engine retry mechanism.
authorGaurav Jain <gaurav.jain@nxp.com>
Mon, 22 Nov 2021 11:32:34 +0000 (17:02 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:03:24 +0000 (11:03 +0100)
[ Upstream commit 087e1d715bccf25dc0e83294576e416b0386ba20 ]

When caam queue is full (-ENOSPC), caam frees descriptor memory.
crypto-engine checks if retry support is true and h/w queue
is full(-ENOSPC), then requeue the crypto request.
During processing the requested descriptor again, caam gives below error.
(caam_jr 30902000.jr: 40000006: DECO: desc idx 0: Invalid KEY Command).

This patch adds a check to return when caam input ring is full
and retry support is true. so descriptor memory is not freed
and requeued request can be processed again.

Fixes: 2d653936eb2cf ("crypto: caam - enable crypto-engine retry mechanism")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamhash.c
drivers/crypto/caam/caampkc.c

index 8697ae5..d3d8bb0 100644 (file)
@@ -1533,6 +1533,9 @@ static int aead_do_one_req(struct crypto_engine *engine, void *areq)
 
        ret = caam_jr_enqueue(ctx->jrdev, desc, aead_crypt_done, req);
 
+       if (ret == -ENOSPC && engine->retry_support)
+               return ret;
+
        if (ret != -EINPROGRESS) {
                aead_unmap(ctx->jrdev, rctx->edesc, req);
                kfree(rctx->edesc);
@@ -1762,6 +1765,9 @@ static int skcipher_do_one_req(struct crypto_engine *engine, void *areq)
 
        ret = caam_jr_enqueue(ctx->jrdev, desc, skcipher_crypt_done, req);
 
+       if (ret == -ENOSPC && engine->retry_support)
+               return ret;
+
        if (ret != -EINPROGRESS) {
                skcipher_unmap(ctx->jrdev, rctx->edesc, req);
                kfree(rctx->edesc);
index e8a6d8b..36ef738 100644 (file)
@@ -765,6 +765,9 @@ static int ahash_do_one_req(struct crypto_engine *engine, void *areq)
 
        ret = caam_jr_enqueue(jrdev, desc, state->ahash_op_done, req);
 
+       if (ret == -ENOSPC && engine->retry_support)
+               return ret;
+
        if (ret != -EINPROGRESS) {
                ahash_unmap(jrdev, state->edesc, req, 0);
                kfree(state->edesc);
index bf6275f..8867275 100644 (file)
@@ -380,6 +380,9 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
 
        ret = caam_jr_enqueue(jrdev, desc, req_ctx->akcipher_op_done, req);
 
+       if (ret == -ENOSPC && engine->retry_support)
+               return ret;
+
        if (ret != -EINPROGRESS) {
                rsa_pub_unmap(jrdev, req_ctx->edesc, req);
                rsa_io_unmap(jrdev, req_ctx->edesc, req);