All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Horia Geantă" <horia.geanta@freescale.com>
To: Russell King <rmk+kernel@arm.linux.org.uk>,
	Fabio Estevam <fabio.estevam@freescale.com>,
	Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>, <linux-crypto@vger.kernel.org>
Subject: Re: [PATCH RFC 10/11] crypto: caam: add ahash_edesc_add_src()
Date: Wed, 9 Dec 2015 18:21:05 +0200	[thread overview]
Message-ID: <566854F1.8020409@freescale.com> (raw)
In-Reply-To: <E1a61DK-0007nF-BJ@rmk-PC.arm.linux.org.uk>

On 12/7/2015 9:12 PM, Russell King wrote:
> Add a helper to map the source scatterlist into the descriptor.
> 
> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

After appending 07/11 ("crypto: caam: check and use dma_map_sg() return code")
as follows:

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 241268d108ec..00b35e763f58 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1120,7 +1120,7 @@ static int ahash_digest(struct ahash_request *req)

src_nents = sg_nents_for_len(req->src, req->nbytes);
mapped_nents = dma_map_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
- if (mapped_nents == 0) {
+ if (src_nents && mapped_nents == 0) {
dev_err(jrdev, "unable to map source for DMA\n");
return -ENOMEM;
}

I still see tcrypts test failures:
caam_jr ffe301000.jr: 4000131c: DECO: desc idx 19: DECO Watchdog timer timeout error
alt: hash: update failed on test 6 for hmac-sha1-caam: ret=-1073746716
alg: hash: Test 4 failed for sha1-caam
00000000: 75 e1 d9 26 df 3b 5c 31 d7 a3 02 ca 79 26 55 0e
00000010: 31 96 8d 9f
[...]

git bisect points to this commit.

> ---
>  drivers/crypto/caam/caamhash.c | 106 +++++++++++++++++++----------------------
>  1 file changed, 49 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
> index 241268d108ec..4e73d3218481 100644
> --- a/drivers/crypto/caam/caamhash.c
> +++ b/drivers/crypto/caam/caamhash.c
> @@ -789,6 +789,40 @@ static struct ahash_edesc *ahash_edesc_alloc(struct caam_hash_ctx *ctx,
>  	return edesc;
>  }
>  
> +static int ahash_edesc_add_src(struct caam_hash_ctx *ctx,
> +			       struct ahash_edesc *edesc,
> +			       struct ahash_request *req, int nents,
> +			       unsigned int first_sg, unsigned int first_bytes)
> +{
> +	dma_addr_t src_dma;
> +	u32 options;
> +
> +	if (nents > 1 || first_sg) {
> +		struct sec4_sg_entry *sg = edesc->sec4_sg;
> +		unsigned int sgsize = sizeof(*sg) * (first_sg + nents);
> +
> +		sg_to_sec4_sg_last(req->src, nents, sg + first_sg, 0);
> +
> +		src_dma = dma_map_single(ctx->jrdev, sg, sgsize, DMA_TO_DEVICE);
> +		if (dma_mapping_error(ctx->jrdev, src_dma)) {
> +			dev_err(ctx->jrdev, "unable to map S/G table\n");
> +			return -ENOMEM;
> +		}
> +
> +		edesc->sec4_sg_bytes = sgsize;
> +		edesc->sec4_sg_dma = src_dma;
> +		options = LDST_SGF;
> +	} else {
> +		src_dma = sg_dma_address(req->src);
> +		options = 0;
> +	}
> +
> +	append_seq_in_ptr(edesc->hw_desc, src_dma, first_bytes + req->nbytes,
> +			  options);
> +
> +	return 0;
> +}
[snip]
> @@ -1471,9 +1486,7 @@ static int ahash_update_first(struct ahash_request *req)
>  		&state->buflen_1 : &state->buflen_0;
>  	int to_hash;
>  	u32 *desc;
> -	int sec4_sg_bytes, src_nents, mapped_nents;
> -	dma_addr_t src_dma;
> -	u32 options;
> +	int src_nents, mapped_nents;
>  	struct ahash_edesc *edesc;
>  	int ret = 0;
>  
> @@ -1490,11 +1503,6 @@ static int ahash_update_first(struct ahash_request *req)
>  			dev_err(jrdev, "unable to map source for DMA\n");
>  			return -ENOMEM;
>  		}
> -		if (mapped_nents > 1)
> -			sec4_sg_bytes = mapped_nents *
> -					sizeof(struct sec4_sg_entry);
> -		else
> -			sec4_sg_bytes = 0;
>  
>  		/*
>  		 * allocate space for base edesc and hw desc commands,
> @@ -1511,28 +1519,14 @@ static int ahash_update_first(struct ahash_request *req)
>  		}
>  
>  		edesc->src_nents = src_nents;
> -		edesc->sec4_sg_bytes = sec4_sg_bytes;
>  		edesc->dst_dma = 0;
>  
> -		if (src_nents > 1) {
> -			sg_to_sec4_sg_last(req->src, mapped_nents,
> -					   edesc->sec4_sg, 0);
> -			edesc->sec4_sg_dma = dma_map_single(jrdev,
> -							    edesc->sec4_sg,
> -							    sec4_sg_bytes,
> -							    DMA_TO_DEVICE);
> -			if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
> -				dev_err(jrdev, "unable to map S/G table\n");
> -				ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len,
> -						DMA_TO_DEVICE);
> -				kfree(edesc);
> -				return -ENOMEM;
> -			}
> -			src_dma = edesc->sec4_sg_dma;
> -			options = LDST_SGF;
> -		} else {
> -			src_dma = sg_dma_address(req->src);
> -			options = 0;
> +		ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 0, 0);
> +		if (ret) {
> +			ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len,
> +					DMA_TO_DEVICE);
> +			kfree(edesc);
> +			return ret;
>  		}
>  
>  		if (*next_buflen)
> @@ -1541,8 +1535,6 @@ static int ahash_update_first(struct ahash_request *req)
>  
>  		desc = edesc->hw_desc;
>  
> -		append_seq_in_ptr(desc, src_dma, to_hash, options);
> -

The refactoring changes the logic here: instead of hashing over "to_hash" input
bytes, it will do over req->nbytes.

Current patch could be fixed as follows, but I guess it's abusing the
"first_bytes" param:

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 6d903398fb0d..7d40765e94c5 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -792,7 +792,7 @@ static struct ahash_edesc *ahash_edesc_alloc(struct
caam_hash_ctx *ctx,
 static int ahash_edesc_add_src(struct caam_hash_ctx *ctx,
                               struct ahash_edesc *edesc,
                               struct ahash_request *req, int nents,
-                              unsigned int first_sg, unsigned int first_bytes)
+                              unsigned int first_sg, int first_bytes)
 {
        dma_addr_t src_dma;
        u32 options;
@@ -817,7 +817,7 @@ static int ahash_edesc_add_src(struct caam_hash_ctx *ctx,
                options = 0;
        }

-       append_seq_in_ptr(edesc->hw_desc, src_dma, first_bytes + req->nbytes,
+       append_seq_in_ptr(edesc->hw_desc, src_dma, req->nbytes + first_bytes,
                          options);

        return 0;
@@ -1521,7 +1521,8 @@ static int ahash_update_first(struct ahash_request *req)
                edesc->src_nents = src_nents;
                edesc->dst_dma = 0;

-               ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 0, 0);
+               ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 0,
+                                         -*next_buflen);
                if (ret) {
                        ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len,
                                        DMA_TO_DEVICE);

Horia

  reply	other threads:[~2015-12-09 16:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-07 19:11 [PATCH RFC 00/13] Further iMX CAAM updates Russell King - ARM Linux
2015-12-07 19:12 ` [PATCH RFC 01/11] crypto: caam: fix DMA API mapping leak Russell King
2015-12-07 19:12 ` [PATCH RFC 02/11] crypto: caam: ensure descriptor buffers are cacheline aligned Russell King
2015-12-07 19:12 ` [PATCH RFC 03/11] crypto: caam: incorporate job descriptor into struct ahash_edesc Russell King
2015-12-07 19:12 ` [PATCH RFC 04/11] crypto: caam: mark the hardware descriptor as cache line aligned Russell King
2015-12-07 19:12 ` [PATCH RFC 05/11] crypto: caam: replace sec4_sg pointer with array Russell King
2015-12-07 19:12 ` [PATCH RFC 06/11] crypto: caam: ensure that we clean up after an error Russell King
2015-12-09 15:08   ` Horia Geantă
2015-12-09 18:30     ` Russell King - ARM Linux
2015-12-07 19:12 ` [PATCH RFC 07/11] crypto: caam: check and use dma_map_sg() return code Russell King
2015-12-09 15:20   ` Horia Geantă
2015-12-09 18:31     ` Russell King - ARM Linux
2015-12-07 19:12 ` [PATCH RFC 08/11] crypto: caam: add ahash_edesc_alloc() for descriptor allocation Russell King
2015-12-07 19:12 ` [PATCH RFC 09/11] crypto: caam: move job descriptor initialisation to ahash_edesc_alloc() Russell King
2015-12-07 19:12 ` [PATCH RFC 10/11] crypto: caam: add ahash_edesc_add_src() Russell King
2015-12-09 16:21   ` Horia Geantă [this message]
2015-12-07 19:12 ` [PATCH RFC 11/11] crypto: caam: get rid of tasklet Russell King
2015-12-07 20:59 ` [PATCH RFC 00/13] Further iMX CAAM updates Fabio Estevam
2015-12-09 15:06 ` Horia Geantă
2015-12-09 18:21   ` Russell King - ARM Linux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=566854F1.8020409@freescale.com \
    --to=horia.geanta@freescale.com \
    --cc=davem@davemloft.net \
    --cc=fabio.estevam@freescale.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.