All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state
@ 2016-02-03 12:46 Fabio Estevam
  2016-02-03 12:46 ` [PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fabio Estevam @ 2016-02-03 12:46 UTC (permalink / raw)
  To: herbert; +Cc: s.trumtrar, marex, linux, linux-crypto, Fabio Estevam

As pointed out by Herbert Xu we should not include the mutex in the
exported state, so let's just get rid of it.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/crypto/sahara.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 6c4f91c..7e8147d 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -182,7 +182,6 @@ struct sahara_sha_reqctx {
 	u8			buf[SAHARA_MAX_SHA_BLOCK_SIZE];
 	u8			rembuf[SAHARA_MAX_SHA_BLOCK_SIZE];
 	u8			context[SHA256_DIGEST_SIZE + 4];
-	struct mutex		mutex;
 	unsigned int		mode;
 	unsigned int		digest_size;
 	unsigned int		context_size;
@@ -1096,7 +1095,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, int last)
 	if (!req->nbytes && !last)
 		return 0;
 
-	mutex_lock(&rctx->mutex);
 	rctx->last = last;
 
 	if (!rctx->active) {
@@ -1109,7 +1107,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, int last)
 	mutex_unlock(&dev->queue_mutex);
 
 	wake_up_process(dev->kthread);
-	mutex_unlock(&rctx->mutex);
 
 	return ret;
 }
@@ -1137,8 +1134,6 @@ static int sahara_sha_init(struct ahash_request *req)
 	rctx->context_size = rctx->digest_size + 4;
 	rctx->active = 0;
 
-	mutex_init(&rctx->mutex);
-
 	return 0;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx
  2016-02-03 12:46 [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Fabio Estevam
@ 2016-02-03 12:46 ` Fabio Estevam
  2016-02-03 12:46 ` [PATCH v3 3/3] crypto: sahara - fill the statesize field Fabio Estevam
  2016-02-06  7:48 ` [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2016-02-03 12:46 UTC (permalink / raw)
  To: herbert; +Cc: s.trumtrar, marex, linux, linux-crypto, Fabio Estevam

Based on commit 434b421241f2d0 ("crypto: caam - avoid needlessly saving and
restoring caam_hash_ctx") from Russell King.

When exporting and importing the hash state, we will only export and
import into hashes which share the same struct crypto_ahash pointer.
(See hash_accept->af_alg_accept->hash_accept_parent.)

This means that saving the sahara_ctx structure on export, and
restoring it on import is a waste of resources.  So, remove this code.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/crypto/sahara.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 7e8147d..9db09b6 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1162,26 +1162,18 @@ static int sahara_sha_digest(struct ahash_request *req)
 
 static int sahara_sha_export(struct ahash_request *req, void *out)
 {
-	struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
-	struct sahara_ctx *ctx = crypto_ahash_ctx(ahash);
 	struct sahara_sha_reqctx *rctx = ahash_request_ctx(req);
 
-	memcpy(out, ctx, sizeof(struct sahara_ctx));
-	memcpy(out + sizeof(struct sahara_sha_reqctx), rctx,
-	       sizeof(struct sahara_sha_reqctx));
+	memcpy(out, rctx, sizeof(struct sahara_sha_reqctx));
 
 	return 0;
 }
 
 static int sahara_sha_import(struct ahash_request *req, const void *in)
 {
-	struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
-	struct sahara_ctx *ctx = crypto_ahash_ctx(ahash);
 	struct sahara_sha_reqctx *rctx = ahash_request_ctx(req);
 
-	memcpy(ctx, in, sizeof(struct sahara_ctx));
-	memcpy(rctx, in + sizeof(struct sahara_sha_reqctx),
-	       sizeof(struct sahara_sha_reqctx));
+	memcpy(rctx, in, sizeof(struct sahara_sha_reqctx));
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 3/3] crypto: sahara - fill the statesize field
  2016-02-03 12:46 [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Fabio Estevam
  2016-02-03 12:46 ` [PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx Fabio Estevam
@ 2016-02-03 12:46 ` Fabio Estevam
  2016-02-06  7:48 ` [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2016-02-03 12:46 UTC (permalink / raw)
  To: herbert; +Cc: s.trumtrar, marex, linux, linux-crypto, Fabio Estevam

Currently the sahara driver fails to probe:

sahara: probe of 63ff8000.crypto failed with error -22

This happens since commit 8996eafdcbad ("crypto: ahash - ensure statesize
is non-zero"), which requires statesize to be filled.

Pass the statesize members for sha1 and sha256, so we can probe
the driver successfully again.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/crypto/sahara.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 9db09b6..c3f3d89 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1259,6 +1259,7 @@ static struct ahash_alg sha_v3_algs[] = {
 	.export		= sahara_sha_export,
 	.import		= sahara_sha_import,
 	.halg.digestsize	= SHA1_DIGEST_SIZE,
+	.halg.statesize         = sizeof(struct sahara_sha_reqctx),
 	.halg.base	= {
 		.cra_name		= "sha1",
 		.cra_driver_name	= "sahara-sha1",
@@ -1286,6 +1287,7 @@ static struct ahash_alg sha_v4_algs[] = {
 	.export		= sahara_sha_export,
 	.import		= sahara_sha_import,
 	.halg.digestsize	= SHA256_DIGEST_SIZE,
+	.halg.statesize         = sizeof(struct sahara_sha_reqctx),
 	.halg.base	= {
 		.cra_name		= "sha256",
 		.cra_driver_name	= "sahara-sha256",
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state
  2016-02-03 12:46 [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Fabio Estevam
  2016-02-03 12:46 ` [PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx Fabio Estevam
  2016-02-03 12:46 ` [PATCH v3 3/3] crypto: sahara - fill the statesize field Fabio Estevam
@ 2016-02-06  7:48 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2016-02-06  7:48 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: s.trumtrar, marex, linux, linux-crypto

On Wed, Feb 03, 2016 at 10:46:50AM -0200, Fabio Estevam wrote:
> As pointed out by Herbert Xu we should not include the mutex in the
> exported state, so let's just get rid of it.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

All applied.
-- 
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] 4+ messages in thread

end of thread, other threads:[~2016-02-06  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-03 12:46 [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Fabio Estevam
2016-02-03 12:46 ` [PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx Fabio Estevam
2016-02-03 12:46 ` [PATCH v3 3/3] crypto: sahara - fill the statesize field Fabio Estevam
2016-02-06  7:48 ` [PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state Herbert Xu

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.