Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-22 Thread Corentin Labbe
On Fri, Dec 22, 2017 at 08:06:03PM +1100, Herbert Xu wrote:
> On Fri, Dec 22, 2017 at 09:41:48AM +0100, Corentin Labbe wrote:
> >
> > It's you that was suggesting using crypto_async_request:
> > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1474434.html
> > "The only wart with this scheme is that the drivers end up seeing
> > struct crypto_async_request and will need to convert that to the
> > respective request types but I couldn't really find a better way."
> > 
> > So I wait for any suggestion.
> 
> The core engine code obviously will use the base type but it should
> not be exposed to the driver authors.  IOW all exposed API should
> take the final types such as aead_request before casting it.
> 

For driver->engine 
calls(crypto_finalize_request/crypto_transfer_request_to_engine) it's easy.

But I do not see how to do it for crypto_engine_op appart re-introducing the 
big if/then/else that
you didnt want.
Or do you agree to set the request parameter for 
crypto_engine_op(prepare_request/unprepare_request/do_one_request) to void * ?

Regards
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-22 Thread Herbert Xu
On Fri, Dec 22, 2017 at 09:41:48AM +0100, Corentin Labbe wrote:
>
> It's you that was suggesting using crypto_async_request:
> https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1474434.html
> "The only wart with this scheme is that the drivers end up seeing
> struct crypto_async_request and will need to convert that to the
> respective request types but I couldn't really find a better way."
> 
> So I wait for any suggestion.

The core engine code obviously will use the base type but it should
not be exposed to the driver authors.  IOW all exposed API should
take the final types such as aead_request before casting it.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-22 Thread Corentin Labbe
On Fri, Dec 22, 2017 at 05:57:24PM +1100, Herbert Xu wrote:
> On Wed, Nov 29, 2017 at 09:41:18AM +0100, Corentin Labbe wrote:
> > The crypto engine could actually only enqueue hash and ablkcipher request.
> > This patch permit it to enqueue any type of crypto_async_request.
> > 
> > Signed-off-by: Corentin Labbe 
> 
> This is going the wrong way.  We do not want to expose any of the
> base types such as crypto_alg, crypto_async_request to end-users
> and that includes drivers.  Only core API code should touch these
> base types.
> 

Hello

It's you that was suggesting using crypto_async_request:
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1474434.html
"The only wart with this scheme is that the drivers end up seeing
struct crypto_async_request and will need to convert that to the
respective request types but I couldn't really find a better way."

So I wait for any suggestion.

Regards
Corentin Labbe
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-21 Thread Herbert Xu
On Wed, Nov 29, 2017 at 09:41:18AM +0100, Corentin Labbe wrote:
> The crypto engine could actually only enqueue hash and ablkcipher request.
> This patch permit it to enqueue any type of crypto_async_request.
> 
> Signed-off-by: Corentin Labbe 

This is going the wrong way.  We do not want to expose any of the
base types such as crypto_alg, crypto_async_request to end-users
and that includes drivers.  Only core API code should touch these
base types.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-13 Thread Fabien DESSENNE


On 29/11/17 09:41, Corentin Labbe wrote:
> The crypto engine could actually only enqueue hash and ablkcipher request.
> This patch permit it to enqueue any type of crypto_async_request.
>
> Signed-off-by: Corentin Labbe 
> ---
>   crypto/crypto_engine.c  | 188 
> +++-
>   include/crypto/engine.h |  46 +---
>   2 files changed, 60 insertions(+), 174 deletions(-)
>
> diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
> index 61e7c4e02fd2..f7c4c4c1f41b 100644
> --- a/crypto/crypto_engine.c
> +++ b/crypto/crypto_engine.c
> @@ -34,11 +34,10 @@ static void crypto_pump_requests(struct crypto_engine 
> *engine,
>bool in_kthread)
>   {
>   struct crypto_async_request *async_req, *backlog;
> - struct ahash_request *hreq;
> - struct ablkcipher_request *breq;
>   unsigned long flags;
>   bool was_busy = false;
> - int ret, rtype;
> + int ret;
> + struct crypto_engine_reqctx *enginectx;
>   
>   spin_lock_irqsave(&engine->queue_lock, flags);
>   
> @@ -94,7 +93,6 @@ static void crypto_pump_requests(struct crypto_engine 
> *engine,
>   
>   spin_unlock_irqrestore(&engine->queue_lock, flags);
>   
> - rtype = crypto_tfm_alg_type(engine->cur_req->tfm);
>   /* Until here we get the request need to be encrypted successfully */
>   if (!was_busy && engine->prepare_crypt_hardware) {
>   ret = engine->prepare_crypt_hardware(engine);
> @@ -104,57 +102,31 @@ static void crypto_pump_requests(struct crypto_engine 
> *engine,
>   }
>   }
>   
> - switch (rtype) {
> - case CRYPTO_ALG_TYPE_AHASH:
> - hreq = ahash_request_cast(engine->cur_req);
> - if (engine->prepare_hash_request) {
> - ret = engine->prepare_hash_request(engine, hreq);
> - if (ret) {
> - dev_err(engine->dev, "failed to prepare 
> request: %d\n",
> - ret);
> - goto req_err;
> - }
> - engine->cur_req_prepared = true;
> - }
> - ret = engine->hash_one_request(engine, hreq);
> - if (ret) {
> - dev_err(engine->dev, "failed to hash one request from 
> queue\n");
> - goto req_err;
> - }
> - return;
> - case CRYPTO_ALG_TYPE_ABLKCIPHER:
> - breq = ablkcipher_request_cast(engine->cur_req);
> - if (engine->prepare_cipher_request) {
> - ret = engine->prepare_cipher_request(engine, breq);
> - if (ret) {
> - dev_err(engine->dev, "failed to prepare 
> request: %d\n",
> - ret);
> - goto req_err;
> - }
> - engine->cur_req_prepared = true;
> - }
> - ret = engine->cipher_one_request(engine, breq);
> + enginectx = crypto_tfm_ctx(async_req->tfm);
> +
> + if (enginectx->op.prepare_request) {
> + ret = enginectx->op.prepare_request(engine, async_req);
>   if (ret) {
> - dev_err(engine->dev, "failed to cipher one request from 
> queue\n");
> + dev_err(engine->dev, "failed to prepare request: %d\n",
> + ret);
>   goto req_err;
>   }
> - return;
> - default:
> - dev_err(engine->dev, "failed to prepare request of unknown 
> type\n");
> - return;
> + engine->cur_req_prepared = true;
> + }
> + if (!enginectx->op.do_one_request) {
> + dev_err(engine->dev, "failed to do request\n");
> + ret = -EINVAL;
> + goto req_err;
> + }
> + ret = enginectx->op.do_one_request(engine, async_req);
> + if (ret) {
> + dev_err(engine->dev, "failed to hash one request from queue\n");
> + goto req_err;
>   }
> + return;
>   
>   req_err:
> - switch (rtype) {
> - case CRYPTO_ALG_TYPE_AHASH:
> - hreq = ahash_request_cast(engine->cur_req);
> - crypto_finalize_hash_request(engine, hreq, ret);
> - break;
> - case CRYPTO_ALG_TYPE_ABLKCIPHER:
> - breq = ablkcipher_request_cast(engine->cur_req);
> - crypto_finalize_cipher_request(engine, breq, ret);
> - break;
> - }
> + crypto_finalize_request(engine, async_req, ret);
>   return;
>   
>   out:
> @@ -170,59 +142,16 @@ static void crypto_pump_work(struct kthread_work *work)
>   }
>   
>   /**
> - * crypto_transfer_cipher_request - transfer the new request into the
> - * enginequeue
> + * crypto_transfer_request - transfer the new request into the engine queue
>* @engine: the hardware engine
>* @req: the request need to

Re: [PATCH RFC 1/4] crypto: engine - Permit to enqueue all async requests

2017-12-07 Thread Corentin Labbe
On Wed, Dec 06, 2017 at 11:02:23AM +, Fabien DESSENNE wrote:
> 
> 
> On 29/11/17 09:41, Corentin Labbe wrote:
> > The crypto engine could actually only enqueue hash and ablkcipher request.
> > This patch permit it to enqueue any type of crypto_async_request.
> >
> > Signed-off-by: Corentin Labbe 
> > ---
> >   crypto/crypto_engine.c  | 188 
> > +++-
> >   include/crypto/engine.h |  46 +---
> >   2 files changed, 60 insertions(+), 174 deletions(-)
> >
> > diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
> > index 61e7c4e02fd2..f7c4c4c1f41b 100644
> > --- a/crypto/crypto_engine.c
> > +++ b/crypto/crypto_engine.c
> > @@ -34,11 +34,10 @@ static void crypto_pump_requests(struct crypto_engine 
> > *engine,
> >  bool in_kthread)
> >   {
> > struct crypto_async_request *async_req, *backlog;
> > -   struct ahash_request *hreq;
> > -   struct ablkcipher_request *breq;
> > unsigned long flags;
> > bool was_busy = false;
> > -   int ret, rtype;
> > +   int ret;
> > +   struct crypto_engine_reqctx *enginectx;
> >   
> > spin_lock_irqsave(&engine->queue_lock, flags);
> >   
> > @@ -94,7 +93,6 @@ static void crypto_pump_requests(struct crypto_engine 
> > *engine,
> >   
> > spin_unlock_irqrestore(&engine->queue_lock, flags);
> >   
> > -   rtype = crypto_tfm_alg_type(engine->cur_req->tfm);
> > /* Until here we get the request need to be encrypted successfully */
> > if (!was_busy && engine->prepare_crypt_hardware) {
> > ret = engine->prepare_crypt_hardware(engine);
> > @@ -104,57 +102,31 @@ static void crypto_pump_requests(struct crypto_engine 
> > *engine,
> > }
> > }
> >   
> > -   switch (rtype) {
> > -   case CRYPTO_ALG_TYPE_AHASH:
> > -   hreq = ahash_request_cast(engine->cur_req);
> > -   if (engine->prepare_hash_request) {
> > -   ret = engine->prepare_hash_request(engine, hreq);
> > -   if (ret) {
> > -   dev_err(engine->dev, "failed to prepare 
> > request: %d\n",
> > -   ret);
> > -   goto req_err;
> > -   }
> > -   engine->cur_req_prepared = true;
> > -   }
> > -   ret = engine->hash_one_request(engine, hreq);
> > -   if (ret) {
> > -   dev_err(engine->dev, "failed to hash one request from 
> > queue\n");
> > -   goto req_err;
> > -   }
> > -   return;
> > -   case CRYPTO_ALG_TYPE_ABLKCIPHER:
> > -   breq = ablkcipher_request_cast(engine->cur_req);
> > -   if (engine->prepare_cipher_request) {
> > -   ret = engine->prepare_cipher_request(engine, breq);
> > -   if (ret) {
> > -   dev_err(engine->dev, "failed to prepare 
> > request: %d\n",
> > -   ret);
> > -   goto req_err;
> > -   }
> > -   engine->cur_req_prepared = true;
> > -   }
> > -   ret = engine->cipher_one_request(engine, breq);
> > +   enginectx = crypto_tfm_ctx(async_req->tfm);
> > +
> > +   if (enginectx->op.prepare_request) {
> > +   ret = enginectx->op.prepare_request(engine, async_req);
> > if (ret) {
> > -   dev_err(engine->dev, "failed to cipher one request from 
> > queue\n");
> > +   dev_err(engine->dev, "failed to prepare request: %d\n",
> > +   ret);
> > goto req_err;
> > }
> > -   return;
> > -   default:
> > -   dev_err(engine->dev, "failed to prepare request of unknown 
> > type\n");
> > -   return;
> > +   engine->cur_req_prepared = true;
> > +   }
> > +   if (!enginectx->op.do_one_request) {
> > +   dev_err(engine->dev, "failed to do request\n");
> > +   ret = -EINVAL;
> > +   goto req_err;
> > +   }
> > +   ret = enginectx->op.do_one_request(engine, async_req);
> > +   if (ret) {
> > +   dev_err(engine->dev, "failed to hash one request from queue\n");
> > +   goto req_err;
> > }
> > +   return;
> >   
> >   req_err:
> > -   switch (rtype) {
> > -   case CRYPTO_ALG_TYPE_AHASH:
> > -   hreq = ahash_request_cast(engine->cur_req);
> > -   crypto_finalize_hash_request(engine, hreq, ret);
> > -   break;
> > -   case CRYPTO_ALG_TYPE_ABLKCIPHER:
> > -   breq = ablkcipher_request_cast(engine->cur_req);
> > -   crypto_finalize_cipher_request(engine, breq, ret);
> > -   break;
> > -   }
> > +   crypto_finalize_request(engine, async_req, ret);
> > return;
> >   
> >   out:
> > @@ -170,59 +142,16 @@ static void crypto_pump_work(struct kthread_work 
> > *work)
> >   }
> >   
> >   /**
> > - * crypto_transfer_cipher_request - transfer the new request into the
> > - *